custom/plugins/LyranetworkLyra/src/Subscriber/CheckoutFinishSubscriber.php line 41

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright © Lyra Network.
  4.  * This file is part of Lyra Collect plugin for Shopware. See COPYING.md for license details.
  5.  *
  6.  * @author    Lyra Network <https://www.lyra.com>
  7.  * @copyright Lyra Network
  8.  * @license   https://opensource.org/licenses/mit-license.html The MIT License (MIT)
  9.  */
  10. declare(strict_types=1);
  11. namespace Lyranetwork\Lyra\Subscriber;
  12. use Shopware\Core\Checkout\Payment\PaymentMethodEntity;
  13. use Shopware\Core\Framework\Context;
  14. use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPageLoadedEvent;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Symfony\Contracts\Translation\TranslatorInterface;
  17. use Lyranetwork\Lyra\PaymentMethods\Standard;
  18. class CheckoutFinishSubscriber implements EventSubscriberInterface
  19. {
  20.     /**
  21.      * @var TranslatorInterface
  22.      */
  23.     private $translator;
  24.     public function __construct(TranslatorInterface $translator)
  25.     {
  26.         $this->translator $translator;
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             CheckoutFinishPageLoadedEvent::class => 'onCheckoutFinish'
  32.         ];
  33.     }
  34.     public function onCheckoutFinish(CheckoutFinishPageLoadedEvent $event): void
  35.     {
  36.         $salesChannelContext $event->getSalesChannelContext();
  37.         $isLyraPayment = ($salesChannelContext->getPaymentMethod()->getHandlerIdentifier() === Standard::class);
  38.         if (! $isLyraPayment) {
  39.             return;
  40.         }
  41.         $session $event->getRequest()->getSession();
  42.         if ($session->has('lyraGoingIntoProductionInfo') && $session->get('lyraGoingIntoProductionInfo')) {
  43.             $message $this->translator->trans('lyraGoingIntoProductionInfo');
  44.             $session->getFlashBag()->add('warning'$message);
  45.         }
  46.         if ($session->has('lyraCheckUrlWarn') && $session->get('lyraCheckUrlWarn')) {
  47.             $message $this->translator->trans('lyraCheckUrlWarn');
  48.             $session->getFlashBag()->add('warning'$message);
  49.             $message $this->translator->trans('lyraCheckUrlWarnDetails');
  50.             $session->getFlashBag()->add('warning'$message);
  51.         }
  52.         if ($session->has('lyraTechError') && $session->get('lyraTechError')) {
  53.             $message $this->translator->trans('lyraPaymentFatal');
  54.             $session->getFlashBag()->add('warning'$message);
  55.         }
  56.     }
  57. }