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 itstoken to the browser:
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 namingframe-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:
Modal in React
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 withdata-polar-payment-method. Clicking the element opens the modal.
HTML
Localization
Pass a BCP 47 locale with thelocale option or the data-polar-payment-method-locale attribute:
TypeScript
Events
Events are cancelableCustomEvents 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 toreturnUrl, 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
usePaymentMethodRedirectResult hook:
React

