custom/plugins/CkoShopware6/src/Content/Flow/Dispatching/Action/CapturePaymentAction.php line 40

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Cko\Shopware6\Content\Flow\Dispatching\Action;
  3. use Cko\Shopware6\Service\Order\AbstractOrderCheckoutService;
  4. use Psr\Log\LoggerInterface;
  5. use Shopware\Core\Content\Flow\Dispatching\Action\FlowAction;
  6. use Shopware\Core\Framework\Event\FlowEvent;
  7. use Shopware\Core\Framework\Event\OrderAware;
  8. class CapturePaymentAction extends FlowAction
  9. {
  10.     private LoggerInterface $logger;
  11.     private AbstractOrderCheckoutService $orderCheckoutService;
  12.     public function __construct(
  13.         LoggerInterface $logger,
  14.         AbstractOrderCheckoutService $orderCheckoutService
  15.     ) {
  16.         $this->logger $logger;
  17.         $this->orderCheckoutService $orderCheckoutService;
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [self::getName() => 'handle'];
  22.     }
  23.     public static function getName(): string
  24.     {
  25.         return 'action.checkout_com.capture_payment';
  26.     }
  27.     public function requirements(): array
  28.     {
  29.         return [OrderAware::class];
  30.     }
  31.     public function handle(FlowEvent $event): void
  32.     {
  33.         $baseEvent $event->getEvent();
  34.         if (!$baseEvent instanceof OrderAware) {
  35.             return;
  36.         }
  37.         $this->logger->info(sprintf('Action starting to capture payment with order ID: %s'$baseEvent->getOrderId()));
  38.         $this->orderCheckoutService->capturePayment($baseEvent->getOrderId(), $baseEvent->getContext());
  39.     }
  40. }