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.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:

