vendor/store.shopware.com/swagb2bplatform/components/Order/BridgePlatform/OrderPaymentChangedSubscriber.php line 32

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\B2B\Order\BridgePlatform;
  3. use Shopware\B2B\Common\IdValue;
  4. use Shopware\B2B\Order\Framework\OrderContextRepository;
  5. use Shopware\B2B\StoreFrontAuthentication\Framework\AuthenticationService;
  6. use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPageLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class OrderPaymentChangedSubscriber implements EventSubscriberInterface
  9. {
  10.     private OrderContextRepository $orderContextRepository;
  11.     private AuthenticationService $authenticationService;
  12.     public function __construct(
  13.         AuthenticationService $authenticationService,
  14.         OrderContextRepository $orderContextRepository
  15.     ) {
  16.         $this->authenticationService $authenticationService;
  17.         $this->orderContextRepository $orderContextRepository;
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             CheckoutFinishPageLoadedEvent::class => 'onFinishPageLoaded',
  23.         ];
  24.     }
  25.     public function onFinishPageLoaded(CheckoutFinishPageLoadedEvent $event): void
  26.     {
  27.         if (!$this->authenticationService->isB2b()) {
  28.             return;
  29.         }
  30.         $page $event->getPage();
  31.         if (!$page->isChangedPayment()) {
  32.             return;
  33.         }
  34.         $order $page->getOrder();
  35.         $newPaymentId IdValue::create($order->getTransactions()->last()->getPaymentMethodId());
  36.         $this->orderContextRepository->updatePaymentMethodByOrderNumber($order->getOrderNumber(), $newPaymentId);
  37.     }
  38. }