Elements Checkout

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/checkout holds what every store's form shares: useCheckout(), <PurchaseButton> and their types. A button built on them works in any form.
  • superwall/checkout/stripe holds what is Stripe's: <StripeCheckout>, ExpressCheckoutElement, LinkAuthenticationElement and 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:

config.ts
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. Check useApplePay(product) before you show its button.
  • Inside the iOS app, in Studio and in a native SDK below 4.10.8, the form is unavailable and 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, paymentMethodCreation and setupFutureUsage. They aren't in the type, and the form ignores them if passed anyway.
  • paymentMethodTypes defaults to ["card", "link"], which covers cards, Apple Pay, Google Pay and Link. Any other type is dropped with a console warning.
  • locale defaults to the paywall's locale, so Stripe's labels and errors match the paywall's language.
  • Everything else, such as appearance, fonts and loader, is passed to Stripe unchanged.

Email

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:

  1. The email prop.
  2. The email typed into LinkAuthenticationElement.
  3. The email a wallet or the Payment Element returns.
  4. The user's email attribute.

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:

statusMeansCallbacks
completedThe purchase was paid.onStart, onSubmit, onComplete
failedThe 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
abandonedNever from submit(). It ends a wallet or Link purchase in ExpressCheckoutElement that the shopper closed.onStart, onAbandon
incompleteNo 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
unavailableThe 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-status to useCheckout().status and aria-busy while paying, so you can style each state.
  • onClick runs before the payment; call event.preventDefault() to stop it.
  • Every other prop goes to the <button>, except type, 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

ElementSupportedNotes
PaymentElementYesCards and Link.
ExpressCheckoutElementWrappedApple Pay, Google Pay and Link. Superwall owns onClick, onConfirm and onCancel.
LinkAuthenticationElementWrappedHands the email to the purchase.
AddressElementYesWith mode: "billing": the address goes onto the payment method.
CardElement, CardNumberElement, CardExpiryElement, CardCvcElementYesThe classic card fields, styled with options.style. A mounted PaymentElement wins over them.
useStripe(), useElements()YesFor reading the form. Don't confirm with them; call useCheckout().submit().
ShippingAddressElement, AddressElement with mode: "shipping"NoA subscription ships nothing, and the purchase has nowhere to send it.
TaxIdElementNoThe purchase has nowhere to send a tax ID.
IbanElement, SEPA, ACH, iDEAL, Klarna, Afterpay, Cash App PayNoThey redirect or need a bank mandate, a return-and-resume flow Superwall doesn't support yet.
PaymentMethodMessagingElementNoIt advertises the buy-now-pay-later methods above.
EmbeddedCheckout, CheckoutProviderNoStripe'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:

reasonMeans
unsupported_hostThis host never takes payment in the paywall: inside the iOS app, in Studio, or in a native SDK below 4.10.8.
external_checkoutThe 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_keyThe host supplied no public API key.
unknown_productThe paywall has no product with this reference.
unsupported_productStripe doesn't sell this product, such as an App Store product. Buy it with usePurchase().purchase().
session_failedFetching the product's price failed; error holds what went wrong.
session_unsupportedThe 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_failedStripe.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.

How is this guide?

On this page