Skip to main content
The Embedded Payment Method opens a Polar-hosted card form on your site, as a modal or an inline iframe. The customer adds a card and Polar attaches it to the customer, as their default payment method unless you pass setAsDefault: false. Card details never touch your servers. Use it in a custom billing portal, or anywhere customers need to update their card without leaving your app.

Create a session token

Every embed is authenticated with a short-lived token for one customer. Create a customer session on your server, so your access token stays secret, and pass its token to the browser:
The token starts with polar_mst_, expires after one hour and is scoped to that customer. Pass customer_id instead of external_customer_id to use Polar’s ID. The examples use the sandbox and API version 2026-10.
API only. Not available from the CLI or MCP server.

Embed hosts

The embed only opens on a host you’ve allowed under Settings → Embedding, the same list as Embedded checkout. See Embed hosts for the accepted formats. If the page isn’t on the list, the browser refuses to load the embed: it stays blank and the console shows a message naming frame-ancestors. An invalid or expired token has the same effect.

Install the library

Open as a modal

PolarEmbedPaymentMethod.create() opens the embed as a full-screen modal overlay.
TypeScript
create() options: Open the modal from a Client Component event handler:
React

Embed inline

Mount a borderless, auto-resizing iframe into an element you control:
TypeScript
createInline() takes the same options as create(), except returnUrl, plus a required element to mount into.

Inline in React

Use the <PolarPaymentMethod /> component:
React

Use the script tag

Without a bundler, add the script and an element with data-polar-payment-method. Clicking the element opens the modal.
HTML
The same script powers embedded checkout, so one tag covers both.

Localization

Pass a BCP 47 locale with the locale option or the data-polar-payment-method-locale attribute:
TypeScript
Without it, the embed is in English. Unsupported locales fall back to English. See Localization for the supported languages.

Events

Events are cancelable CustomEvents on the embed instance. Call event.preventDefault() to skip the default action. To check the result from your backend, list the customer’s saved methods with polar customers list_payment_methods_external user_123 or List Customer Payment Methods. The MCP operation is customers_list_payment_methods_external.

Redirect-based payment methods

Some payment methods authorize on the provider’s site. The whole tab navigates away and back to returnUrl, which defaults to the page the embed was opened from, so the modal doesn’t survive the round trip. Read the outcome on the returned page with the static getRedirectResult():
TypeScript
In React, use the usePaymentMethodRedirectResult hook:
React
Either way, the status query parameter is removed from the URL, so a refresh doesn’t show a stale result. Cards, including 3D Secure, complete inside the embed and never take this path.

Learn more