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 Swag\PayPal\Checkout\Payment\Method\AbstractPaymentMethodHandler;
  11. use Swag\PayPal\Checkout\Payment\Method\PUIHandler;
  12. use Swag\PayPal\Checkout\Payment\PayPalPaymentHandler;
  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.         PayPalPaymentHandler::PAYPAL_SMART_PAYMENT_BUTTONS_ID,
  19.         AbstractPaymentMethodHandler::PAYPAL_PAYMENT_ORDER_ID_INPUT_NAME,
  20.         PUIHandler::PUI_FRAUD_NET_SESSION_ID,
  21.         PUICustomerDataService::PUI_CUSTOMER_DATA_BIRTHDAY,
  22.         PUICustomerDataService::PUI_CUSTOMER_DATA_PHONE_NUMBER,
  23.     ];
  24.     private LoggerInterface $logger;
  25.     public function __construct(LoggerInterface $logger)
  26.     {
  27.         $this->logger $logger;
  28.     }
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         return [
  32.             HandlePaymentMethodRouteRequestEvent::class => 'addHandlePaymentParameters',
  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. }