Skip to main content

Embedded hosted checkout

Embedded hosted checkout lets your page keep its layout while COPE renders the payment form inside an iframe. Your site owns the surrounding experience. COPE owns the checkout route, payment collection, tax finality, order creation, and buyer-facing terminal states. Use embedded checkout when you need a custom storefront or in-page checkout modal. Use redirect checkout when the simplest integration is enough or when a browser blocks the iframe flow.

Requirements

Before creating embedded checkout sessions:
  • Create a Checkout SDK publishable key for the COPE business.
  • Register every parent page origin that may host the iframe, for example https://shop.example.com.
  • Use an origin only: scheme, host, and optional port. Do not include a path, query string, fragment, or userinfo.
  • Use HTTPS in production. http://localhost is only for development and test environments.
  • Register the success and cancel URLs used for redirect-based completion or fallback. They are matched as complete URL strings, not as origins — see redirect URLs.
The parent origin must exactly match the browser page origin that calls checkout({ embed_origin }). https://shop.example.com and https://www.shop.example.com are different origins. Embed origins and redirect URLs are separate allowlists with different matching rules. An embed origin is scheme, host, and optional port only. A redirect URL is the entire URL, including its path and any query string.

Create an iframe checkout

The checkout response includes both URL shapes: mountCheckout() refuses to mount when checkout.embedOrigin is missing or does not exactly match window.location.origin.

Mount behavior

mountCheckout() creates the iframe for you:
  • src is checkout.embedCheckoutUrl.
  • title defaults to COPE checkout.
  • allow is set to payment * for browser wallet support.
  • referrerPolicy is set to no-referrer.
  • width is set to 100%.
  • min-height is set to 720px.
  • No sandbox attribute is added by the SDK.
Do not build the iframe manually unless you are testing the embed contract. The SDK also performs the trusted mount handshake and filters all iframe messages by origin, source window, message source, and version.

Fallbacks

Set fallback: "redirect" for buyer-safe recovery if the iframe does not complete the trusted ready handshake before readyTimeoutMs.
With the default fallback: "error", the SDK calls:

Events

The iframe sends sanitized events to the SDK. Callback payloads do not include checkout credentials, payment client secrets, or buyer PII.
Use onMessage when you need the raw sanitized event stream:
onSuccess and onCancel are convenience callbacks derived from terminal events.

Security model

Embedded checkout has two layers of authorization:
  1. COPE validates embed_origin against the business checkout embed domain allowlist when checkout is created.
  2. The iframe route validates the same embed contract before rendering checkout UI.
The SDK sends the mount message with a specific targetOrigin; it never uses *. It accepts iframe messages only when:
  • event.origin matches the checkout iframe origin.
  • event.source is the mounted iframe window.
  • event.data.source is cope.checkout.
  • event.data.version is 1.
The regular hosted checkout route is frame-denied. Only /checkout/embed/:token is intended for iframe rendering.

Test your integration

Use a development or staging page that matches the origin you registered for the COPE business. Exercise the full flow before launch:
  1. Create a cart.
  2. Add a product and payment plan.
  3. Set buyer identity.
  4. Reprice.
  5. Create checkout with embed_origin.
  6. Mount the iframe and inspect the postMessage conversation.
Also verify rejected unregistered origins, expired checkout sessions, missing mount handshakes, and redirect fallback behavior.

Troubleshooting