Elements Checkout

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 with submit() or <PurchaseButton>, and a wallet or Link paid in its ExpressCheckoutElement.
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 doesCallbacks, in order
Pays with a cardonStart, onSubmit, onComplete
Pays with an incomplete form or no emailNone: submit() returns incomplete
Card declinedonStart, onSubmit, onFailure
Pays again after a declineA new onStart, then as above
Fails 3D SecureonStart, onSubmit, onFailure
Opens Link or a wallet in ExpressCheckoutElementonStart
… and paysonSubmit, onComplete
… and closes it before authorizingonAbandon
Taps Superwall's Apple Pay button and paysonStart, onSubmit, onComplete, from usePurchase only
… and closes the sheet before authorizingonAbandon, 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:

CallbackPayment sheet (sheet)Apple Pay (applePay)Elements form (elements)
onStartThe sheet opens.The wallet opens.submit() starts paying, or a wallet or Link opens in ExpressCheckoutElement.
onSubmitThe shopper submits payment in the sheet.The shopper authorizes the payment.The form is read, or a wallet authorizes the payment.
onCompleteThe purchase was paid.The purchase was paid.The purchase was paid.
onAbandonThe 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.
onFailureEach 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.

How is this guide?

On this page