Elements Checkout

Migrate a Stripe Checkout to Elements Checkout

Move an existing custom Stripe Elements checkout onto Superwall in 8 steps: keep your elements and design, and delete your payment backend.

If you already run a custom checkout on Stripe Elements, you can move it onto a Superwall paywall and keep almost all of its front end. Your elements, their options and your design stay. Your <Elements> provider, the endpoint that creates the PaymentIntent or subscription, the confirmPayment() call and the webhook that grants access go: Superwall does that part.

Your checkout todayWith Superwall
<Elements stripe={...} options={{ clientSecret }}><StripeCheckout product="annual">
Elements from @stripe/react-stripe-jsThe same elements from superwall/checkout/stripe
elements.submit() and stripe.confirmPayment()useCheckout().submit() or <PurchaseButton>
A server endpoint that creates the PaymentIntentNothing: Superwall creates the subscription
A webhook that grants accessNothing: Superwall grants the entitlement and redeems it in the app
Metadata on the subscriptionstripeMetadata on <StripeCheckout>

Requirements

  • Your Stripe account connected and your products set up in the dashboard, see Web Checkout.
  • Subscription prices. One-time prices, redirect methods (iDEAL, Klarna) and bank debits (SEPA, ACH) aren't supported yet, see Which elements work.

Steps

  1. 1

    Set the mode

    Set checkout to elements in config.ts, and list your Stripe products:

    config.ts
    export default definePaywall({
      products: {
        annual: "live:price_1QxAnnual:no-trial",
      },
      checkout: { mode: "elements" },
    });

    See Products for the identifier format.

  2. 2

    Swap the provider

    Replace <Elements> with <StripeCheckout>. Move appearance, fonts, locale and paymentMethodTypes into its options. Drop clientSecret, mode, amount and currency: they come from the product.

    // Before
    <Elements stripe={stripePromise} options={{ clientSecret, appearance, fonts }}>
      <CheckoutForm />
    </Elements>
    
    // After
    import { StripeCheckout } from "superwall/checkout/stripe";
    
    <StripeCheckout product="annual" options={{ appearance, fonts }}>
      <CheckoutForm />
    </StripeCheckout>

    You don't call loadStripe(): Superwall loads Stripe.js with your app's key.

  3. 3

    Keep the elements

    Change the import, nothing else. The elements take the same props:

    // Before
    import { PaymentElement, AddressElement } from "@stripe/react-stripe-js";
    
    // After
    import { PaymentElement, AddressElement } from "superwall/checkout/stripe";

    Import every element from superwall/checkout/stripe. Your own copy of @stripe/react-stripe-js has its own React context, so its elements can't see <StripeCheckout> and throw "Could not find Elements context". You can remove the package once nothing imports it.

  4. 4

    Swap the submit

    Where you called elements.submit() and stripe.confirmPayment(), call useCheckout().submit(). It validates the fields, pays, runs 3D Secure and the free trial, and completes the purchase:

    import { useCheckout } from "superwall/checkout";
    
    const PayButton = () => {
      const { canSubmit, submit } = useCheckout();
      const [problem, setProblem] = React.useState<string>();
      return (
        <>
          {problem ? <p role="alert">{problem}</p> : null}
          <button
            disabled={!canSubmit}
            onClick={async () => {
              setProblem(undefined);
              const result = await submit();
              if (result.status === "incomplete") setProblem(result.error.message);
            }}
          >
            Subscribe
          </button>
        </>
      );
    };

    Or render <PurchaseButton>, which does this and disables itself while it pays. See submit() results.

  5. 5

    Collect the email

    Every purchase needs an email. Keep LinkAuthenticationElement, or pass your own field's value as <StripeCheckout email>, with "" while it's empty:

    const [email, setEmail] = React.useState("");
    
    <StripeCheckout product="annual" email={email}>
      <input type="email" value={email} onChange={(event) => setEmail(event.target.value)} />
      {/* card fields */}
    </StripeCheckout>;

    Without an email, submit() returns incomplete with email_required and charges nothing. <PurchaseButton> doesn't show that error, so a form with its own email box should use its own button, as in the previous step.

  6. 6

    Move the metadata

    What you set on the subscription goes in stripeMetadata:

    <StripeCheckout product="annual" stripeMetadata={{ campaign: "spring", source: "web" }}>

    It's the same option as on purchase(), see Custom metadata on the sale.

  7. 7

    Delete the backend

    Remove the endpoint that created the PaymentIntent or subscription, and the webhook that granted access. Superwall creates the subscription, grants the entitlement and redeems it in the app. If other systems read your old webhook, point them at Superwall's webhooks instead.

  8. 8

    Move the reactions

    Your success and error handling moves to the callbacks on <StripeCheckout>, or to usePurchase()'s:

    <StripeCheckout
      product="annual"
      onComplete={() => track("subscribed")}
      onFailure={(failure) => setError(failure.message ?? "Your payment was declined.")}
      onAbandon={() => track("checkout_abandoned")}
    >

    There's no return URL to handle: the form completes on the page. See Elements Checkout Events for which callback fires when.

Limitations

  • Saved cards aren't offered. The form pays as a new customer each time.
  • No shipping, tax IDs, redirect methods or bank debits. See Which elements work for each one's reason.
  • Not inside the iOS app. There, a Stripe purchase leaves for the browser, see Where the form can't take payment.

How is this guide?

On this page