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

Fixes Pay for Order page functionality in split-UPE #6177

Merged
merged 17 commits into from
May 16, 2023

Conversation

FangedParakeet
Copy link
Contributor

@FangedParakeet FangedParakeet commented Apr 28, 2023

Fixes #5808

Changes proposed in this Pull Request

Pay for Order Page: Preserved at Last

Previously when the split-UPE was enabled, the Pay for Order page had very limited functionality. The card payment method could fail, if the customer elected to change their currency, and the other additional payment methods would fail in all cases. I have identified three issues that are causing these frustrating failures.

  1. If order currency and customer selected currency do not match, if the customer selected currency is not supported by available payment method, payment intent will produce an error and payment elements will fail to mount.
  2. Pay for order form incorrectly detects when WCPay payment method is selected at checkout.
  3. Payment intent confirms successfully, but process_redirect_payment function exits early, order is not updated, and instead marked as a failure.

I hurdle the first obstacle by ensuring that when the Pay for Order page is open, multi-currency will disregard the currency selected by the customer and enforce that the correct currency on the order is used instead. This ensures that we only present the correct relevant and valid payment methods to the customer on this page and ensures that the customer cannot produce an invalid combination of selected currencies and payment methods.

I vault the second hurdle by removing the isWCPayChosen() function from the Pay for Order client script, instead relying on the getSelectedUPEGatewayPaymentMethod() function to test when a WCPay payment method is selected. isWCPayChosen() only checks for the presence of the woocommerce_payments gateway, ignoring the additional split-UPE gateways, and causing the Pay for Order scripts to consequently be skipped when an alternate WCPay gateway is selected.

The third barrier is the one described in #5854 and should be fixed by #6170.

Testing instructions

  1. Create an order from WC Admin (WooCommerce > Orders > Add new).
  2. Open the newly created order, add an item, customer, billing, and shipping details. Update the order
  3. Select the "Customer payment page" to be sent to the Pay for Order page.
  4. Fill in payment information and complete checkout for order. Use all payment methods (CC + additional UPE LPMs).
  5. Try to change the currency using the currency switcher widget. Currency displayed on Pay for Order page should remain the same. Payment elements should all load when appropriate without any errors.
  6. In all above cases, customer should be able to complete checkout without receiving errors. Order status should be successfully updated to "Processing". Order details on payment intent should all be correct and valid.

  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Post merge

@botwoo
Copy link
Collaborator

botwoo commented Apr 28, 2023

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 6177 or branch name fix/5808-upe-pay-for-order-page in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

Option 2. Jurassic Ninja - available for logged-in A12s

🚀 Launch a JN site with this branch 🚀

ℹ️ Install this Tampermonkey script to get more options.


Build info:

  • Latest commit: cc37adf
  • Build time: 2023-05-16 16:52:11 UTC

Note: the build is updated when a new commit is pushed to this PR.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 28, 2023

Size Change: -4 B (0%)

Total Size: 1.1 MB

Filename Size Change
release/woocommerce-payments/dist/upe_split_checkout.js 33.5 kB -4 B (0%)
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.01 kB
release/woocommerce-payments/assets/css/success.css 401 B
release/woocommerce-payments/dist/blocks-checkout.css 1.39 kB
release/woocommerce-payments/dist/blocks-checkout.js 39.8 kB
release/woocommerce-payments/dist/checkout.css 444 B
release/woocommerce-payments/dist/checkout.js 27.9 kB
release/woocommerce-payments/dist/index.css 39.4 kB
release/woocommerce-payments/dist/index.js 234 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.05 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 58.2 kB
release/woocommerce-payments/dist/multi-currency.css 2.99 kB
release/woocommerce-payments/dist/multi-currency.js 52.7 kB
release/woocommerce-payments/dist/order.css 248 B
release/woocommerce-payments/dist/order.js 15 kB
release/woocommerce-payments/dist/payment-gateways.css 704 B
release/woocommerce-payments/dist/payment-gateways.js 31.3 kB
release/woocommerce-payments/dist/payment-request.js 12 kB
release/woocommerce-payments/dist/settings.css 8.7 kB
release/woocommerce-payments/dist/settings.js 160 kB
release/woocommerce-payments/dist/subscription-edit-page.js 668 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 527 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 13 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 703 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 298 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 11.9 kB
release/woocommerce-payments/dist/tos.css 236 B
release/woocommerce-payments/dist/tos.js 14.5 kB
release/woocommerce-payments/dist/upe_checkout.css 444 B
release/woocommerce-payments/dist/upe_checkout.js 33.1 kB
release/woocommerce-payments/dist/upe_split_checkout.css 444 B
release/woocommerce-payments/dist/upe_with_deferred_intent_creation_checkout.js 31.4 kB
release/woocommerce-payments/dist/upe-blocks-checkout.css 1.39 kB
release/woocommerce-payments/dist/upe-blocks-checkout.js 39.1 kB
release/woocommerce-payments/dist/upe-split-blocks-checkout.css 1.39 kB
release/woocommerce-payments/dist/upe-split-blocks-checkout.js 39.7 kB
release/woocommerce-payments/dist/woopay-express-button.js 16.6 kB
release/woocommerce-payments/dist/woopay.css 4.03 kB
release/woocommerce-payments/dist/woopay.js 70.4 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 633 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 720 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.43 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.01 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 522 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 581 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/babel.config.js 160 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.css 2.32 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.js 13.8 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.rtl.css 2.32 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.2 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 403 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.56 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 299 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 742 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 572 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 411 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.07 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.8 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.83 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 544 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.6 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 502 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 355 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 429 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 387 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.27 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 392 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.06 kB

compressed-size-action

@FangedParakeet FangedParakeet marked this pull request as ready for review May 12, 2023 00:35
@FangedParakeet FangedParakeet requested a review from mdmoore May 12, 2023 00:35
Copy link
Member

@mdmoore mdmoore left a comment

Choose a reason for hiding this comment

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

I'm able to successfully process orders with all LPMs and CC, so that's all good. When testing the currency switch, the following error is showing up:

We're not able to process this payment. Please refresh the page and try again.

In the console:

Uncaught (in promise) IntegrationError: In order to create a payment element, you must pass a clientSecret or mode when creating the Elements group.

  e.g. stripe.elements({clientSecret: "{{CLIENT_SECRET}}"})
    n (index):1
    r (index):1
    t (index):1
    ro (index):1
    pi (index):1
    t (index):1
    create (index):1
    B (index):1
    mountUPEElement upe-split.js:284
    async* upe-split.js:361
    jQuery 13
v3:1:478949

This is occurring when the store/order currency is euros and changed to usd on the Pay for Order page. I haven't been able to pinpoint the cause unfortunately. I'm testing with the Split UPE flag enabled with CC and all LPMs enabled, WooPay/Link disabled. Let me know if you have other questions about the setup.

@FangedParakeet
Copy link
Contributor Author

Nice catch, @mdmoore. The issue was that AJAX requests could not pick up the URL query var for the Order Pay page, so in these cases the order currency was still not being used. Amended in a559588, if you wouldn't mind re-checking and double-checking that there aren't any other regressions with other feature flags enabled/disabled (deferred intent flag excepted).

@FangedParakeet FangedParakeet requested a review from mdmoore May 16, 2023 17:46
Copy link
Member

@mdmoore mdmoore left a comment

Choose a reason for hiding this comment

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

The previously mentioned errors are no longer present. All is now working well on the Pay for Order page with both CC and LPMs. Stripe metadata is all looking good with the correct currency and payment methods. I wasn't able to find any regressions when testing the legacy UPE feature flag or with all feature flags disabled.

Pay for Order under the Split UPE checkout with deferred intent creation isn't functional but that's unrelated to this PR. It looks like it will be handled in #5023.

This one is ready to go! 🚢

@FangedParakeet FangedParakeet added this pull request to the merge queue May 16, 2023
Merged via the queue into develop with commit 273ba35 May 16, 2023
@FangedParakeet FangedParakeet deleted the fix/5808-upe-pay-for-order-page branch May 16, 2023 20:42
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.

Users encountering an error while attempting to pay for order using UPE method
3 participants