Skip to content

Stripe embedded Checkout: the initEmbeddedCheckout fix and full setup

Stripe renamed stripe.initEmbeddedCheckout to stripe.createEmbeddedCheckoutPage in Stripe.js dahlia, and the ui_mode value embedded to embedded_page in API version 2026-03-25.dahlia. The options and the returned object did not change, so most fixes are a rename plus matching package versions. On Flint, the same checkout is one call for a hosted page, or runs on your own page with Flint pricing the order.
Verified against official documentationReviewed Send a correction (opens in a new tab)

Embedded Checkout is Stripe Checkout mounted inside your site. Your server creates a Checkout Session with an embedded UI mode and returns its client_secret; Stripe.js inserts an iframe into an empty div on your page and runs the whole payment form inside it. The buyer never leaves your URL unless a payment method needs a redirect.

What Stripe renamed in dahlia

Stripe's changelog lists these as breaking changes dated 2026-03-25. The old names stop working once you move to the new version, not before:

BeforeNowFrom
stripe.initEmbeddedCheckout()stripe.createEmbeddedCheckoutPage()Stripe.js dahlia and later (@stripe/stripe-js 9+). Same options, same returned object.
ui_mode: "embedded"ui_mode: "embedded_page"API version 2026-03-25.dahlia and later. The old value is rejected.
ui_mode: "hosted"ui_mode: "hosted_page"API version 2026-03-25.dahlia and later. Still the default.
ui_mode: "custom"ui_mode: "elements"API version 2026-03-25.dahlia and later, for Elements with Checkout Sessions.
stripe.initCheckout()stripe.initCheckoutElementsSdk()Stripe.js dahlia and later. This is Elements with Checkout Sessions, not embedded Checkout.

Which versions throw

The method rename follows the Stripe.js version your page loads; the ui_mode rename follows your server's API version. Stripe recommends keeping both on the same release train.

How your page loads Stripe.jsinitEmbeddedCheckoutTypeScript typesReact
@stripe/stripe-js 8 or lower, or js.stripe.com/v3, acacia, basil, or cloverWorks. createEmbeddedCheckoutPage also works at runtime.Declare initEmbeddedCheckout only@stripe/react-stripe-js 5 and earlier call initEmbeddedCheckout
@stripe/stripe-js 9, or js.stripe.com/dahliaThrows an IntegrationErrorDeclare createEmbeddedCheckoutPage only@stripe/react-stripe-js 6 calls createEmbeddedCheckoutPage
@stripe/stripe-js 10 (the current npm latest), or js.stripe.com/endiveThrows an IntegrationErrorDeclare createEmbeddedCheckoutPage only@stripe/react-stripe-js 7 calls createEmbeddedCheckoutPage

Every Stripe.js version served today, back to v3, already has createEmbeddedCheckoutPage, so you can switch the call name before you upgrade the package. Only the TypeScript types on @stripe/stripe-js 8 and earlier lack it.

A working embedded Checkout

1. Create the session on your server

Creating a session needs your secret key, so it runs on a server. Return the client secret:

JavaScript
// server.js (Express). The secret key stays on the server.
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);

app.post("/create-checkout-session", async (req, res) => {
  const session = await stripe.checkout.sessions.create({
    ui_mode: "embedded_page", // "embedded" before API version 2026-03-25.dahlia
    mode: "payment",
    line_items: [{ price: "price_...", quantity: 1 }],
    // No success_url or cancel_url: they are not allowed with embedded_page.
    return_url: "https://example.com/return?session_id={CHECKOUT_SESSION_ID}",
  });
  // The browser needs the client secret, not the ID or a URL.
  res.json({ clientSecret: session.client_secret });
});

return_url is required when redirect-based payment methods are enabled. Stripe replaces {CHECKOUT_SESSION_ID} with the session ID when it sends the buyer there.

2. Mount it with Stripe.js

HTML
<div id="checkout"><!-- Stripe inserts the checkout iframe here --></div>
<script src="https://js.stripe.com/endive/stripe.js"></script>
<script type="module" src="/checkout.js"></script>
JavaScript
// checkout.js
const stripe = Stripe("pk_test_...");

const fetchClientSecret = async () => {
  const response = await fetch("/create-checkout-session", { method: "POST" });
  const data = await response.json();
  if (data.error) throw new Error(data.error);
  return data.clientSecret; // a string, not the whole object
};

// Was stripe.initEmbeddedCheckout() before Stripe.js dahlia.
const checkout = await stripe.createEmbeddedCheckoutPage({ fetchClientSecret });
checkout.mount("#checkout");

mount takes a CSS selector or a DOM element. unmount() detaches Checkout so you can mount it again; destroy() removes it for good, and you create a new instance afterward. Don't place the container inside another iframe: Stripe warns that some payment methods redirect to confirm.

3. Or mount it in React

TSX
import { useCallback } from "react";
import { loadStripe } from "@stripe/stripe-js";
import { EmbeddedCheckoutProvider, EmbeddedCheckout } from "@stripe/react-stripe-js";

// Outside the component, so the Stripe object is created once.
const stripePromise = loadStripe("pk_test_...");

export function CheckoutPage() {
  // useCallback keeps the function stable: the provider reads options once.
  const fetchClientSecret = useCallback(
    () =>
      fetch("/create-checkout-session", { method: "POST" })
        .then((res) => res.json())
        .then((data) => data.clientSecret),
    [],
  );

  return (
    <EmbeddedCheckoutProvider stripe={stripePromise} options={{ fetchClientSecret }}>
      <EmbeddedCheckout />
    </EmbeddedCheckoutProvider>
  );
}

EmbeddedCheckoutProvider creates the instance once and ignores later changes to stripe, fetchClientSecret, clientSecret, or onComplete, with a console warning. To load a new session, unmount the provider and mount a new one, for example by changing its key. Unmounting destroys the Checkout instance for you.

@stripe/react-stripe-js 6 and later call createEmbeddedCheckoutPage; 5 and earlier call the old name, which throws on dahlia. Upgrade the two packages together:

Shell
# Upgrade the pair together: each react-stripe-js major pins one stripe-js major.
npm install @stripe/stripe-js@10 @stripe/react-stripe-js@7

The return page and onComplete

redirect_on_completion on the session decides what happens after payment:

  • always (the default) sends every buyer to return_url. Your return page reads the session's status from your server:
JavaScript
app.get("/session-status", async (req, res) => {
  const session = await stripe.checkout.sessions.retrieve(req.query.session_id);
  // "complete": show the confirmation. "open": the payment failed or was
  // canceled, so mount Checkout again. Fulfill from the webhook, not here.
  res.json({ status: session.status, email: session.customer_details?.email });
});
  • if_required redirects only buyers who used a redirect-based method. Cards finish in place, where Checkout shows its own success state unless you pass onComplete.
  • never never redirects, removes the return_url requirement, and disables redirect-based payment methods.

onComplete runs only with if_required or never. Stripe's pattern destroys the instance and renders your own confirmation:

JavaScript
// The session was created with redirect_on_completion: "if_required".
const checkout = await stripe.createEmbeddedCheckoutPage({
  fetchClientSecret,
  onComplete: async () => {
    checkout.destroy(); // a destroyed instance cannot be mounted again
    showReceipt(await fetch("/purchase-details").then((r) => r.json()));
  },
});
checkout.mount("#checkout");

Neither the return page nor onComplete is a fulfillment signal. Stripe states that webhooks are required for fulfillment, because a buyer can pay and lose their connection before your page loads. Fulfill from checkout.session.completed; the webhook events reference covers which event to trust.

The errors, and what each means

Each message is quoted from the served Stripe.js script or from @stripe/react-stripe-js, so it matches what your console shows.

  1. IntegrationError: stripe.initEmbeddedCheckout() has been removed. Please use stripe.createEmbeddedCheckoutPage() instead.#

    The checkout div stays empty and the console shows the error as the page loads.

    Your page loads Stripe.js dahlia or later, where the method was renamed. A common route here is upgrading @stripe/stripe-js to 9 or 10 while @stripe/react-stripe-js stays on 5, which still calls the old name inside EmbeddedCheckoutProvider.

    Confirm it

    Run npm ls @stripe/stripe-js @stripe/react-stripe-js. stripe-js 9 or higher with react-stripe-js 5 or lower is the mismatch; with a script tag, the version name is in the URL path.

    Fix

    Call stripe.createEmbeddedCheckoutPage({ fetchClientSecret }) with the same options. In React, upgrade @stripe/react-stripe-js to the major that matches stripe-js: 6 for stripe-js 9, 7 for stripe-js 10.

  2. Property 'initEmbeddedCheckout' (or 'createEmbeddedCheckoutPage') does not exist on type 'Stripe'#

    TypeScript fails the build before any code runs.

    @stripe/stripe-js 9.0.0 replaced initEmbeddedCheckout with createEmbeddedCheckoutPage in its types. Versions 8 and earlier declare only the old name, even though the served script has both.

    Confirm it

    Compare the name in the error with your installed @stripe/stripe-js major.

    Fix

    On stripe-js 9 or later, use createEmbeddedCheckoutPage. On 8 or earlier, keep initEmbeddedCheckout until you upgrade, rather than casting the type away.

  3. Invalid Checkout session. Only Checkout sessions with ui_mode=embedded_page can be used with embedded Checkout.#

    Older Stripe.js versions word it with ui_mode=embedded. Either way, nothing mounts.

    The client secret belongs to a session created with another UI mode. Sessions default to hosted_page, and elements and form sessions also carry a client secret, for different Stripe.js entry points.

    Confirm it

    Retrieve the session on your server and read ui_mode.

    Fix

    Create the session with ui_mode: "embedded_page" on API version 2026-03-25.dahlia or later, or "embedded" on an older version. Stripe recommends keeping Stripe.js and your server's API version on the same release train.

  4. Creating the session fails on ui_mode, success_url, cancel_url, or return_url#

    Your server's checkout.sessions.create call returns an invalid request error instead of a session.

    Three rules from Stripe's API reference: embedded is no longer accepted from 2026-03-25.dahlia; success_url and cancel_url are not allowed with embedded_page; and return_url is required when redirect-based payment methods are enabled.

    Confirm it

    Read the error's param and your Stripe API version.

    Fix

    Send embedded_page, drop success_url and cancel_url, and pass return_url with {CHECKOUT_SESSION_ID} in it. To skip a return page entirely, set redirect_on_completion: "never", which disables redirect-based payment methods.

  5. The fetchClientSecret function should always resolve with a client secret as a string.#

    The message ends with the type it received, usually object or undefined.

    fetchClientSecret returned the whole JSON body, or a Response, or nothing, instead of the secret string.

    Confirm it

    Log what your function resolves with. It should look like cs_test_..._secret_....

    Fix

    Return the field: .then((r) => r.json()).then((data) => data.clientSecret), and throw if your server sent an error instead.

  6. You must provide one of either `clientSecret` or `fetchClientSecret` to `createEmbeddedCheckoutPage`.#

    A sibling message says "only one of either" when both are set. React logs its own version from EmbeddedCheckoutProvider.

    The options object has neither field, often because it was built before the secret arrived, or has both.

    Confirm it

    Log the options you pass, at the moment you pass them.

    Fix

    Pass fetchClientSecret alone. Stripe deprecated clientSecret in favor of it because it loads faster.

  7. Unable to parse client secret. Please ensure you are using a valid embedded Checkout client secret.#

    Thrown as soon as Stripe.js reads the secret.

    The value is not a Checkout Session client secret: usually the session ID (cs_...) instead of client_secret, or a secret truncated or re-encoded on the way to the browser.

    Confirm it

    Compare it with session.client_secret as your server received it.

    Fix

    Return session.client_secret exactly as Stripe sent it.

  8. Unsupported prop change on EmbeddedCheckoutProvider: You cannot change fetchClientSecret after setting it.#

    A console warning in React. Checkout keeps the first session, so a changed cart or price never shows up.

    The provider reads its options once. An inline fetchClientSecret is a new function on every render, and the same applies to clientSecret and onComplete.

    Confirm it

    Look for an arrow function or options object created inline in the component that renders the provider.

    Fix

    Wrap fetchClientSecret in useCallback. To start a new session, unmount the provider and mount a new one, for example by changing its key.

  9. You passed an `onComplete` handler for a session that has `redirect_on_completion: always`. This `onComplete` handler will never be called.#

    Stripe.js warns, and the buyer is redirected instead of seeing your success state.

    always is the default, and it redirects every buyer to return_url.

    Confirm it

    Read redirect_on_completion on the session.

    Fix

    Create the session with redirect_on_completion: "if_required" (cards finish in place, redirect methods still return) or "never".

On Flint, checkout that prices the order for you

Flint is a payments API with orders, tax, and inventory built in, running on Stripe rails. The order is the record of the sale from the start: Flint computes its total, collects payment against it, keeps refunds and reporting on it, and sends order.paid when it is paid. You choose where the buyer pays it.

A prebuilt page: hosted checkout

Your backend creates a checkout session for an order and sends the buyer to its url. Your page needs only that URL, with no client secret and no Stripe.js to load:

cURL
curl -X POST https://api.withflintpay.com/v1/checkout-sessions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Idempotency-Key: checkout-order-tote-001" \
  -d '{
    "type": "order",
    "order_id": "ord_1kmn0aExample",
    "redirects": {
      "success_url": "https://example.com/thanks",
      "cancel_url": "https://example.com/cart"
    }
  }'

Flint's checkout page carries your logo, colors, font, and corner radius. It quotes your delivery methods, collects the tax location, takes promotion codes, tips, and gift cards, and accepts cards, Apple Pay and Google Pay with no domain registration, Affirm, and ACH debit, with 3D Secure handled.

Checkout on your own page: a headless session

For checkout inside your site, Flint does not hand you an iframe of its layout. You own every screen, in any language, on your own domain, and Stripe Elements collects the card on Stripe's domain, so card numbers never reach your servers or Flint's. Create the session with surface: "headless":

cURL
curl -X POST https://api.withflintpay.com/v1/checkout-sessions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Idempotency-Key: checkout-pro-annual-001" \
  -d '{
    "type": "order",
    "order_id": "ord_1kmn0aExample",
    "surface": "headless",
    "page_origin": "https://shop.example.com",
    "payment_return_url": "https://shop.example.com/checkout/return"
  }'

The response has no url. It carries checkout_auth_token, a ckat_ credential scoped to this one checkout, which stays on your backend. Read the order and pass its payment_collection to the browser to mount the Payment Element:

JavaScript
// Your backend read GET /v1/orders/{order_id} and passed on payment_collection.
// It holds no secrets: the publishable key is Stripe's, for Stripe.js.
const { stripe: collection } = paymentCollection;
const guidance = collection.elements;

const stripe = Stripe(collection.publishable_key, {
  ...(collection.account_id ? { stripeAccount: collection.account_id } : {}),
});

// Apple Pay and Google Pay ride on card in Stripe Elements.
const TYPES = { card: "card", apple_pay: "card", google_pay: "card", affirm: "affirm", ach_debit: "us_bank_account" };
const elements = stripe.elements({
  mode: guidance.mode,
  amount: guidance.amount_money.amount,
  currency: guidance.amount_money.currency.toLowerCase(),
  paymentMethodCreation: guidance.payment_method_creation, // "manual"
  paymentMethodTypes: [...new Set(guidance.payment_options.flatMap((o) => TYPES[o] ?? []))],
});
elements
  .create("payment", {
    // Show only the wallets Flint offers; Stripe's default can show others.
    wallets: {
      applePay: guidance.payment_options.includes("apple_pay") ? "auto" : "never",
      googlePay: guidance.payment_options.includes("google_pay") ? "auto" : "never",
    },
  })
  .mount("#payment-element");

form.addEventListener("submit", async (event) => {
  event.preventDefault();
  const { error: submitError } = await elements.submit();
  if (submitError) return showMessage(submitError.message);

  // A single-use credential. Flint confirms the payment, not the browser.
  const { error, confirmationToken } = await stripe.createConfirmationToken({ elements });
  if (error) return showMessage(error.message);

  const result = await fetch("/checkout/pay", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ confirmationToken: confirmationToken.id }),
  }).then((r) => r.json());
  handlePaymentResult(result); // succeeded, requires_action, or failed
});

Your backend sends the token to Flint with the balance the buyer approved. If the order changed in between, Flint returns 409 VERSION_CONFLICT before charging anything:

cURL
curl -X POST https://api.withflintpay.com/v1/orders/ord_1kmn0aExample/pay \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Idempotency-Key: pay-ord_1kmn0aExample-ctoken_1kmn0aExample" \
  -d '{
    "action": "pay",
    "payment_source": {
      "credential_type": "stripe_confirmation_token",
      "stripe": {"confirmation_token": "ctoken_1kmn0aExample"}
    },
    "expected_outstanding_money": {"amount": 9900, "currency": "USD"},
    "expected_version": 1790760000,
    "buyer_contact": {"email": "ada@example.com"}
  }'

The response's order_payment_attempt.status plays the part of onComplete: succeeded, requires_action for 3D Secure, or failed with the decline message to show. Fulfill from the order.paid webhook.

Stripe embedded Checkout, mapped to Flint

JobStripe embedded CheckoutFlint headless checkout
Start a checkoutCheckout Session with ui_mode: "embedded_page"Checkout session for an order with surface: "headless"
What the browser holdsThe session's client_secretpayment_collection, which holds no secrets; the checkout_auth_token stays on your backend
The checkout UIStripe's prebuilt page in an iframeYour page, with the Payment Element for card and wallet fields
The totalLine items and prices sent on the sessionFlint prices the order: tax, delivery, promotion codes, tips, and gift cards
Redirect-based methodsreturn_urlpayment_return_url
Knowing it finishedThe return page or onCompleteorder_payment_attempt.status in the pay response
Fulfillmentcheckout.session.completedorder.paid, after checking the order's dispute_status

Both Flint surfaces use the same orders, sessions, and webhooks, so you can start on hosted checkout and move to your own page later without rewriting fulfillment. The embedded payments guide covers the payment step with 3D Secure and retries, Build your own checkout adds delivery, saved cards, and gift cards, and checkout sessions covers the hosted page.

Questions, answered

Why does stripe.initEmbeddedCheckout throw an error now?

Stripe renamed it to createEmbeddedCheckoutPage in Stripe.js dahlia, released with API version 2026-03-25.dahlia. Pages that load @stripe/stripe-js 9 or later, or a dahlia or endive script URL, get an IntegrationError from the old name. The options and returned object are unchanged, so the fix is the new name.

What is the difference between embedded_page, elements, form, and hosted_page?

They are Checkout Session UI modes. hosted_page sends the buyer to a Stripe-hosted page at session.url, and is the default. embedded_page mounts Stripe's prebuilt checkout page inside your site with createEmbeddedCheckoutPage. elements uses Checkout Sessions with individual Elements you lay out yourself, through initCheckoutElementsSdk. form is Stripe's Checkout form UI mode, started with initCheckoutFormSdk. Before 2026-03-25.dahlia, embedded_page was embedded, elements was custom, and hosted_page was hosted.

Is Stripe embedded Checkout an iframe?

Yes. You provide an empty div, and Stripe inserts an iframe into it that sends payment details to Stripe. Stripe advises against placing Checkout inside another iframe, because some payment methods redirect to another page to confirm.

Do I need a return_url with embedded Checkout?

When redirect-based payment methods are enabled, yes. success_url and cancel_url are not allowed with embedded_page, so return_url, with {CHECKOUT_SESSION_ID} in it, is where buyers land. Setting redirect_on_completion to never removes the requirement and disables redirect-based payment methods.

When is the onComplete callback called?

Only for sessions with redirect_on_completion set to if_required or never; with the default, always, the buyer is redirected instead. Stripe says onComplete is called when the session completes successfully, or when the checkout.session.completed event is sent. Use it to destroy the Checkout instance and render your own success state.

Can I fulfill the order from the return page or onComplete?

No. Stripe states that webhooks are required for fulfillment, because a buyer can pay and lose their connection before your page loads. Fulfill from checkout.session.completed on your server and use the return page only to show the result.

How do I show embedded Checkout again after the buyer leaves or a payment fails?

If your return page reads a session status of open, the payment failed or was canceled, and Stripe's quickstart says to mount Checkout again. unmount() detaches an instance you can mount again; destroy() removes it for good, after which you create a new one with createEmbeddedCheckoutPage. In React, unmounting EmbeddedCheckoutProvider destroys the instance for you.

Does Flint have an embedded checkout?

Flint gives you two ways to take the same payment. Hosted checkout is one API call that returns a URL to Flint's checkout page, branded with your logo, colors, and font. Or run checkout on your own page with a headless checkout session: Stripe Elements collects the card, and Flint prices the order, runs the payment, and sends order.paid. Flint does not offer a prebuilt checkout iframe.

Sources