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

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\Method\AbstractPaymentMethodHandler;
  12. use Swag\PayPal\Checkout\Payment\Method\PUIHandler;
  13. use Swag\PayPal\Checkout\PUI\Service\PUICustomerDataService;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class RequestSubscriber implements EventSubscriberInterface
  16. {
  17.     public const PAYMENT_PARAMETERS = [
  18.         AbstractPaymentMethodHandler::PAYPAL_PAYMENT_ORDER_ID_INPUT_NAME,
  19.         PUIHandler::PUI_FRAUD_NET_SESSION_ID,
  20.         PUICustomerDataService::PUI_CUSTOMER_DATA_BIRTHDAY,
  21.         PUICustomerDataService::PUI_CUSTOMER_DATA_PHONE_NUMBER,
  22.     ];
  23.     private LoggerInterface $logger;
  24.     public function __construct(LoggerInterface $logger)
  25.     {
  26.         $this->logger $logger;
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             HandlePaymentMethodRouteRequestEvent::class => 'addHandlePaymentParameters',
  32.             PaymentMethodRouteRequestEvent::class => 'addAfterOrderId',
  33.         ];
  34.     }
  35.     public function addHandlePaymentParameters(HandlePaymentMethodRouteRequestEvent $event): void
  36.     {
  37.         $this->logger->debug('Adding request parameter');
  38.         $storefrontRequest $event->getStorefrontRequest();
  39.         $storeApiRequest $event->getStoreApiRequest();
  40.         $originalRoute $storefrontRequest->attributes->get('_route');
  41.         if ($originalRoute !== 'frontend.account.edit-order.update-order') {
  42.             return;
  43.         }
  44.         foreach (self::PAYMENT_PARAMETERS as $paymentParameter) {
  45.             $storeApiRequest->request->set($paymentParameter$storefrontRequest->request->get($paymentParameter));
  46.         }
  47.         $this->logger->debug('Added request parameter');
  48.     }
  49.     public function addAfterOrderId(PaymentMethodRouteRequestEvent $event): void
  50.     {
  51.         $storefrontRequest $event->getStorefrontRequest();
  52.         $storeApiRequest $event->getStoreApiRequest();
  53.         $originalRoute $storefrontRequest->attributes->get('_route');
  54.         if ($originalRoute !== 'frontend.account.edit-order.page') {
  55.             return;
  56.         }
  57.         if (!$storefrontRequest->attributes->has('orderId')) {
  58.             return;
  59.         }
  60.         $storeApiRequest->attributes->set('orderId'$storefrontRequest->attributes->getAlnum('orderId'));
  61.     }
  62. }