custom/plugins/EasyCreditRatenkauf/src/Flow/Action/CaptureAction.php line 60

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /*
  3.  * (c) NETZKOLLEKTIV GmbH <kontakt@netzkollektiv.com>
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Netzkollektiv\EasyCredit\Flow\Action;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Shopware\Core\Content\Flow\Dispatching\Action\FlowAction;
  10. use Shopware\Core\Content\Flow\Dispatching\StorableFlow;
  11. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  12. use Shopware\Core\Framework\Uuid\Uuid;
  13. use Shopware\Core\Framework\Event\OrderAware;
  14. use Shopware\Core\Framework\Event\FlowEvent;
  15. use Shopware\Core\Checkout\Order\Event\OrderStateMachineStateChangeEvent;
  16. use Netzkollektiv\EasyCredit\Service\TransactionService;
  17. class CaptureAction extends FlowAction implements EventSubscriberInterface
  18. {
  19.     private TransactionService $transactionService;
  20.     public function __construct(TransactionService $transactionService)
  21.     {
  22.         $this->transactionService $transactionService;
  23.     }
  24.     public static function getName(): string
  25.     {
  26.         return 'action.easycredit.capture';
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             self::getName() => 'handle',
  32.         ];
  33.     }
  34.     public function requirements(): array
  35.     {
  36.         return [OrderAware::class];
  37.     }
  38.     // SW >= v6.5.1.0
  39.     public function handleFlow(StorableFlow $flow): void
  40.     {
  41.         if (!$flow->hasData(OrderAware::ORDER)) {
  42.             return;
  43.         }
  44.         $order $flow->getData(OrderAware::ORDER);
  45.         $event = new OrderStateMachineStateChangeEvent('unknown'$order$flow->getContext());
  46.         $this->transactionService->captureTransaction($event);
  47.     }
  48.     // SW >= v6.4.6.0
  49.     // SW <= v6.5.1.0
  50.     public function handle(FlowEvent $event): void
  51.     {
  52.         if (!$event->getEvent() instanceof OrderAware) {
  53.             return;
  54.         }
  55.         $this->transactionService->captureTransaction($event->getEvent());
  56.     }
  57. }