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

Checkout: extract calling payment processor and handling response to useProcessPayment hook #48283

Merged
merged 12 commits into from
Dec 16, 2020

Conversation

sirbrillig
Copy link
Member

@sirbrillig sirbrillig commented Dec 11, 2020

Changes proposed in this Pull Request

When a payment method's submitButton prop is rendered by @automattic/composite-checkout, it is provided with an onClick prop that can be used to call a payment processor function and handle the response. As consumers of the package (like the one-click upsell; see #48152) might want to implement their own submit button, we should expose that automated process in its own hook.

This PR creates a hook called useProcessPayment that does just that and adds it to the @automattic/composite-checkout package.

This PR shouldn't have any user-facing effect on checkout.

Testing instructions

  1. Add a product to your cart and visit checkout.
  2. Complete checkout with any payment method.
  3. Verify that the transaction completes successfully and that you are redirected to a thank-you page as expected.

@matticbot
Copy link
Contributor

@sirbrillig sirbrillig self-assigned this Dec 11, 2020
@sirbrillig sirbrillig added the [Feature] Checkout The checkout screen and process for purchases made on WordPress.com. label Dec 11, 2020
@matticbot
Copy link
Contributor

matticbot commented Dec 11, 2020

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~91 bytes added 📈 [gzipped])

name            parsed_size           gzip_size
site-purchases       +172 B  (+0.0%)      +42 B  (+0.0%)
purchases            +172 B  (+0.0%)      +29 B  (+0.0%)
checkout             +170 B  (+0.0%)      +51 B  (+0.0%)
woocommerce          -118 B  (-0.0%)      -31 B  (-0.0%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Async-loaded Components (~48 bytes added 📈 [gzipped])

name                                             parsed_size           gzip_size
async-load-calypso-blocks-editor-checkout-modal       +170 B  (+0.0%)      +48 B  (+0.0%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@sirbrillig sirbrillig marked this pull request as ready for review December 11, 2020 22:53
@sirbrillig sirbrillig requested a review from a team as a code owner December 11, 2020 22:53
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Dec 11, 2020
@sirbrillig sirbrillig force-pushed the add/use-process-payment branch from 6c398c7 to c26c402 Compare December 15, 2020 15:47
@sirbrillig sirbrillig force-pushed the add/use-process-payment branch from c26c402 to 08c0d4e Compare December 16, 2020 17:37
@sirbrillig
Copy link
Member Author

Rebased after #48385

Copy link
Contributor

@nbloomf nbloomf 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 and works as described.

@nbloomf nbloomf added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Dec 16, 2020
@sirbrillig sirbrillig merged commit 100413f into trunk Dec 16, 2020
@sirbrillig sirbrillig deleted the add/use-process-payment branch December 16, 2020 18:11
sarayourfriend pushed a commit that referenced this pull request Dec 23, 2020
…useProcessPayment hook (#48283)

* Clarify manual transaction processing in composite-checkout README

* Separate payment processor response handling into own function

* Export useCreatePaymentProcessorOnClick from composite-checkout

* Add missing useCreatePaymentProcessorOnClick

* Rethrow PaymentProcessorResponse error

* Allow payment complete callback to include isComingFromUpsell

* Add withPaymentCompleteCallback HOC

* Clean up PaymentCompleteCallback type a bit

* Remove withPaymentCompleteCallback and shouldHideUpsellNudges

* Fix useCreatePaymentProcessorOnClick import

* Rename onClick creator to useProcessPayment

* Throw if using useStripe outside StripeHookProvider
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Estimate] 3 [Feature] Checkout The checkout screen and process for purchases made on WordPress.com.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants