Elements Checkout Reference
Every prop, option, return field and result of StripeCheckout, useCheckout and PurchaseButton, plus which Stripe elements work in the form.
This page lists the API of the Elements checkout. It has two entry points:
superwall/checkoutholds what every store's form shares:useCheckout(),<PurchaseButton>and their types. A button built on them works in any form.superwall/checkout/stripeholds what is Stripe's:<StripeCheckout>,ExpressCheckoutElement,LinkAuthenticationElementand Stripe's own elements. A paywall that never imports it ships none of Stripe's React code.
import { PurchaseButton, useCheckout } from "superwall/checkout";
import { StripeCheckout, PaymentElement } from "superwall/checkout/stripe";checkout: "elements"
The config mode that turns the form on. Set it in config.ts, with an optional prefetch to load a plan's price as the paywall opens:
checkout: { mode: "elements", prefetch: "trial" },In this mode:
<StripeCheckout>takes payment on a web paywall, the Web SDK and a teleport checkout route.- A plain
purchase()opens Superwall's sheet. purchase(product, { checkout: "applePay" })opens Superwall's Apple Pay sheet, prepared from the same price as the form. CheckuseApplePay(product)before you show its button.- Inside the iOS app, in Studio and in a native SDK below 4.10.8, the form is
unavailableand a purchase uses the hosted checkout instead. See Unavailable reasons.
See Web Checkout for every mode.
<StripeCheckout>
Sells one Stripe product. It wraps Stripe's <Elements> in deferred mode: it prices the form from the product, so it renders at once, and nothing is created in Stripe until the shopper pays. Every element and useCheckout() call inside it pays through it.
<StripeCheckout
product="annual"
stripeMetadata={{ campaign: "spring" }}
onComplete={() => track("subscribed")}
>
<LinkAuthenticationElement />
<PaymentElement />
<PurchaseButton>Subscribe</PurchaseButton>
</StripeCheckout>Prop
Type
The callbacks hear only this form's purchases. usePurchase()'s callbacks hear them too. See Elements Checkout Events for their order.
options
StripeCheckoutOptions is Stripe's Elements options for deferred mode, less what Superwall sets from the product.
- Superwall sets:
mode,amount,currency,paymentMethodCreationandsetupFutureUsage. They aren't in the type, and the form ignores them if passed anyway. paymentMethodTypesdefaults to["card", "link"], which covers cards, Apple Pay, Google Pay and Link. Any other type is dropped with a console warning.localedefaults to the paywall's locale, so Stripe's labels and errors match the paywall's language.- Everything else, such as
appearance,fontsandloader, is passed to Stripe unchanged.
Every purchase needs the shopper's email. It's the Stripe customer's email, for the receipt, the redemption link and the billing portal. The form takes the first of:
- The
emailprop. - The email typed into
LinkAuthenticationElement. - The email a wallet or the Payment Element returns.
- The user's
emailattribute.
A form with no way to get one logs a warning once it's ready. Without an email, submit() returns incomplete with an email_required error and charges nothing.
useCheckout()
The state of the nearest checkout form, and submit() to pay with what the shopper entered. Call it from any component inside <StripeCheckout>; outside one it throws. It reads the same for every store.
const PayButton = () => {
const checkout = useCheckout();
return (
<button disabled={!checkout.canSubmit} onClick={() => checkout.submit()}>
{checkout.status === "paying" ? "Paying…" : "Subscribe"}
</button>
);
};It returns UseCheckoutResult:
Prop
Type
CheckoutAmounts
Amounts are in the currency's minor units, such as cents for USD.
Prop
Type
dueNow === 0 alone doesn't mean a free trial: check trialDays before you say "Start free trial".
submit() results
submit() resolves with a CheckoutSubmitResult:
status | Means | Callbacks |
|---|---|---|
completed | The purchase was paid. | onStart, onSubmit, onComplete |
failed | The payment failed; failure says why. The form stays open. | onStart, onSubmit, onFailure; a payment method the form can't take (card_not_supported) fails before onSubmit |
abandoned | Never from submit(). It ends a wallet or Link purchase in ExpressCheckoutElement that the shopper closed. | onStart, onAbandon |
incomplete | No purchase started. The form isn't filled in and its fields show what's missing, or Stripe couldn't read the form, such as with no PaymentElement mounted. error says why; email_required means there's no email. | None |
unavailable | The form can't take payment now. reason is an unavailable reason, or preparing or paying while the form is busy. | None |
const result = await checkout.submit();
if (result.status === "incomplete" && result.error.name === "email_required") {
setError("Enter your email to continue.");
}<PurchaseButton> shows nothing for incomplete. A paywall with its own email field should call submit() from its own button and show the message itself.
<PurchaseButton>
A <button> that calls submit() on the nearest checkout form.
- It's disabled until the form can take payment and while it pays.
- It sets
data-statustouseCheckout().statusandaria-busywhile paying, so you can style each state. onClickruns before the payment; callevent.preventDefault()to stop it.- Every other prop goes to the
<button>, excepttype, which is always"button".
<PurchaseButton className="cta">Start free trial</PurchaseButton>.cta[data-status="paying"] { opacity: 0.6; }Stripe elements
Every element comes from superwall/checkout/stripe and takes all of Stripe's own options. Two are wrapped, because Superwall needs their events.
ExpressCheckoutElement
Stripe's Express Checkout Element: one-tap buttons for Apple Pay, Google Pay and Link, each shown where the device and browser offer it. It takes Stripe's props except onClick, onConfirm and onCancel, which <StripeCheckout> handles:
- A wallet payment completes the purchase without a
<PurchaseButton>. - Closing the wallet reports
onAbandon. - The wallet always asks for the shopper's email, which Superwall sets on the customer.
Use paymentMethods to choose the buttons, such as only Link:
<ExpressCheckoutElement
options={{ paymentMethods: { applePay: "never", googlePay: "never", link: "auto" } }}
/>On a device with no wallet it renders nothing; its onReady tells you which buttons it shows.
LinkAuthenticationElement
Stripe's email field, which also signs Link shoppers in. It hands the email to the purchase, and fills itself in from the user's email attribute unless options.defaultValues.email is set. Its onChange still fires.
Which elements work
| Element | Supported | Notes |
|---|---|---|
PaymentElement | Yes | Cards and Link. |
ExpressCheckoutElement | Wrapped | Apple Pay, Google Pay and Link. Superwall owns onClick, onConfirm and onCancel. |
LinkAuthenticationElement | Wrapped | Hands the email to the purchase. |
AddressElement | Yes | With mode: "billing": the address goes onto the payment method. |
CardElement, CardNumberElement, CardExpiryElement, CardCvcElement | Yes | The classic card fields, styled with options.style. A mounted PaymentElement wins over them. |
useStripe(), useElements() | Yes | For reading the form. Don't confirm with them; call useCheckout().submit(). |
ShippingAddressElement, AddressElement with mode: "shipping" | No | A subscription ships nothing, and the purchase has nowhere to send it. |
TaxIdElement | No | The purchase has nowhere to send a tax ID. |
IbanElement, SEPA, ACH, iDEAL, Klarna, Afterpay, Cash App Pay | No | They redirect or need a bank mandate, a return-and-resume flow Superwall doesn't support yet. |
PaymentMethodMessagingElement | No | It advertises the buy-now-pay-later methods above. |
EmbeddedCheckout, CheckoutProvider | No | Stripe's own hosted checkout. Use checkout: "sheet" instead. |
Saved cards aren't offered: the form pays as a new customer each time.
The form enforces this list. It drops paymentMethodTypes beyond card and link with a console warning. A payment method of any other type fails with card_not_supported, code payment_method_unsupported, before anything is charged.
Import every element from superwall/checkout/stripe, never from @stripe/react-stripe-js. Your own copy of Stripe's React package has its own context, so its elements can't see <StripeCheckout> and throw "Could not find Elements context".
Unavailable reasons
When useCheckout().status is "unavailable", reason is a CheckoutUnavailableReason:
reason | Means |
|---|---|
unsupported_host | This host never takes payment in the paywall: inside the iOS app, in Studio, or in a native SDK below 4.10.8. |
external_checkout | The config's checkout is external or not set, so it sends shoppers to Superwall's hosted checkout. Set it to "elements". With sheet or applePay the form still pays. |
missing_public_api_key | The host supplied no public API key. |
unknown_product | The paywall has no product with this reference. |
unsupported_product | Stripe doesn't sell this product, such as an App Store product. Buy it with usePurchase().purchase(). |
session_failed | Fetching the product's price failed; error holds what went wrong. |
session_unsupported | The backend can't take this product's payment in a form, such as a one-time price or an account on Stripe managed payments. A plain purchase() still opens the sheet. |
store_load_failed | Stripe.js didn't load. |
Inside the iOS app, a Stripe purchase always leaves for the browser: the hosted checkout or your teleport route, where the form can pay.
Types
superwall/checkout exports UseCheckoutResult, CheckoutSubmitResult, CheckoutAmounts, CheckoutUnavailableReason, CheckoutError and PurchaseButtonProps.
superwall/checkout/stripe exports StripeCheckoutProps, StripeCheckoutOptions, ExpressCheckoutElementProps, and Stripe's own prop types for the elements it re-exports.
Related
- Elements Checkout: build a paywall with Apple Pay, Link and a card form
- Elements Checkout Events: which callbacks fire, and when
- Payment failure reasons: what
onFailureandfailurehold
How is this guide?
Elements Checkout
Build your own checkout form from Stripe's official elements: Apple Pay, Link and a card form on the paywall, while Superwall takes the payment.
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.