Elements Checkout Events
Which purchase callbacks fire, in what order, for an Elements form, its wallets, Superwall's Apple Pay sheet and the payment sheet.
An Elements checkout reports its purchases through the same five callbacks as every other purchase: onStart, onSubmit, onComplete, onAbandon and onFailure. This page says which listener hears a purchase, and the order the callbacks fire in for each way a shopper can pay.
Who hears what
There are two places to listen:
usePurchase(options)hears every purchase on the paywall, whichever component started it. That includes the form's purchases and Superwall's Apple Pay sheet opened from your own button.<StripeCheckout>'s callbacks hear only that form's purchases: a card paid withsubmit()or<PurchaseButton>, and a wallet or Link paid in itsExpressCheckoutElement.
const { purchase } = usePurchase({
onAbandon: () => track("checkout_abandoned"),
});
<StripeCheckout product={plan} onFailure={(failure) => setError(failure.message)}>
…
</StripeCheckout>;The native SDK also gets the matching stripe_checkout_* messages, such as stripe_checkout_start, stripe_checkout_complete and stripe_checkout_abandon, as for the sheet and Apple Pay. A form purchase reaches the SDK's analytics, including its transaction_abandon.
The callbacks don't say which payment method paid. A paywall that needs to know can tell from which of its buttons the shopper used.
In an Elements form
| What the shopper does | Callbacks, in order |
|---|---|
| Pays with a card | onStart, onSubmit, onComplete |
| Pays with an incomplete form or no email | None: submit() returns incomplete |
| Card declined | onStart, onSubmit, onFailure |
| Pays again after a decline | A new onStart, then as above |
| Fails 3D Secure | onStart, onSubmit, onFailure |
Opens Link or a wallet in ExpressCheckoutElement | onStart |
| … and pays | onSubmit, onComplete |
| … and closes it before authorizing | onAbandon |
| Taps Superwall's Apple Pay button and pays | onStart, onSubmit, onComplete, from usePurchase only |
| … and closes the sheet before authorizing | onAbandon, from usePurchase only |
A wallet close counts as abandoned only before the shopper authorizes the payment. Once they've authorized it, closing the wallet reports nothing: the purchase goes on and ends in onComplete or onFailure. A card payment opens no sheet, so it has nothing to close: a card form never reports onAbandon. A decline keeps the form open, useCheckout().failure holds the failure until the next payment starts, and each retry is a purchase of its own.
Across checkout modes
The same callbacks mean slightly different things in each mode:
| Callback | Payment sheet (sheet) | Apple Pay (applePay) | Elements form (elements) |
|---|---|---|---|
onStart | The sheet opens. | The wallet opens. | submit() starts paying, or a wallet or Link opens in ExpressCheckoutElement. |
onSubmit | The shopper submits payment in the sheet. | The shopper authorizes the payment. | The form is read, or a wallet authorizes the payment. |
onComplete | The purchase was paid. | The purchase was paid. | The purchase was paid. |
onAbandon | The shopper closes the sheet without trying to pay. | The shopper closes the wallet before authorizing. | The shopper closes a wallet or Link before authorizing. Never for a card. |
onFailure | Each decline, while the sheet stays open for another card. | The payment fails. | Each failed payment; the form stays open. |
Closing the sheet after a decline isn't an abandon: the purchase resolves failed with the latest failure. See Callbacks for each callback's timing on other hosts, and Payment failure reasons for what onFailure receives.
Related
- Elements Checkout: build the form
- Elements Checkout Reference:
submit()results and every callback prop - Purchases: callbacks on
usePurchaseandpurchase()
How is this guide?
Elements Checkout Reference
Every prop, option, return field and result of StripeCheckout, useCheckout and PurchaseButton, plus which Stripe elements work in the form.
Style Elements Checkout
Make Stripe's elements match your paywall: appearance variables and rules from your design tokens, fonts that load, and styles for the card fields.