Skip to content

Conversation

AlexP11223
Copy link
Collaborator

@AlexP11223 AlexP11223 commented Jul 31, 2025

Added handling of cross-browser AppSwitch (started in non-default browser, then redirected to the default one).

We save the current cart + PayPal order ID into transient before going to PayPal and add the transient key into the return URL, then after returning we retrieve the saved cart and PayPal order, create a WC order and redirect to Pay for order.

The WC order creation is done using the existing WooCommerceOrderCreator, refactored to use CartData instead of the current WC cart.
I had to change the woocommerce_paypal_payments_shipping_callback_woocommerce_order_created hook parameters. I hope it was used only internally 🤔 And renamed it to woocommerce_paypal_payments_woocommerce_order_created_from_cart, so that at least nothing crashes, and because it's not just the shipping callback.

Remaining issues:

  • Cross-browser AppSwitch does not work when starting from block checkout because WC redirects to cart if the cart is empty on checkout losing all parameters.
  • AppSwitch resume does not work in block cart if PayPal is not the default gateway.

@AlexP11223 AlexP11223 requested review from Narek13 and hmouhtar July 31, 2025 08:13
Copy link
Collaborator

@hmouhtar hmouhtar left a comment

Choose a reason for hiding this comment

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

Hi @AlexP11223, thanks for working on this!

I added some comments, and I have a couple of questions:

  1. What happens if the EarlyOrderHandler is enabled? Wouldn't we end up with 2 orders?
  2. If the user is authenticated, will the order be associated with that user upon returning from AppSwitch on a different browser? configure_customer just sets the current user ID, which will be 0, so it seems that there won't be an association

@AlexP11223
Copy link
Collaborator Author

AlexP11223 commented Aug 1, 2025

I think EarlyOrderHandler is not creating anything? It only adds a hook handler to set some meta.

For authenticated users as I understand currently AppSwitch will not trigger at all. But should be possible to save the customer id too. However then WC will ask to log in or enter the email to access the order pay page.

Copy link
Collaborator

@Narek13 Narek13 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 Alex. LGTM

@hmouhtar
Copy link
Collaborator

hmouhtar commented Aug 1, 2025

I think EarlyOrderHandler is not creating anything? It only adds a hook handler to set some meta.

For authenticated users as I understand currently AppSwitch will not trigger at all. But should be possible to save the customer id too. However then WC will ask to log in or enter the email to access the order pay page.

@AlexP11223 AppSwitch does trigger for authenticated users. AFAIK PayPal expects the order to be associated with the customer account in the cross browser flow

@AlexP11223 AlexP11223 changed the base branch from trunk to develop August 22, 2025 13:53
Copy link

github-actions bot commented Aug 25, 2025

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

🔗 Test this pull request with WordPress Playground

What's included:

  • ✅ WordPress (latest)
  • ✅ WooCommerce (latest)
  • ✅ PayPal Payments plugin v3.0.9-pr3569-17199984186-g2cb2758 (built from this PR)

Login credentials:

  • Username: admin
  • Password: password

Plugin Details:

  • Version: 3.0.9-pr3569-17199984186-g2cb2758
  • Commit: 2cb2758
  • Artifact: woocommerce-paypal-payments-3.0.9-pr3569-17199984186-g2cb2758

💡 The demo environment resets each time you refresh. Perfect for testing!

🔄 This link updates automatically with each new commit to the PR.

⚠️ This URL is valid for 30 days from when this comment was last updated.


🤖 Auto-generated for commit 2cb2758 • Last updated: 2025-08-25T05:35:59.943Z

@Dinamiko Dinamiko merged commit 5a4d7f3 into develop Sep 3, 2025
21 checks passed
@Dinamiko Dinamiko deleted the PCP-4992-cross-browser-appswitch branch September 3, 2025 07:18
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.

4 participants