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

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