# Stripe billing

> Each tenant's Stripe customer, seat counts (options.seatRoles) and the active subscription item from the Stripe Sync Engine, for createBilling(): checkout, the customer portal, seat sync and Stripe webhook handling.

- Category: Billing & commerce
- Module: `billing`
- Modes: `managed`, `custom`
- Docs: https://bettersupabase.com/docs/blocks/billing
- Page: https://bettersupabase.com/blocks/billing

## Install

```bash
npx better-supabase add billing
```

The command also installs `updated-at`, `memberships`, `permissions`.

## Configure

Add the block to `better-supabase.config.ts`:

```ts
import { defineConfig } from "better-supabase/config";

export default defineConfig({
  blocks: {
    // Required by billing; add installs them too.
    "updated-at": {},
    memberships: {},
    permissions: {},
    // Modes: "managed", "custom". The default is "managed".
    billing: { mode: "managed" },
  },
});
```

## Client

The React hooks are the registry item `@better-supabase/use-billing` (`npx shadcn add @better-supabase/use-billing`). They return data and actions and render no UI. Source: https://github.com/ScaleDockHQ/better-supabase/blob/main/packages/registry/items/hooks/use-billing.ts

## Events

- `billing.account_linked`
- `billing.customer_linked`

## Related blocks

Requires: [memberships](https://bettersupabase.com/blocks/memberships.md), [permissions](https://bettersupabase.com/blocks/permissions.md)

Works with: [ledger](https://bettersupabase.com/blocks/ledger.md), [organizations](https://bettersupabase.com/blocks/organizations.md), [usage](https://bettersupabase.com/blocks/usage.md)

## Recipes

- [Plan picker](https://bettersupabase.com/recipes/plan-picker.md): The plans with their prices and a checkout button each. Checkout starts in a server action or API route that holds the Stripe key, and the client opens the URL it returns.
