woocommerce / woocommerce-gateway-paypal-express-checkout

59 stars 64 forks source link

Closing the modal window redirects to the cart page #757

Closed rynaldos-zz closed 4 years ago

rynaldos-zz commented 4 years ago

Howdy!

I am not entirely sure if this is the intended behavior or not, but was able to replicate the issue on the most recent version of WooCommerce core (v4.1.1), WordPress (v5.4.1), and PayPal Checkout (v2.0.2).

When on the checkout page, after clicking the payment button, a modal will pop up to continue the payment. At this point, close the modal window, and the user will automatically be redirected back to the cart page.

Reproducing:

  1. Install and activate the most recent version of PayPal checkout (v2.0.2)
  2. Add product to your cart and proceed to the checkout page
  3. Click the payment button for PayPal checkout
  4. Close the modal window for payment
  5. Issue happens here, the user is redirected to the cart page

Is this the intended behavior, and if so, why? If it isn't, is there a way to prevent the redirect from happening?

Cheers!

mattallan commented 4 years ago

Hey @rynaldos,

Thanks for opening this issue. In 2.0 we added a new onCancel function handler to our PayPal Smart Buttons implementation.

We are then redirecting the user back to the cancel URL (the cart page) when the customer closes/cancels the PayPal form.

To answer your question, yes, this is working as intended, but why the cart page? I'm not 100% sure on this, but the cart page is what we use as the cancel URL in other areas of PayPal Checkout (see _get_cancel_url()).

You can change this cancel URL by using the following filtering 'woocommerce_paypal_express_checkout_payment_button_data' and changing the value of 'cancel_url' in that array.


cc @jorgeatorres 👋 It looks like in 1.6.21, cancelling/closing the Paypal form would redirect the customer back to the same page they came from. In 2.0.0, we now redirect the customer to the cart page, but one issue I see with this is not every store has a cart page. For instance, if you don't have a cart page set in WooCommerce > Settings > Advanced the customer is redirected back to the home page which feels odd.

Is there a reason we have to set/use the onCancel function?

Looking at the PayPal docs, if we don't have an onCancel function, the customer is redirected back to the parent page by default which sounds like something we want. Thoughts?

jorgeatorres commented 4 years ago

Hey @mattallan!

Is there a reason we have to set/use the onCancel function?

I don't think there's a reason other than maybe consistency with other areas of our codebase (as you have mentioned). If redirecting to the parent page makes more sense to most users (or for backwards compatibility with 1.6.x), I have nothing against changing the default behavior.

My only suggestion would be that we don't entirely remove 'cancel_url' from the button settings. Maybe we can use a default value of '' (meaning no onCancel handler is used i.e. redirect to parent), but if a URL is configured via 'woocommerce_paypal_express_checkout_payment_button_data' we redirect to that particular URL passing the order ID in the querystring, as we currently do.

Would that make sense?