diff --git a/src/EventListener/CheckoutConfirmPayolutionEventListener.php b/src/EventListener/CheckoutConfirmPayolutionEventListener.php index 8c2f0ce9b..567059393 100644 --- a/src/EventListener/CheckoutConfirmPayolutionEventListener.php +++ b/src/EventListener/CheckoutConfirmPayolutionEventListener.php @@ -5,6 +5,11 @@ namespace PayonePayment\EventListener; use PayonePayment\Components\ConfigReader\ConfigReaderInterface; +use PayonePayment\Configuration\ConfigurationPrefixes; +use PayonePayment\PaymentHandler\PayonePayolutionDebitPaymentHandler; +use PayonePayment\PaymentHandler\PayonePayolutionInstallmentPaymentHandler; +use PayonePayment\PaymentHandler\PayonePayolutionInvoicingPaymentHandler; +use PayonePayment\PaymentMethod\PayonePayolutionDebit; use PayonePayment\PaymentMethod\PayonePayolutionInstallment; use PayonePayment\PaymentMethod\PayonePayolutionInvoicing; use Shopware\Core\Checkout\Payment\PaymentMethodCollection; @@ -24,24 +29,31 @@ public function __construct(private readonly ConfigReaderInterface $configReader public static function getSubscribedEvents(): array { return [ - CheckoutConfirmPageLoadedEvent::class => 'hidePaymentMethodsForCompanies', - AccountPaymentMethodPageLoadedEvent::class => 'hidePaymentMethodsForCompanies', - AccountEditOrderPageLoadedEvent::class => 'hidePaymentMethodsForCompanies', + CheckoutConfirmPageLoadedEvent::class => 'hidePaymentMethods', + AccountPaymentMethodPageLoadedEvent::class => 'hidePaymentMethods', + AccountEditOrderPageLoadedEvent::class => 'hidePaymentMethods', ]; } - public function hidePaymentMethodsForCompanies( + public function hidePaymentMethods( CheckoutConfirmPageLoadedEvent|AccountPaymentMethodPageLoadedEvent|AccountEditOrderPageLoadedEvent $event ): void { $page = $event->getPage(); - if (!$this->customerHasCompanyAddress($event->getSalesChannelContext())) { - return; + $paymentMethods = $page->getPaymentMethods(); + $paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionInstallment::UUID); + + if ($this->companyNameMissing($event->getSalesChannelContext(), PayonePayolutionInvoicingPaymentHandler::class)) { + $paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionInvoicing::UUID); } - $paymentMethods = $page->getPaymentMethods(); + if ($this->companyNameMissing($event->getSalesChannelContext(), PayonePayolutionDebitPaymentHandler::class)) { + $paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionDebit::UUID); + } - $paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionInstallment::UUID); + if ($this->companyNameMissing($event->getSalesChannelContext(), PayonePayolutionInstallmentPaymentHandler::class)) { + $paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionInstallment::UUID); + } if ($this->companyDataHandlingIsDisabled($event->getSalesChannelContext())) { $paymentMethods = $this->removePaymentMethod($paymentMethods, PayonePayolutionInvoicing::UUID); @@ -57,27 +69,18 @@ private function removePaymentMethod(PaymentMethodCollection $paymentMethods, st ); } - private function customerHasCompanyAddress(SalesChannelContext $context): bool + private function companyDataHandlingIsDisabled(SalesChannelContext $context): bool { - $customer = $context->getCustomer(); - - if ($customer === null) { - return false; - } - - $billingAddress = $customer->getActiveBillingAddress(); - - if ($billingAddress === null) { - return false; - } - - return !empty($billingAddress->getCompany()); + return !($this->getConfiguration($context, 'payolutionInvoicingTransferCompanyData')); } - private function companyDataHandlingIsDisabled(SalesChannelContext $context): bool + private function companyNameMissing(SalesChannelContext $context, string $paymentHandler): bool { - $configuration = $this->configReader->read($context->getSalesChannel()->getId()); + return empty($this->getConfiguration($context, ConfigurationPrefixes::CONFIGURATION_PREFIXES[$paymentHandler] . 'CompanyName')); + } - return !($configuration->get('payolutionInvoicingTransferCompanyData')); + private function getConfiguration(SalesChannelContext $context, string $configName): array|bool|int|string|null + { + return $this->configReader->read($context->getSalesChannel()->getId())->get($configName); } } diff --git a/src/Resources/snippet/en_GB/messages.en-GB.json b/src/Resources/snippet/en_GB/messages.en-GB.json index 83289573f..5436f187c 100644 --- a/src/Resources/snippet/en_GB/messages.en-GB.json +++ b/src/Resources/snippet/en_GB/messages.en-GB.json @@ -101,7 +101,7 @@ }, "consentCheckbox": { "introduction": "With the transmission of the data necessary for the completion of the invoice purchase, an identity check and credit check to payolution GmbH, Am Euro Platz 2, 1120 Wien I agree.", - "textWithLink": "I can revoke my consent at any time with effect for the future." + "textWithLink": "I can revoke my consent at any time with effect for the future." }, "mandateCheckbox": { "textWithLink": "I hereby issue the SEPA direct debit mandate."