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

Remove the redundant network requests in capture_charge #6408

Merged
merged 12 commits into from
Sep 28, 2023

Conversation

mordeth
Copy link
Contributor

@mordeth mordeth commented May 31, 2023

Fixes #6358

Changes proposed in this Pull Request

By removing the redundant network requests, we aim to make capturing an intent faster.

In capture_charge:

  • Remove the Get Intent API request, which was earlier used to fetch intent metadata from Stripe. This method now receives metadata from the calling function.
  • Remove the Update Intent API request, which was earlier used to update an intent's metadata with metadata from both the order and itself. We now send the merged metadata to Stripe in the Capture Intent request.

Testing instructions

Prerequisite: Server#3937

Do this first with trunk and then with this branch. Compare the response time in both case: it should be less with this branch.

Note

On @anu-rock's MacBook Pro 16" with M2 Pro: Before: 9 secs, After: 6 secs.

  • Create a new order in WooCommerce frontend with "Cash on delivery" as the payment method.

  • Create a payment intent in Stripe Dashboard. Go to: Your test account → Payments → Create payment → Manual payment. Select the "capture funds later" option.

  • On the intent details page, scroll down to the "Metadata" section. Create a new key order_id with value from the order created in the previous step. Create another key reader_ID with value "wisepad".

  • Make a POST request to /wp-json/wc/v3/payments/orders/<order_id>/capture_terminal_payment.

  • Verify that the payment succeeds.

  • Also verify on the intent details page that the metadata contains reader_ID along with order-related key-value pairs.

BONUS: Testing with mobile app

Use this guide (PdfdoF-D-p2) to test with the Woo mobile app and verify that:

  1. IPP payment goes through successfully.
  2. The payment intent's metadata contains data from both order and app (screenshot 👇).
Screenshot 2023-09-27 at 4 14 10 PM
  • 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

@mordeth mordeth requested a review from a team May 31, 2023 09:33
@botwoo
Copy link
Collaborator

botwoo commented May 31, 2023

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 6408 or branch name fix/optimise-capture-charge-calls 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: 77ca53d
  • Build time: 2023-09-28 02:44:06 UTC

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

@github-actions
Copy link
Contributor

github-actions bot commented May 31, 2023

Size Change: 0 B

Total Size: 1.42 MB

ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.03 kB
release/woocommerce-payments/assets/css/success.css 158 B
release/woocommerce-payments/dist/blocks-checkout-rtl.css 1.51 kB
release/woocommerce-payments/dist/blocks-checkout.css 1.51 kB
release/woocommerce-payments/dist/blocks-checkout.js 74 kB
release/woocommerce-payments/dist/checkout-rtl.css 440 B
release/woocommerce-payments/dist/checkout.css 441 B
release/woocommerce-payments/dist/checkout.js 28.8 kB
release/woocommerce-payments/dist/index-rtl.css 36.4 kB
release/woocommerce-payments/dist/index.css 36.4 kB
release/woocommerce-payments/dist/index.js 282 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.05 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 2.88 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 60.1 kB
release/woocommerce-payments/dist/multi-currency.css 2.88 kB
release/woocommerce-payments/dist/multi-currency.js 54.7 kB
release/woocommerce-payments/dist/order-rtl.css 676 B
release/woocommerce-payments/dist/order.css 679 B
release/woocommerce-payments/dist/order.js 40.9 kB
release/woocommerce-payments/dist/payment-gateways-rtl.css 690 B
release/woocommerce-payments/dist/payment-gateways.css 692 B
release/woocommerce-payments/dist/payment-gateways.js 38.4 kB
release/woocommerce-payments/dist/payment-request-rtl.css 146 B
release/woocommerce-payments/dist/payment-request.css 146 B
release/woocommerce-payments/dist/payment-request.js 11.7 kB
release/woocommerce-payments/dist/product-details.js 789 B
release/woocommerce-payments/dist/settings-rtl.css 8.92 kB
release/woocommerce-payments/dist/settings.css 8.92 kB
release/woocommerce-payments/dist/settings.js 231 kB
release/woocommerce-payments/dist/subscription-edit-page.js 669 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 519 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 519 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 20.3 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 693 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 117 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 117 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 19.4 kB
release/woocommerce-payments/dist/tos-rtl.css 230 B
release/woocommerce-payments/dist/tos.css 231 B
release/woocommerce-payments/dist/tos.js 21.9 kB
release/woocommerce-payments/dist/upe_checkout-rtl.css 440 B
release/woocommerce-payments/dist/upe_checkout.css 441 B
release/woocommerce-payments/dist/upe_checkout.js 34.1 kB
release/woocommerce-payments/dist/upe_split_checkout-rtl.css 440 B
release/woocommerce-payments/dist/upe_split_checkout.css 441 B
release/woocommerce-payments/dist/upe_split_checkout.js 34.6 kB
release/woocommerce-payments/dist/upe_with_deferred_intent_creation_checkout.js 36.7 kB
release/woocommerce-payments/dist/upe-blocks-checkout-rtl.css 1.51 kB
release/woocommerce-payments/dist/upe-blocks-checkout.css 1.51 kB
release/woocommerce-payments/dist/upe-blocks-checkout.js 39.6 kB
release/woocommerce-payments/dist/upe-split-blocks-checkout-rtl.css 1.51 kB
release/woocommerce-payments/dist/upe-split-blocks-checkout.css 1.51 kB
release/woocommerce-payments/dist/upe-split-blocks-checkout.js 41 kB
release/woocommerce-payments/dist/woopay-express-button-rtl.css 146 B
release/woocommerce-payments/dist/woopay-express-button.css 146 B
release/woocommerce-payments/dist/woopay-express-button.js 50.9 kB
release/woocommerce-payments/dist/woopay-rtl.css 3.85 kB
release/woocommerce-payments/dist/woopay.css 3.85 kB
release/woocommerce-payments/dist/woopay.js 71.5 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-empty-state.css 291 B
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.63 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 781 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

This has allows us to further reduce a network call by removing the update
intention API request before the capture step.
@anu-rock anu-rock changed the title [Draft] Remove the extra get intent call on capture_charge Remove the redundant network requests in capture_charge Sep 14, 2023
@anu-rock anu-rock self-assigned this Sep 14, 2023
@anu-rock anu-rock marked this pull request as ready for review September 14, 2023 12:50
@anu-rock anu-rock requested a review from kalessil September 14, 2023 12:50
Copy link
Contributor

@dpaun1985 dpaun1985 left a comment

Choose a reason for hiding this comment

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

Looks good overall. Left some comments.

includes/core/server/request/class-capture-intention.php Outdated Show resolved Hide resolved
includes/class-wc-payment-gateway-wcpay.php Show resolved Hide resolved
@kalessil
Copy link
Contributor

kalessil commented Sep 19, 2023

Tracing steps back: IIRC (should be double-checked toward the PR which added it initially), getting intent, which we are dropping here, was introduced to pull original meta-data created by mobile apps via Stripe SDK directly. And extending the metas to WooPayments goodies. So both mobile/WooPayments can live easy lives and extend metas as needed.

This change might work if Strpe merges meta with old ones. But the documentation doesn't clarify if this merge/override handling of metadata data happens there.

So, the questions:

  • do we know which of merge/override handling of meta is in the capture intent endpoint on Stripe's end?
  • did we test the change with the mobile APP?

@anu-rock
Copy link
Contributor

@kalessil

I'm glad you brought up this point. Based on my testing, metadata merge works the same way as before.

do we know which of merge/override handling of meta is in the capture intent endpoint on Stripe's end?

Merging of metadata happens in our code rather than Stripe:

$merged_metadata = array_merge( (array) $metadata_from_order, (array) $intent_metadata ); // prioritize metadata from mobile app.

The metadata param exposed in Stripe's capture intent API merely allows us to set it to whatever value we'd like. In this case, we set it to our merged dataset.

did we test the change with the mobile APP?

I haven't tested with the mobile app, but I believe my testing instructions cover this, especially this point:

"Also verify on the intent details page that the metadata contains reader_ID along with order-related key-value pairs."

P.S. I have added a prerequisite in testing instructions above for Server#3937.

@kalessil
Copy link
Contributor

@anu-rock: oki-doki. But the order meta-data, including many WooPayments internal fields - I'm not sure if we shall expose those blindly in intent and if the mobile app creates intents with the same set of data.

I'd cross-check an intent meta created by the mobile app vs complimentary order meta-data.

@kalessil
Copy link
Contributor

kalessil commented Sep 21, 2023

Okay ignore my previous comment - we did use order meta previously, so no big change there.
I have no further remarks/comments - waving out further reviews to fellow folks from Fusion =)

@anu-rock
Copy link
Contributor

@kalessil Awesome, thanks 🙌

Copy link
Contributor

@dpaun1985 dpaun1985 left a comment

Choose a reason for hiding this comment

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

✅ LGTM

@anu-rock
Copy link
Contributor

@kalessil Just an FYI - I tested using the mobile app just to be double sure. All worked as expected (including metadata). I've updated the testing instructions accordingly 🙌

This means reverting the Payment_Type constant fix I did earlier. In fact,
that's also how it's used in other places (eg. in Payment_Information).
@anu-rock anu-rock added this pull request to the merge queue Sep 28, 2023
Merged via the queue into develop with commit 32e8bd0 Sep 28, 2023
26 of 27 checks passed
@anu-rock anu-rock deleted the fix/optimise-capture-charge-calls branch September 28, 2023 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IPP: Speed up capture terminal payment endpoint
5 participants