-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAYOSWXP-47: payolution: migrate payment-filter
… from event-listener to standardized payment-filter functionality
- Loading branch information
1 parent
a5cd02e
commit 1b20ec3
Showing
7 changed files
with
149 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/Components/PaymentFilter/PayolutionPaymentMethodFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\Components\PaymentFilter; | ||
|
||
use PayonePayment\Components\ConfigReader\ConfigReader; | ||
use PayonePayment\Components\PaymentFilter\Exception\PaymentMethodNotAllowedException; | ||
use PayonePayment\PaymentHandler\PayonePayolutionInvoicingPaymentHandler; | ||
use Shopware\Core\Checkout\Payment\PaymentMethodCollection; | ||
use Shopware\Core\System\SalesChannel\SalesChannelContext; | ||
|
||
class PayolutionPaymentMethodFilter extends DefaultPaymentFilterService | ||
{ | ||
protected function additionalChecks(PaymentMethodCollection $methodCollection, PaymentFilterContext $filterContext): void | ||
{ | ||
if (empty($this->getPaymentHandlerConfiguration($filterContext->getSalesChannelContext(), 'CompanyName'))) { | ||
throw new PaymentMethodNotAllowedException('Payolution: missing merchant-company name.'); | ||
} | ||
|
||
if ($this->paymentHandlerClass === PayonePayolutionInvoicingPaymentHandler::class | ||
&& !($this->getPaymentHandlerConfiguration($filterContext->getSalesChannelContext(), 'TransferCompanyData')) | ||
) { | ||
throw new PaymentMethodNotAllowedException('Payolution Invoicing: Missing configuration.'); | ||
} | ||
} | ||
|
||
private function getPaymentHandlerConfiguration(SalesChannelContext $context, string $configKey): mixed | ||
{ | ||
return $this->getConfiguration($context, ConfigReader::getConfigKeyByPaymentHandler($this->paymentHandlerClass, $configKey)); | ||
} | ||
|
||
private function getConfiguration(SalesChannelContext $context, string $configName): mixed | ||
{ | ||
return $this->systemConfigService->get($configName, $context->getSalesChannel()->getId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 0 additions & 85 deletions
85
src/EventListener/CheckoutConfirmPayolutionEventListener.php
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
tests/Components/PaymentFilter/PayolutionPaymentFilterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\Components\PaymentFilter; | ||
|
||
use PayonePayment\Configuration\ConfigurationPrefixes; | ||
use PayonePayment\PaymentHandler\PayonePayolutionDebitPaymentHandler; | ||
use PayonePayment\PaymentHandler\PayonePayolutionInstallmentPaymentHandler; | ||
use PayonePayment\PaymentHandler\PayonePayolutionInvoicingPaymentHandler; | ||
use PayonePayment\TestCaseBase\ConfigurationHelper; | ||
use Shopware\Core\System\Currency\CurrencyEntity; | ||
|
||
/** | ||
* @covers \PayonePayment\Components\PaymentFilter\PayolutionPaymentMethodFilter | ||
*/ | ||
class PayolutionPaymentFilterTest extends AbstractPaymentFilterTest | ||
{ | ||
use ConfigurationHelper; | ||
|
||
protected function setUp(): void | ||
{ | ||
foreach ($this->getPaymentHandlerClasses() as $handlerClass) { | ||
$this->setPayoneConfig($this->getContainer(), ConfigurationPrefixes::CONFIGURATION_PREFIXES[$handlerClass] . 'CompanyName', 'the-company'); | ||
} | ||
$this->setPayoneConfig($this->getContainer(), 'payolutionInvoicingTransferCompanyData', true); | ||
} | ||
|
||
protected function getFilterService(?string $paymentHandlerClass = null): PaymentFilterServiceInterface | ||
{ | ||
$serviceId = match ($paymentHandlerClass) { | ||
PayonePayolutionInvoicingPaymentHandler::class => 'payone.payment_filter_method.payolution.invoice', | ||
PayonePayolutionDebitPaymentHandler::class => 'payone.payment_filter_method.payolution.debit', | ||
PayonePayolutionInstallmentPaymentHandler::class => 'payone.payment_filter_method.payolution.installment', | ||
}; | ||
|
||
if (!$serviceId) { | ||
throw new \RuntimeException('unknown payment-handler: ' . $paymentHandlerClass); | ||
} | ||
|
||
return $this->getContainer()->get($serviceId); | ||
} | ||
|
||
protected function getDisallowedBillingCountry(): ?string | ||
{ | ||
return null; | ||
} | ||
|
||
protected function getAllowedBillingCountry(): string | ||
{ | ||
return 'DE'; | ||
} | ||
|
||
protected function getDisallowedCurrency(): ?CurrencyEntity | ||
{ | ||
return null; | ||
} | ||
|
||
protected function getAllowedCurrency(): CurrencyEntity | ||
{ | ||
$currency = $this->createMock(CurrencyEntity::class); | ||
$currency->method('getIsoCode')->willReturn('EUR'); | ||
|
||
return $currency; | ||
} | ||
|
||
protected function getTooLowValue(): ?float | ||
{ | ||
return null; | ||
} | ||
|
||
protected function getTooHighValue(): ?float | ||
{ | ||
return null; | ||
} | ||
|
||
protected function getAllowedValue(): float | ||
{ | ||
return 100.0; | ||
} | ||
|
||
protected function getPaymentHandlerClasses(): array | ||
{ | ||
return [ | ||
PayonePayolutionInvoicingPaymentHandler::class, | ||
PayonePayolutionDebitPaymentHandler::class, | ||
PayonePayolutionInstallmentPaymentHandler::class, | ||
]; | ||
} | ||
} |
Oops, something went wrong.