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

UPE: intent caching tweaks #5653

Closed
wants to merge 25 commits into from
Closed

Conversation

kalessil
Copy link
Contributor

@kalessil kalessil commented Mar 1, 2023

Fixes #5310

Changes proposed in this Pull Request

  • Re-works UPE intent cache cleanup (hooks onto order state change + 2 places where order status change might not happen)
  • Implements error logging as order note when payment fails at intent update phase

Testing instructions

  • TBD

To be done

  • Impact analysis and testing scenarios for:
    • UPE checkout
    • Split UPE checkout
    • Blocks checkout
    • Subscriptions

  • 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

@kalessil kalessil self-assigned this Mar 1, 2023
@kalessil kalessil requested a review from anu-rock March 1, 2023 09:32
@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2023

Size Change: 0 B

Total Size: 1.37 MB

ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 913 B
release/woocommerce-payments/assets/css/success.css 401 B
release/woocommerce-payments/dist/blocks-checkout.css 2.33 kB
release/woocommerce-payments/dist/blocks-checkout.js 39.6 kB
release/woocommerce-payments/dist/checkout.css 1.34 kB
release/woocommerce-payments/dist/checkout.js 28.1 kB
release/woocommerce-payments/dist/index.css 36.1 kB
release/woocommerce-payments/dist/index.js 385 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.05 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 56.3 kB
release/woocommerce-payments/dist/multi-currency.css 14.8 kB
release/woocommerce-payments/dist/multi-currency.js 72.7 kB
release/woocommerce-payments/dist/order.css 248 B
release/woocommerce-payments/dist/order.js 12.7 kB
release/woocommerce-payments/dist/payment-gateways.css 1.2 kB
release/woocommerce-payments/dist/payment-gateways.js 47.2 kB
release/woocommerce-payments/dist/payment-request.js 12 kB
release/woocommerce-payments/dist/platform-checkout-express-button.js 16 kB
release/woocommerce-payments/dist/platform-checkout.css 4.03 kB
release/woocommerce-payments/dist/platform-checkout.js 75.5 kB
release/woocommerce-payments/dist/settings.css 51.3 kB
release/woocommerce-payments/dist/settings.js 181 kB
release/woocommerce-payments/dist/subscription-edit-page.js 668 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 7.18 kB
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 12.8 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 44.3 kB
release/woocommerce-payments/dist/tos.css 236 B
release/woocommerce-payments/dist/tos.js 15.7 kB
release/woocommerce-payments/dist/upe_checkout.css 1.34 kB
release/woocommerce-payments/dist/upe_checkout.js 32.9 kB
release/woocommerce-payments/dist/upe_split_checkout.css 1.34 kB
release/woocommerce-payments/dist/upe_split_checkout.js 33.3 kB
release/woocommerce-payments/dist/upe-blocks-checkout.css 2.33 kB
release/woocommerce-payments/dist/upe-blocks-checkout.js 39.1 kB
release/woocommerce-payments/dist/upe-split-blocks-checkout.css 2.34 kB
release/woocommerce-payments/dist/upe-split-blocks-checkout.js 39.7 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-admin-ui/src/css/jetpack-icon.css 224 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-identity-crisis/babel.config.js 160 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.css 2.27 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.js 13.3 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.rtl.css 2.27 kB
release/woocommerce-payments/vendor/automattic/jetpack-tracking/src/js/tracks-ajax.js 789 B
release/woocommerce-payments/vendor/automattic/jetpack-tracking/src/js/tracks-callables.js 925 B
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

@kalessil kalessil requested review from htdat and dmvrtx March 1, 2023 14:25
Copy link
Contributor

@dmvrtx dmvrtx left a comment

Choose a reason for hiding this comment

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

Thank you for looking into making this part more reliable. Looking at the changes I start to think that there is a gap in WooCommerce API for payment plugins and it might require us looking upstream to properly solve such issues.

includes/class-wc-payments-upe-checkout.php Outdated Show resolved Hide resolved
includes/payment-methods/class-upe-payment-gateway.php Outdated Show resolved Hide resolved
Copy link
Member

@htdat htdat 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. I am leaving some early comments.

@kalessil
Copy link
Contributor Author

kalessil commented Mar 2, 2023

A new batch of changes, and it makes sense to describe the current version.

Three major decisions:

  • rely on order status change to clear cached intent ID
  • improve error handling in UPE gateway to mark order failed and create a note for failing intent updates
  • remove most of the clear cached intent calls and keep them only in the place where order status change can not be guaranteed

Tradeoffs:

  • we have to keep the intent verification (vs order and intent status), as the generated checkout pages are not refreshing the intent id.

This means it should be possible to open two pages and complete the order on one page; voila, the second open one uses a processed intent. Changes preventing duplicate orders/charges will likely cover this, but I suggest keeping the introduced verifications for now - I don't have better ideas on how to sync cached intent ID.

@kalessil
Copy link
Contributor Author

kalessil commented Mar 2, 2023

I need inputs from more folks:

  • @FangedParakeet: are there changes from the PR which need to be adopted from UPE_Payment_Gateway to UPE_Split_Payment_Gateway?
  • @Automattic/helix: could this PR affect subscriptions? What test scenarios would you recommend performing?
  • @htdat: based on the duplicate charges prevention project, which test scenarios for checkout blocks would you recommend performing?

@haszari haszari requested a review from a team March 2, 2023 19:37
Copy link
Contributor

@anu-rock anu-rock left a comment

Choose a reason for hiding this comment

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

The code changes look good based on my first-pass review. Keeping the caching logic exclusively in UPE gateway is a good idea. And thanks for various reliability improvements. I'll come back after some functional testing.

if ( $intent_data ) {
// Extract the intent and ensure it's not bound to an order yet nor being processed.
list( $cart_hash, $intent_id, $client_secret ) = explode( '-', $intent_data, 3 );
$order = ( new WC_Payments_DB() )->order_from_intent_id( $intent_id );
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we instead get the instance of WC_Payments_DB from DI, like in webhook service?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

// The invoked method already handles order status changes on success and partially on failure.
// But, not all exceptions are triggering order status changes, so we have to clear intent cache.
// The intent caching is UPE-specific, so we have to keep it in the UPE-gateways only.
self::remove_upe_payment_intent_from_session();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self::remove_upe_payment_intent_from_session();
self::remove_upe_payment_intent_from_session();
throw $e;

Do we not need to rethrow the exception here as well? Otherwise if the parent gateway class throws an exception, for whatever reason, won't we just catch it and then continue on to return sucess instead of failure?

@brucealdridge
Copy link
Contributor

I have removed Helix from the review-queue due to Subscriptions being passed off to Quark. I have asked them to review.

@brucealdridge brucealdridge removed the request for review from a team June 20, 2023 23:32
@kalessil kalessil closed this Jun 20, 2024
@kalessil kalessil deleted the fix/5310-usage-of-processed-intent branch June 20, 2024 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants