custom/plugins/CkoShopware6/src/Subscriber/HandlePaymentRequestSubscriber.php line 21

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Cko\Shopware6\Subscriber;
  3. use Cko\Shopware6\Helper\RequestUtil;
  4. use Shopware\Storefront\Event\RouteRequest\HandlePaymentMethodRouteRequestEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class HandlePaymentRequestSubscriber implements EventSubscriberInterface
  7. {
  8.     public static function getSubscribedEvents(): array
  9.     {
  10.         return [
  11.             HandlePaymentMethodRouteRequestEvent::class => 'onHandlePaymentMethodRouteRequest',
  12.         ];
  13.     }
  14.     /**
  15.      * Modify the payment method route request to add payment details from the StoreFront request to the API request
  16.      */
  17.     public function onHandlePaymentMethodRouteRequest(HandlePaymentMethodRouteRequestEvent $event): void
  18.     {
  19.         $storeFrontRequest $event->getStorefrontRequest();
  20.         $dataBagKey RequestUtil::DATA_BAG_KEY;
  21.         // We skip if the storefront request does not have the checkout request key
  22.         if (!$storeFrontRequest->request->has($dataBagKey)) {
  23.             return;
  24.         }
  25.         $paymentDetails $storeFrontRequest->request->get($dataBagKey);
  26.         /*
  27.          * Have to add to store api request from storefront request
  28.          * Because when the storefront request is sent to the API on order edit screen, the payment details are not available
  29.          *
  30.          * @see \Shopware\Storefront\Controller\AccountOrderController::updateOrder
  31.          */
  32.         $event->getStoreApiRequest()->request->set($dataBagKey$paymentDetails);
  33.     }
  34. }