Skip to content

Commit

Permalink
Merge pull request #50 from FLUX-SE/fix-double-admin-actions
Browse files Browse the repository at this point in the history
[FIX] double admin actions
  • Loading branch information
Prometee authored Jan 4, 2024
2 parents b7ab104 + 6dc653c commit 50c3f36
Show file tree
Hide file tree
Showing 27 changed files with 927 additions and 306 deletions.
40 changes: 13 additions & 27 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ 8.0 ]
php: [ 8.1 ]
symfony: [ ^5.4, ^6.0 ]

steps:
Expand Down Expand Up @@ -100,6 +100,11 @@ jobs:
name: Run PHPStan
run: vendor/bin/phpstan analyse
if: always() && steps.end-of-setup.outcome == 'success'

-
name: Run PHPSpec
run: vendor/bin/phpspec run --ansi -f progress --no-interaction
if: always() && steps.end-of-setup.outcome == 'success'
tests:
runs-on: ubuntu-latest

Expand All @@ -108,40 +113,25 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [7.3, 7.4, 8.0]
php: [7.4, 8.0, 8.1, 8.2, 8.3]
symfony: [^5.4, ^6.0]
sylius: [~1.9.0, ~1.10.0, ~1.11.0, ~1.12.0]
sylius: [~1.10.0, ~1.11.0, ~1.12.0]
node: [18.x]
mysql: [5.7]

exclude:
-
sylius: ~1.9.0
php: 8.0
-
sylius: ~1.10.0
php: 7.3
-
sylius: ~1.10.0
symfony: ^6.0
-
sylius: ~1.11.0
php: 7.3
-
sylius: ~1.11.0
php: 7.4
-
sylius: ~1.11.0
symfony: ^6.0
-
sylius: ~1.12.0
php: 7.3
-
sylius: ~1.12.0
php: 7.4
-
php: 7.3
symfony: ^6.0
-
php: 7.4
symfony: ^6.0
Expand Down Expand Up @@ -220,14 +210,6 @@ jobs:
if: matrix.sylius != ''
run: composer require "sylius/sylius:${{ matrix.sylius }}" --no-update --no-scripts --no-interaction

-
name: Fix build on Sylius 1.9
if: matrix.sylius == '~1.9.0'
run: |
composer require "friendsofsymfony/oauth-server-bundle:>2.0.0-alpha.0 ^2.0@dev" --no-update --no-scripts --no-interaction
# Sylius issues on `json_array` type not existing
composer require "doctrine/dbal:^2.6" --no-update --no-scripts --no-interaction
composer require "nyholm/psr7" --no-update --no-scripts --no-interaction
-
name: Fix build on Sylius 1.10
if: matrix.sylius == '~1.10.0'
Expand All @@ -238,7 +220,11 @@ jobs:
if: matrix.sylius == '~1.11.0'
run: |
composer require "nyholm/psr7" --no-update --no-scripts --no-interaction
-
name: Fix build with PHP 8.3
if: matrix.php == '8.3'
run: |
composer remove --dev "phpspec/phpspec" --no-update --no-scripts --no-interaction
-
name: Install PHP dependencies
run: composer install --no-interaction
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"phpspec/phpspec": "^7.0",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan-doctrine": "^1",
"phpstan/phpstan-strict-rules": "^1",
"phpstan/phpstan-webmozart-assert": "^1",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan-doctrine": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpstan/phpstan-webmozart-assert": "^1.0",
"phpunit/phpunit": "^9.5",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"sylius-labs/coding-standard": "^4.0",
Expand All @@ -42,8 +42,8 @@
"symfony/intl": "^5.4|^6.0",
"symfony/runtime": "^5.4|^6.0",
"symfony/web-profiler-bundle": "^5.4|^6.0",
"symfony/webpack-encore-bundle": "^1.16",
"vimeo/psalm": "^4|^5"
"symfony/webpack-encore-bundle": "^1|^2",
"vimeo/psalm": "^5"
},
"autoload": {
"psr-4": { "FluxSE\\SyliusPayumStripePlugin\\": "src/" }
Expand Down
25 changes: 25 additions & 0 deletions features/admin/cancel_authorized_order.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@managing_orders
Feature: Canceling an authorized order
In order to cancel an order already authorized
As an Administrator
I want to be able to cancel a Stripe authorized order

Background:
Given the store operates on a single channel in "United States"
And the store has a product "Green Arrow"
And the store ships everywhere for free
And the store has a payment method "Stripe" with a code "stripe" and Stripe payment gateway using authorize
And there is a customer "[email protected]" that placed an order "#00000001"
And the customer bought a single "Green Arrow"
And the customer chose "Free" shipping method to "United States" with "Stripe" payment
And this order is already authorized as "pi_123" Stripe payment intent
And I am logged in as an administrator

@ui
Scenario: Initializing the Stripe refund
Given I am viewing the summary of this order
And I am prepared to cancel this order
When I cancel this order
Then I should be notified that it has been successfully updated
And it should have payment with state cancelled
And it should have payment state cancelled
25 changes: 25 additions & 0 deletions features/admin/cancel_order.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@managing_orders
Feature: Canceling an order
In order to cancel a not paid order
As an Administrator
I want to be able to cancel a Stripe not paid order

Background:
Given the store operates on a single channel in "United States"
And the store has a product "Green Arrow"
And the store ships everywhere for free
And the store has a payment method "Stripe" with a code "stripe" and Stripe payment gateway without using authorize
And there is a customer "[email protected]" that placed an order "#00000001"
And the customer bought a single "Green Arrow"
And the customer chose "Free" shipping method to "United States" with "Stripe" payment
And this order is not yet paid as "cs_123" Stripe checkout session
And I am logged in as an administrator

@ui
Scenario: Initializing the Stripe refund
Given I am viewing the summary of this order
And I am prepared to expire the checkout session this order
When I cancel this order
Then I should be notified that it has been successfully updated
And it should have payment with state cancelled
And it should have payment state cancelled
25 changes: 25 additions & 0 deletions features/admin/capture_authorization_order.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@managing_orders
Feature: Capturing the authorization of an order
In order to complete a payment
As an Administrator
I want to be able to capture the authorization of a Stripe paid order

Background:
Given the store operates on a single channel in "United States"
And the store has a product "Green Arrow"
And the store ships everywhere for free
And the store has a payment method "Stripe" with a code "stripe" and Stripe payment gateway using authorize
And there is a customer "[email protected]" that placed an order "#00000001"
And the customer bought a single "Green Arrow"
And the customer chose "Free" shipping method to "United States" with "Stripe" payment
And this order is already authorized as "pi_123" Stripe payment intent
And I am logged in as an administrator

@ui
Scenario: Initializing the Stripe refund
Given I am viewing the summary of this order
And I am prepared to capture authorization of this order
When I mark this order as paid
Then I should be notified that the order's payment has been successfully completed
And it should have payment with state completed
And it should have payment state completed
25 changes: 25 additions & 0 deletions features/admin/refunding_order.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@managing_orders
Feature: Refunding an order
In order to return the money to the Customer
As an Administrator
I want to be able to refund a Stripe paid order

Background:
Given the store operates on a single channel in "United States"
And the store has a product "Green Arrow"
And the store ships everywhere for free
And the store has a payment method "Stripe" with a code "stripe" and Stripe payment gateway without using authorize
And there is a customer "[email protected]" that placed an order "#00000001"
And the customer bought a single "Green Arrow"
And the customer chose "Free" shipping method to "United States" with "Stripe" payment
And this order is already paid as "pi_123" Stripe payment intent
And I am logged in as an administrator

@ui
Scenario: Initializing the Stripe refund
Given I am viewing the summary of this order
And I am prepared to refund this order
When I mark this order's payment as refunded
Then I should be notified that the order's payment has been successfully refunded
And it should have payment with state refunded
And it's payment state should be refunded
5 changes: 4 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ parameters:
- '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./'
- '/Parameter #1 \$request \(Payum\\Core\\Request\\Convert\) of method FluxSE\\SyliusPayumStripePlugin\\Action\\ConvertPaymentAction::execute\(\) should be contravariant with parameter \$request \(mixed\) of method Payum\\Core\\Action\\ActionInterface::execute\(\)/'
- message: '/Call to an undefined method Mockery\\ExpectationInterface\|Mockery\\HigherOrderMessage::(once|andReturnUsing)\(\)\./'
path: tests/Behat/Mocker/StripeCheckoutSessionMocker.php
paths:
- tests/Behat/Mocker/Api/CheckoutSessionMocker.php
- tests/Behat/Mocker/Api/PaymentIntentMocker.php
- tests/Behat/Mocker/Api/RefundMocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
use Payum\Core\Security\TokenFactoryInterface;
use Payum\Core\Security\TokenInterface;
use PhpSpec\ObjectBehavior;
use SM\Event\TransitionEvent;
use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;

final class CancelAuthorizedOrderProcessorSpec extends ObjectBehavior
final class CancelOrderProcessorSpec extends ObjectBehavior
{
public function let(
CancelRequestFactoryInterface $cancelRequestFactory,
Expand All @@ -27,6 +28,7 @@ public function let(
public function it_is_invokable(
Payum $payum,
PaymentInterface $payment,
TransitionEvent $event,
PaymentMethodInterface $paymentMethod,
GatewayConfigInterface $gatewayConfig,
GatewayInterface $gateway,
Expand All @@ -35,7 +37,6 @@ public function it_is_invokable(
CancelRequestFactoryInterface $cancelRequestFactory,
ModelAggregateInterface $request
): void {
$payment->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED);

$payment->getMethod()->willReturn($paymentMethod);
$paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);
Expand All @@ -46,21 +47,26 @@ public function it_is_invokable(
$payum->getGateway($gatewayName)->willReturn($gateway);

$payum->getTokenFactory()->willReturn($tokenFactory);
$tokenFactory->createToken($gatewayName, $payment, 'sylius_shop_order_after_pay')->willReturn($token);
$tokenFactory->createToken($gatewayName, $payment, 'payum_notify_do')->willReturn($token);

$request->beConstructedWith([$token]);
$cancelRequestFactory->createNewWithToken($token)->willReturn($request);

$gateway->execute($request)->shouldBeCalled();

$this->__invoke($payment);
$this->__invoke($payment, $event);
}

public function it_do_nothing_when_it_is_not_an_authorized_state(
PaymentInterface $payment
public function it_do_nothing_when_gateway_is_unknown(
PaymentInterface $payment,
TransitionEvent $event,
PaymentMethodInterface $paymentMethod,
GatewayConfigInterface $gatewayConfig
): void {
$payment->getState()->willReturn(PaymentInterface::STATE_COMPLETED);
$payment->getMethod()->willReturn($paymentMethod);
$paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);
$gatewayConfig->getConfig()->willReturn(['factory' => 'foo']);

$this->__invoke($payment);
$this->__invoke($payment, $event);
}
}
30 changes: 24 additions & 6 deletions spec/StateMachine/CompleteAuthorizedOrderProcessorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Payum\Core\Security\TokenFactoryInterface;
use Payum\Core\Security\TokenInterface;
use PhpSpec\ObjectBehavior;
use SM\Event\TransitionEvent;
use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
Expand All @@ -27,6 +28,7 @@ public function let(
public function it_is_invokable(
Payum $payum,
PaymentInterface $payment,
TransitionEvent $event,
PaymentMethodInterface $paymentMethod,
GatewayConfigInterface $gatewayConfig,
GatewayInterface $gateway,
Expand All @@ -35,7 +37,7 @@ public function it_is_invokable(
CaptureRequestFactoryInterface $captureRequestFactory,
ModelAggregateInterface $request
): void {
$payment->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED);
$event->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED);

$payment->getMethod()->willReturn($paymentMethod);
$paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);
Expand All @@ -46,21 +48,37 @@ public function it_is_invokable(
$payum->getGateway($gatewayName)->willReturn($gateway);

$payum->getTokenFactory()->willReturn($tokenFactory);
$tokenFactory->createToken($gatewayName, $payment, 'sylius_shop_order_after_pay')->willReturn($token);
$tokenFactory->createToken($gatewayName, $payment, 'payum_notify_do')->willReturn($token);

$request->beConstructedWith([$token]);
$captureRequestFactory->createNewWithToken($token)->willReturn($request);

$gateway->execute($request)->shouldBeCalled();

$this->__invoke($payment);
$this->__invoke($payment, $event);
}

public function it_do_nothing_when_it_is_not_an_authorized_state(
PaymentInterface $payment
PaymentInterface $payment,
TransitionEvent $event
): void {
$event->getState()->willReturn(PaymentInterface::STATE_COMPLETED);

$this->__invoke($payment, $event);
}

public function it_do_nothing_when_gateway_is_unknown(
PaymentInterface $payment,
TransitionEvent $event,
PaymentMethodInterface $paymentMethod,
GatewayConfigInterface $gatewayConfig
): void {
$payment->getState()->willReturn(PaymentInterface::STATE_COMPLETED);
$event->getState()->willReturn(PaymentInterface::STATE_AUTHORIZED);

$payment->getMethod()->willReturn($paymentMethod);
$paymentMethod->getGatewayConfig()->willReturn($gatewayConfig);
$gatewayConfig->getConfig()->willReturn(['factory' => 'foo']);

$this->__invoke($payment);
$this->__invoke($payment, $event);
}
}
Loading

0 comments on commit 50c3f36

Please sign in to comment.