2026-10. Build against the sandbox first. Nothing there moves real money.
Install the SDK
Terminal
Set the secrets
Encore manages secrets the same way locally and in the cloud.Access token and environment
Create an organization access token in your sandbox organization’s Settings → Access Tokens, or runpolar auth token. Add it to Encore, along with POLAR_MODE set to sandbox:
Terminal
POLAR_WEBHOOK_SECRET in Receive webhooks. When you deploy to Encore Cloud, set production secrets in its dashboard or your CI pipeline.
Create an API client
Create the client withcreatePolar, reading the token and environment from Encore’s secrets:
payments/polar.ts
POLAR_MODE to production, with a production token, when you go live.
Add a checkout endpoint
This endpoint creates a Checkout Session and redirects the customer to it:payments/payments.ts
/checkout?product=<product_id> to start a checkout. To link the customer to your user, also pass external_customer_id to checkouts.create.
Receive webhooks
Webhooks keep your app in sync with checkouts, orders and subscriptions.Forward webhooks locally
The Polar CLI forwards your sandbox organization’s webhooks to your Encore app:Terminal
POLAR_WEBHOOK_SECRET:
Terminal
https://<your-domain>/webhooks/polar and set that endpoint’s secret in Encore Cloud.
Add the webhook handler
Useapi.raw() so the handler gets the raw request body, which signature verification needs. webhooks.validateEvent verifies the signature and returns a typed event:
payments/webhooks.ts
Run it locally
Start your Encore app:Terminal
localhost:9400 lets you:
- View traces for every request, including checkout redirects and webhook deliveries
- Inspect API calls between services
- Query local databases
- View logs and errors as they happen
Deploy to production
Deploy to Encore Cloud or your own cloud account:Terminal
- Set production secrets in the Encore Cloud dashboard, with
POLAR_MODEset toproduction - Create a webhook endpoint in your production organization for your production domain
- Update
success_urlto your production URL

