Polar
Leave Localhost supports Polar as a billing provider.
Leave Localhost supports Polar as a billing provider.
Setup
-
Select Polar as the active provider:
BILLING_PROVIDER=polarAll provider integrations are compiled into the deployment;
BILLING_PROVIDERalone decides which one is active. Leaving it blank disables billing regardless of the other variables. -
Set environment variables in your Convex deployment:
BILLING_PROVIDER=polar POLAR_ORGANIZATION_TOKEN=org_... POLAR_SERVER=sandbox # or "production" POLAR_WEBHOOK_SECRET=... POLAR_PRO_MONTHLY_PRODUCT_ID=... POLAR_PRO_YEARLY_PRODUCT_ID=... POLAR_PRO_LIFETIME_PRODUCT_ID=... -
Create products in the Polar dashboard:
- A monthly subscription product
- A yearly subscription product
- A lifetime (one-time) product
-
Set up the webhook in the Polar dashboard:
- URL:
https://<your-convex-url>/webhooks/polar - Subscribe to subscription and order events
- URL:
How It Works
The Polar adapter at billing/polar/adapter.ts implements the
BillingProviderAdapter interface:
createCheckout— creates a Polar checkout session with the mapped product ID.createCustomerPortal— redirects to Polar's customer portal.cancelCurrentSubscription— cancels the active subscription via the Polar API.
Webhook Handler
The Polar webhook handler at billing/polar/webhook.ts is an HTTP action that
verifies the webhook signature and processes subscription events.
Sandbox vs Production
Set POLAR_SERVER=sandbox during development to use Polar's test environment.
Switch to production for live payments.
Next Reads
- Webhooks — general webhook architecture.
- Billing Overview — billing system overview.