custom/plugins/PayonePayment/src/EventListener/DeviceFingerprintEventListener.php line 36

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace PayonePayment\EventListener;
  4. use PayonePayment\Components\DeviceFingerprint\DeviceFingerprintServiceCollectionInterface;
  5. use PayonePayment\Storefront\Struct\DeviceFingerprintData;
  6. use Shopware\Storefront\Page\Account\Order\AccountEditOrderPageLoadedEvent;
  7. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  8. use Shopware\Storefront\Page\Page;
  9. use Shopware\Storefront\Page\PageLoadedEvent;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class DeviceFingerprintEventListener implements EventSubscriberInterface
  12. {
  13.     protected DeviceFingerprintServiceCollectionInterface $deviceFingerprintServiceCollection;
  14.     public function __construct(DeviceFingerprintServiceCollectionInterface $deviceFingerprintServiceCollection)
  15.     {
  16.         $this->deviceFingerprintServiceCollection $deviceFingerprintServiceCollection;
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             CheckoutConfirmPageLoadedEvent::class => [
  22.                 ['addDeviceFingerprintData'],
  23.             ],
  24.             AccountEditOrderPageLoadedEvent::class => [
  25.                 ['addDeviceFingerprintData'],
  26.             ],
  27.         ];
  28.     }
  29.     public function addDeviceFingerprintData(PageLoadedEvent $event): void
  30.     {
  31.         /** @var Page $page */
  32.         $page $event->getPage();
  33.         $salesChannelContext $event->getSalesChannelContext();
  34.         $deviceFingerprintService $this->deviceFingerprintServiceCollection->getForPaymentHandler(
  35.             $salesChannelContext->getPaymentMethod()->getHandlerIdentifier()
  36.         );
  37.         if ($deviceFingerprintService && !$deviceFingerprintService->isDeviceIdentTokenAlreadyGenerated()) {
  38.             $deviceIdentToken $deviceFingerprintService->getDeviceIdentToken($salesChannelContext);
  39.             $snippet $deviceFingerprintService->getDeviceIdentSnippet($deviceIdentToken$salesChannelContext);
  40.             $extension = new DeviceFingerprintData();
  41.             $extension->setSnippet($snippet);
  42.             $page->addExtension(DeviceFingerprintData::EXTENSION_NAME$extension);
  43.         }
  44.     }
  45. }