Payments
Payments are powered by Polar.sh, offering a developer-friendly platform for subscriptions and one-time payments.
Setup
- Create a Polar.sh account.
- Get your API keys and Organization ID.
- Add them to your
.envfile:
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.
- The user selects a plan.
- A request is made to
/api/checkoutto create a checkout session. - The user is redirected to the Polar checkout page.
- 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.