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 today | With Superwall |
|---|---|
<Elements stripe={...} options={{ clientSecret }}> | <StripeCheckout product="annual"> |
Elements from @stripe/react-stripe-js | The same elements from superwall/checkout/stripe |
elements.submit() and stripe.confirmPayment() | useCheckout().submit() or <PurchaseButton> |
| A server endpoint that creates the PaymentIntent | Nothing: Superwall creates the subscription |
| A webhook that grants access | Nothing: Superwall grants the entitlement and redeems it in the app |
| Metadata on the subscription | stripeMetadata 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
Set the mode
Set
checkouttoelementsinconfig.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
Swap the provider
Replace
<Elements>with<StripeCheckout>. Moveappearance,fonts,localeandpaymentMethodTypesinto itsoptions. DropclientSecret,mode,amountandcurrency: 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
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-jshas 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
Swap the submit
Where you called
elements.submit()andstripe.confirmPayment(), calluseCheckout().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. Seesubmit()results. - 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()returnsincompletewithemail_requiredand 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
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
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
Move the reactions
Your success and error handling moves to the callbacks on
<StripeCheckout>, or tousePurchase()'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.
Related
- Elements Checkout: the feature and a full build
- Style Elements Checkout: bring your design across
- Elements Checkout Recipes: common layouts, including separate card fields
How is this guide?
Elements Checkout Recipes
Ready-made Elements Checkout layouts: wallets and card, Apple Pay with card fields, card first, a one-line card, wallets only, billing address and promo codes.
Web Funnels
Quizzes and checkout funnels on the web: one paywall whose steps are pages, every answer kept in the URL so the flow survives any browser hand-off, and payment at the end.