custom/plugins/MolliePayments/src/Subscriber/ApplePaySubscriber.php line 40

Open in your IDE?
  1. <?php
  2. namespace Kiener\MolliePayments\Subscriber;
  3. use Kiener\MolliePayments\Components\ApplePayDirect\ApplePayDirect;
  4. use Shopware\Storefront\Event\StorefrontRenderEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class ApplePaySubscriber implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * @var ApplePayDirect
  10.      */
  11.     private $applePay;
  12.     /**
  13.      * @param ApplePayDirect $applePay
  14.      */
  15.     public function __construct(ApplePayDirect $applePay)
  16.     {
  17.         $this->applePay $applePay;
  18.     }
  19.     /**
  20.      * @inheritDoc
  21.      */
  22.     public static function getSubscribedEvents()
  23.     {
  24.         return [
  25.             StorefrontRenderEvent::class => 'onStorefrontRender',
  26.         ];
  27.     }
  28.     /**
  29.      * @param StorefrontRenderEvent $event
  30.      * @throws \Exception
  31.      * @return void
  32.      */
  33.     public function onStorefrontRender(StorefrontRenderEvent $event): void
  34.     {
  35.         try {
  36.             $applePayEnabled $this->applePay->getActiveApplePayID($event->getSalesChannelContext());
  37.         } catch (\Exception $ex) {
  38.             $applePayEnabled false;
  39.         }
  40.         $event->setParameter('mollie_applepay_enabled'$applePayEnabled);
  41.     }
  42. }