Let your customers securely add a payment method without leaving your site.
Getting a session token
Every embed is authenticated with a short-lived customer session token. Create it on your server to keep the Polar access token secret, then hand the token to the client.Embed hosts
The payment method embed only opens on a host you’ve allowed. It uses the same list as Embedded Checkout: add your site under Settings → Preferences → Embedding before embedding it. The list applies as soon as you save it. See Writing a host for the accepted formats, including wildcards, ports and local development hosts. If the page isn’t on the list, the browser refuses to frame the embed, so it stays blank and the browser console shows a message namingframe-ancestors. An invalid or expired session token has the same effect.
Implementation
Start by installing the SDK.Modal
PolarEmbedPaymentMethod.create() opens the embed as a full-screen modal overlay.
create() options:
Modal in React
Open the modal from a Client Component event handler:Inline embed (vanilla JS)
Mount a chrome-less, auto-resizing iframe into an element you control:createInline() accepts the same options as create() (except returnUrl) plus a required element (the container to mount into).
Inline embed (React)
Use the<PolarPaymentMethod /> component:
Code Snippet
The simplest integration: add the script and a trigger element withdata-polar-payment-method. Clicking the element opens the modal.
Localization
The embed is fully localized, pass a BCP47 code via thelocale option (or data-polar-payment-method-locale attribute):
Events
All events are dispatched as cancelableCustomEvents on the embed instance. Call event.preventDefault() to opt out of the SDK’s default action.
Redirect-based payment methods
Some payment methods authorise on the provider’s own site. The browser navigates the whole tab away and back toreturnUrl (defaults to the page the SDK was opened from), so the modal can’t survive the round-trip.
Read the outcome on the returned page with the static getRedirectResult():
usePaymentMethodRedirectResult hook to avoid writing your own effect:

