custom/plugins/RpayPayments/src/Components/CheckoutRedirectFix/Subscriber/CheckoutSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * Copyright (c) Ratepay GmbH
  5.  *
  6.  * For the full copyright and license information, please view the LICENSE
  7.  * file that was distributed with this source code.
  8.  */
  9. namespace Ratepay\RpayPayments\Components\CheckoutRedirectFix\Subscriber;
  10. use Ratepay\RpayPayments\Components\Checkout\Service\ExtensionService;
  11. use Ratepay\RpayPayments\Components\CheckoutRedirectFix\Helper\AddressHelper;
  12. use Ratepay\RpayPayments\Util\MethodHelper;
  13. use Shopware\Core\Framework\Struct\ArrayStruct;
  14. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class CheckoutSubscriber implements EventSubscriberInterface
  17. {
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             CheckoutConfirmPageLoadedEvent::class => ['addRatepayTemplateData'310],
  22.         ];
  23.     }
  24.     public function addRatepayTemplateData(CheckoutConfirmPageLoadedEvent $event): void
  25.     {
  26.         $paymentMethod $event->getSalesChannelContext()->getPaymentMethod();
  27.         if (MethodHelper::isRatepayMethod($paymentMethod->getHandlerIdentifier()) &&
  28.             $event->getPage()->getPaymentMethods()->has($paymentMethod->getId())
  29.         ) {
  30.             $customer $event->getSalesChannelContext()->getCustomer();
  31.             if ($customer) {
  32.                 $extension $event->getPage()->getExtension(ExtensionService::PAYMENT_PAGE_EXTENSION_NAME) ?? new ArrayStruct();
  33.                 $extension->assign([
  34.                     'validation' => [
  35.                         'billing_address_md5' => AddressHelper::createMd5Hash($customer->getActiveBillingAddress()),
  36.                         'shipping_address_md5' => AddressHelper::createMd5Hash($customer->getActiveShippingAddress()),
  37.                     ],
  38.                 ]);
  39.                 $event->getPage()->addExtension(ExtensionService::PAYMENT_PAGE_EXTENSION_NAME$extension);
  40.             }
  41.         }
  42.     }
  43. }