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

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