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: Convert PurchaseModal to use composite checkout #48152

Merged
merged 24 commits into from
Dec 18, 2020

Conversation

sirbrillig
Copy link
Member

@sirbrillig sirbrillig commented Dec 9, 2020

Changes proposed in this Pull Request

The one-click upsell code is the only remaining place using the TransactionFlow object which is the way that old checkout submits its payments for processing.

This PR modifies PurchaseModal to use the existing card payment processor that is part of composite checkout as follows:

  1. Replace the CheckoutContainer wrapper around UpsellNudge with CalypsoShoppingCartProvider and some additional redux selectors.
  2. Wrap PurchaseModal in CheckoutProvider to get access to the transaction status manager.
  3. Replace TransactionFlow.submit with useProcessPayment.
  4. Replace handleCheckoutCompleteRedirect with useCreatePaymentCompleteCallback.

Fixes #48132

Testing instructions

  1. With a free site, add a personal plan to your cart and visit checkout.
  2. Complete the purchase with a new or existing credit card but not a 3DS card and verify that you are redirected to an upsell page.
  3. On the upsell, click to purchase and click to confirm the purchase in the modal that appears.
  4. Verify that you are redirected to the thank-you page successfully and that the purchase completed successfully.
  5. Repeat the above steps, but click to decline the upsell and verify that you are redirected to the thank-you page.

@matticbot
Copy link
Contributor

@sirbrillig sirbrillig self-assigned this Dec 9, 2020
@matticbot
Copy link
Contributor

matticbot commented Dec 9, 2020

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

Sections (~840 bytes added 📈 [gzipped])

name         parsed_size           gzip_size
checkout         +4827 B  (+0.3%)     +923 B  (+0.3%)
woocommerce       -716 B  (-0.0%)      -83 B  (-0.0%)
signup            -203 B  (-0.1%)      -15 B  (-0.0%)
plans             -203 B  (-0.0%)      -15 B  (-0.0%)
export            -203 B  (-0.1%)      -15 B  (-0.0%)
email             -203 B  (-0.1%)      -15 B  (-0.0%)
domains           -203 B  (-0.0%)      -15 B  (-0.0%)
customize         -203 B  (-0.1%)      -15 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 (~467 bytes added 📈 [gzipped])

name                                             parsed_size           gzip_size
async-load-calypso-blocks-editor-checkout-modal      +3079 B  (+0.3%)     +467 B  (+0.2%)

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 force-pushed the update/convert-upsell-to-composite-checkout branch 2 times, most recently from 52f5971 to 2b0eefd Compare December 11, 2020 19:13
@sirbrillig
Copy link
Member Author

Ok, this seems to work now! Just need to clean up the PR.

@sirbrillig
Copy link
Member Author

This is now ready to be tested, although it will need to be rebased when #48069 and #48283 are merged, as they are included in here. Until that time, it may be hard to review the code changes. To that end, I've made a cleaned-up version of this PR with the dependencies removed in #48284. You can test the behavior here and read the code changes there.

@sirbrillig sirbrillig marked this pull request as ready for review December 11, 2020 23:37
@sirbrillig sirbrillig requested a review from a team as a code owner December 11, 2020 23:37
@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 requested review from a team and southp and removed request for a team December 11, 2020 23:37
@sirbrillig sirbrillig force-pushed the update/convert-upsell-to-composite-checkout branch from 59e6c1f to a525851 Compare December 11, 2020 23:56
@sirbrillig sirbrillig force-pushed the update/convert-upsell-to-composite-checkout branch from ac81a05 to c02622f Compare December 15, 2020 17:40
@sirbrillig sirbrillig mentioned this pull request Dec 16, 2020
@sirbrillig sirbrillig force-pushed the update/convert-upsell-to-composite-checkout branch 2 times, most recently from fa5d99c to 9340c45 Compare December 16, 2020 18:14
@sirbrillig
Copy link
Member Author

Rebased after the dependencies were merged. This is ready for final review.

@nbloomf
Copy link
Contributor

nbloomf commented Dec 16, 2020

Edit: this comment is describing expected behavior; never mind :)

Just noting that I needed to manually put myself in the noOffer variant of the conciergeUpsellDial AB test and manually reload local calypso after going through gutenboarding to get a free site in order to get into the right state to test this.

After completing checkout with a personal plan, I end up at what looks like a generic thank you page with no upsell: http://calypso.localhost:3000/checkout/thank-you/nbloomftestingpurchasemodal02.wordpress.com/:receiptId

Screen Shot 2020-12-16 at 12 34 31 PM

@nbloomf
Copy link
Contributor

nbloomf commented Dec 16, 2020

The following case works as expected:

  • In the offer variant of conciergeUpsellDial
  • Upgrading from free to personal
  • Using a 3DS card
  • Opting for the concierge upsell

I am redirected to the correct thank you page (scheduling a session).

@sirbrillig
Copy link
Member Author

The upsell page is not shown if the card used is a 3DS card due to the fact that 3DS cards may display a pending page before displaying the thank-you page. I updated the testing instructions to specify not using a 3DS card.

One interesting thing to note (and this is existing behavior) is that the upsell defaults to the most recently added card and not necessarily the card used for the purchase that triggered the upsell.

@niranjan-uma-shankar niranjan-uma-shankar force-pushed the update/convert-upsell-to-composite-checkout branch from f510bb6 to e43d60a Compare December 18, 2020 12:13
Copy link
Contributor

@niranjan-uma-shankar niranjan-uma-shankar left a comment

Choose a reason for hiding this comment

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

LGTM 🚢

I rebased the PR since one my changes caused a merge conflict.

I tested the following scenarios:

  • Purchased a Business plan -> saw the Quick Start offer -> one-click purchase completed successfully
  • Purchase a Premium plan -> saw the Business bump offer -> one-click purchase completed successfully
  • Assigned myself to the Premium bump A/B test treatment group -> Purchased a Personal plan -> saw the Premium bump offer -> one-click purchase completed successfully
  • Tried purchase via Calypso /plans -> after one-click purchase, got redirected to the appropriate Thank You page.
  • Tried paying for a plan with PayPal -> one click upsell did not show and that's the correct behaviour
  • Clicking No on the offer took to Home page

@sirbrillig sirbrillig merged commit 87919af into trunk Dec 18, 2020
@sirbrillig sirbrillig deleted the update/convert-upsell-to-composite-checkout branch December 18, 2020 15:51
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Dec 18, 2020
sarayourfriend pushed a commit that referenced this pull request Dec 23, 2020
* Fill in missing PropTypes for UpsellNudge

* Replace CheckoutContainer with ShoppingCartProvider around UpsellNudge

* Wrap UpsellNudge with withShoppingCart

* Explicitly add isFetchingStoredCards, cards to UpsellNudge selectors

* Refactor CheckoutProvider to be a named function

* Make total and items optional props to CheckoutProvider

* Convert useSubmitTransaction to use useProcessPayment

* Update UpsellNudge to use shoppingCartManager

* Remove handleCheckoutCompleteRedirect from UpsellNudge

* Add CheckoutProvider to PurchaseModal

Along with useCreatePaymentCompleteCallback and existingCardProcessor.

* Remove onComplete from useSubmitTransaction

That will be handled by CheckoutProvider.

* Use withPaymentCompleteCallback on UpsellNudge

* Use getThankYouPageUrl directly in UpsellNudge

* Add QueryStoredCards to UpsellNudge

* Move CheckoutProvider outside PurchaseModal by adding wrapper

* Allow mounting UpsellNudge if products are still fetching

* Pass siteId to PurchaseModal

* Pass correct args to existingCardProcessor

* Pass country/postalCode to existingCardProcessor

* Set tax country code in UpsellNudge

* Add StripeHookProvider to UpsellNudge

* Set form to processing before submit in useSubmitTransaction

* Remove declined support session when closing modal

* Include receiptId in UpsellNudge getThankYouPageUrlArguments
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.

Convert one-click upsell to stop using TransactionFlow
4 participants