Skip to main content
These guides provide complete, production-ready examples for integrating Polar’s payment and subscription features into your application.

Getting Started

Next.js Integration

Complete setup for Next.js applications with server actions

Laravel Integration

Full integration guide for Laravel applications

Core Features

Checkout Sessions

Create secure checkout flows for products and subscriptions

Subscription Upgrades

Handle subscription plan upgrades with proration

Subscription Downgrades

Manage subscription downgrades and cancellations

Seat-Based Pricing

Implement team subscriptions with seat management

Prerequisites

Before following these guides, you’ll need:
1

Polar Account

Sign up at polar.sh and create an organization.
2

API Keys

Generate API keys from your Polar dashboard under Settings > API Keys.
3

Products Setup

Create at least one product with pricing in your Polar dashboard.
4

Development Environment

Set up your development environment with your preferred framework.

API Authentication

All Polar API requests require authentication using your API key:
curl https://api.polar.sh/v1/products \
  -H "Authorization: Bearer polar_sk_..."
Never expose your API keys in client-side code. Always make API calls from your backend.

SDK Libraries

Polar provides official SDK libraries for popular languages:
import { Polar } from '@polar-sh/sdk'

const polar = new Polar({
  accessToken: process.env.POLAR_API_KEY,
})

Testing

Use Polar’s sandbox environment for testing:
  1. Sandbox API Keys: Use polar_sk_test_... keys for testing
  2. Test Cards: Use Stripe test card numbers (4242 4242 4242 4242)
  3. Webhooks: Use webhook test mode or tools like ngrok for local testing

Common Patterns

Error Handling

All guides include comprehensive error handling examples:
try {
  const checkout = await polar.checkouts.create({
    productPriceId: 'price_123',
  })
} catch (error) {
  if (error.statusCode === 404) {
    // Product not found
  } else if (error.statusCode === 403) {
    // Permission denied
  } else {
    // Other error
  }
}

Webhooks

Many guides demonstrate webhook handling for async events:
app.post('/webhooks/polar', async (req, res) => {
  const event = polar.webhooks.verifyEvent(
    req.body,
    req.headers['polar-signature']
  )
  
  switch (event.type) {
    case 'subscription.created':
      // Handle new subscription
      break
    case 'order.succeeded':
      // Handle successful order
      break
  }
  
  res.json({ received: true })
})

Customer Portal

Building customer-facing portals for subscription management:
// Authenticate customer
const { token } = await polar.customerSessions.create({
  email: customer.email,
  organizationId: 'org_123',
})

// Customer can now manage their subscriptions
const subscriptions = await polar.customerPortal.subscriptions.list()

Next Steps

Choose a guide based on your use case:

Support

Need help? We’re here for you:

Build docs developers (and LLMs) love