Skip to main content

Prerequisites

  1. go to sandbox.polar.sh and create an organization.
  2. go to your organization and create a product.
  3. get the product id and set it in the environment variables.
  4. Required environment variables: in apps/server/.env

Installation

Install the required dependencies:

Server-Side Configuration

  1. Initialize the Polar client: in apps/server/src/lib/polar.ts
  1. Configure BetterAuth with Polar plugin:

Webhook Handling

Client-Side Configuration

Set up the auth client with Polar support:

Product Configuration

Define your products in a configuration file: in apps/web/src/src/products.ts
in apps/server/src/utils/products-list.ts

Webhook Handling

Set up webhook handling for Polar events:

Subscription Management

Starting a Checkout

Common Issues

  1. Webhook Signature Verification
    • Ensure the webhook secret is correctly set
    • Verify the signature in the webhook handler
  2. Subscription Status Sync
    • Implement proper webhook handling
    • Update the database on subscription changes
  3. Checkout Session
    • Set correct success and cancel URLs
    • Handle failed payments gracefully