Skip to content

Commit

Permalink
Make method more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Jun 26, 2024
1 parent 4a3c60a commit 68fa984
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 39 deletions.
4 changes: 2 additions & 2 deletions features/shop/stripe_checkout_session/api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: Paying with Stripe Checkout Session during checkout
Given the store has a payment method "Stripe" with a code "stripe" and Stripe Checkout Session payment gateway without using authorize
And I added product "PHP T-Shirt" to the cart
And I have proceeded selecting "Stripe" payment method
When I see the payment configuration
When I see the payment configuration for Stripe Checkout Session
Then I should be able to get "publishable_key" with value "pk_test_publishablekey"
And I should be able to get "use_authorize" with a boolean value 0
And I should be able to get "stripe_checkout_session_url" with value "https://checkout.stripe.com/c/pay/cs_1"
Expand All @@ -27,7 +27,7 @@ Feature: Paying with Stripe Checkout Session during checkout
Given the store has a payment method "Stripe authorize" with a code "stripe_authorize" and Stripe Checkout Session payment gateway using authorize
And I added product "PHP T-Shirt" to the cart
And I have proceeded selecting "Stripe authorize" payment method
When I see the payment configuration
When I see the payment configuration for Stripe Checkout Session
Then I should be able to get "publishable_key" with value "pk_test_publishablekey"
And I should be able to get "use_authorize" with a boolean value 1
And I should be able to get "stripe_checkout_session_url" with value "https://checkout.stripe.com/c/pay/cs_1"
53 changes: 23 additions & 30 deletions tests/Behat/Context/Api/Shop/CartContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,12 @@ public function __construct(
}

/**
* @When /^I see the payment configuration$/
* @When /^I see the payment configuration for Stripe Checkout Session$/
*/
public function iSeeThePaymentConfiguration(): void
public function iSeeThePaymentConfigurationForStripeCheckoutSession(): void
{
$this->stripeCheckoutSessionMocker->mockCreatePayment(function () {
$tokenValue = $this->getCartTokenValue();

$this->shopClient->show(
Resources::ORDERS,
sprintf(
'%s/%s/%s/configuration',
$tokenValue,
Resources::PAYMENTS,
$this->getCart()['payments'][0]['id']
)
);

$this->sharedStorage->set('response', $this->shopClient->getLastResponse());
$this->stripeCheckoutSessionMocker->mockCaptureOrAuthorize(function () {
$this->showPaymentConfiguration();
});
}

Expand All @@ -67,20 +55,8 @@ public function iSeeThePaymentConfiguration(): void
*/
public function iSeeThePaymentConfigurationForStripeJs(): void
{
$this->stripeJsMocker->mockCreatePayment(function () {
$tokenValue = $this->getCartTokenValue();

$this->shopClient->show(
Resources::ORDERS,
sprintf(
'%s/%s/%s/configuration',
$tokenValue,
Resources::PAYMENTS,
$this->getCart()['payments'][0]['id']
)
);

$this->sharedStorage->set('response', $this->shopClient->getLastResponse());
$this->stripeJsMocker->mockCaptureOrAuthorize(function () {
$this->showPaymentConfiguration();
});
}

Expand All @@ -104,6 +80,23 @@ public function iShouldBeAbleToGetWithABooleanValue(string $key, bool $expectedV
Assert::eq($value, $expectedValue);
}

function showPaymentConfiguration(): void
{
$tokenValue = $this->getCartTokenValue();

$this->shopClient->show(
Resources::ORDERS,
sprintf(
'%s/%s/%s/configuration',
$tokenValue,
Resources::PAYMENTS,
$this->getCart()['payments'][0]['id']
)
);

$this->sharedStorage->set('response', $this->shopClient->getLastResponse());
}

private function getCart(): array
{
return $this->responseChecker->getResponseContent($this->shopClient->show(Resources::ORDERS, $this->getCartTokenValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
*/
public function iConfirmMyOrderWithStripePayment(): void
{
$this->stripeCheckoutSessionMocker->mockCreatePayment(function () {
$this->stripeCheckoutSessionMocker->mockCaptureOrAuthorize(function () {
$this->summaryPage->confirmOrder();
});
}
Expand Down Expand Up @@ -147,7 +147,7 @@ public function iClickOnGoBackDuringMyStripePayment(): void
*/
public function iTryToPayAgainWithStripePayment(): void
{
$this->stripeCheckoutSessionMocker->mockCreatePayment(function () {
$this->stripeCheckoutSessionMocker->mockCaptureOrAuthorize(function () {
$this->orderDetails->pay();
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Behat/Context/Ui/Shop/StripeJsShopContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function theStripeJsFormIsDisplayedAndICompleteThePaymentWithoutWebhookUs
*/
public function iConfirmMyOrderWithStripePayment(): void
{
$this->stripeJsMocker->mockCreatePayment(function () {
$this->stripeJsMocker->mockCaptureOrAuthorize(function () {
$this->summaryPage->confirmOrder();
});
}
Expand All @@ -147,7 +147,7 @@ public function iClickOnGoBackDuringMyStripePayment(): void
*/
public function iTryToPayAgainWithStripePayment(): void
{
$this->stripeJsMocker->mockCreatePayment(function () {
$this->stripeJsMocker->mockCaptureOrAuthorize(function () {
$this->orderDetails->pay();
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Behat/Mocker/StripeCheckoutSessionMocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
$this->refundMocker = $refundMocker;
}

public function mockCreatePayment(callable $action): void
public function mockCaptureOrAuthorize(callable $action): void
{
$this->checkoutSessionMocker->mockCreateAction();

Expand Down
5 changes: 3 additions & 2 deletions tests/Behat/Mocker/StripeJsMocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public function __construct(
$this->refundMocker = $refundMocker;
}

public function mockCreatePayment(callable $action): void
public function mockCaptureOrAuthorize(callable $action): void
{
$this->paymentIntentMocker->mockCreateAction();
$this->mocker->unmockAll();

$this->paymentIntentMocker->mockCreateAction();
$this->mockPaymentIntentSync(
$action,
PaymentIntent::STATUS_REQUIRES_PAYMENT_METHOD
Expand Down
2 changes: 2 additions & 0 deletions tests/Behat/Page/Admin/PaymentMethod/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public function setStripeIsAuthorized(bool $isAuthorized): void
} else {
$this->getElement('use_authorize')->uncheck();
}

sleep(1);
}

/**
Expand Down

0 comments on commit 68fa984

Please sign in to comment.