Skip to content

Commit fb06406

Browse files
committed
AC-8920:: User navigated back to shipping steps if any order error occurred
1 parent 1819863 commit fb06406

File tree

10 files changed

+198
-6
lines changed

10 files changed

+198
-6
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="CheckoutSelectCreditCardPaymentActionGroup">
12+
<annotations>
13+
<description>Selects the 'Credit card' Payment Method on the Storefront Checkout page.</description>
14+
</annotations>
15+
16+
<waitForPageLoad stepKey="waitForLoadingMask"/>
17+
<waitForPageLoad stepKey="waitForPageLoad"/>
18+
<click selector="{{StorefrontCheckoutPaymentMethodSection.checkCreditCard}}" stepKey="selectCreditCardPaymentMethod"/>
19+
<waitForPageLoad stepKey="waitForLoadingMaskAfterPaymentMethodSelection"/>
20+
</actionGroup>
21+
</actionGroups>

app/code/Magento/Checkout/Test/Mftf/Section/StorefrontCheckoutPaymentMethodSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<section name="StorefrontCheckoutPaymentMethodSection">
1212
<element name="billingAddress" type="text" selector=".checkout-billing-address"/>
1313
<element name="checkPaymentMethodByName" type="radio" selector="//div[@id='checkout-payment-method-load']//div[@class='payment-method']//label//span[contains(., '{{methodName}}')]/../..//input" parameterized="true"/>
14+
<element name="checkCreditCard" type="radio" selector="//div[@id='checkout-payment-method-load']//div[@class='payment-method payment-method-braintree']//label//span[contains(., 'Credit Card')]/../..//input"/>
1415
<element name="billingAddressSameAsShipping" type="checkbox" selector=".payment-method._active [name='billing-address-same-as-shipping']"/>
1516
<element name="billingAddressSameAsShippingShared" type="checkbox" selector="#billing-address-same-as-shipping-shared"/>
1617
<element name="paymentOnAccount" type="radio" selector="#companycredit" deprecated="Use StorefrontCheckoutPaymentSection.paymentOnAccount B2B repository"/>

app/code/Magento/Customer/Test/Mftf/Data/AddressData.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,4 +511,20 @@
511511
<data key="postcode">5555</data>
512512
<data key="telephone">555-55-555-55</data>
513513
</entity>
514+
<entity name="US_Address_CA_CC" type="address">
515+
<data key="firstname">CCREJECT-BANK_ERROR</data>
516+
<data key="lastname">Doe</data>
517+
<array key="street">
518+
<item>119 Belmont St</item>
519+
</array>
520+
<data key="city">Ontario</data>
521+
<data key="state">California</data>
522+
<data key="country_id">US</data>
523+
<data key="country">United States</data>
524+
<data key="postcode">91761</data>
525+
<data key="telephone">7865438767</data>
526+
<data key="default_billing">Yes</data>
527+
<data key="default_shipping">Yes</data>
528+
<requiredEntity type="region">RegionCA</requiredEntity>
529+
</entity>
514530
</entities>

app/code/Magento/Customer/Test/Mftf/Data/CustomerData.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,4 +489,18 @@
489489
<data key="group">General</data>
490490
<requiredEntity type="address">Canada_Address</requiredEntity>
491491
</entity>
492+
<entity name="Custom_US_Customer" type="customer">
493+
<data key="group_id">1</data>
494+
<data key="default_billing">true</data>
495+
<data key="default_shipping">true</data>
496+
<data key="email" unique="prefix">John.Doe@example.com</data>
497+
<data key="firstname">John</data>
498+
<data key="lastname">Doe</data>
499+
<data key="fullname">John Doe</data>
500+
<data key="password">pwdTest123!</data>
501+
<data key="store_id">0</data>
502+
<data key="website_id">0</data>
503+
<data key="group">General</data>
504+
<requiredEntity type="address">US_Address_CA_CC</requiredEntity>
505+
</entity>
492506
</entities>

app/code/Magento/Quote/Model/QuoteValidator.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Quote\Model\Quote as QuoteEntity;
1515
use Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage as OrderAmountValidationMessage;
1616
use Magento\Quote\Model\ValidationRules\QuoteValidationRuleInterface;
17+
use Magento\Framework\Webapi\Rest\Response as RestResponse;
1718

1819
/**
1920
* Class to validate the quote
@@ -43,24 +44,32 @@ class QuoteValidator
4344
*/
4445
private $quoteValidationRule;
4546

47+
/**
48+
* @var RestResponse
49+
*/
50+
private $_response;
51+
4652
/**
4753
* QuoteValidator constructor.
4854
*
4955
* @param AllowedCountries|null $allowedCountryReader
5056
* @param OrderAmountValidationMessage|null $minimumAmountMessage
5157
* @param QuoteValidationRuleInterface|null $quoteValidationRule
58+
* @param RestResponse|null $response
5259
*/
5360
public function __construct(
5461
AllowedCountries $allowedCountryReader = null,
5562
OrderAmountValidationMessage $minimumAmountMessage = null,
56-
QuoteValidationRuleInterface $quoteValidationRule = null
63+
QuoteValidationRuleInterface $quoteValidationRule = null,
64+
RestResponse $response = null
5765
) {
5866
$this->allowedCountryReader = $allowedCountryReader ?: ObjectManager::getInstance()
5967
->get(AllowedCountries::class);
6068
$this->minimumAmountMessage = $minimumAmountMessage ?: ObjectManager::getInstance()
6169
->get(OrderAmountValidationMessage::class);
6270
$this->quoteValidationRule = $quoteValidationRule ?: ObjectManager::getInstance()
6371
->get(QuoteValidationRuleInterface::class);
72+
$this->_response = $response ?: ObjectManager::getInstance()->get(RestResponse::class);
6473
}
6574

6675
/**
@@ -106,6 +115,7 @@ public function validateBeforeSubmit(QuoteEntity $quote)
106115
$defaultMessage .= ' %1';
107116
}
108117
if ($defaultMessage) {
118+
$this->_response->setHeader('errorRedirectAction', '#shipping');
109119
throw new ValidatorException(__($defaultMessage, implode(' ', $messages)));
110120
}
111121
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
10+
<entity name="SampleBraintreeConfig" type="braintree_config">
11+
<data key="braintree_username">MagentoPB</data>
12+
<data key="braintree_password">123123q</data>
13+
<data key="braintree_merchant_id">d4pdjhxgjfrsmzbf</data>
14+
<data key="braintree_public_key">m7q4wmh43xrgyrst</data>
15+
<data key="braintree_private_key">67de364080b1b4e2492d7a3de413a572</data>
16+
</entity>
17+
<entity name="InvalidCreditCard" type="data">
18+
<data key="cardNumber">4032031062519193</data>
19+
<data key="expiry">12/25</data>
20+
<data key="cvv">123</data>
21+
</entity>
22+
</entities>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
10+
<section name="BraintreeConfigSection">
11+
<element name="configureBtn" type="button" selector="#payment_{{countryCode}}_braintree_section_braintree-head" parameterized="true"/>
12+
<element name="environment" type="input" selector="#payment_{{countryCode}}_braintree_section_braintree_braintree_required_environment" parameterized="true"/>
13+
<element name="paymentAction" type="input" selector="#payment_{{countryCode}}_braintree_section_braintree_braintree_required_payment_action" parameterized="true"/>
14+
<element name="merchantID" type="input" selector="#payment_{{countryCode}}_braintree_section_braintree_braintree_required_sandbox_merchant_id" parameterized="true"/>
15+
<element name="publicKey" type="input" selector="#payment_{{countryCode}}_braintree_section_braintree_braintree_required_sandbox_public_key" parameterized="true"/>
16+
<element name="privateKey" type="input" selector="#payment_{{countryCode}}_braintree_section_braintree_braintree_required_sandbox_private_key" parameterized="true"/>
17+
<element name="enableCard" type="input" selector="#payment_{{countryCode}}_braintree_section_braintree_active" parameterized="true"/>
18+
</section>
19+
</sections>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="BraintreeCreditCardSection">
12+
<element name="ccNumberIframe" type="iframe" selector="//*[@id='braintree-hosted-field-number']"/>
13+
<element name="ccExpiryIframe" type="iframe" selector="//*[@id='braintree-hosted-field-expirationDate']"/>
14+
<element name="ccCvvIframe" type="iframe" selector="//*[@id='braintree-hosted-field-cvv']"/>
15+
<element name="creditCardNumber" type="input" selector="//input[@id='credit-card-number']"/>
16+
<element name="expirationDate" type="input" selector="//input[@id='expiration']"/>
17+
<element name="cvv" type="input" selector="//input[@id='cvv']"/>
18+
</section>
19+
</sections>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="StorefrontAddProductToCartAndGoToCheckoutWithInvalidCreditCardTest">
11+
<annotations>
12+
<features value="Braintree"/>
13+
<stories value="Checkout with invalid credit card details through Braintree credit card payment method"/>
14+
<title value="Checkout with invalid credit card details through Braintree credit card payment method"/>
15+
<description value="Checkout with invalid credit card details through Braintree credit card payment method"/>
16+
<severity value="MINOR"/>
17+
<testCaseId value="AC-8920"/>
18+
<group value="pr_exclude"/>
19+
</annotations>
20+
<before>
21+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
22+
<!-- New Customer -->
23+
<createData entity="Custom_US_Customer" stepKey="createCustomer">
24+
<field key="firstname">CCREJECT-BANK_ERROR</field>
25+
<field key="lastname">Doe1</field>
26+
</createData>
27+
<!-- New Product -->
28+
<createData entity="SimpleProduct2" stepKey="simpleProduct">
29+
<field key="price">100</field>
30+
</createData>
31+
<!-- Reindex and cache flush -->
32+
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
33+
<argument name="indices" value=""/>
34+
</actionGroup>
35+
<actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCache">
36+
<argument name="tags" value=""/>
37+
</actionGroup>
38+
<!-- Enable Braintree -->
39+
<actionGroup ref="AdminBraintreeEnableActionGroup" stepKey="ConfigBraintree">
40+
<argument name="credentials" value="SampleBraintreeConfig"/>
41+
</actionGroup>
42+
</before>
43+
<after>
44+
<magentoCLI command="config:set paypal/general/merchant_country US" stepKey="setMerchantCountry"/>
45+
<magentoCLI command="config:set payment/braintree/active 0" stepKey="disablePayPalExpress"/>
46+
<actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="logoutCustomer" />
47+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
48+
<deleteData createDataKey="simpleProduct" stepKey="deleteSimpleProduct"/>
49+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
50+
</after>
51+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="signUpNewUser">
52+
<argument name="Customer" value="$$createCustomer$$"/>
53+
</actionGroup>
54+
<actionGroup ref="AddSimpleProductToCartActionGroup" stepKey="addSimpleProductToCart">
55+
<argument name="product" value="$simpleProduct$"/>
56+
</actionGroup>
57+
<!--Go to checkout from minicart-->
58+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart"/>
59+
<!-- Select Shipping method and fill the credit card details -->
60+
<actionGroup ref="CheckoutSelectFlatRateShippingMethodActionGroup" stepKey="selectFlatRate"/>
61+
<actionGroup ref="StorefrontCheckoutClickNextOnShippingStepActionGroup" stepKey="goToReview"/>
62+
<actionGroup ref="CheckoutSelectCreditCardPaymentActionGroup" stepKey="selectCreditCard"/>
63+
<checkOption selector="{{StorefrontCheckoutPaymentMethodSection.billingAddressSameAsShipping}}" stepKey="checkBillingAddressSameAsShippingCheckbox"/>
64+
<actionGroup ref="FillBraintreeCreditCardActionGroup" stepKey="fillCreditCardDetails">
65+
<argument name="creditCardDetails" value="InvalidCreditCard"/>
66+
</actionGroup>
67+
<!-- Place Order and assert the error message -->
68+
<click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrder"/>
69+
<actionGroup ref="StorefrontAssertCheckoutErrorMessageActionGroup" stepKey="assertErrorMessage">
70+
<argument name="message" value="Your payment could not be taken. Please try again or use a different payment method. Credit card number is not an accepted test number."/>
71+
</actionGroup>
72+
<wait time="6" stepKey="waitForPageLoad" />
73+
<seeCurrentUrlMatches regex="~\/checkout/#payment~" stepKey="seeCurrentUrl"/>
74+
</test>
75+
</tests>

app/code/Magento/Webapi/Controller/Rest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Magento\Webapi\Controller;
88

99
use Magento\Framework\Exception\AuthorizationException;
10-
use Magento\Framework\Exception\CouldNotSaveException;
1110
use Magento\Framework\Webapi\Authorization;
1211
use Magento\Framework\Webapi\ErrorProcessor;
1312
use Magento\Framework\Webapi\Rest\Request as RestRequest;
@@ -200,10 +199,6 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
200199
$this->requestValidator->validate($this->_request);
201200
$processor = $this->requestProcessorPool->getProcessor($this->_request);
202201
$processor->process($this->_request);
203-
} catch (CouldNotSaveException $e) {
204-
$maskedException = $this->_errorProcessor->maskException($e);
205-
$this->_response->setException($maskedException);
206-
$this->_response->setHeader('errorRedirectAction', '#shipping');
207202
} catch (\Exception $e) {
208203
$maskedException = $this->_errorProcessor->maskException($e);
209204
$this->_response->setException($maskedException);

0 commit comments

Comments
 (0)