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

fix(modal-checkout): treat express checkouts as modal checkouts #1654

Merged
merged 3 commits into from
Jan 31, 2024

Conversation

dkoo
Copy link
Contributor

@dkoo dkoo commented Jan 26, 2024

All Submissions:

Changes proposed in this Pull Request:

Fixes some issues with checkout when using express checkout methods (also called "payment requests" in Stripe terminology) in modal checkout. Our is_modal_checkout method isn't recognizing express checkout requests as being triggered by modal checkout, so there can be mismatches in the data we're providing via modal checkout and what WooCommerce would expect, thinking the checkout requests is happening via a standard checkout flow. This could affect any behavior we customize for the modal checkout, including:

  • Required billing fields (e.g. if you partially set up Google Pay but don't add an address, and your site is set to not collect address fields during modal checkout, Woo might still throw errors about missing required address fields).
  • Behavior we enforce to allow guest checkout and account registration during checkout

I'm not sure if this is the right answer, but this PR makes all express checkouts behave as modal checkouts. I couldn't figure out a way to differentiate between express checkout requests from modal checkout vs. standard, but if we have to choose it seems making it inherit modal checkout behavior is preferable.

How to test the changes in this Pull Request:

  1. There are some prerequisites for testing these features. Set up your local site with Newspack + Stripe Gateway for reader revenue. In the Stripe Gateway settings, make sure express checkout methods are enabled, and in your connected Stripe account dashboard, make sure to whitelist your test site's domain.
  2. To set up Apple Pay, you'll need to log into an Apple ID account on your dev machine and connect a real credit card with a valid billing address to your Apple Wallet. When completing transactions on a site where Stripe is set to test mode, the card won't be charged.
  3. To set up Google Pay, you'll need to connect a real credit card + billing address to your Google account at https://pay.google.com/. You'll also need to log in with this Google account in your Chrome browser and enable account syncing and autofilling of both payment methods and credit cards in browser settings. After doing all this you may also have to clear all browser data and wait several minutes in order for these things to take effect. It may also help to view the site while emulating an Android phone using Chrome dev tools.
  4. Test Apple Pay: on release, visit your site in Safari and make a donation. You should be able to see the "Buy with Apple Pay" button and use it to complete the transaction.
Screenshot 2024-01-26 at 4 12 40 PM
  1. Still on release, open a new session and attempt to complete another transaction with Apple Pay. This time you should see an error stating "An account is already registered with your email address. Please log in" even though modal checkout should allow the unauthenticated checkout to occur.
  2. Check out this branch and repeat step 6. Confirm that it completes this time, and that the order/subscription is tied to the same reader account in WP admin.
  3. Try to test with Google Pay in Chrome, too, but this is a bit more challenging to make appear. The logic/behavior should be the same as Apple Pay.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@dkoo dkoo self-assigned this Jan 26, 2024
@dkoo dkoo requested a review from a team as a code owner January 26, 2024 23:52
Copy link
Member

@adekbadek adekbadek left a comment

Choose a reason for hiding this comment

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

This change breaks the checkout for non-Newspack products. modal_checkout is set under conditions different than defined in this change. The result is that when using the payment request with a non-Newspack product, the customer is redirected to our "Transaction Successful" screen which assumes it's rendered in a modal. The "Continue browsing" button won't do anything, trapping the user on this screen for eternity.

@dkoo
Copy link
Contributor Author

dkoo commented Jan 29, 2024

This change breaks the checkout for non-Newspack products. modal_checkout is set under conditions different than defined in this change. The result is that when using the payment request with a non-Newspack product, the customer is redirected to our "Transaction Successful" screen which assumes it's rendered in a modal. The "Continue browsing" button won't do anything, trapping the user on this screen for eternity.

Noooo! Great points. I was overly optimistic about this change, but it looks like we'll have to figure out a way to pass the modal_checkout param to the payment_request request so we can see the source of the payment. :\

@dkoo
Copy link
Contributor Author

dkoo commented Jan 30, 2024

@adekbadek 712858a adds the check we were missing. We can still fetch the referrer URL from the express checkout request, so that lets us see if the request was triggered in a modal checkout.

@dkoo dkoo requested a review from adekbadek January 30, 2024 01:07
@dkoo dkoo merged commit a352511 into release Jan 31, 2024
8 checks passed
@dkoo dkoo deleted the hotfix/payment-requests branch January 31, 2024 16:57
matticbot pushed a commit that referenced this pull request Jan 31, 2024
## [2.6.1](v2.6.0...v2.6.1) (2024-01-31)

### Bug Fixes

* **modal-checkout:** treat express checkouts as modal checkouts ([#1654](#1654)) ([a352511](a352511))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 2.6.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants