> ## Documentation Index
> Fetch the complete documentation index at: https://polar.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrate checkout & customers

> Link Polar customers to your users and send them to checkout.

> [!NOTE]
>
> **Why this matters:** Every order, subscription, benefit and usage event belongs to a customer. Linking customers to your own users by external ID means you never have to store Polar's IDs. See [Customers](https://polar.sh/docs/concepts/customers.md).

In this step you'll create a customer for one of your users, then send them to a checkout for **Pro**.

The examples use the sandbox client from the [quickstart overview](https://polar.sh/docs/quickstart/overview.md#prerequisites), on API version `2026-10`.

## Create the customer when a user signs up

Create a Polar customer when a user signs up in your application, with your user ID as `external_id`:

```typescript TypeScript theme={null}
await polar.customers.create({
  email: "jane@example.com",
  external_id: "user_123",
});
```

```python Python theme={null}
polar.customers.create(
    email="jane@example.com",
    external_id="user_123",
)
```

```bash cURL theme={null}
curl -X POST https://sandbox-api.polar.sh/v1/customers/ \
  -H "Authorization: Bearer $POLAR_ACCESS_TOKEN" \
  -H "Polar-Version: 2026-10" \
  -H "Content-Type: application/json" \
  -d '{ "email": "jane@example.com", "external_id": "user_123" }'
```

To add a test customer by hand, open **Customers**, click **+**, fill in **Email** and **External ID**, and click **Create Customer**. From the CLI: `polar customers create --email jane@example.com --external-id user_123`.

The events you sent in [step 1](https://polar.sh/docs/quickstart/track-usage.md) with `external_customer_id: "user_123"` now belong to this customer.

Creating customers up front is optional, since checkout creates the customer if it doesn't exist. Doing it at sign-up means usage, free plans and the [customer portal](https://polar.sh/docs/features/customer-portal/introduction.md) work from the first moment.

## Send the user to checkout

When the user clicks **Upgrade**, create a checkout session from your backend and redirect them to the `url` in the response:

```typescript TypeScript theme={null}
const checkout = await polar.checkouts.create({
  products: [product.id],
  external_customer_id: "user_123",
  success_url: "https://example.com/billing?checkout_id={CHECKOUT_ID}",
});

redirect(checkout.url);
```

```python Python theme={null}
checkout = polar.checkouts.create(
    products=[product.id],
    external_customer_id="user_123",
    success_url="https://example.com/billing?checkout_id={CHECKOUT_ID}",
)

return redirect(checkout.url)
```

```bash cURL theme={null}
curl -X POST https://sandbox-api.polar.sh/v1/checkouts/ \
  -H "Authorization: Bearer $POLAR_ACCESS_TOKEN" \
  -H "Polar-Version: 2026-10" \
  -H "Content-Type: application/json" \
  -d '{
    "products": ["'"$PRODUCT_ID"'"],
    "external_customer_id": "user_123",
    "success_url": "https://example.com/billing?checkout_id={CHECKOUT_ID}"
  }'
```

Passing `external_customer_id` ties the purchase to your user and locks the email field to theirs. After paying, the customer returns to your `success_url`, with `{CHECKOUT_ID}` replaced by the session ID.

> [!TIP]
>
> Don't need per-user sessions? Create a [Checkout Link](https://polar.sh/docs/features/checkout/links.md) under **Products → Checkout Links**, or with `polar checkout_links create`, and link to it from your pricing page. To keep customers on your site, use [embedded checkout](https://polar.sh/docs/features/checkout/embed.md).

## Verify it works

Paying requires a person to complete the checkout page. Ask the user to pay with the test card before checking the customer state.

Open the checkout URL and pay with Stripe's test card `4242 4242 4242 4242`, any future expiry date and any CVC. Then check Jane's customer: she has an active **Pro** subscription and 100,000 credited tokens on the **AI tokens** meter. In the customer state, these are `active_subscriptions` and `active_meters`.

> [tab] Dashboard
>
> * Open **Customers**
> * Select Jane
> * **Overview** lists the **Pro** subscription
> * **Usage** shows the **AI tokens** meter and its credits

> [tab] CLI
>
> ```bash theme={null}
> polar customers get_state_external user_123
> ```

> [tab] Prompt
>
> ```text Prompt theme={null}
> Show the customer state for user_123 in my Polar sandbox.
> ```
>
> Uses the `customers_get_state_external` operation of the [Polar MCP server](https://polar.sh/docs/integrate/mcp.md).

## Learn more

| Resource | Description |
| - | - |
| [Checkout API](https://polar.sh/docs/features/checkout/session.md) | Multiple products, ad-hoc prices and prefilled fields |
| [Customer management](https://polar.sh/docs/features/customer-management.md) | External IDs and metadata |
| [Customer portal](https://polar.sh/docs/features/customer-portal/introduction.md) | Let customers manage their own billing |
| [Framework adapters](https://polar.sh/docs/integrate/sdk/adapters/introduction.md) | Checkout routes for Next.js, Nuxt, Better Auth and more |

> [card] [Next: Sync customer state](https://polar.sh/docs/quickstart/webhooks.md)
>
> Grant access in your application when the subscription starts or changes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.