vendor/store.shopware.com/adyenpaymentshopware6/src/Subscriber/ContextResolvedSubscriber.php line 60

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  *                       ######
  4.  *                       ######
  5.  * ############    ####( ######  #####. ######  ############   ############
  6.  * #############  #####( ######  #####. ######  #############  #############
  7.  *        ######  #####( ######  #####. ######  #####  ######  #####  ######
  8.  * ###### ######  #####( ######  #####. ######  #####  #####   #####  ######
  9.  * ###### ######  #####( ######  #####. ######  #####          #####  ######
  10.  * #############  #############  #############  #############  #####  ######
  11.  *  ############   ############  #############   ############  #####  ######
  12.  *                                      ######
  13.  *                               #############
  14.  *                               ############
  15.  *
  16.  * Adyen Payment Module
  17.  *
  18.  * Copyright (c) 2021 Adyen B.V.
  19.  * This file is open source and available under the MIT license.
  20.  * See the LICENSE file for more info.
  21.  *
  22.  * Author: Adyen <shopware@adyen.com>
  23.  */
  24. namespace Adyen\Shopware\Subscriber;
  25. use Adyen\Shopware\Service\ConfigurationService;
  26. use Adyen\Shopware\Service\PaymentStateDataService;
  27. use Adyen\Shopware\Struct\AdyenContextDataStruct;
  28. use Shopware\Core\Framework\Routing\Event\SalesChannelContextResolvedEvent;
  29. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  30. class ContextResolvedSubscriber implements EventSubscriberInterface
  31. {
  32.     /**
  33.      * @var ConfigurationService
  34.      */
  35.     private $configurationService;
  36.     /**
  37.      * @var PaymentStateDataService
  38.      */
  39.     private $paymentStateDataService;
  40.     public function __construct(
  41.         ConfigurationService $configurationService,
  42.         PaymentStateDataService $paymentStateDataService
  43.     ) {
  44.         $this->configurationService $configurationService;
  45.         $this->paymentStateDataService $paymentStateDataService;
  46.     }
  47.     public static function getSubscribedEvents()
  48.     {
  49.         return [
  50.             SalesChannelContextResolvedEvent::class => 'addAdyenData',
  51.         ];
  52.     }
  53.     public function addAdyenData(SalesChannelContextResolvedEvent $event): void
  54.     {
  55.         $context $event->getSalesChannelContext();
  56.         $salesChannelId $context->getSalesChannelId();
  57.         $extension = new AdyenContextDataStruct();
  58.         $context->addExtension('adyenData'$extension);
  59.         $extension->setClientKey($this->configurationService->getClientKey($salesChannelId) ?: null);
  60.         $extension->setEnvironment($this->configurationService->getEnvironment($salesChannelId));
  61.         $data $this->paymentStateDataService->getPaymentStateDataFromContextToken($context->getToken());
  62.         $extension->setHasPaymentStateData(!empty($data));
  63.     }
  64. }