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

Convert one-click upsell to stop using TransactionFlow #48132

Closed
sirbrillig opened this issue Dec 8, 2020 · 4 comments · Fixed by #48152
Closed

Convert one-click upsell to stop using TransactionFlow #48132

sirbrillig opened this issue Dec 8, 2020 · 4 comments · Fixed by #48152
Assignees
Labels
[Feature] Checkout The checkout screen and process for purchases made on WordPress.com. [Type] Task

Comments

@sirbrillig
Copy link
Member

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.

The biggest issue here is that any fixes or updates we make to new checkout will not apply to the one-click upsell and any fixes to the upsell (eg: #47774) will be eventually lost.

We'll need to change PurchaseModal to use the payment processors that are part of composite checkout. This requires two things: first we need to change the inputs getting to that component to remove the dependency on CartStore by switching to ShoppingCartProvider and second we need to replace TransactionFlow.submit with existingCardProcessor. We'll also need the rest of the "checkout complete" behavior which currently lives in useCreatePaymentCompleteCallback.

@sirbrillig
Copy link
Member Author

Some PRs that are part of this process:

@sirbrillig
Copy link
Member Author

sirbrillig commented Dec 8, 2020

To do this, we should first refactor UpsellNudge to remove it from CheckoutContainer, which requires replicating or replacing the functionality of CartData and Checkout.

CartData provides the cart prop which it pulls directly from the CartStore. This can be replaced with CalypsoShoppingCartProvider and withShoppingCart.

Checkout injects the following props into its children: cart (from CartData, see above), cards, isFetchingStoredCards, and handleCheckoutCompleteRedirect. Those are all used by UpsellNudge. Furthermore, its cart prop uses the client_metadata property added by CartStore, which we will have to replace with cart_generated_at_timestamp that exists on the cart itself.

cards and isFetchingStoredCards come right out of the Redux store's getStoredCards and isFetchingStoredCards selectors, so that's easy to replace by using the selectors directly in connect or useSelector.

handleCheckoutCompleteRedirect is a method in Checkout that calls clearPurchases (which is a Redux action that forces the refresh of the purchases data), displays success messages, and then redirects to the redirect URL. This is analogous to onPaymentComplete in CompositeCheckout, which does all those things as well. This PR should help that by moving the generation of onPaymentComplete to its own hook.

Unfortunately because we haven't converted the payment processors to use ResponseCart data directly (they assume WPCOMCartItem objects which pass through createTransactionEndpointCartFromLineItems), we'll also need to pull in translateResponseCartToWPCOMCart.

@sirbrillig
Copy link
Member Author

sirbrillig commented Dec 9, 2020

These changes have brought up a lot of questions about where we store the transaction data after the purchase (eg: the receipt id). Right now we're storing it in the "wpcom" @wordpress/data store, but that's maybe not ideal. I need to give it some more thought. It turns out that I already have it inside the CheckoutProvider, so we'll need to include that but i've set the stage for it above.

@sirbrillig sirbrillig self-assigned this Dec 9, 2020
@cathymcbride cathymcbride added [Feature] Checkout The checkout screen and process for purchases made on WordPress.com. [Type] Task labels Dec 10, 2020
@sirbrillig
Copy link
Member Author

#48152 is ready to be reviewed. Since it has its dependencies mixed in, if you want to review just the code changes, see #48284

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Checkout The checkout screen and process for purchases made on WordPress.com. [Type] Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants