diff --git a/features/admin/stripe_checkout_session/cancel_authorized_order.feature b/features/admin/stripe_checkout_session/cancel_authorized_order.feature new file mode 100644 index 0000000..0b5fcf4 --- /dev/null +++ b/features/admin/stripe_checkout_session/cancel_authorized_order.feature @@ -0,0 +1,25 @@ +@managing_orders +Feature: Canceling an authorized order with Stripe Checkout Session + 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 Checkout Session payment gateway using authorize + And there is a customer "oliver@teamarrow.com" 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: Cancelling the order with an authorized payment + 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 diff --git a/features/admin/cancel_order.feature b/features/admin/stripe_checkout_session/cancel_order.feature similarity index 88% rename from features/admin/cancel_order.feature rename to features/admin/stripe_checkout_session/cancel_order.feature index 81039df..ef79c8c 100644 --- a/features/admin/cancel_order.feature +++ b/features/admin/stripe_checkout_session/cancel_order.feature @@ -1,5 +1,5 @@ @managing_orders -Feature: Canceling an order +Feature: Canceling an order with Stripe Checkout Session In order to cancel a not paid order As an Administrator I want to be able to cancel a Stripe not paid order @@ -8,11 +8,11 @@ Feature: Canceling an order 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 the store has a payment method "Stripe" with a code "stripe" and Stripe Checkout Session payment gateway without using authorize And there is a customer "oliver@teamarrow.com" 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 this order is not yet paid as "cs_123" Stripe Checkout Session And I am logged in as an administrator @ui diff --git a/features/admin/stripe_checkout_session/capture_authorization_order.feature b/features/admin/stripe_checkout_session/capture_authorization_order.feature new file mode 100644 index 0000000..7782c00 --- /dev/null +++ b/features/admin/stripe_checkout_session/capture_authorization_order.feature @@ -0,0 +1,25 @@ +@managing_orders +Feature: Capturing the authorization of an order with Stripe Checkout Session + 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 Checkout Session payment gateway using authorize + And there is a customer "oliver@teamarrow.com" 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 diff --git a/features/admin/managing_payment_method.feature b/features/admin/stripe_checkout_session/managing_payment_method.feature similarity index 86% rename from features/admin/managing_payment_method.feature rename to features/admin/stripe_checkout_session/managing_payment_method.feature index 88b40e7..d1552b8 100644 --- a/features/admin/managing_payment_method.feature +++ b/features/admin/stripe_checkout_session/managing_payment_method.feature @@ -1,5 +1,5 @@ @managing_payment_methods -Feature: Adding a new Stripe payment method +Feature: Adding a new Stripe Checkout Session payment method In order to allow payment for orders, using the Stripe gateway As an Administrator I want to add new payment methods to the system @@ -10,7 +10,7 @@ Feature: Adding a new Stripe payment method @ui @javascript Scenario: Adding a new stripe payment method using authorize - Given I want to create a new Stripe 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,7 +23,7 @@ Feature: Adding a new Stripe payment method @ui @javascript Scenario: Adding a new stripe payment method not using authorize - Given I want to create a new Stripe 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" @@ -32,4 +32,4 @@ Feature: Adding a new Stripe payment method And I add it Then I should be notified that it has been successfully created And I shouldn't see a warning message under the use authorize field - And the payment method "Stripe Checkout Session" should appear in the registry \ No newline at end of file + And the payment method "Stripe Checkout Session" should appear in the registry diff --git a/features/admin/stripe_checkout_session/refunding_order.feature b/features/admin/stripe_checkout_session/refunding_order.feature new file mode 100644 index 0000000..0513286 --- /dev/null +++ b/features/admin/stripe_checkout_session/refunding_order.feature @@ -0,0 +1,25 @@ +@managing_orders +Feature: Refunding an order with Stripe Checkout Session + 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 Checkout Session payment gateway without using authorize + And there is a customer "oliver@teamarrow.com" 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 diff --git a/features/admin/cancel_authorized_order.feature b/features/admin/stripe_js/cancel_authorized_order.feature similarity index 91% rename from features/admin/cancel_authorized_order.feature rename to features/admin/stripe_js/cancel_authorized_order.feature index 3ee4100..a61420d 100644 --- a/features/admin/cancel_authorized_order.feature +++ b/features/admin/stripe_js/cancel_authorized_order.feature @@ -1,5 +1,5 @@ @managing_orders -Feature: Canceling an authorized order +Feature: Canceling an authorized order with Stripe JS In order to cancel an order already authorized As an Administrator I want to be able to cancel a Stripe authorized order @@ -8,7 +8,7 @@ Feature: Canceling an authorized order 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 the store has a payment method "Stripe" with a code "stripe" and Stripe JS payment gateway using authorize And there is a customer "oliver@teamarrow.com" 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 diff --git a/features/admin/stripe_js/cancel_order.feature b/features/admin/stripe_js/cancel_order.feature new file mode 100644 index 0000000..9a99fc5 --- /dev/null +++ b/features/admin/stripe_js/cancel_order.feature @@ -0,0 +1,35 @@ +@managing_orders +Feature: Canceling an order with Stripe JS + 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 JS payment gateway without using authorize + And there is a customer "oliver@teamarrow.com" 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 "pi_123" Stripe JS + And I am logged in as an administrator + + @ui + Scenario: Cancelling the order when a payment intent is still available + Given I am viewing the summary of this order + And I am prepared to cancel the payment intent on 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 + + @ui + Scenario: Cancelling the order after the customer canceled the payment + Given this order payment has been canceled + And 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 diff --git a/features/admin/capture_authorization_order.feature b/features/admin/stripe_js/capture_authorization_order.feature similarity index 90% rename from features/admin/capture_authorization_order.feature rename to features/admin/stripe_js/capture_authorization_order.feature index 4ac3d05..324c480 100644 --- a/features/admin/capture_authorization_order.feature +++ b/features/admin/stripe_js/capture_authorization_order.feature @@ -1,5 +1,5 @@ @managing_orders -Feature: Capturing the authorization of an order +Feature: Capturing the authorization of an order with Stripe JS In order to complete a payment As an Administrator I want to be able to capture the authorization of a Stripe paid order @@ -8,7 +8,7 @@ Feature: Capturing the authorization of an order 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 the store has a payment method "Stripe" with a code "stripe" and Stripe JS payment gateway using authorize And there is a customer "oliver@teamarrow.com" 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 diff --git a/features/admin/stripe_js/managing_payment_method.feature b/features/admin/stripe_js/managing_payment_method.feature new file mode 100644 index 0000000..7ae29d8 --- /dev/null +++ b/features/admin/stripe_js/managing_payment_method.feature @@ -0,0 +1,35 @@ +@managing_payment_methods +Feature: Adding a new Stripe JS payment method + In order to allow payment for orders, using the Stripe gateway + As an Administrator + I want to add new payment methods to the system + + 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 + 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" + And I add a webhook secret key "TEST" + And I use authorize + And I add it + Then I should be notified that it has been successfully created + And I should see a warning message under the use authorize field + And the payment method "Stripe JS" should appear in the registry + + @ui @javascript + Scenario: Adding a new stripe payment method not using authorize + 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" + And I add a webhook secret key "TEST" + And I don't use authorize + And I add it + Then I should be notified that it has been successfully created + And I shouldn't see a warning message under the use authorize field + And the payment method "Stripe JS" should appear in the registry diff --git a/features/admin/refunding_order.feature b/features/admin/stripe_js/refunding_order.feature similarity index 91% rename from features/admin/refunding_order.feature rename to features/admin/stripe_js/refunding_order.feature index 502f661..494d263 100644 --- a/features/admin/refunding_order.feature +++ b/features/admin/stripe_js/refunding_order.feature @@ -1,5 +1,5 @@ @managing_orders -Feature: Refunding an order +Feature: Refunding an order with Stripe JS In order to return the money to the Customer As an Administrator I want to be able to refund a Stripe paid order @@ -8,7 +8,7 @@ Feature: Refunding an order 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 the store has a payment method "Stripe" with a code "stripe" and Stripe JS payment gateway without using authorize And there is a customer "oliver@teamarrow.com" 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 diff --git a/tests/Behat/Context/Ui/Admin/ManagingOrdersContext.php b/tests/Behat/Context/Ui/Admin/ManagingOrdersContext.php index e65c955..b5b5ef2 100644 --- a/tests/Behat/Context/Ui/Admin/ManagingOrdersContext.php +++ b/tests/Behat/Context/Ui/Admin/ManagingOrdersContext.php @@ -19,14 +19,11 @@ class ManagingOrdersContext implements Context { - /** @var FactoryInterface */ - private $stateMachineFactory; + private FactoryInterface $stateMachineFactory; - /** @var ObjectManager */ - private $objectManager; + private ObjectManager $objectManager; - /** @var StripeCheckoutSessionMocker */ - private $stripeCheckoutSessionMocker; + private StripeCheckoutSessionMocker $stripeCheckoutSessionMocker; public function __construct( FactoryInterface $stateMachineFactory, @@ -85,9 +82,9 @@ public function thisOrderIsAlreadyAuthorized(OrderInterface $order, string $stri } /** - * @Given /^(this order) is not yet paid as "([^"]+)" Stripe checkout session$/ + * @Given /^(this order) is not yet paid as "([^"]+)" Stripe Checkout Session$/ */ - public function thisOrderIsNotYetPaid(OrderInterface $order, string $stripeCheckoutSessionId): void + public function thisOrderIsNotYetPaidStripeCheckoutSession(OrderInterface $order, string $stripeCheckoutSessionId): void { /** @var PaymentInterface $payment */ $payment = $order->getPayments()->first(); @@ -103,6 +100,24 @@ public function thisOrderIsNotYetPaid(OrderInterface $order, string $stripeCheck $this->objectManager->flush(); } + /** + * @Given /^(this order) is not yet paid as "([^"]+)" Stripe JS$/ + */ + public function thisOrderIsNotYetPaidStripeJs(OrderInterface $order, string $stripePaymentIntentId): void + { + /** @var PaymentInterface $payment */ + $payment = $order->getPayments()->first(); + + $details = [ + 'object' => PaymentIntent::OBJECT_NAME, + 'id' => $stripePaymentIntentId, + 'status' => PaymentIntent::STATUS_REQUIRES_PAYMENT_METHOD, + ]; + $payment->setDetails($details); + + $this->objectManager->flush(); + } + /** * @Given /^(this order) payment has been canceled$/ */ @@ -141,6 +156,17 @@ public function iAmPreparedToExpireTheCheckoutSessionOnThisOrder(): void $this->stripeCheckoutSessionMocker->mockExpirePayment(); } + /** + * @Given I am prepared to cancel the payment intent on this order + */ + public function iAmPreparedToExpireThePaymentIntentOnThisOrder(): void + { + $this->stripeCheckoutSessionMocker->mockCancelPayment( + PaymentIntent::STATUS_REQUIRES_PAYMENT_METHOD, + PaymentIntent::CAPTURE_METHOD_AUTOMATIC + ); + } + /** * @Given I am prepared to refund this order */ diff --git a/tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php b/tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php index 2495d81..465a27d 100644 --- a/tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php +++ b/tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php @@ -20,15 +20,25 @@ public function __construct(CreatePageInterface $createPage) } /** - * @Given /^I want to create a new Stripe payment method$/ + * @Given /^I want to create a new Stripe Checkout Session payment method$/ * * @throws UnexpectedPageException */ - public function iWantToCreateANewStripePaymentMethod(): void + public function iWantToCreateANewStripeCheckoutSessionPaymentMethod(): void { $this->createPage->open(['factory' => 'stripe_checkout_session']); } + /** + * @Given /^I want to create a new Stripe JS payment method$/ + * + * @throws UnexpectedPageException + */ + public function iWantToCreateANewStripeJsPaymentMethod(): void + { + $this->createPage->open(['factory' => 'stripe_js']); + } + /** * @When I configure it with test stripe gateway data :secretKey, :publishableKey */ diff --git a/tests/Behat/Page/Admin/PaymentMethod/CreatePage.php b/tests/Behat/Page/Admin/PaymentMethod/CreatePage.php index 64448d4..d14d0bd 100644 --- a/tests/Behat/Page/Admin/PaymentMethod/CreatePage.php +++ b/tests/Behat/Page/Admin/PaymentMethod/CreatePage.php @@ -9,14 +9,14 @@ final class CreatePage extends BaseCreatePage implements CreatePageInterface { - /** @var int */ - private $webhookSecretKeysListIndex = 0; + private int $webhookSecretKeysListIndex = 0; protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ 'webhook_secret_keys_list_element' => '#sylius_payment_method_gatewayConfig_config_webhook_secret_keys_%index%', 'use_authorize_info' => '#sylius_payment_method_gatewayConfig_config_use_authorize_info', + 'use_authorize' => '#sylius_payment_method_gatewayConfig_config_use_authorize', ]); } @@ -51,9 +51,10 @@ public function setStripeWebhookSecretKey(string $webhookSecretKey): void public function setStripeIsAuthorized(bool $isAuthorized): void { if ($isAuthorized) { - $this->getDocument()->checkField('Use authorize'); + // ->check() is not working anymore because the checkbox is not visible + $this->getElement('use_authorize')->click(); } else { - $this->getDocument()->uncheckField('Use authorize'); + $this->getElement('use_authorize')->uncheck(); } }