Automattic / woocommerce-payments

Accept payments via credit card. Manage transactions within WordPress.
https://wordpress.org/plugins/woocommerce-payments/
Other
173 stars 69 forks source link

Redirection to WooPay Not Triggering on Shortcode Checkout Pages #8398

Closed rafaelzaleski closed 5 months ago

rafaelzaleski commented 6 months ago

Describe the bug

Users with matching WooPay email addresses are not automatically redirected to WooPay during the checkout process on stores using shortcode checkout pages. This issue arose after implementing a new precondition check for WooPayments activation within the shop (see https://github.com/Automattic/woocommerce-payments/pull/8116). The core of the problem lies in the reliance on the wc/store/payment store, which only is working within the checkout block context, returning an empty object in shortcode checkouts. This results in the redirection condition failing (hasWCPayPaymentMethod = false).

To Reproduce

Prerequisites:

  1. Add a product to the cart.
  2. Proceed to the shortcode checkout page.
  3. Notice the absence of redirection to WooPay and the email field not initiating an email check (no loading spinner displayed).

Actual behavior

The expected behavior of redirecting to WooPay or displaying the OTP authentication iframe does not occur upon page load.

Screenshots

https://github.com/Automattic/woocommerce-payments/assets/4153905/c2838a4b-4d18-459b-afc4-9c41bed2fcf1

Expected behavior

To maintain compatibility with shortcode checkouts, an alternative method to verify WooPayments activation in the shop, applicable outside the checkout block context, is required.

pierorocca commented 6 months ago

Doesn't look intentional, however, we are moving away from the auto-redirect as part of the Direct Checkout project. The only use case that will remain that triggers the OTP modal is a signed out shopper that manually enters the email address.

pierorocca commented 5 months ago

@bborman22 worth working on this one? As part of Direct Checkout I had wanted the auto-redirect to be suppressed and for the OTP to only display when the shopper is manually keying in the email address. However it sounds like this was achieved unintentionally?

bborman22 commented 5 months ago

@asumaran I was thinking this issue could be a good one to pick up as you get into some of the Direct Checkout work. To summarize, the original bug listed is actually very close to how we want it to operate and this issue can be repurposed to confirm the following:

This issue will likely involve some removal of code (like calls to openLoginSessionIframe that happen outside of an input change event).

asumaran commented 5 months ago

@bborman22 Thanks. I'll take a look at this.

pierorocca commented 5 months ago

@asumaran the thinking is that since Direct Checkout now gets signed in shoppers to WooPay directly, that leaves non-WooPay shoppers and signed out shoppers to address. For signed-out WooPay shoppers, if the form field is pre-filled or they've used autofill, eliminating the on-page load OTP is less intrusive. And we want to respect shopper choice by not trying to force them to sign-in so aggressively. Fine balance. Thanks for picking this up.

asumaran commented 5 months ago

@bborman22 @pierorocca If a signed in shopper go to the checkout page and the email is populated it shouldn't redirect to WooPay right? If they type their WooPay email it should open the OTP page or should be redirected automatically given that they are already signed in on WooPay?

pierorocca commented 5 months ago

Correct. Once we enable direct checkout for all merchants signed in shoppers shouldn't get to store checkout page with the exception of being in Hosted Checkout and clicking "alternative payment methods". The idea is to prevent the redirect on page load as it's an aggressive experience

asumaran commented 5 months ago

@pierorocca just to double check. We shouldn't redirect only if the direct checkout feature is enabled for the site?

If the feature is disabled, we should redirect the user (if the email is already present) on page load just like before?

Or should we remove the auto redirect completely?

pierorocca commented 5 months ago

Good question. Let's remove the auto-redirect completely. Doesn't make sense for a shopper to have checkout loaded and then be redirected to another checkout.

bborman22 commented 5 months ago

Let's remove the auto-redirect completely.

Just to be clear, we'll be removing all auto-redirects from checkout page even if the shopper entered their email on checkout (not pre-populated)?

pierorocca commented 5 months ago

@bborman22 removing all on page load auto-redirects. The redirects related to entering an email, post page load, remain.

asumaran commented 5 months ago

removing all on page load auto-redirects. The redirects related to entering an email, post page load, remain.

Yes, that's right. I am only removing the automatic redirect when the page loads. Those already logged into WooPay will still be redirected after manually entering a valid WooPay email. cc @bborman22