Shopify-Partners / shop-pay-sfcc-connector

MIT License
2 stars 0 forks source link

Cannot submit payment method twice #4

Open jamiely opened 5 months ago

jamiely commented 5 months ago

When a user uses a card which is declined, such as test card 4000000000000341, they should be able to select a different card and try to complete the purchase again.

However, when you try this with the current cartridge, the second attempt will be blocked. The backend response will be something like this:

```json { "action": "ShopPay-SubmitPayment", "queryString": "csrf_token=bq9_lCwtM35C919DNtbQGsdvd2qEMjNmFxtYv-ONGt4WmH3km8X1iDUA4xHdhF3JDXKlcGFdbF1B-_6nQG5S-w9Dc9IybRq-p0e0O6_0GldqqH79LbI41y3wSaVJrQfNjRSqcNpzIQR4GztBgDEl1zIIsabxy0xiBATAvc23DnNBboDr1NU%3D", "locale": "en_US", "error": true, "errorMsg": "This transaction cannot be completed because your shopping cart has changed during your Shop Pay checkout", "paymentRequest": { "shippingAddress": null, "discountCodes": [], "lineItems": [ { "label": "Slim Crossbody", "quantity": 1, "sku": "CR238 SVRT2", "requiresShipping": true, "image": { "url": "https://img1.cohimg.net/is/image/Coach/cr238_svrt2_a0?$shopifyProduct$", "alt": "COACH®,SLIM CROSSBODY,Pebbled Leather,Mini,Silver/Soft Green,Front View" }, "originalLinePrice": { "amount": 75, "currencyCode": "USD" }, "finalLinePrice": { "amount": 75, "currencyCode": "USD" }, "originalItemPrice": { "amount": 75, "currencyCode": "USD" }, "finalItemPrice": { "amount": 75, "currencyCode": "USD" } } ], "shippingLines": [ { "label": "STANDARD", "amount": { "amount": 0, "currencyCode": "USD" }, "code": "STANDARD" } ], "deliveryMethods": [], "locale": "en", "presentmentCurrency": "USD", "subtotal": { "amount": 75, "currencyCode": "USD" }, "discounts": [], "totalShippingPrice": { "discounts": [], "originalTotal": { "amount": 0, "currencyCode": "USD" }, "finalTotal": { "amount": 0, "currencyCode": "USD" } }, "totalTax": { "amount": 0, "currencyCode": "USD" }, "total": { "amount": 75, "currencyCode": "USD" }, "paymentMethod": "U3dZQmZ0VjZxNXBFd1FIcWx" } } ```

The error message is

This transaction cannot be completed because your shopping cart has changed during your Shop Pay checkout

This is because the check validatePaymentRequest is returning false. Looking at the function, my guess is that it's this section:

        if (clientRequest.paymentMethod && !serverRequest.paymentMethod) {
            serverRequest.paymentMethod = clientRequest.paymentMethod;
        }

Probably it should be changed to

        if (clientRequest.paymentMethod) {
            serverRequest.paymentMethod = clientRequest.paymentMethod;
        }

because the payment method will change in the second request (having a different credit card)

jamiely commented 5 months ago

There are reports that this works, but leads to an error further down the line:

Your Shopping Bag is empty