Payments

Payments are powered by Polar.sh, offering a developer-friendly platform for subscriptions and one-time payments.

Setup

  1. Create a Polar.sh account.
  2. Get your API keys and Organization ID.
  3. Add them to your .env file:
POLAR_ACCESS_TOKEN="your-access-token"
POLAR_WEBHOOK_SECRET="your-webhook-secret"
POLAR_ORGANIZATION_ID="your-org-id"

Checkout Flow

The checkout process is handled via the /api/checkout endpoint.

  1. The user selects a plan.
  2. A request is made to /api/checkout to create a checkout session.
  3. The user is redirected to the Polar checkout page.
  4. Upon success, they are redirected back to your app.

Webhooks

Webhooks are handled at /api/webhook/polar. This endpoint receives events from Polar (e.g., subscription.created, payment.succeeded) and updates your database accordingly.

Ensure you configure the webhook URL in your Polar dashboard to point to https://your-domain.com/api/webhook/polar.

Customer Portal

Users can manage their subscriptions via the Customer Portal. The /api/portal endpoint handles redirecting the user to their Polar portal.