@polar-sh/nextjs adapter and API version 2026-10.
Build against the sandbox first. Nothing there moves real money. The complete code is in the polar-next example on GitHub.
To scaffold the routes in an existing Next.js project instead, run:
Terminal
Install the packages
Terminal
Set the access token
Create an organization access token in your sandbox organization’s Settings → Access Tokens, or runpolar auth token, and add it to .env.local:
.env.local
Create an API client
Use the client for any API call your app makes, such as listing products:src/polar.ts
environment or set it to "production", and use a production token.
Add a checkout route
TheCheckout handler creates a Checkout Session and redirects the customer to it:
src/app/checkout/route.ts
/checkout?products=<product_id>. Add &external_customer_id=<your user ID> so Polar links the customer to your user. The handler appends checkout_id={CHECKOUT_ID} to successUrl. See the adapter reference for every query parameter.
Receive webhooks
Webhooks keep your database in sync with checkouts, orders and subscriptions.Forward webhooks locally
The Polar CLI forwards your sandbox organization’s webhooks to your dev server:Terminal
.env.local:
.env.local
https://<your-domain>/api/webhook/polar and use that endpoint’s secret instead.
Add the webhook route
TheWebhooks handler verifies the signature, then calls your handlers with a typed payload:
src/app/api/webhook/polar/route.ts
onCustomerStateChanged is often all you need for access control. See Customer state and Webhook events.
Verify it works
- Start your dev server and
polar webhook listen - Open
/checkout?products=<product_id>and pay with the test card4242 4242 4242 4242 - You land on your success URL, and the CLI logs
order.paidandcustomer.state_changeddeliveries to your route
succeeded shortly after payment. Polar sends checkout.updated when it does, so a confirmation page that waits for it can update its UI then.

