src/Payum/PayumHipay/Event/HipayStoreTokenPaymentEventSubscriber.php line 47

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the HipaySyliusPlugin
  4.  *
  5.  * (c) Smile <dirtech@smile.fr>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace App\Payum\PayumHipay\Event;
  12. use App\Payum\PayumHipay\Context\PaymentContext;
  13. use App\Payum\PayumHipay\Factory\HipayCardGatewayFactory;
  14. use App\Payum\PayumHipay\Factory\HipayAlmaGatewayFactory;
  15. use App\Payum\PayumHipay\Factory\HipayPaypalGatewayFactory;
  16. use App\Payum\PayumHipay\Factory\HipayAppleGatewayFactory;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. use Symfony\Component\HttpKernel\Event\KernelEvent;
  19. class HipayStoreTokenPaymentEventSubscriber implements EventSubscriberInterface
  20. {
  21.     private const AUTHORIZED_ROUTE = [
  22.         'sylius_shop_checkout_select_payment',
  23.         'bitbag_sylius_one_page_checkout_shop_checkout_complete',
  24.         'sylius_shop_order_pay',
  25.         'sylius_shop_order_show',
  26.         'app_order_payment_link_complete'
  27.     ];
  28.     private PaymentContext $paymentContext;
  29.     public function __construct(PaymentContext $paymentContext)
  30.     {
  31.         $this->paymentContext $paymentContext;
  32.     }
  33.     public static function getSubscribedEvents()
  34.     {
  35.         return [
  36.             'kernel.controller' => 'handle',
  37.         ];
  38.     }
  39.     public function handle(KernelEvent $event): void
  40.     {
  41.         $request $event->getRequest();
  42.         $route $request->attributes->get('_route');
  43.         if (!in_array($routeself::AUTHORIZED_ROUTE)) {
  44.             return;
  45.         }
  46.         // dump( $route);
  47.         $hipayTokenCard $request->request->get(
  48.             sprintf('%s_%s'PaymentContext::HIPAY_TOKENHipayCardGatewayFactory::FACTORY_NAME)
  49.         );
  50.         $hipayPaymentProductCard $request->request->get(
  51.             sprintf('%s_%s'PaymentContext::HIPAY_PAYMENT_PRODUCTHipayCardGatewayFactory::FACTORY_NAME)
  52.         );
  53.         if ($hipayTokenCard !== '') {
  54.             $token $hipayTokenCard;
  55.         }
  56.         // dump($route);    
  57.         // dump($request->request);    
  58.         // dump($hipayPaymentProductCard);    
  59.         if ($hipayPaymentProductCard !== '' && $hipayPaymentProductCard !== null) {
  60.             $paymentProduct $hipayPaymentProductCard;
  61.         } else {
  62.             
  63.             // exit();
  64.             $paymentProduct $request->request->get(
  65.                 sprintf('%s_%s'PaymentContext::HIPAY_PAYMENT_PRODUCTHipayAlmaGatewayFactory::FACTORY_NAME)
  66.             ) ?? null;
  67.             if ($paymentProduct === null) {
  68.                 $paymentProduct $request->request->get(
  69.                     sprintf('%s_%s'PaymentContext::HIPAY_PAYMENT_PRODUCTHipayPaypalGatewayFactory::FACTORY_NAME)
  70.                 ) ?? null;
  71.             }
  72.             if ($paymentProduct === null) {
  73.                 $paymentProduct $request->request->get(
  74.                     sprintf('%s_%s'PaymentContext::HIPAY_PAYMENT_PRODUCTHipayAppleGatewayFactory::FACTORY_NAME)
  75.                 ) ?? null;
  76.             }
  77.         }
  78.         if ($token !== null) {
  79.             $this->paymentContext->set(PaymentContext::HIPAY_TOKEN$token);
  80.         }
  81.         if ($paymentProduct !== null) {
  82.             $this->paymentContext->set(PaymentContext::HIPAY_PAYMENT_PRODUCT$paymentProduct);
  83.         }
  84.     }
  85. }