custom/plugins/TpayShopwarePayment/src/Subscriber/PagePaymentSearch.php line 49

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * @copyright 2020 Tpay Krajowy Integrator Płatności S.A. <https://tpay.com/>
  4.  *
  5.  * @author    Jakub Medyński <jme@crehler.com>
  6.  * @support   Tpay <pt@tpay.com>
  7.  * @created   23 kwi 2020
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Tpay\ShopwarePayment\Subscriber;
  13. use Shopware\Core\Checkout\Payment\PaymentMethodCollection;
  14. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  15. use Shopware\Storefront\Page\Account\Order\AccountEditOrderPageLoadedEvent;
  16. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. use Tpay\ShopwarePayment\Component\TpayPayment\BankList\TpayBankListInterface;
  19. use Tpay\ShopwarePayment\Util\Payments\BankTransfer;
  20. class PagePaymentSearch implements EventSubscriberInterface
  21. {
  22.     /** @var TpayBankListInterface */
  23.     private $bankListService;
  24.     public function __construct(TpayBankListInterface $bankListService)
  25.     {
  26.         $this->bankListService $bankListService;
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.       return [
  31.           CheckoutConfirmPageLoadedEvent::class => 'onPaymentSearchResult',
  32.           AccountEditOrderPageLoadedEvent::class => 'onAccountEditPaymentSearchResult'
  33.       ];
  34.     }
  35.     public function onPaymentSearchResult(CheckoutConfirmPageLoadedEvent $event): void
  36.     {
  37.         $payments $event->getPage()->getPaymentMethods();
  38.         $this->addBankListExtension($payments$event->getSalesChannelContext());
  39.     }
  40.     public function onAccountEditPaymentSearchResult(AccountEditOrderPageLoadedEvent $event):void
  41.     {
  42.         $payments $event->getPage()->getPaymentMethods();
  43.         $this->addBankListExtension($payments$event->getSalesChannelContext());
  44.     }
  45.     public function addBankListExtension(PaymentMethodCollection $paymentsSalesChannelContext $salesChannelContext): void
  46.     {
  47.         $bankTransferHandler = (new BankTransfer())->getHandlerIdentifier();
  48.         foreach ($payments as $payment) {
  49.             if ($payment->getHandlerIdentifier() === $bankTransferHandler) {
  50.                 $payment->addExtension('tpayBankList'$this->bankListService->getBankList($salesChannelContext));
  51.             }
  52.         }
  53.     }
  54. }