vendor/lnb/shopware6-fraud-prevention/src/Subscriber/SetOrderStateActionDecorator.php line 37

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Lnb\Shopware6\FraudPrevention\Subscriber;
  4. use Lnb\Shopware6\FraudPrevention\Installer\StateInstaller;
  5. use Shopware\Core\Checkout\Order\Event\OrderStateMachineStateChangeEvent;
  6. use Shopware\Core\Content\Flow\Dispatching\Action\FlowAction;
  7. use Shopware\Core\Content\Flow\Dispatching\Action\SetOrderStateAction;
  8. use Shopware\Core\Content\Flow\Dispatching\DelayableAction;
  9. use Shopware\Core\Content\Flow\Dispatching\StorableFlow;
  10. use Shopware\Core\Framework\Event\FlowEvent;
  11. use Shopware\Core\Framework\Event\OrderAware;
  12. use Shopware\Core\Framework\Feature;
  13. class SetOrderStateActionDecorator extends FlowAction implements DelayableAction
  14. {
  15.     public function __construct(
  16.         private readonly SetOrderStateAction $decorated
  17.     ) {
  18.     }
  19.     public static function getName(): string
  20.     {
  21.         return SetOrderStateAction::getName();
  22.     }
  23.     public function getDecorated(): SetOrderStateAction
  24.     {
  25.         return $this->decorated;
  26.     }
  27.     /**
  28.      * @deprecated tag:v6.5.0 Will be removed, implement handleFlow instead
  29.      */
  30.     public function handle(FlowEvent $event): void
  31.     {
  32.         $flowEvent $event->getFlowState()->event;
  33.         if (! $flowEvent instanceof OrderStateMachineStateChangeEvent) {
  34.             $this->getDecorated()->handle($event);
  35.         }
  36.         $event $this->parseFraudAwareness($event);
  37.         $this->getDecorated()->handle($event);
  38.     }
  39.     public function requirements(): array
  40.     {
  41.         return [OrderAware::class];
  42.     }
  43.     public static function getSubscribedEvents(): array
  44.     {
  45.         if (Feature::isActive('v6.5.0.0')) {
  46.             return [];
  47.         }
  48.         return [
  49.             self::getName() => 'handle',
  50.         ];
  51.     }
  52.     public function handleFlow(StorableFlow $flow): void
  53.     {
  54.         Feature::triggerDeprecationOrThrow(
  55.             'v6.5.0.0',
  56.             Feature::deprecatedMethodMessage(__CLASS____METHOD__'v6.5.0.0')
  57.         );
  58.         $this->getDecorated()->handleFlow($flow);
  59.     }
  60.     /**
  61.      * @deprecated tag:v6.5.0 Will be invalid because StorableFlow will be used instead of FlowEvent
  62.      */
  63.     private function parseFraudAwareness(FlowEvent $event): FlowEvent
  64.     {
  65.         $flowEvent $event->getFlowState()->event;
  66.         if (! $flowEvent instanceof OrderStateMachineStateChangeEvent) {
  67.             return $event;
  68.         }
  69.         $config $event->getConfig();
  70.         if (! isset($config['fraud_prevention_aware']) || $config['fraud_prevention_aware'] !== true) {
  71.             return $event;
  72.         }
  73.         $order $flowEvent->getOrder();
  74.         if ($order->getStateMachineState()?->getTechnicalName() !== StateInstaller::FRAUD_PREVENTED_STATE_TECHNICAL_NAME) {
  75.             return $event;
  76.         }
  77.         //order is set to fraud -> so prevent new order state
  78.         $newConfig $event->getConfig();
  79.         $newConfig['order'] = '';
  80.         return new FlowEvent(
  81.             $event->getActionName(),
  82.             $event->getFlowState(),
  83.             $newConfig
  84.         );
  85.     }
  86. }