custom/plugins/SwagPayPal/src/Storefront/RequestSubscriber.php line 50

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /*
  3.  * (c) shopware AG <info@shopware.com>
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Swag\PayPal\Storefront;
  8. use Psr\Log\LoggerInterface;
  9. use Shopware\Storefront\Event\RouteRequest\HandlePaymentMethodRouteRequestEvent;
  10. use Shopware\Storefront\Event\RouteRequest\PaymentMethodRouteRequestEvent;
  11. use Swag\PayPal\Checkout\Payment\Handler\PlusPuiHandler;
  12. use Swag\PayPal\Checkout\Payment\Method\AbstractPaymentMethodHandler;
  13. use Swag\PayPal\Checkout\Payment\Method\PUIHandler;
  14. use Swag\PayPal\Checkout\Payment\PayPalPaymentHandler;
  15. use Swag\PayPal\Checkout\PUI\Service\PUICustomerDataService;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. /**
  18.  * @internal
  19.  */
  20. class RequestSubscriber implements EventSubscriberInterface
  21. {
  22.     public const PAYMENT_PARAMETERS = [
  23.         AbstractPaymentMethodHandler::PAYPAL_PAYMENT_ORDER_ID_INPUT_NAME,
  24.         PUIHandler::PUI_FRAUD_NET_SESSION_ID,
  25.         PUICustomerDataService::PUI_CUSTOMER_DATA_BIRTHDAY,
  26.         PUICustomerDataService::PUI_CUSTOMER_DATA_PHONE_NUMBER,
  27.         PlusPuiHandler::PAYPAL_PAYMENT_ID_INPUT_NAME,
  28.         PlusPuiHandler::PAYPAL_PAYMENT_TOKEN_INPUT_NAME,
  29.         PayPalPaymentHandler::PAYPAL_PLUS_CHECKOUT_ID,
  30.     ];
  31.     private LoggerInterface $logger;
  32.     public function __construct(LoggerInterface $logger)
  33.     {
  34.         $this->logger $logger;
  35.     }
  36.     public static function getSubscribedEvents(): array
  37.     {
  38.         return [
  39.             HandlePaymentMethodRouteRequestEvent::class => 'addHandlePaymentParameters',
  40.             PaymentMethodRouteRequestEvent::class => 'addAfterOrderId',
  41.         ];
  42.     }
  43.     public function addHandlePaymentParameters(HandlePaymentMethodRouteRequestEvent $event): void
  44.     {
  45.         $this->logger->debug('Adding request parameter');
  46.         $storefrontRequest $event->getStorefrontRequest();
  47.         $storeApiRequest $event->getStoreApiRequest();
  48.         $originalRoute $storefrontRequest->attributes->get('_route');
  49.         if ($originalRoute !== 'frontend.account.edit-order.update-order') {
  50.             return;
  51.         }
  52.         foreach (self::PAYMENT_PARAMETERS as $paymentParameter) {
  53.             $storeApiRequest->request->set($paymentParameter$storefrontRequest->request->get($paymentParameter));
  54.         }
  55.         $this->logger->debug('Added request parameter');
  56.     }
  57.     public function addAfterOrderId(PaymentMethodRouteRequestEvent $event): void
  58.     {
  59.         $storefrontRequest $event->getStorefrontRequest();
  60.         $storeApiRequest $event->getStoreApiRequest();
  61.         $originalRoute $storefrontRequest->attributes->get('_route');
  62.         if ($originalRoute !== 'frontend.account.edit-order.page') {
  63.             return;
  64.         }
  65.         if (!$storefrontRequest->attributes->has('orderId')) {
  66.             return;
  67.         }
  68.         $storeApiRequest->attributes->set('orderId'$storefrontRequest->attributes->getAlnum('orderId'));
  69.     }
  70. }