Skip to main content
When you want to prevent customers from changing their email address during the checkout process, you can link the checkout session to an existing customer. This is useful when customers are already authenticated in your application and you want to ensure the purchase is associated with their verified account.

Overview

By passing either customer_id or external_customer_id when creating a checkout session, Polar will:
  • Pre-fill the customer’s information in the checkout form
  • Disable the email field so it cannot be edited
  • Link the resulting order to the specified customer

Using Customer ID

If you’ve already created a customer in Polar and have their Polar customer ID, you can use it directly.
1

Get the Customer ID

Retrieve the customer ID from your Polar dashboard or through the Customers API.The customer ID is a UUID format like: 992fae2a-2a17-4b7a-8d9e-e287cf90131b
2

Create Checkout Session with customer_id

Pass the customer_id parameter when creating the checkout session.
import { Polar } from "@polar-sh/sdk";

const polar = new Polar({ accessToken: process.env["POLAR_ACCESS_TOKEN"] });

const checkout = await polar.checkouts.create({
    products: ["<product_id>"],
    customerId: "992fae2a-2a17-4b7a-8d9e-e287cf90131b", 
});

console.log(checkout.url);
3

Redirect to Checkout

Redirect your customer to the checkout URL returned in the response. The email field will be pre-filled and disabled for editing.

Using External Customer ID

If you have your own user management system, you can use your internal customer ID. This is the recommended approach as it makes reconciliation between your system and Polar easier.
1

Use Your Internal Customer ID

When creating a checkout session, pass your application’s user ID as the external_customer_id.Polar will:
  • Look for an existing customer with this external ID
  • If found, link to that customer and pre-fill their data
2

Create Checkout Session with external_customer_id

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({ accessToken: process.env["POLAR_ACCESS_TOKEN"] });

const checkout = await polar.checkouts.create({
    products: ["<product_id>"],
    externalCustomerId: "user_12345", // Your application's user ID
});

console.log(checkout.url);
3

Redirect to Checkout

Redirect your customer to the checkout URL. The email field will be disabled from editing.