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

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\Checkout\Customer\CustomerEntity;
  14. use Shopware\Core\Framework\Struct\ArrayStruct;
  15. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. class CheckoutSubscriber implements EventSubscriberInterface
  18. {
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             CheckoutConfirmPageLoadedEvent::class => ['addRatepayTemplateData'310],
  23.         ];
  24.     }
  25.     public function addRatepayTemplateData(CheckoutConfirmPageLoadedEvent $event): void
  26.     {
  27.         $paymentMethod $event->getSalesChannelContext()->getPaymentMethod();
  28.         if (MethodHelper::isRatepayMethod($paymentMethod->getHandlerIdentifier()) &&
  29.             $event->getPage()->getPaymentMethods()->has($paymentMethod->getId())
  30.         ) {
  31.             $customer $event->getSalesChannelContext()->getCustomer();
  32.             if ($customer instanceof CustomerEntity) {
  33.                 $extension $event->getPage()->getExtension(ExtensionService::PAYMENT_PAGE_EXTENSION_NAME) ?? new ArrayStruct();
  34.                 $extension->assign([
  35.                     'validation' => [
  36.                         'billing_address_md5' => AddressHelper::createMd5Hash($customer->getActiveBillingAddress()),
  37.                         'shipping_address_md5' => AddressHelper::createMd5Hash($customer->getActiveShippingAddress()),
  38.                     ],
  39.                 ]);
  40.                 $event->getPage()->addExtension(ExtensionService::PAYMENT_PAGE_EXTENSION_NAME$extension);
  41.             }
  42.         }
  43.     }
  44. }