custom/plugins/RpayPayments/src/Components/PaymentLock/Subscriber/PaymentFilterSubscriber.php line 34

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * Copyright (c) Ratepay GmbH
  5.  *
  6.  * For the full copyright and license information, please view the LICENSE
  7.  * file that was distributed with this source code.
  8.  */
  9. namespace Ratepay\RpayPayments\Components\PaymentLock\Subscriber;
  10. use Ratepay\RpayPayments\Components\Checkout\Event\RatepayPaymentFilterEvent;
  11. use Ratepay\RpayPayments\Components\PaymentLock\Service\LockService;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class PaymentFilterSubscriber implements EventSubscriberInterface
  14. {
  15.     private LockService $lockService;
  16.     public function __construct(LockService $lockService)
  17.     {
  18.         $this->lockService $lockService;
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             RatepayPaymentFilterEvent::class => 'filterPayments',
  24.         ];
  25.     }
  26.     public function filterPayments(RatepayPaymentFilterEvent $event): void
  27.     {
  28.         if ($event->getOrderEntity()) {
  29.             $customerId $event->getOrderEntity()->getOrderCustomer()->getCustomerId();
  30.         } else {
  31.             $customer $event->getSalesChannelContext()->getCustomer();
  32.             if (!$customer) {
  33.                 // customer is not logged in, or customer session has not been started yet.
  34.                 return;
  35.             }
  36.             $customerId $customer->getId();
  37.         }
  38.         $isLocked $this->lockService->isPaymentLocked(
  39.             $event->getPaymentMethod()->getId(),
  40.             $customerId,
  41.             $event->getSalesChannelContext()->getContext()
  42.         );
  43.         $event->setIsAvailable($isLocked !== true);
  44.     }
  45. }