Introduction

billing-sdk is a TypeScript SDK that provides a unified API for subscription billing. Check "can this user access X?" regardless of whether you use Stripe, Polar, or other providers.

Features

  • Provider adapters - Stripe, Polar, and mock adapter for testing
  • Entitlement caching - Memory or Redis with auto-invalidation on webhooks
  • Feature gating - Declarative plan-to-features mapping with hasFeature() checks
  • Normalized webhooks - Same event types across all providers

Quick example

lib/billing.ts
import { createEnhancedClient } from '@fuime/billing-sdk'
import { stripe } from '@fuime/billing-sdk/stripe'

const billing = createEnhancedClient({
  provider: stripe({ apiKey: process.env.STRIPE_KEY }),
  cache: { ttlMs: 60_000 },
  plans: {
    'prod_pro': { features: ['api', 'export'] },
    'prod_enterprise': { features: '*' },
  }
})

// Check feature access
if (await billing.hasFeature(userId, 'api')) {
  // User has access
}

Next steps