Tinda comes with built-in support for Polar payments through the Better Auth plugin, allowing you to accept payments and manage subscriptions with minimal configuration.
The Polar integration is powered by @polar-sh/better-auth, which seamlessly
integrates with Tinda's authentication system for automatic customer creation
and subscription management.
What is Polar?
Polar is a developer-first payment infrastructure that provides checkout, subscriptions, and customer management out of the box. It's designed to make payment integration simple and straightforward.
Prerequisites
Before you begin, make sure you have:
- A Polar account (sign up at polar.sh)
- Your Polar Organization Access Token
- Products created in your Polar dashboard
Step 1: Get Your Polar Credentials
- Log in to your Polar dashboard
- Navigate to Organization Settings → Access Tokens
- Create a new Organization Access Token with the required scopes
- Copy your token and organization ID
For development, use Polar's Sandbox environment. Remember that access tokens, products, and data are completely separated between Production and Sandbox.
Step 2: Configure Environment Variables
Add the following variables to your .env file:
POLAR_ACCESS_TOKEN="your_organization_access_token"
POLAR_WEBHOOK_SECRET="your_webhook_secret"
POLAR_SERVER="sandbox" # or "production"
Step 3: Set Up Your Products
- In your Polar dashboard, navigate to Products → Catalogue
- Create your subscription products
- Copy the Product IDs for each product
- Update
config/plans.tswith your Product IDs:
export const PLANS = [
{
id: "pro-monthly",
name: "Pro",
description: "For growing teams and businesses.",
polarProductId: "your_polar_product_id_here",
// ... other plan details
},
];
Step 4: Configure Webhooks
Webhooks are handled automatically by the Better Auth Polar plugin.
- In your Polar dashboard, go to Settings → Webhooks
- Add a new webhook endpoint:
- Development:
https://your-ngrok-url.ngrok.io/api/auth/webhook/polar - Production:
https://your-domain.com/api/auth/webhook/polar
- Development:
- Copy the webhook secret and add it to your
.envfile
For local development, use ngrok or a similar tool to expose your local server to the internet.
How It Works
Automatic Customer Creation
When a user signs up in Tinda, the Polar plugin automatically creates a corresponding customer in Polar with the user's email. This happens seamlessly in the background.
Checkout Flow
Users can initiate checkout directly from your app:
await authClient.checkout({
products: ["your_product_id"],
referenceId: workspaceId, // Optional: for organization support
});
Customer Portal
Users can manage their subscriptions through the Polar Customer Portal:
await authClient.customer.portal();
Subscription Status
Check a user's subscription status:
const { data: subscriptions } = await authClient.customer.subscriptions.list();
const isSubscribed = subscriptions.some((sub) => sub.status === "active");
Testing Your Integration
- Set
POLAR_SERVER="sandbox"in your.env - Start your development server:
pnpm dev - Navigate to the pricing page
- Click "Get started" on a plan
- Complete the checkout in Polar's sandbox
- Verify the redirect back to your app
- Check the subscription status in the billing page
Additional Resources
For more advanced configurations like usage-based billing, custom benefits, or organization support, check out the billing integration guide.