custom/plugins/PayonePayment/src/EventListener/CheckoutConfirmPaydirektEventListener.php line 33

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace PayonePayment\EventListener;
  4. use PayonePayment\PaymentMethod\PayonePaydirekt;
  5. use Shopware\Storefront\Page\Account\PaymentMethod\AccountPaymentMethodPageLoadedEvent;
  6. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. /**
  9.  * This event listener removes the Paydirekt payment method for customers
  10.  * which have a billing address that is outside from DE.
  11.  */
  12. class CheckoutConfirmPaydirektEventListener implements EventSubscriberInterface
  13. {
  14.     use ChecksCurrency;
  15.     use ChecksBillingAddressCountry;
  16.     use RemovesPaymentMethod;
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             CheckoutConfirmPageLoadedEvent::class => 'hidePaydirektForNonDeCustomers',
  21.             AccountPaymentMethodPageLoadedEvent::class => 'hidePaydirektForNonDeCustomers',
  22.         ];
  23.     }
  24.     /**
  25.      * @param AccountPaymentMethodPageLoadedEvent|CheckoutConfirmPageLoadedEvent $event
  26.      */
  27.     public function hidePaydirektForNonDeCustomers($event): void
  28.     {
  29.         $paymentMethods $event->getPage()->getPaymentMethods();
  30.         if (
  31.             $this->isCurrency($event->getSalesChannelContext(), 'EUR')
  32.             && $this->isBillingAddressFromCountry($event->getSalesChannelContext(), 'DE')
  33.         ) {
  34.             return;
  35.         }
  36.         $paymentMethods $this->removePaymentMethod($paymentMethodsPayonePaydirekt::UUID);
  37.         $event->getPage()->setPaymentMethods($paymentMethods);
  38.     }
  39. }