diff --git a/src/DependencyInjection/requestParameter/builder.xml b/src/DependencyInjection/requestParameter/builder.xml index f9f1e05f..0eb6db73 100644 --- a/src/DependencyInjection/requestParameter/builder.xml +++ b/src/DependencyInjection/requestParameter/builder.xml @@ -15,13 +15,11 @@ - + - - getPaymentMethod(); + if ($arguments instanceof PaymentTransactionStruct) { + $config = $this->serviceAccessor->configReader->read($arguments->getPaymentTransaction()->getOrder()->getSalesChannelId()); - switch ($paymentMethod) { - case PayonePayolutionDebitPaymentHandler::class: - case PayonePayolutionInstallmentPaymentHandler::class: - case PayonePayolutionInvoicingPaymentHandler::class: - case PayoneSecureInvoicePaymentHandler::class: - case PayoneOpenInvoicePaymentHandler::class: - case PayoneBancontactPaymentHandler::class: - case PayoneRatepayDebitPaymentHandler::class: - case PayoneRatepayInstallmentPaymentHandler::class: - case PayoneRatepayInvoicingPaymentHandler::class: - case PayonePrzelewy24PaymentHandler::class: - case PayoneWeChatPayPaymentHandler::class: - case PayoneAlipayPaymentHandler::class: - case PayoneSecuredInvoicePaymentHandler::class: - case PayoneSecuredInstallmentPaymentHandler::class: - case PayoneSecuredDirectDebitPaymentHandler::class: + if (\in_array($arguments->getAction(), [self::REQUEST_ACTION_AUTHORIZE, self::REQUEST_ACTION_PREAUTHORIZE], true) + && $config->get('submitOrderLineItems', false) + ) { return true; + } } - if (is_subclass_of($arguments->getPaymentMethod(), AbstractPostfinancePaymentHandler::class)) { - return true; + if ($arguments instanceof FinancialTransactionStruct) { + switch ($arguments->getPaymentMethod()) { + case PayonePayolutionDebitPaymentHandler::class: + case PayonePayolutionInstallmentPaymentHandler::class: + case PayonePayolutionInvoicingPaymentHandler::class: + case PayoneSecureInvoicePaymentHandler::class: + case PayoneOpenInvoicePaymentHandler::class: + case PayoneBancontactPaymentHandler::class: + case PayoneRatepayDebitPaymentHandler::class: + case PayoneRatepayInstallmentPaymentHandler::class: + case PayoneRatepayInvoicingPaymentHandler::class: + case PayonePrzelewy24PaymentHandler::class: + case PayoneWeChatPayPaymentHandler::class: + case PayoneAlipayPaymentHandler::class: + case PayoneSecuredInvoicePaymentHandler::class: + case PayoneSecuredInstallmentPaymentHandler::class: + case PayoneSecuredDirectDebitPaymentHandler::class: + return true; + } + + if (is_subclass_of($arguments->getPaymentMethod(), AbstractPostfinancePaymentHandler::class)) { + return true; + } } return false; diff --git a/src/Payone/RequestParameter/Builder/RequestBuilderServiceAccessor.php b/src/Payone/RequestParameter/Builder/RequestBuilderServiceAccessor.php index b1579486..3bed1ada 100644 --- a/src/Payone/RequestParameter/Builder/RequestBuilderServiceAccessor.php +++ b/src/Payone/RequestParameter/Builder/RequestBuilderServiceAccessor.php @@ -4,6 +4,7 @@ namespace PayonePayment\Payone\RequestParameter\Builder; +use PayonePayment\Components\ConfigReader\ConfigReader; use PayonePayment\Components\Currency\CurrencyPrecisionInterface; use PayonePayment\Components\Hydrator\LineItemHydrator\LineItemHydratorInterface; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; @@ -16,7 +17,8 @@ public function __construct( public readonly EntityRepository $customerAddressRepository, public readonly EntityRepository $currencyRepository, public readonly CurrencyPrecisionInterface $currencyPrecision, - public readonly LineItemHydratorInterface $lineItemHydrator + public readonly LineItemHydratorInterface $lineItemHydrator, + public readonly ConfigReader $configReader ) { } } diff --git a/src/Resources/config/settings.xml b/src/Resources/config/settings.xml index bcc345fa..25d8a0af 100644 --- a/src/Resources/config/settings.xml +++ b/src/Resources/config/settings.xml @@ -58,6 +58,14 @@ When activated, the data entered by the customer into the fields provided by PAYONE will be saved in the customer account, allowing them to be directly reused for future orders. Wenn aktiviert, werden die Daten, welche der Kunde in die von PAYONE bereitgestellten Felder, eingibt, in den Kundenaccount gespeichert, sodass diese bei weiteren Bestellungen direkt wiederverwendet werden können. + + + submitOrderLineItems + + + If activated, all order line-items are submitted to the PAYONE gateway. This enables the generation of invoices through PAYONE. + Wenn aktiviert, werden alle Bestellpositionen an das PAYONE-Gateway übermittelt. Dadurch ist es möglich, Rechnungen direkt über PAYONE zu erstellen. + diff --git a/tests/Payone/RequestParameter/Builder/OrderLinesRequestParameterBuilderTest.php b/tests/Payone/RequestParameter/Builder/OrderLinesRequestParameterBuilderTest.php index 59e3456a..cf20cae7 100644 --- a/tests/Payone/RequestParameter/Builder/OrderLinesRequestParameterBuilderTest.php +++ b/tests/Payone/RequestParameter/Builder/OrderLinesRequestParameterBuilderTest.php @@ -5,6 +5,7 @@ namespace PayonePayment\Payone\RequestParameter\Builder; use DMS\PHPUnitExtensions\ArraySubset\Assert; +use PayonePayment\Components\ConfigReader\ConfigReader; use PayonePayment\Components\Hydrator\LineItemHydrator\LineItemHydrator; use PayonePayment\Constants; use PayonePayment\PaymentHandler\PayoneBancontactPaymentHandler; @@ -22,6 +23,8 @@ use PayonePayment\TestCaseBase\PayoneTestBehavior; use PHPUnit\Framework\TestCase; use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; +use Shopware\Core\System\SystemConfig\SystemConfigService; +use stdClass; use Symfony\Component\HttpFoundation\ParameterBag; /** @@ -65,19 +68,6 @@ public function testItNotSupportsInvalidPaymentMethods($paymentHandler): void static::assertFalse($builder->supports($struct)); } - public function testItNotSupportsPaymentRequests(): void - { - $struct = $this->getPaymentTransactionStruct( - new RequestDataBag([]), - PayonePayolutionDebitPaymentHandler::class, - AbstractRequestParameterBuilder::REQUEST_ACTION_AUTHORIZE - ); - - $builder = $this->getContainer()->get(OrderLinesRequestParameterBuilder::class); - - static::assertFalse($builder->supports($struct)); - } - public function testItAddsCorrectOrderLineParametersForFullCapture(): void { $dataBag = new ParameterBag(); @@ -254,6 +244,60 @@ public function testItAddsCorrectOrderLineParametersForPartialRefund(): void static::assertArrayNotHasKey('it[2]', $parameters); } + public function testItNotSendItemsIfDisabledForOptionalMethods(): void + { + $configService = $this->getContainer()->get(SystemConfigService::class); + $builder = $this->getContainer()->get(OrderLinesRequestParameterBuilder::class); + + $struct = $this->getPaymentTransactionStruct( + new RequestDataBag(), + stdClass::class, + AbstractRequestParameterBuilder::REQUEST_ACTION_PREAUTHORIZE + ); + + $configService->set(ConfigReader::SYSTEM_CONFIG_DOMAIN . 'submitOrderLineItems', false, $struct->getPaymentTransaction()->getOrder()->getSalesChannelId()); + static::assertFalse($builder->supports($struct), 'builder should not supports stdclass if configuration (send order items) is disabled.'); + } + + public function testItSendItemsIfEnabledForOptionalMethods(): void + { + $configService = $this->getContainer()->get(SystemConfigService::class); + $builder = $this->getContainer()->get(OrderLinesRequestParameterBuilder::class); + + $allowedActions = [ + AbstractRequestParameterBuilder::REQUEST_ACTION_PREAUTHORIZE, + AbstractRequestParameterBuilder::REQUEST_ACTION_AUTHORIZE, + ]; + + foreach ($allowedActions as $allowedAction) { + $struct = $this->getPaymentTransactionStruct(new RequestDataBag(), stdClass::class, $allowedAction); + $configService->set(ConfigReader::SYSTEM_CONFIG_DOMAIN . 'submitOrderLineItems', true, $struct->getPaymentTransaction()->getOrder()->getSalesChannelId()); + static::assertTrue($builder->supports($struct), sprintf('builder should supports stdclass if configuration (send order items) is enabled and action %s is given.', $allowedAction)); + } + } + + public function testItNotSendItemsIfEnabledWithDisallowedActionForOptionalMethods(): void + { + $configService = $this->getContainer()->get(SystemConfigService::class); + $builder = $this->getContainer()->get(OrderLinesRequestParameterBuilder::class); + + $disallowedActions = [ + AbstractRequestParameterBuilder::REQUEST_ACTION_CAPTURE, + AbstractRequestParameterBuilder::REQUEST_ACTION_REFUND, + AbstractRequestParameterBuilder::REQUEST_ACTION_GENERIC_PAYMENT, + 'something-else', + ]; + + $salesChannelContext = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation(); + $order = $this->getRandomOrder($salesChannelContext); + + foreach ($disallowedActions as $disallowedAction) { + $struct = $this->getPaymentTransactionStruct(new RequestDataBag(), stdClass::class, $disallowedAction); + $configService->set(ConfigReader::SYSTEM_CONFIG_DOMAIN . 'submitOrderLineItems', true, $struct->getPaymentTransaction()->getOrder()->getSalesChannelId()); + static::assertFalse($builder->supports($struct), sprintf('builder should not supports stdclass if configuration (send order items) is enabled and not allowed action %s is given.', $disallowedAction)); + } + } + public function getValidPaymentHandler(): array { return [