mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
@paying_for_order&&@api fully working
This commit is contained in:
parent
8adbd8b31e
commit
8bdba2209c
5 changed files with 30 additions and 64 deletions
|
|
@ -13,7 +13,7 @@ Feature: Preventing to pay for the cancelled order
|
|||
And the store allows paying Offline
|
||||
And there is a customer "sylius@example.com" that placed an order "#00000022"
|
||||
|
||||
@ui @no-api
|
||||
@ui @api
|
||||
Scenario: Not being able to pay for cancelled order
|
||||
Given the customer bought 3 "Iron Maiden T-Shirt" products
|
||||
And the customer chose "Free" shipping method to "United States" with "Offline" payment
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ Feature: Viewing available payment methods based on current channel
|
|||
And I should see "Bank of America" and "Offline" payment methods
|
||||
But I should not see "Bank of Poland" and "Bank of Universe" payment methods
|
||||
|
||||
@api @ui
|
||||
@ui @api
|
||||
Scenario: Seeing shipping methods that are available in another channel as an logged in customer
|
||||
Given I am a logged in customer
|
||||
And I am in the "Poland" channel
|
||||
|
|
|
|||
|
|
@ -15,17 +15,20 @@ namespace Sylius\Behat\Context\Api\Shop\Checkout;
|
|||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Sylius\Behat\Client\ApiClientInterface;
|
||||
use Sylius\Behat\Client\RequestFactoryInterface;
|
||||
use Sylius\Behat\Client\ResponseCheckerInterface;
|
||||
use Sylius\Behat\Context\Api\Resources;
|
||||
use Sylius\Behat\Service\SharedStorageInterface;
|
||||
use Sylius\Component\Core\Model\OrderInterface;
|
||||
use Sylius\Component\Core\OrderPaymentStates;
|
||||
use Sylius\Component\Payment\Model\PaymentInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final class CheckoutOrderDetailsContext implements Context
|
||||
{
|
||||
public function __construct(
|
||||
private RequestFactoryInterface $requestFactory,
|
||||
private SharedStorageInterface $sharedStorage,
|
||||
private ApiClientInterface $client,
|
||||
private ResponseCheckerInterface $responseChecker,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -34,43 +37,8 @@ final class CheckoutOrderDetailsContext implements Context
|
|||
*/
|
||||
public function iWantToBrowseOrderDetailsForThisOrder(OrderInterface $order): void
|
||||
{
|
||||
$this->orderDetails->open(['tokenValue' => $order->getTokenValue()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I try to pay with :paymentMethodName payment method
|
||||
*/
|
||||
public function iChangePaymentMethodTo(string $paymentMethodName): void
|
||||
{
|
||||
$this->orderDetails->choosePaymentMethod($paymentMethodName);
|
||||
$this->orderDetails->pay();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I retry the payment with :paymentMethodName payment method
|
||||
*/
|
||||
public function iChangePaymentMethodAfterCheckout(string $paymentMethodName): void
|
||||
{
|
||||
$this->thankYouPage->goToTheChangePaymentMethodPage();
|
||||
$this->orderDetails->choosePaymentMethod($paymentMethodName);
|
||||
$this->orderDetails->pay();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I want to pay for my order
|
||||
*/
|
||||
public function iWantToPayForMyOrder(): void
|
||||
{
|
||||
$this->thankYouPage->goToTheChangePaymentMethodPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I try to pay for my order
|
||||
*/
|
||||
public function iTryToPayForMyOrder(): void
|
||||
{
|
||||
$this->thankYouPage->goToTheChangePaymentMethodPage();
|
||||
$this->orderDetails->pay();
|
||||
$this->sharedStorage->set('cart_token', $order->getTokenValue());
|
||||
$this->client->show(Resources::ORDERS, $order->getTokenValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -78,7 +46,8 @@ final class CheckoutOrderDetailsContext implements Context
|
|||
*/
|
||||
public function iShouldBeAbleToPay(): void
|
||||
{
|
||||
Assert::true($this->orderDetails->hasPayAction());
|
||||
$state = $this->getLatestPaymentState();
|
||||
Assert::eq($state, PaymentInterface::STATE_NEW);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -86,31 +55,27 @@ final class CheckoutOrderDetailsContext implements Context
|
|||
*/
|
||||
public function iShouldNotBeAbleToPay(): void
|
||||
{
|
||||
Assert::false($this->orderDetails->canBePaid());
|
||||
$state = $this->getLatestPaymentState();
|
||||
Assert::notEq($state, PaymentInterface::STATE_NEW);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should see :quantity as number of items
|
||||
*/
|
||||
public function iShouldSeeAsNumberOfItems(int $quantity): void
|
||||
{
|
||||
Assert::same($this->orderDetails->getAmountOfItems(), $quantity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should have chosen :paymentMethodName payment method
|
||||
*/
|
||||
public function iShouldHaveChosenPaymentMethod(string $paymentMethodName): void
|
||||
private function getLatestPaymentState(): ?string
|
||||
{
|
||||
$this->thankYouPage->goToTheChangePaymentMethodPage();
|
||||
Assert::same($this->orderDetails->getChosenPaymentMethod(), $paymentMethodName);
|
||||
}
|
||||
$response = $this->client->show(Resources::ORDERS, $this->sharedStorage->get('cart_token'));
|
||||
Assert::same($this->client->getLastResponse()->getStatusCode(), 200);
|
||||
|
||||
/**
|
||||
* @Then I should be notified to choose a payment method
|
||||
*/
|
||||
public function iShouldBeNotifiedToChooseAPaymentMethod(): void
|
||||
{
|
||||
Assert::contains($this->orderDetails->getPaymentValidationMessage(), 'Please select a payment method.');
|
||||
// If the payment is canceled we won't be able to retrieve it because only new one are retrievable
|
||||
if (OrderPaymentStates::STATE_CANCELLED === $this->responseChecker->getValue($response, 'paymentState')) {
|
||||
return PaymentInterface::STATE_CANCELLED;
|
||||
}
|
||||
|
||||
$payments = $this->responseChecker->getValue($response, 'payments');
|
||||
$payment = end($payments);
|
||||
|
||||
$paymentId = $payment['id'];
|
||||
$response = $this->client->show(Resources::PAYMENTS, (string) $paymentId);
|
||||
|
||||
return $this->responseChecker->getValue($response, 'state');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -200,9 +200,9 @@
|
|||
</service>
|
||||
|
||||
<service id="sylius.behat.context.api.shop.checkout.order_details" class="Sylius\Behat\Context\Api\Shop\Checkout\CheckoutOrderDetailsContext">
|
||||
<argument type="service" id="sylius.behat.request_factory" />
|
||||
<argument type="service" id="sylius.behat.shared_storage" />
|
||||
<argument type="service" id="sylius.behat.api_platform_client.shop" />
|
||||
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
|
||||
</service>
|
||||
|
||||
<service id="Sylius\Behat\Context\Api\Shop\TaxonContext">
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ default:
|
|||
- sylius.behat.context.api.shop.cart
|
||||
- sylius.behat.context.api.shop.checkout
|
||||
- sylius.behat.context.api.shop.checkout.complete
|
||||
- sylius.behat.context.api.shop.checkout.order_details
|
||||
- sylius.behat.context.api.shop.order
|
||||
- sylius.behat.context.api.shop.response
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue