Better Billing

Better Billing

TypeScript-first, provider-agnostic billing infrastructure for modern applications

A comprehensive billing solution that simplifies subscription management, payment processing, and usage-based billing for modern TypeScript applications.

Heavily inspired by better-auth and their excellent approach to building flexible, type-safe authentication infrastructure.

Why Better Billing?

Building billing infrastructure is complex and time-consuming. Better Billing provides:

  • Type Safety: Full TypeScript support with auto-generated types
  • Provider Flexibility: Switch between Stripe, Polar, and other providers without changing your code
  • Database Agnostic: Works with Drizzle ORM, Prisma, and other adapters
  • Framework Support: Integrates seamlessly with Next.js, Remix, Hono, and more
  • Developer Experience: Simple CLI tools and intuitive APIs

Key Features

🚀 Quick Setup

Get started in minutes with our CLI tool that handles initialization, migrations, and schema generation.

💳 Multi-Provider Support

Write once, work with any payment provider. Currently supports Stripe with more coming soon.

🗄️ Flexible Database Layer

Choose your preferred ORM without vendor lock-in.

🔌 Plugin System

Extend functionality with custom plugins for usage metering, webhooks, and business logic.

Quick Example

import { betterBilling } from 'better-billing';
import drizzleAdapter from '@better-billing/db/adapters/drizzle';
import { corePlugin } from 'better-billing/plugins/core';
import { stripePlugin } from 'better-billing/plugins/stripe';
import Stripe from 'stripe';

const stripe = new Stripe('sk_test_...');

const billing = betterBilling({
  serverUrl: 'http://localhost:3000',
  adapter: drizzleAdapter(db, { provider: 'pg', schema: {} }),
  plugins: [
    corePlugin({
      subscriptionPlans: [
        { planName: 'Free' },
        { planName: 'Pro', trialDays: 7 },
      ],
    }),
    stripePlugin({
      stripe,
      subscriptionPlans: {
        monthly: [
          { planName: 'Free', items: [{ price: 'price_free_monthly' }] },
          { planName: 'Pro', items: [{ price: 'price_pro_monthly' }] },
        ],
      },
      postSuccessUrl: 'https://app.com/success',
      postCancelUrl: 'https://app.com/cancel',
      webhookEndpointSecret: process.env.STRIPE_WEBHOOK_SECRET,
    }),
  ] as const,
});

// Start a subscription checkout
const session = await billing.providers.stripe.startSubscriptionCheckout({
  billableId: 'user_123',
  billableType: 'user',
  planName: 'Pro',
  cadence: 'monthly',
  email: 'customer@example.com',
});

Platform Support

Better Billing is designed to be provider and database agnostic. Here's what's currently supported and what we can support in the future:

Payment Providers

ProviderStatusPluginDescription
StripeSupportedstripePluginFull subscription management, checkout sessions, webhooks
Polar🚧 OpenpolarPluginPolar payment processing
Paddle🚧 OpenpaddlePluginMoR (Merchant of Record) payment processing
PayPal🚧 OpenpaypalPluginGlobal payment solutions
Lemonsqueezy🚧 OpenlemonsqueezyPluginCreator-focused payment platform
Razorpay🚧 OpenrazorpayPluginIndia-focused payment gateway
CustomSupportedCustom pluginsBuild your own payment provider integration

Database Adapters

Database/ORMStatusAdapterDescription
Drizzle ORMSupporteddrizzleAdapterWorks with PostgreSQL, MySQL, SQLite
Prisma🚧 OpenprismaAdapterPopular TypeScript ORM
Kysely🚧 OpenkyselyAdapterType-safe SQL query builder
TypeORM🚧 OpentypeormAdapterMature ORM with decorators
Raw SQL🚧 OpensqlAdapterDirect SQL query interface
CustomSupportedCustom adaptersImplement your own database adapter

Framework Integrations

All major frameworks are supported through dedicated adapters:

FrameworkStatusIntegration
Next.jsSupportedtoNextJsHandler
React StartSupportedtoReactStartHandler
Solid StartSupportedtoSolidStartHandler
SvelteKitSupportedtoSvelteKitHandler
Node.js/ExpressSupportedtoNodeHandler
HonoSupportedtoHonoHandler
FastifySupportedtoFastifyHandler

Get Started