diff --git a/features/checkout/paying_for_order/seeing_payment_method_instructions_on_thank_you_page.feature b/features/checkout/paying_for_order/seeing_payment_method_instructions_after_checkout.feature similarity index 80% rename from features/checkout/paying_for_order/seeing_payment_method_instructions_on_thank_you_page.feature rename to features/checkout/paying_for_order/seeing_payment_method_instructions_after_checkout.feature index e04dab4860f..813c4f19b40 100644 --- a/features/checkout/paying_for_order/seeing_payment_method_instructions_on_thank_you_page.feature +++ b/features/checkout/paying_for_order/seeing_payment_method_instructions_after_checkout.feature @@ -1,5 +1,5 @@ @paying_for_order -Feature: Seeing payment method instructions on thank you page +Feature: Seeing payment method instructions after checkout In order to know how to pay for my order As a Customer I want to be informed about payment instructions for chosen payment method @@ -11,11 +11,10 @@ Feature: Seeing payment method instructions on thank you page And the store has a payment method "Offline" with a code "OFFLINE" And it has instructions "Account number: 0000 1111 2222 3333" - @ui - Scenario: Being informed about payment instructions on thank you page + @ui @api + Scenario: Being informed about payment instructions Given I am a logged in customer And I have product "PHP T-Shirt" in the cart When I proceed selecting "Offline" payment method And I confirm my order - Then I should see the thank you page And I should be informed with "Offline" payment method instructions diff --git a/src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php b/src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php index 5fe80b0fcec..2eef494cf77 100644 --- a/src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php +++ b/src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php @@ -553,6 +553,38 @@ public function iShouldBeOnTheCheckoutCompleteStep(): void ); } + /** + * @Then I should be informed with :paymentMethod payment method instructions + */ + public function iShouldBeInformedWithPaymentMethodInstructions(PaymentMethodInterface $paymentMethod): void + { + $response = $this->client->getLastResponse(); + $payments = $this->responseChecker->getValue($response, 'payments'); + + Assert::notEmpty($payments, 'No payments found in response.'); + $paymentMethodIri = $this->iriConverter->getIriFromItem($paymentMethod); + foreach ($payments as $payment) { + if ($payment['method'] !== $paymentMethodIri) { + continue; + } + + $customRequest = $this->requestFactory->custom($payment['method'], HTTPRequest::METHOD_GET); + $paymentMethodResponse = $this->client->executeCustomRequest($customRequest); + Assert::same( + $this->responseChecker->getValue( + $paymentMethodResponse, + 'instructions', + ), + $paymentMethod->getInstructions(), + sprintf('Payment method instructions should be equal to %s', $paymentMethod->getInstructions()), + ); + + return; + } + + throw new \Exception(sprintf('Payment method %s not found in response.', $paymentMethod->getName())); + } + /** * @Then I should not be able to confirm order because products do not fit :shippingMethod requirements */