From d184accfaa2d51cad1e9cb3379aad8b9a312bef1 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 26 Sep 2024 11:16:02 +0200 Subject: [PATCH 01/11] Set symfony_workflow for the test app --- .../sylius/1.13/packages/sylius_state_machine_abstraction.yaml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/Application/config/sylius/1.13/packages/sylius_state_machine_abstraction.yaml diff --git a/tests/Application/config/sylius/1.13/packages/sylius_state_machine_abstraction.yaml b/tests/Application/config/sylius/1.13/packages/sylius_state_machine_abstraction.yaml new file mode 100644 index 0000000..ceee098 --- /dev/null +++ b/tests/Application/config/sylius/1.13/packages/sylius_state_machine_abstraction.yaml @@ -0,0 +1,2 @@ +sylius_state_machine_abstraction: + default_adapter: symfony_workflow From 1f221455f476caf3c2cfca959dc17085fc09b103 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 26 Sep 2024 11:16:38 +0200 Subject: [PATCH 02/11] Clean start --- behat.yml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/behat.yml.dist b/behat.yml.dist index c07a0d1..0b7f897 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -15,7 +15,7 @@ default: FriendsOfBehat\MinkDebugExtension: directory: etc/build - clean_start: false + clean_start: true screenshot: true Behat\MinkExtension: From 308ab3799c5bd230ed5464f9d1aecc2626f184b6 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 26 Sep 2024 11:17:08 +0200 Subject: [PATCH 03/11] Update ECS config --- ecs.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/ecs.php b/ecs.php index 98fbfe6..aee42dc 100644 --- a/ecs.php +++ b/ecs.php @@ -5,19 +5,15 @@ use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; -return static function (ECSConfig $ecsConfig): void { - $ecsConfig->import(__DIR__ . '/vendor/sylius-labs/coding-standard/ecs.php'); +return static function (ECSConfig $config): void { + $config->import(__DIR__ . '/vendor/sylius-labs/coding-standard/ecs.php'); - $ecsConfig->paths([ + $config->paths([ 'src', 'tests/Behat', ]); - $services = $ecsConfig->services(); - // PHP 7 compatibility - $services - ->set(TrailingCommaInMultilineFixer::class) - ->call('configure', [['elements' => ['arrays']]]) - ; + $config->ruleWithConfiguration(TrailingCommaInMultilineFixer::class, ['elements' => ['arrays']]); + }; From 3d5e397a36f8a900d66b9b5aa1d422bd6398d640 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 26 Sep 2024 11:17:34 +0200 Subject: [PATCH 04/11] Support Symfony Workflow --- .../UpdatePaymentStateExtensionSpec.php | 35 ++++++++----- .../StateMachine/CancelOrderProcessorSpec.php | 8 +-- .../CaptureAuthorizedOrderProcessorSpec.php | 6 +-- .../StateMachine/RefundOrderProcessorSpec.php | 4 +- .../StateMachine/CompositeStateMachine.php | 26 ++++++++++ .../StateMachine/StateMachineInterface.php | 12 +++++ .../StateMachine/WinzouStateMachine.php | 34 +++++++++++++ .../WinzouStateMachineCallbacksModifier.php | 28 ----------- .../FluxSESyliusPayumStripeExtension.php | 5 ++ .../PaymentCompletedStateListener.php | 35 +++++++++++++ src/Extension/UpdatePaymentStateExtension.php | 50 ++++++------------- src/FluxSESyliusPayumStripePlugin.php | 2 - src/Resources/config/app/twig.yaml | 3 ++ .../config/app/winzou_state_machine.yaml | 18 +++++++ src/Resources/config/config.yaml | 25 ++-------- .../services/abstraction/abstraction.yaml | 6 +++ .../listener/workflow/sylius_payment.yaml | 25 ++++++++++ src/Resources/config/services/payum.yaml | 10 +++- .../config/services/state_machine.yaml | 1 + src/StateMachine/CancelOrderProcessor.php | 12 ++--- .../CaptureAuthorizedOrderProcessor.php | 12 ++--- .../PaymentStateProcessorInterface.php | 12 +++++ src/StateMachine/RefundOrderProcessor.php | 21 ++++---- .../Shop/StripeCheckoutSessionShopContext.php | 2 +- .../Context/Ui/Shop/StripeJsShopContext.php | 2 +- 25 files changed, 261 insertions(+), 133 deletions(-) create mode 100644 src/Abstraction/StateMachine/CompositeStateMachine.php create mode 100644 src/Abstraction/StateMachine/StateMachineInterface.php create mode 100644 src/Abstraction/StateMachine/WinzouStateMachine.php delete mode 100644 src/DependencyInjection/Compiler/WinzouStateMachineCallbacksModifier.php create mode 100644 src/EventListener/Workflow/PaymentCompletedStateListener.php create mode 100644 src/Resources/config/app/twig.yaml create mode 100644 src/Resources/config/app/winzou_state_machine.yaml create mode 100644 src/Resources/config/services/abstraction/abstraction.yaml create mode 100644 src/Resources/config/services/listener/workflow/sylius_payment.yaml create mode 100644 src/StateMachine/PaymentStateProcessorInterface.php diff --git a/spec/Extension/UpdatePaymentStateExtensionSpec.php b/spec/Extension/UpdatePaymentStateExtensionSpec.php index bb38cf2..d82c281 100644 --- a/spec/Extension/UpdatePaymentStateExtensionSpec.php +++ b/spec/Extension/UpdatePaymentStateExtensionSpec.php @@ -5,6 +5,7 @@ namespace spec\FluxSE\SyliusPayumStripePlugin\Extension; use Exception; +use FluxSE\SyliusPayumStripePlugin\Abstraction\StateMachine\StateMachineInterface; use Payum\Core\Extension\Context; use Payum\Core\Extension\ExtensionInterface; use Payum\Core\GatewayInterface; @@ -15,20 +16,18 @@ use Payum\Core\Storage\IdentityInterface; use Payum\Core\Storage\StorageInterface; use PhpSpec\ObjectBehavior; -use SM\Factory\FactoryInterface; use Sylius\Bundle\PayumBundle\Factory\GetStatusFactoryInterface; use Sylius\Component\Core\Model\PaymentInterface; use Sylius\Component\Payment\PaymentTransitions; -use Sylius\Component\Resource\StateMachine\StateMachineInterface; final class UpdatePaymentStateExtensionSpec extends ObjectBehavior { public function let( - FactoryInterface $factory, + StateMachineInterface $stateMachine, StorageInterface $storage, GetStatusFactoryInterface $getStatusRequestFactory ): void { - $this->beConstructedWith($factory, $storage, $getStatusRequestFactory); + $this->beConstructedWith($stateMachine, $storage, $getStatusRequestFactory); } public function it_is_initializable(): void @@ -96,7 +95,6 @@ public function it_OnPostExecute_apply_a_transition( GetStatusInterface $status, GetStatusFactoryInterface $getStatusRequestFactory, GatewayInterface $gateway, - FactoryInterface $factory, StateMachineInterface $stateMachine ): void { $context->getException()->willReturn(null); @@ -114,9 +112,16 @@ public function it_OnPostExecute_apply_a_transition( $payment->getState()->willReturn(PaymentInterface::STATE_NEW); $status->getValue()->willReturn(PaymentInterface::STATE_COMPLETED); - $factory->get($payment, PaymentTransitions::GRAPH)->willReturn($stateMachine); - $stateMachine->getTransitionToState(PaymentInterface::STATE_COMPLETED)->willReturn('complete'); - $stateMachine->apply('complete')->shouldBeCalled(); + $stateMachine->getTransitionToState( + $payment, + PaymentTransitions::GRAPH, + PaymentInterface::STATE_COMPLETED + )->willReturn('complete'); + $stateMachine->apply( + $payment, + PaymentTransitions::GRAPH, + 'complete' + )->shouldBeCalled(); $this->onPostExecute($context); } @@ -131,7 +136,6 @@ public function it_OnPostExecute_apply_a_transition_without_a_Sylius_PaymentInte GetStatusInterface $status, GetStatusFactoryInterface $getStatusRequestFactory, GatewayInterface $gateway, - FactoryInterface $factory, StateMachineInterface $stateMachine ): void { $context->getException()->willReturn(null); @@ -152,9 +156,16 @@ public function it_OnPostExecute_apply_a_transition_without_a_Sylius_PaymentInte $previousPayment->getState()->willReturn(PaymentInterface::STATE_NEW); $status->getValue()->willReturn(PaymentInterface::STATE_COMPLETED); - $factory->get($previousPayment, PaymentTransitions::GRAPH)->willReturn($stateMachine); - $stateMachine->getTransitionToState(PaymentInterface::STATE_COMPLETED)->willReturn('complete'); - $stateMachine->apply('complete')->shouldBeCalled(); + $stateMachine->getTransitionToState( + $previousPayment, + PaymentTransitions::GRAPH, + PaymentInterface::STATE_COMPLETED + )->willReturn('complete'); + $stateMachine->apply( + $previousPayment, + PaymentTransitions::GRAPH, + 'complete' + )->shouldBeCalled(); $this->onPreExecute($previousContext); diff --git a/spec/StateMachine/CancelOrderProcessorSpec.php b/spec/StateMachine/CancelOrderProcessorSpec.php index bbc17d2..f79eae6 100644 --- a/spec/StateMachine/CancelOrderProcessorSpec.php +++ b/spec/StateMachine/CancelOrderProcessorSpec.php @@ -29,7 +29,7 @@ public function it_is_invokable_when_it_is_new( $command = new CancelPayment(1); $commandBus->dispatch($command)->willReturn(new Envelope($command)); - $this->__invoke($payment, $event); + $this->__invoke($payment); } public function it_is_invokable_when_is_authorized( @@ -45,7 +45,7 @@ public function it_is_invokable_when_is_authorized( $command = new CancelPayment(1); $commandBus->dispatch($command)->willReturn(new Envelope($command)); - $this->__invoke($payment, $event); + $this->__invoke($payment); } public function it_do_nothing_when_it_is_completed( @@ -54,7 +54,7 @@ public function it_do_nothing_when_it_is_completed( ): void { $event->getState()->willReturn(PaymentInterface::STATE_COMPLETED); - $this->__invoke($payment, $event); + $this->__invoke($payment); } public function it_do_nothing_when_it_is_refunded( @@ -63,6 +63,6 @@ public function it_do_nothing_when_it_is_refunded( ): void { $event->getState()->willReturn(PaymentInterface::STATE_REFUNDED); - $this->__invoke($payment, $event); + $this->__invoke($payment); } } diff --git a/spec/StateMachine/CaptureAuthorizedOrderProcessorSpec.php b/spec/StateMachine/CaptureAuthorizedOrderProcessorSpec.php index 530b4d2..d25d524 100644 --- a/spec/StateMachine/CaptureAuthorizedOrderProcessorSpec.php +++ b/spec/StateMachine/CaptureAuthorizedOrderProcessorSpec.php @@ -29,7 +29,7 @@ public function it_is_invokable( $command = new CaptureAuthorizedPayment(1); $commandBus->dispatch($command)->willReturn(new Envelope($command)); - $this->__invoke($payment, $event); + $this->__invoke($payment); } public function it_do_nothing_when_it_is_completed( @@ -38,7 +38,7 @@ public function it_do_nothing_when_it_is_completed( ): void { $event->getState()->willReturn(PaymentInterface::STATE_COMPLETED); - $this->__invoke($payment, $event); + $this->__invoke($payment); } public function it_do_nothing_when_it_is_refunded( @@ -47,6 +47,6 @@ public function it_do_nothing_when_it_is_refunded( ): void { $event->getState()->willReturn(PaymentInterface::STATE_REFUNDED); - $this->__invoke($payment, $event); + $this->__invoke($payment); } } diff --git a/spec/StateMachine/RefundOrderProcessorSpec.php b/spec/StateMachine/RefundOrderProcessorSpec.php index f376c74..7488111 100644 --- a/spec/StateMachine/RefundOrderProcessorSpec.php +++ b/spec/StateMachine/RefundOrderProcessorSpec.php @@ -29,7 +29,7 @@ public function it_is_invokable( $command = new RefundPayment(1); $commandBus->dispatch($command)->willReturn(new Envelope($command)); - $this->__invoke($payment, $event); + $this->__invoke($payment); } public function it_do_nothing_when_it_is_authorized( @@ -38,6 +38,6 @@ public function it_do_nothing_when_it_is_authorized( ): void { $event->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED); - $this->__invoke($payment, $event); + $this->__invoke($payment); } } diff --git a/src/Abstraction/StateMachine/CompositeStateMachine.php b/src/Abstraction/StateMachine/CompositeStateMachine.php new file mode 100644 index 0000000..3af6975 --- /dev/null +++ b/src/Abstraction/StateMachine/CompositeStateMachine.php @@ -0,0 +1,26 @@ +stateMachine = $stateMachine; + } + + public function getTransitionToState(object $subject, string $graphName, string $toState): ?string + { + return $this->stateMachine->getTransitionToState($subject, $graphName, $toState); + } + + public function apply(object $subject, string $graphName, string $transition, array $context = []): void { + $this->stateMachine->apply($subject, $graphName, $transition, $context); + } +} diff --git a/src/Abstraction/StateMachine/StateMachineInterface.php b/src/Abstraction/StateMachine/StateMachineInterface.php new file mode 100644 index 0000000..a8d27da --- /dev/null +++ b/src/Abstraction/StateMachine/StateMachineInterface.php @@ -0,0 +1,12 @@ +factory = $factory; + } + + public function getTransitionToState(object $subject, string $graphName, string $toState): ?string + { + $stateMachine = $this->factory->get($subject, $graphName); + Assert::isInstanceOf($stateMachine, SyliusStateMachineInterface::class); + + return $stateMachine->getTransitionToState($toState); + } + + public function apply(object $subject, string $graphName, string $transition, array $context = []): void + { + $stateMachine = $this->factory->get($subject, $graphName); + + $stateMachine->apply($transition); + } +} diff --git a/src/DependencyInjection/Compiler/WinzouStateMachineCallbacksModifier.php b/src/DependencyInjection/Compiler/WinzouStateMachineCallbacksModifier.php deleted file mode 100644 index e0fd4e4..0000000 --- a/src/DependencyInjection/Compiler/WinzouStateMachineCallbacksModifier.php +++ /dev/null @@ -1,28 +0,0 @@ -getParameter('flux_se.sylius_payum_stripe.refund.disabled'); - - $container->prependExtensionConfig('winzou_state_machine', [ - 'sylius_payment' => [ - 'callbacks' => [ - 'before' => [ - 'flux_se.sylius_payum_stripe_refund' => [ - 'disabled' => $refundDisabled, - ], - ], - ], - ], - ]); - } -} diff --git a/src/DependencyInjection/FluxSESyliusPayumStripeExtension.php b/src/DependencyInjection/FluxSESyliusPayumStripeExtension.php index 1f09038..9554d76 100644 --- a/src/DependencyInjection/FluxSESyliusPayumStripeExtension.php +++ b/src/DependencyInjection/FluxSESyliusPayumStripeExtension.php @@ -47,5 +47,10 @@ public function load(array $configs, ContainerBuilder $container): void new FileLocator(dirname(__DIR__) . '/Resources/config'), ); $loader->load('services.yaml'); + + if ($container->hasExtension('sylius_state_machine_abstraction')) { + $loader->load('services/abstraction/abstraction.yaml'); + $loader->load('services/listener/workflow/sylius_payment.yaml'); + } } } diff --git a/src/EventListener/Workflow/PaymentCompletedStateListener.php b/src/EventListener/Workflow/PaymentCompletedStateListener.php new file mode 100644 index 0000000..48e2b56 --- /dev/null +++ b/src/EventListener/Workflow/PaymentCompletedStateListener.php @@ -0,0 +1,35 @@ +paymentStateProcessor = $paymentStateProcessor; + } + + public function __invoke(CompletedEvent $event): void + { + /** @var PaymentInterface $payment */ + $payment = $event->getSubject(); + Assert::isInstanceOf($payment, PaymentInterface::class); + + $transition = $event->getTransition(); + Assert::notNull($transition); + // state machine transition from list always contains 1 element + $fromState = $transition->getFroms()[0]; + Assert::notNull($fromState); + + $this->paymentStateProcessor->__invoke($payment, $fromState); + } +} diff --git a/src/Extension/UpdatePaymentStateExtension.php b/src/Extension/UpdatePaymentStateExtension.php index f9c8e69..4f67dde 100644 --- a/src/Extension/UpdatePaymentStateExtension.php +++ b/src/Extension/UpdatePaymentStateExtension.php @@ -4,18 +4,15 @@ namespace FluxSE\SyliusPayumStripePlugin\Extension; +use FluxSE\SyliusPayumStripePlugin\Abstraction\StateMachine\StateMachineInterface; use Payum\Core\Extension\Context; use Payum\Core\Extension\ExtensionInterface; use Payum\Core\Model\ModelAggregateInterface; use Payum\Core\Storage\IdentityInterface; use Payum\Core\Storage\StorageInterface; -use SM\Factory\FactoryInterface; -use SM\SMException; use Sylius\Bundle\PayumBundle\Factory\GetStatusFactoryInterface; use Sylius\Component\Payment\Model\PaymentInterface; use Sylius\Component\Payment\PaymentTransitions; -use Sylius\Component\Resource\StateMachine\StateMachineInterface; -use Webmozart\Assert\Assert; /** * Reproduction of the Payum Core StorageExtension behaviour for Sylius payments @@ -24,26 +21,14 @@ */ final class UpdatePaymentStateExtension implements ExtensionInterface { - /** @var FactoryInterface */ - private $factory; - - /** @var StorageInterface */ - private $storage; - - /** @var GetStatusFactoryInterface */ - private $getStatusRequestFactory; - /** @var PaymentInterface[] */ - private $scheduledPaymentsToProcess = []; + private array $scheduledPaymentsToProcess = []; public function __construct( - FactoryInterface $factory, - StorageInterface $storage, - GetStatusFactoryInterface $getStatusRequestFactory + private StateMachineInterface $stateMachine, + private StorageInterface $storage, + private GetStatusFactoryInterface $getStatusRequestFactory ) { - $this->factory = $factory; - $this->storage = $storage; - $this->getStatusRequestFactory = $getStatusRequestFactory; } public function onPreExecute(Context $context): void @@ -73,9 +58,6 @@ public function onExecute(Context $context): void { } - /** - * @throws SMException - */ public function onPostExecute(Context $context): void { if (null !== $context->getException()) { @@ -105,9 +87,6 @@ public function onPostExecute(Context $context): void } } - /** - * @throws SMException - */ private function processPayment(Context $context, PaymentInterface $payment): void { $status = $this->getStatusRequestFactory->createNewWithModel($payment); @@ -125,21 +104,22 @@ private function processPayment(Context $context, PaymentInterface $payment): vo $this->updatePaymentState($payment, $value); } - /** - * @throws SMException - */ private function updatePaymentState(PaymentInterface $payment, string $nextState): void { - $stateMachine = $this->factory->get($payment, PaymentTransitions::GRAPH); - - Assert::isInstanceOf($stateMachine, StateMachineInterface::class); - - $transition = $stateMachine->getTransitionToState($nextState); + $transition = $this->stateMachine->getTransitionToState( + $payment, + PaymentTransitions::GRAPH, + $nextState + ); if (null === $transition) { return; } - $stateMachine->apply($transition); + $this->stateMachine->apply( + $payment, + PaymentTransitions::GRAPH, + $transition + ); } private function scheduleForProcessingIfSupported(PaymentInterface $payment): void diff --git a/src/FluxSESyliusPayumStripePlugin.php b/src/FluxSESyliusPayumStripePlugin.php index eea7f66..b28a4df 100644 --- a/src/FluxSESyliusPayumStripePlugin.php +++ b/src/FluxSESyliusPayumStripePlugin.php @@ -6,7 +6,6 @@ use FluxSE\SyliusPayumStripePlugin\DependencyInjection\Compiler\PayumGatewayConfigOverride; use FluxSE\SyliusPayumStripePlugin\DependencyInjection\Compiler\PayumStoragePaymentAliaser; -use FluxSE\SyliusPayumStripePlugin\DependencyInjection\Compiler\WinzouStateMachineCallbacksModifier; use Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -26,7 +25,6 @@ public function build(ContainerBuilder $container): void ], ])); - $container->addCompilerPass(new WinzouStateMachineCallbacksModifier()); $container->addCompilerPass(new PayumStoragePaymentAliaser()); parent::build($container); diff --git a/src/Resources/config/app/twig.yaml b/src/Resources/config/app/twig.yaml new file mode 100644 index 0000000..e10fdb2 --- /dev/null +++ b/src/Resources/config/app/twig.yaml @@ -0,0 +1,3 @@ +twig: + form_themes: + - '@FluxSESyliusPayumStripePlugin/Admin/PaymentMethod/Form/useAuthorize.html.twig' diff --git a/src/Resources/config/app/winzou_state_machine.yaml b/src/Resources/config/app/winzou_state_machine.yaml new file mode 100644 index 0000000..fe094ef --- /dev/null +++ b/src/Resources/config/app/winzou_state_machine.yaml @@ -0,0 +1,18 @@ +winzou_state_machine: + sylius_payment: + callbacks: + after: + flux_se.sylius_payum_stripe_refund: + # By default, this callback is disabled to avoid mistake + # you can enable it using this plugin config : `refund_disabled: false` + on: ["refund"] + do: ["@flux_se.sylius_payum_stripe.state_machine.refund", "__invoke"] + args: ["object", "event.getState()"] + flux_se.sylius_payum_stripe_cancel: + on: ["cancel"] + do: ["@flux_se.sylius_payum_stripe.state_machine.cancel", "__invoke"] + args: ["object", "event.getState()"] + flux_se.sylius_payum_stripe_complete_authorized: + on: ["complete"] + do: ["@flux_se.sylius_payum_stripe.state_machine.capture_authorized", "__invoke"] + args: ["object", "event.getState()"] diff --git a/src/Resources/config/config.yaml b/src/Resources/config/config.yaml index 3b0bef6..43a9fe8 100644 --- a/src/Resources/config/config.yaml +++ b/src/Resources/config/config.yaml @@ -1,22 +1,5 @@ -twig: - form_themes: - - '@FluxSESyliusPayumStripePlugin/Admin/PaymentMethod/Form/useAuthorize.html.twig' +imports: + - { resource: 'app/twig.yaml' } + - { resource: 'app/winzou_state_machine.yaml' } + -winzou_state_machine: - sylius_payment: - callbacks: - after: - flux_se.sylius_payum_stripe_refund: - # By default, this callback is disabled to avoid mistake - # you can enable it using this plugin config : `refund_disabled: false` - on: ["refund"] - do: ["@flux_se.sylius_payum_stripe.state_machine.refund", "__invoke"] - args: ["object", "event"] - flux_se.sylius_payum_stripe_cancel: - on: ["cancel"] - do: ["@flux_se.sylius_payum_stripe.state_machine.cancel", "__invoke"] - args: ["object", "event"] - flux_se.sylius_payum_stripe_complete_authorized: - on: ["complete"] - do: ["@flux_se.sylius_payum_stripe.state_machine.capture_authorized", "__invoke"] - args: ["object", "event"] diff --git a/src/Resources/config/services/abstraction/abstraction.yaml b/src/Resources/config/services/abstraction/abstraction.yaml new file mode 100644 index 0000000..e192a99 --- /dev/null +++ b/src/Resources/config/services/abstraction/abstraction.yaml @@ -0,0 +1,6 @@ +services: + + flux_se.sylius_payum_stripe.abstraction.state_machine.composite: + class: FluxSE\SyliusPayumStripePlugin\Abstraction\StateMachine\CompositeStateMachine + arguments: + $stateMachine: '@sylius_abstraction.state_machine.composite' diff --git a/src/Resources/config/services/listener/workflow/sylius_payment.yaml b/src/Resources/config/services/listener/workflow/sylius_payment.yaml new file mode 100644 index 0000000..92196c3 --- /dev/null +++ b/src/Resources/config/services/listener/workflow/sylius_payment.yaml @@ -0,0 +1,25 @@ +services: + + flux_se.sylius_payum_stripe_plugin.event_listener.workflow.payment_complete_state.cancel: + class: FluxSE\SyliusPayumStripePlugin\EventListener\Workflow\PaymentCompletedStateListener + arguments: + $paymentStateProcessor: '@flux_se.sylius_payum_stripe.state_machine.cancel' + tags: + - name: kernel.event_listener + event: workflow.sylius_payment.completed.cancel + + flux_se.sylius_payum_stripe_plugin.event_listener.workflow.payment_complete_state.refund: + class: FluxSE\SyliusPayumStripePlugin\EventListener\Workflow\PaymentCompletedStateListener + arguments: + $paymentStateProcessor: '@flux_se.sylius_payum_stripe.state_machine.refund' + tags: + - name: kernel.event_listener + event: workflow.sylius_payment.completed.refund + + flux_se.sylius_payum_stripe_plugin.event_listener.workflow.payment_complete_state.complete_authorized: + class: FluxSE\SyliusPayumStripePlugin\EventListener\Workflow\PaymentCompletedStateListener + arguments: + $paymentStateProcessor: '@flux_se.sylius_payum_stripe.state_machine.capture_authorized' + tags: + - name: kernel.event_listener + event: workflow.sylius_payment.completed.complete diff --git a/src/Resources/config/services/payum.yaml b/src/Resources/config/services/payum.yaml index d22547a..b553714 100644 --- a/src/Resources/config/services/payum.yaml +++ b/src/Resources/config/services/payum.yaml @@ -1,10 +1,18 @@ services: + flux_se.sylius_payum_stripe.abstraction.state_machine.winzou: + class: FluxSE\SyliusPayumStripePlugin\Abstraction\StateMachine\WinzouStateMachine + arguments: + $factory: '@sm.factory' + + flux_se.sylius_payum_stripe.abstraction.state_machine.composite: + alias: flux_se.sylius_payum_stripe.abstraction.state_machine.winzou + flux_se.sylius_payum_stripe.extension.update_payment_state: public: true class: FluxSE\SyliusPayumStripePlugin\Extension\UpdatePaymentStateExtension arguments: - $factory: '@sm.factory' + $stateMachine: '@flux_se.sylius_payum_stripe.abstraction.state_machine.composite' # Alias of "@payum.storage.sylius_component_core_model_payment" # or "@payum.storage.app_entity_payment_payment" or any other available # Payum storage handling Payment entity diff --git a/src/Resources/config/services/state_machine.yaml b/src/Resources/config/services/state_machine.yaml index 4676790..7dc87a7 100644 --- a/src/Resources/config/services/state_machine.yaml +++ b/src/Resources/config/services/state_machine.yaml @@ -5,6 +5,7 @@ services: class: FluxSE\SyliusPayumStripePlugin\StateMachine\RefundOrderProcessor arguments: $commandBus: '@sylius.command_bus' + $disabled: '%flux_se.sylius_payum_stripe.refund.disabled%' flux_se.sylius_payum_stripe.state_machine.cancel: public: true diff --git a/src/StateMachine/CancelOrderProcessor.php b/src/StateMachine/CancelOrderProcessor.php index 0ad3b18..faf1a55 100644 --- a/src/StateMachine/CancelOrderProcessor.php +++ b/src/StateMachine/CancelOrderProcessor.php @@ -5,15 +5,13 @@ namespace FluxSE\SyliusPayumStripePlugin\StateMachine; use FluxSE\SyliusPayumStripePlugin\Command\CancelPayment; -use SM\Event\TransitionEvent; use Sylius\Component\Core\Model\PaymentInterface; use Symfony\Component\Messenger\MessageBusInterface; use Webmozart\Assert\Assert; -final class CancelOrderProcessor +final class CancelOrderProcessor implements PaymentStateProcessorInterface { - /** @var MessageBusInterface */ - private $commandBus; + private MessageBusInterface $commandBus; public function __construct( MessageBusInterface $commandBus @@ -21,9 +19,9 @@ public function __construct( $this->commandBus = $commandBus; } - public function __invoke(PaymentInterface $payment, TransitionEvent $event): void + public function __invoke(PaymentInterface $payment, string $fromState): void { - if (false === in_array($event->getState(), [ + if (false === in_array($fromState, [ PaymentInterface::STATE_NEW, PaymentInterface::STATE_AUTHORIZED, ], true)) { @@ -32,7 +30,7 @@ public function __invoke(PaymentInterface $payment, TransitionEvent $event): voi /** @var int|null $paymentId */ $paymentId = $payment->getId(); - Assert::notNull($paymentId); + Assert::notNull($paymentId, 'A payment ID was not provided on the payment object.'); $this->commandBus->dispatch(new CancelPayment($paymentId)); } } diff --git a/src/StateMachine/CaptureAuthorizedOrderProcessor.php b/src/StateMachine/CaptureAuthorizedOrderProcessor.php index 228c108..33f2b63 100644 --- a/src/StateMachine/CaptureAuthorizedOrderProcessor.php +++ b/src/StateMachine/CaptureAuthorizedOrderProcessor.php @@ -5,30 +5,28 @@ namespace FluxSE\SyliusPayumStripePlugin\StateMachine; use FluxSE\SyliusPayumStripePlugin\Command\CaptureAuthorizedPayment; -use SM\Event\TransitionEvent; use Sylius\Component\Core\Model\PaymentInterface; use Symfony\Component\Messenger\MessageBusInterface; use Webmozart\Assert\Assert; -final class CaptureAuthorizedOrderProcessor +final class CaptureAuthorizedOrderProcessor implements PaymentStateProcessorInterface { - /** @var MessageBusInterface */ - private $commandBus; + private MessageBusInterface $commandBus; public function __construct(MessageBusInterface $commandBus) { $this->commandBus = $commandBus; } - public function __invoke(PaymentInterface $payment, TransitionEvent $event): void + public function __invoke(PaymentInterface $payment, string $fromState): void { - if (PaymentInterface::STATE_AUTHORIZED !== $event->getState()) { + if (PaymentInterface::STATE_AUTHORIZED !== $fromState) { return; } /** @var int|null $paymentId */ $paymentId = $payment->getId(); - Assert::notNull($paymentId); + Assert::notNull($paymentId, 'A payment ID was not provided on the payment object.'); $this->commandBus->dispatch(new CaptureAuthorizedPayment($paymentId)); } } diff --git a/src/StateMachine/PaymentStateProcessorInterface.php b/src/StateMachine/PaymentStateProcessorInterface.php new file mode 100644 index 0000000..97c04ea --- /dev/null +++ b/src/StateMachine/PaymentStateProcessorInterface.php @@ -0,0 +1,12 @@ +commandBus = $commandBus; + $this->disabled = $disabled; } - public function __invoke(PaymentInterface $payment, TransitionEvent $event): void + public function __invoke(PaymentInterface $payment, string $fromState): void { - if (PaymentInterface::STATE_COMPLETED !== $event->getState()) { + if ($this->disabled) { return; } /** @var int|null $paymentId */ $paymentId = $payment->getId(); - Assert::notNull($paymentId); + Assert::notNull($paymentId, 'A payment ID was not provided on the payment object.'); $this->commandBus->dispatch(new RefundPayment($paymentId)); } } diff --git a/tests/Behat/Context/Ui/Shop/StripeCheckoutSessionShopContext.php b/tests/Behat/Context/Ui/Shop/StripeCheckoutSessionShopContext.php index 198fad3..86165e7 100644 --- a/tests/Behat/Context/Ui/Shop/StripeCheckoutSessionShopContext.php +++ b/tests/Behat/Context/Ui/Shop/StripeCheckoutSessionShopContext.php @@ -37,8 +37,8 @@ public function __construct( } /** - * @When I confirm my order with Stripe payment * @Given I have confirmed my order with Stripe payment + * @When I confirm my order with Stripe payment */ public function iConfirmMyOrderWithStripePayment(): void { diff --git a/tests/Behat/Context/Ui/Shop/StripeJsShopContext.php b/tests/Behat/Context/Ui/Shop/StripeJsShopContext.php index ad1ee7a..f452dd9 100644 --- a/tests/Behat/Context/Ui/Shop/StripeJsShopContext.php +++ b/tests/Behat/Context/Ui/Shop/StripeJsShopContext.php @@ -121,8 +121,8 @@ public function theStripeJsFormIsDisplayedAndICompleteThePaymentWithoutWebhookUs } /** - * @When I confirm my order with Stripe payment * @Given I have confirmed my order with Stripe payment + * @When I confirm my order with Stripe payment */ public function iConfirmMyOrderWithStripePayment(): void { From a01be0cf6b96577e703e18a1ff1aa9761b5a7778 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 26 Sep 2024 11:37:51 +0200 Subject: [PATCH 05/11] Fix phpspec --- .../StateMachine/CancelOrderProcessorSpec.php | 23 ++++--------------- .../CaptureAuthorizedOrderProcessorSpec.php | 19 ++++----------- .../StateMachine/RefundOrderProcessorSpec.php | 19 +++++++-------- 3 files changed, 20 insertions(+), 41 deletions(-) diff --git a/spec/StateMachine/CancelOrderProcessorSpec.php b/spec/StateMachine/CancelOrderProcessorSpec.php index f79eae6..7f3eea3 100644 --- a/spec/StateMachine/CancelOrderProcessorSpec.php +++ b/spec/StateMachine/CancelOrderProcessorSpec.php @@ -19,50 +19,37 @@ public function let(MessageBusInterface $commandBus): void { public function it_is_invokable_when_it_is_new( PaymentInterface $payment, - TransitionEvent $event, MessageBusInterface $commandBus, ): void { - $event->getState()->willReturn(PaymentInterface::STATE_NEW); - $payment->getId()->willReturn(1); $command = new CancelPayment(1); $commandBus->dispatch($command)->willReturn(new Envelope($command)); - $this->__invoke($payment); + $this->__invoke($payment, PaymentInterface::STATE_NEW); } public function it_is_invokable_when_is_authorized( PaymentInterface $payment, - TransitionEvent $event, MessageBusInterface $commandBus ): void { - - $event->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED); - $payment->getId()->willReturn(1); $command = new CancelPayment(1); $commandBus->dispatch($command)->willReturn(new Envelope($command)); - $this->__invoke($payment); + $this->__invoke($payment, PaymentInterface::STATE_AUTHORIZED); } public function it_do_nothing_when_it_is_completed( - PaymentInterface $payment, - TransitionEvent $event + PaymentInterface $payment ): void { - $event->getState()->willReturn(PaymentInterface::STATE_COMPLETED); - - $this->__invoke($payment); + $this->__invoke($payment, PaymentInterface::STATE_COMPLETED); } public function it_do_nothing_when_it_is_refunded( PaymentInterface $payment, - TransitionEvent $event ): void { - $event->getState()->willReturn(PaymentInterface::STATE_REFUNDED); - - $this->__invoke($payment); + $this->__invoke($payment, PaymentInterface::STATE_REFUNDED); } } diff --git a/spec/StateMachine/CaptureAuthorizedOrderProcessorSpec.php b/spec/StateMachine/CaptureAuthorizedOrderProcessorSpec.php index d25d524..81fa63c 100644 --- a/spec/StateMachine/CaptureAuthorizedOrderProcessorSpec.php +++ b/spec/StateMachine/CaptureAuthorizedOrderProcessorSpec.php @@ -19,34 +19,25 @@ public function let(MessageBusInterface $commandBus): void { public function it_is_invokable( PaymentInterface $payment, - TransitionEvent $event, MessageBusInterface $commandBus ): void { - $event->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED); - $payment->getId()->willReturn(1); $command = new CaptureAuthorizedPayment(1); $commandBus->dispatch($command)->willReturn(new Envelope($command)); - $this->__invoke($payment); + $this->__invoke($payment, PaymentInterface::STATE_AUTHORIZED); } public function it_do_nothing_when_it_is_completed( - PaymentInterface $payment, - TransitionEvent $event + PaymentInterface $payment ): void { - $event->getState()->willReturn(PaymentInterface::STATE_COMPLETED); - - $this->__invoke($payment); + $this->__invoke($payment, PaymentInterface::STATE_COMPLETED); } public function it_do_nothing_when_it_is_refunded( - PaymentInterface $payment, - TransitionEvent $event + PaymentInterface $payment ): void { - $event->getState()->willReturn(PaymentInterface::STATE_REFUNDED); - - $this->__invoke($payment); + $this->__invoke($payment, PaymentInterface::STATE_REFUNDED); } } diff --git a/spec/StateMachine/RefundOrderProcessorSpec.php b/spec/StateMachine/RefundOrderProcessorSpec.php index 7488111..8e8663a 100644 --- a/spec/StateMachine/RefundOrderProcessorSpec.php +++ b/spec/StateMachine/RefundOrderProcessorSpec.php @@ -14,30 +14,31 @@ final class RefundOrderProcessorSpec extends ObjectBehavior { public function let(MessageBusInterface $commandBus): void { - $this->beConstructedWith($commandBus); + $this->beConstructedWith($commandBus, false); } public function it_is_invokable( PaymentInterface $payment, - TransitionEvent $event, MessageBusInterface $commandBus ): void { - $event->getState()->willReturn(PaymentInterface::STATE_COMPLETED); - $payment->getId()->willReturn(1); $command = new RefundPayment(1); $commandBus->dispatch($command)->willReturn(new Envelope($command)); - $this->__invoke($payment); + $this->__invoke($payment, PaymentInterface::STATE_COMPLETED); } - public function it_do_nothing_when_it_is_authorized( + public function it_do_nothing_when_it_is_disabled( PaymentInterface $payment, - TransitionEvent $event + MessageBusInterface $commandBus ): void { - $event->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED); - $this->__invoke($payment); + $this->beConstructedWith($commandBus, true); + + $command = new RefundPayment(1); + $commandBus->dispatch($command)->shouldNotBeCalled(); + + $this->__invoke($payment, PaymentInterface::STATE_COMPLETED); } } From 39a960975f1dbcc81ef3361633e16186f0d03b10 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 26 Sep 2024 12:11:41 +0200 Subject: [PATCH 06/11] Fix ecs --- src/Abstraction/StateMachine/CompositeStateMachine.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Abstraction/StateMachine/CompositeStateMachine.php b/src/Abstraction/StateMachine/CompositeStateMachine.php index 3af6975..38adc44 100644 --- a/src/Abstraction/StateMachine/CompositeStateMachine.php +++ b/src/Abstraction/StateMachine/CompositeStateMachine.php @@ -20,7 +20,8 @@ public function getTransitionToState(object $subject, string $graphName, string return $this->stateMachine->getTransitionToState($subject, $graphName, $toState); } - public function apply(object $subject, string $graphName, string $transition, array $context = []): void { + public function apply(object $subject, string $graphName, string $transition, array $context = []): void + { $this->stateMachine->apply($subject, $graphName, $transition, $context); } } From 306652457782c13331df5f615a83c8645453bc55 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 26 Sep 2024 16:44:32 +0200 Subject: [PATCH 07/11] Enhance Behat suites --- behat.yml.dist | 4 ---- .../Behat/Resources/suites/stripe_checkout_session/shop.yaml | 1 + tests/Behat/Resources/suites/stripe_js/shop.yaml | 1 + 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/behat.yml.dist b/behat.yml.dist index 0b7f897..642653d 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -30,10 +30,6 @@ default: chrome: api_url: http://127.0.0.1:9222 validate_certificate: false - chrome_headless_second_session: - chrome: - api_url: http://127.0.0.1:9222 - validate_certificate: false panther: panther: options: diff --git a/tests/Behat/Resources/suites/stripe_checkout_session/shop.yaml b/tests/Behat/Resources/suites/stripe_checkout_session/shop.yaml index 0f4e9ea..f6bfa3c 100644 --- a/tests/Behat/Resources/suites/stripe_checkout_session/shop.yaml +++ b/tests/Behat/Resources/suites/stripe_checkout_session/shop.yaml @@ -47,6 +47,7 @@ default: contexts: - sylius.behat.context.hook.doctrine_orm - sylius.behat.context.transform.address + - sylius.behat.context.transform.cart - sylius.behat.context.transform.customer - sylius.behat.context.transform.lexical - sylius.behat.context.transform.locale diff --git a/tests/Behat/Resources/suites/stripe_js/shop.yaml b/tests/Behat/Resources/suites/stripe_js/shop.yaml index 9f530df..a84f855 100644 --- a/tests/Behat/Resources/suites/stripe_js/shop.yaml +++ b/tests/Behat/Resources/suites/stripe_js/shop.yaml @@ -47,6 +47,7 @@ default: contexts: - sylius.behat.context.hook.doctrine_orm - sylius.behat.context.transform.address + - sylius.behat.context.transform.cart - sylius.behat.context.transform.customer - sylius.behat.context.transform.lexical - sylius.behat.context.transform.locale From eae33b1b9958d4036588b4b3bbdd054e59f15ecc Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 26 Sep 2024 17:32:28 +0200 Subject: [PATCH 08/11] Fix wrong class reference --- src/Abstraction/StateMachine/WinzouStateMachine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Abstraction/StateMachine/WinzouStateMachine.php b/src/Abstraction/StateMachine/WinzouStateMachine.php index 280c743..b9a4031 100644 --- a/src/Abstraction/StateMachine/WinzouStateMachine.php +++ b/src/Abstraction/StateMachine/WinzouStateMachine.php @@ -5,7 +5,7 @@ namespace FluxSE\SyliusPayumStripePlugin\Abstraction\StateMachine; use SM\Factory\FactoryInterface; -use Sylius\Resource\StateMachine\StateMachineInterface as SyliusStateMachineInterface; +use Sylius\Component\Resource\StateMachine\StateMachine as SyliusStateMachineInterface; use Webmozart\Assert\Assert; final class WinzouStateMachine implements StateMachineInterface From a9e3b9e2cfdaf4eed43b255a2d65c76792d3c3b8 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 26 Sep 2024 17:42:36 +0200 Subject: [PATCH 09/11] Move login to the scenario to get the driver started --- .../managing_payment_method.feature | 7 ++++--- features/admin/stripe_js/managing_payment_method.feature | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/features/admin/stripe_checkout_session/managing_payment_method.feature b/features/admin/stripe_checkout_session/managing_payment_method.feature index d1552b8..ff5cfc4 100644 --- a/features/admin/stripe_checkout_session/managing_payment_method.feature +++ b/features/admin/stripe_checkout_session/managing_payment_method.feature @@ -6,11 +6,11 @@ Feature: Adding a new Stripe Checkout Session payment method Background: Given the store operates on a single channel in "United States" - And I am logged in as an administrator @ui @javascript Scenario: Adding a new stripe payment method using authorize - Given I want to create a new Stripe Checkout Session payment method + Given I am logged in as an administrator + And I want to create a new Stripe Checkout Session payment method When I name it "Stripe Checkout Session" in "English (United States)" And I specify its code as "stripe_sca_test" And I configure it with test stripe gateway data "TEST", "TEST" @@ -23,7 +23,8 @@ Feature: Adding a new Stripe Checkout Session payment method @ui @javascript Scenario: Adding a new stripe payment method not using authorize - Given I want to create a new Stripe Checkout Session payment method + Given I am logged in as an administrator + And I want to create a new Stripe Checkout Session payment method When I name it "Stripe Checkout Session" in "English (United States)" And I specify its code as "stripe_sca_test" And I configure it with test stripe gateway data "TEST", "TEST" diff --git a/features/admin/stripe_js/managing_payment_method.feature b/features/admin/stripe_js/managing_payment_method.feature index 7ae29d8..b20d79a 100644 --- a/features/admin/stripe_js/managing_payment_method.feature +++ b/features/admin/stripe_js/managing_payment_method.feature @@ -6,11 +6,11 @@ Feature: Adding a new Stripe JS payment method Background: Given the store operates on a single channel in "United States" - And I am logged in as an administrator @ui @javascript Scenario: Adding a new stripe payment method using authorize - Given I want to create a new Stripe JS payment method + Given I am logged in as an administrator + And I want to create a new Stripe JS payment method When I name it "Stripe JS" in "English (United States)" And I specify its code as "stripe_sca_test" And I configure it with test stripe gateway data "TEST", "TEST" @@ -23,7 +23,8 @@ Feature: Adding a new Stripe JS payment method @ui @javascript Scenario: Adding a new stripe payment method not using authorize - Given I want to create a new Stripe JS payment method + Given I am logged in as an administrator + And I want to create a new Stripe JS payment method When I name it "Stripe JS" in "English (United States)" And I specify its code as "stripe_sca_test" And I configure it with test stripe gateway data "TEST", "TEST" From 1f2e2ec1fb7d28e5cf5d770b9bce78658465321d Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 26 Sep 2024 18:06:25 +0200 Subject: [PATCH 10/11] Rmove dmore/* --- behat.yml.dist | 10 +++------- composer.json | 2 -- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/behat.yml.dist b/behat.yml.dist index 642653d..bbe243e 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -10,7 +10,6 @@ default: snippets: false extensions: - DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~ Robertfausk\Behat\PantherExtension: ~ FriendsOfBehat\MinkDebugExtension: @@ -22,15 +21,11 @@ default: files_path: "%paths.base%/vendor/sylius/sylius/src/Sylius/Behat/Resources/fixtures/" base_url: "https://127.0.0.1:8080/" default_session: symfony - javascript_session: panther + javascript_session: javascript_chrome sessions: symfony: symfony: ~ - chromedriver: - chrome: - api_url: http://127.0.0.1:9222 - validate_certificate: false - panther: + javascript_chrome: panther: options: webServerDir: "%paths.base%/tests/Application/public" @@ -45,6 +40,7 @@ default: acceptInsecureCerts: true unexpectedAlertBehaviour: accept show_auto: false + browser_name: 'behat_browser' FriendsOfBehat\SymfonyExtension: bootstrap: tests/Application/config/bootstrap.php diff --git a/composer.json b/composer.json index ca5ff17..9b98185 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,6 @@ "ext-json": "*", "behat/behat": "^3.7", "dbrekelmans/bdi": "^1.2", - "dmore/behat-chrome-extension": "^1.4", - "dmore/chrome-mink-driver": "^2.8", "friends-of-behat/mink": "^1.9", "friends-of-behat/mink-browserkit-driver": "^1.4", "friends-of-behat/mink-debug-extension": "^2.0", From 41efc97b5f7c341ef83f71b1427cca6225b9b044 Mon Sep 17 00:00:00 2001 From: Francis Hilaire Date: Thu, 26 Sep 2024 18:24:56 +0200 Subject: [PATCH 11/11] Handle Panther driver for Sylius 1.12 --- .../managing_payment_method.feature | 7 ++--- .../stripe_js/managing_payment_method.feature | 7 ++--- tests/Behat/Bug/PantherCookieSetter.php | 31 +++++++++++++++++++ tests/Behat/Resources/services.xml | 1 + tests/Behat/Resources/services/bug.xml | 10 ++++++ 5 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 tests/Behat/Bug/PantherCookieSetter.php create mode 100644 tests/Behat/Resources/services/bug.xml diff --git a/features/admin/stripe_checkout_session/managing_payment_method.feature b/features/admin/stripe_checkout_session/managing_payment_method.feature index ff5cfc4..d1552b8 100644 --- a/features/admin/stripe_checkout_session/managing_payment_method.feature +++ b/features/admin/stripe_checkout_session/managing_payment_method.feature @@ -6,11 +6,11 @@ Feature: Adding a new Stripe Checkout Session payment method Background: Given the store operates on a single channel in "United States" + And I am logged in as an administrator @ui @javascript Scenario: Adding a new stripe payment method using authorize - Given I am logged in as an administrator - And I want to create a new Stripe Checkout Session payment method + Given I want to create a new Stripe Checkout Session payment method When I name it "Stripe Checkout Session" in "English (United States)" And I specify its code as "stripe_sca_test" And I configure it with test stripe gateway data "TEST", "TEST" @@ -23,8 +23,7 @@ Feature: Adding a new Stripe Checkout Session payment method @ui @javascript Scenario: Adding a new stripe payment method not using authorize - Given I am logged in as an administrator - And I want to create a new Stripe Checkout Session payment method + Given I want to create a new Stripe Checkout Session payment method When I name it "Stripe Checkout Session" in "English (United States)" And I specify its code as "stripe_sca_test" And I configure it with test stripe gateway data "TEST", "TEST" diff --git a/features/admin/stripe_js/managing_payment_method.feature b/features/admin/stripe_js/managing_payment_method.feature index b20d79a..7ae29d8 100644 --- a/features/admin/stripe_js/managing_payment_method.feature +++ b/features/admin/stripe_js/managing_payment_method.feature @@ -6,11 +6,11 @@ Feature: Adding a new Stripe JS payment method Background: Given the store operates on a single channel in "United States" + And I am logged in as an administrator @ui @javascript Scenario: Adding a new stripe payment method using authorize - Given I am logged in as an administrator - And I want to create a new Stripe JS payment method + Given I want to create a new Stripe JS payment method When I name it "Stripe JS" in "English (United States)" And I specify its code as "stripe_sca_test" And I configure it with test stripe gateway data "TEST", "TEST" @@ -23,8 +23,7 @@ Feature: Adding a new Stripe JS payment method @ui @javascript Scenario: Adding a new stripe payment method not using authorize - Given I am logged in as an administrator - And I want to create a new Stripe JS payment method + Given I want to create a new Stripe JS payment method When I name it "Stripe JS" in "English (United States)" And I specify its code as "stripe_sca_test" And I configure it with test stripe gateway data "TEST", "TEST" diff --git a/tests/Behat/Bug/PantherCookieSetter.php b/tests/Behat/Bug/PantherCookieSetter.php new file mode 100644 index 0000000..0cf3c7f --- /dev/null +++ b/tests/Behat/Bug/PantherCookieSetter.php @@ -0,0 +1,31 @@ +minkSession->getDriver(); + + if ($driver instanceof PantherDriver) { + if (!$driver->isStarted()) { + $driver->start(); + } + } + + $this->decoratedCookieSetter->setCookie($name, $value); + } +} diff --git a/tests/Behat/Resources/services.xml b/tests/Behat/Resources/services.xml index 27485e3..1b2a5c7 100644 --- a/tests/Behat/Resources/services.xml +++ b/tests/Behat/Resources/services.xml @@ -2,6 +2,7 @@ + diff --git a/tests/Behat/Resources/services/bug.xml b/tests/Behat/Resources/services/bug.xml new file mode 100644 index 0000000..5539df3 --- /dev/null +++ b/tests/Behat/Resources/services/bug.xml @@ -0,0 +1,10 @@ + + + + + + + + + +