Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wallets] Display payment declines on the checkout and re-enable the Place order button after closing the modal #3187

Merged
merged 17 commits into from
Jul 17, 2024

Conversation

james-allan
Copy link
Contributor

@james-allan james-allan commented Jun 7, 2024

Fixes #3168

Changes proposed in this Pull Request:

This PR fixes 2 issues with Wallet payment methods (Cash App and WeChat).

  1. If you close the QR code modal on the Block checkout, the Place order button remains disabled and the customer would need to refresh the page to bring it back.
  2. If you fail the payment, you're redirected to the order received page rather than being left on the checkout.

With this PR if you fail the wallet payment it will now leave you on the checkout and display the error received from Stripe. If you close the modal, the block checkout is reinitialised so you can reattempt payment.

Testing instructions

  1. As a merchant, enable WeChat and Cash App.
  2. Create a Checkout Block page, if you don't have one already.
  3. As a shopper, add a product to the cart and go to the Block Checkout page
  4. Select WeChat or Cash App as the payment method
  5. Click on Place Order
  6. Close the modal without proceeding with the payment
    7. On develop the Place Order button remains disabled. It's not possible to place the order until you reload the page.
    8. On this branch the place order button should be ready to go again.
develop This branch
Screenshot 2024-06-07 at 10 01 15 PM Screenshot 2024-06-07 at 9 59 27 PM
  1. As a shopper, add a product to the cart and go to the Block Checkout page
  2. Select WeChat or Cash App as the payment method
  3. Click on Place Order
  4. Scan the QR code on your mobile device.
  5. At Stripe click the Fail test payment button.
    • On develop you would be redirected to the order received page. Where you would need to re-navigate to the checkout to reattempt payment.
    • On this branch you should receive the failed notice on the checkout.

Screenshot 2024-06-07 at 10 06 01 PM


  • Covered with tests (or have a good reason not to test in description ☝️)
  • Added changelog entry in both changelog.txt and readme.txt (or does not apply)
  • Tested on mobile (or does not apply)

Post merge

@james-allan james-allan requested review from a team and diegocurbelo and removed request for a team June 7, 2024 12:06
@james-allan james-allan marked this pull request as ready for review June 7, 2024 12:06
// We need to unset the redirect URL otherwise WC core will redirect the the previous checkout redirectURL.
// For Wallet payment methods, that will include the #wc-stripe-wallet-... hash and cause the modal to show again.
checkoutStore.__internalSetRedirectUrl( null );
checkoutStore.__internalSetIdle();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch uses a number of functions marked as internal. I'm not sure if that's not a good idea but this was the only way I could get the payment form to unblock and for the payment elements to be reusable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works as described, but I agree the internal functions are not ideal... maybe we can get some guidance from @woocommerce/rubik?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling to understand this, what would cause this flow to trigger? a failed express payment?

Copy link
Contributor Author

@james-allan james-allan Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling to understand this, what would cause this flow to trigger?

So the set up is a little unorthodox.

When you click the place order button, the process payment request on the server responds with a redirect URL that triggers a modal to be shown.

Wechat.mov

When you close that modal, or if payment fails (and Stripe auto close the modal) we needed to reinit the checkout because it was stuck in the "complete" status from the previous request. This code is essentially doing that.

  1. We need to set the URL to null because otherwise calling __internalSetIdle() would cause WC core to redirect the "currentURL" which was the last URL response. I've lost the copy of the stacktrace I had that indicated this but let me know if you want it I should be able to find it again.
  2. I then set the status to idle so the checkout can be resubmitted. Without this the checkout remained completed and the place order button was disabled.

So, this function is called when the modal is closed so the customer can reattempt checkout.

Copy link
Member

@diegocurbelo diegocurbelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @james-allan.

I found a problem with reading window.wc.wcBlocksData in the utils.js... getting the constants after checking wcSettings.wcBlocksConfig in each function seems like the easiest solution 🤷🏼

client/stripe-utils/utils.js Outdated Show resolved Hide resolved
@wjrosa wjrosa requested a review from diegocurbelo July 9, 2024 13:25
Copy link
Member

@diegocurbelo diegocurbelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @james-allan... it works perfectly now 🚢

@james-allan james-allan merged commit e668087 into develop Jul 17, 2024
33 checks passed
@james-allan james-allan deleted the display-cash-app-declines-on-checkout branch July 17, 2024 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Wallets] The Place Order button remains disabled on the Block checkout after closing the wallet modal
3 participants