Skip to content

Commit

Permalink
Add admin StripeJS behat tests and fix use_authorize click
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Jun 25, 2024
1 parent ef956d0 commit a8a07c7
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -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 "[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: 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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 "[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 this order is not yet paid as "cs_123" Stripe Checkout Session
And I am logged in as an administrator

@ui
Expand Down
Original file line number Diff line number Diff line change
@@ -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 "[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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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
And the payment method "Stripe Checkout Session" should appear in the registry
25 changes: 25 additions & 0 deletions features/admin/stripe_checkout_session/refunding_order.feature
Original file line number Diff line number Diff line change
@@ -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 "[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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 "[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
Expand Down
35 changes: 35 additions & 0 deletions features/admin/stripe_js/cancel_order.feature
Original file line number Diff line number Diff line change
@@ -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 "[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 "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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 "[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
Expand Down
35 changes: 35 additions & 0 deletions features/admin/stripe_js/managing_payment_method.feature
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 "[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
Expand Down
42 changes: 34 additions & 8 deletions tests/Behat/Context/Ui/Admin/ManagingOrdersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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$/
*/
Expand Down Expand Up @@ -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
*/
Expand Down
14 changes: 12 additions & 2 deletions tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
9 changes: 5 additions & 4 deletions tests/Behat/Page/Admin/PaymentMethod/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
}

Expand Down Expand Up @@ -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();
}
}

Expand Down

0 comments on commit a8a07c7

Please sign in to comment.