---
title: "Billing provider"
description: "Sell plans monthly or yearly through Stripe, or run with no payment provider: the variables, the webhook, AI overage metering and what startup refuses."
---

A deployment either sells subscriptions through Stripe or sells nothing and
has plans assigned by an operator. That is one setting, `BILLING_PROVIDER`,
and the second answer is the default.

This page is the operator's side. For what plans contain and how a customer
experiences an upgrade, a failed payment or a cancellation, see
[Billing and plans](/concepts/billing-and-plans).

## The two providers

| Variable | Default | Purpose |
|---|---|---|
| `BILLING_PROVIDER` | `manual` | `manual` or `stripe`. Any other value stops the API at startup |

| | `manual` | `stripe` |
|---|---|---|
| Plans are enforced | Yes | Yes |
| A plan changes when | An operator assigns it | Stripe reports a subscription, or an operator assigns it |
| **Upgrade** and **Manage billing** in the dashboard | Not offered | Offered, for plans with a configured price |
| `POST /api/v1/billing/checkout`, `POST /api/v1/billing/portal` | `501` | A redirect URL to Stripe |
| `POST /api/v1/billing/webhook` | `400` for every payload | Verified Stripe events only |
| Outbound calls to a payment provider | None | To `https://api.stripe.com` |

## Without a payment provider

Leave `BILLING_PROVIDER` unset. This is a supported, permanent way to run
TRUSTIVAN, and it is what a self-hosted install or a contract-invoiced
deployment is expected to do.

What that means in practice:

- **Every organization starts on Free**, and its plan's limits and features
  are enforced exactly as they would be with a provider.
- **You change a plan from the [staff console](/deployment/staff-console)**:
  assign `free`, `pro` or `enterprise`, or grant a single limit or feature as
  an override. Both need a reason and both are audited. There is no
  customer-facing route that changes a plan.
- **Checkout and the billing portal answer `501`** with
  `this deployment does not sell subscriptions; your plan is set by agreement`.
  The dashboard does not offer the buttons.
- **The webhook endpoint accepts nothing.** It answers `400` with
  `this deployment does not accept billing webhooks` to every request, so an
  unauthenticated caller cannot post themselves a plan.
- **No reconciliation runs** and nothing calls out.

A stray Stripe variable under the manual provider is treated as a mistake
rather than ignored. If `STRIPE_SECRET_KEY` or `STRIPE_WEBHOOK_SECRET` is set
while `BILLING_PROVIDER` is `manual`, the API refuses to start and names the
variable, because that combination almost always means an operator believes
billing is live.

## Selling through Stripe

| Variable | Required | Purpose |
|---|---|---|
| `BILLING_PROVIDER` | Yes | `stripe` |
| `STRIPE_SECRET_KEY` | Yes | Authenticates TRUSTIVAN's calls to Stripe |
| `STRIPE_WEBHOOK_SECRET` | Yes | The signing secret of the webhook endpoint you register. Every event is verified against it |
| `STRIPE_PRICE_PRO` | At least one price | The monthly Stripe price that sells Team (plan id `pro`) |
| `STRIPE_PRICE_BUSINESS` | At least one price | The monthly price for Business |
| `STRIPE_PRICE_TEAM_CERTIFICATES`, `STRIPE_PRICE_BUSINESS_CERTIFICATES`, `STRIPE_PRICE_TEAM_EXPOSURE`, `STRIPE_PRICE_BUSINESS_EXPOSURE` | At least one price | The monthly prices for the single-product Certificates and Exposure plans |
| `STRIPE_PRICE_ENTERPRISE` | At least one price | The Stripe price that sells the Enterprise plan |
| `STRIPE_PRICE_PRO_ANNUAL`, `STRIPE_PRICE_BUSINESS_ANNUAL`, `STRIPE_PRICE_TEAM_CERTIFICATES_ANNUAL`, `STRIPE_PRICE_BUSINESS_CERTIFICATES_ANNUAL`, `STRIPE_PRICE_TEAM_EXPOSURE_ANNUAL`, `STRIPE_PRICE_BUSINESS_EXPOSURE_ANNUAL` | No | The yearly prices for the same plans (ten months' price). A plan without one is sold monthly only |
| `STRIPE_METER_EVENT_NAME` | No | The Stripe Billing meter AI overage credits are reported to. Default `ai_credits` |
| `STRIPE_API_BASE` | No | Overrides the Stripe API origin. It exists so tests can run against a mock. Leave it unset |

<Steps>
  <Step title="Create a recurring price for each plan you sell">
    In Stripe, create a product and a recurring monthly price for each plan
    you sell, and a yearly price beside it if you sell yearly. A plan with no
    price configured cannot be bought through checkout, and a plan with no
    yearly price is offered monthly only. The amount, currency, tax treatment
    and trial terms live in Stripe; TRUSTIVAN stores only the price identifier.
  </Step>

  <Step title="Register the webhook endpoint">
    Point a Stripe webhook endpoint at:

    ```text
    https://<api-origin>/api/v1/billing/webhook
    ```

    Subscribe it to these events:

    - `checkout.session.completed`
    - `customer.subscription.created`
    - `customer.subscription.updated`
    - `customer.subscription.deleted`
    - `invoice.paid`
    - `invoice.payment_failed`

    Copy the endpoint's signing secret.
  </Step>

  <Step title="Set the variables and restart">
    ```bash
    BILLING_PROVIDER=stripe
    STRIPE_SECRET_KEY=<secret key>
    STRIPE_WEBHOOK_SECRET=<endpoint signing secret>
    STRIPE_PRICE_PRO=<monthly price id>
    STRIPE_PRICE_PRO_ANNUAL=<yearly price id>
    STRIPE_PRICE_ENTERPRISE=<price id>
    ```

    Set them on the API **and** on the worker. The API serves checkout and the
    webhook; the process that runs the scan worker runs reconciliation and the
    AI overage meter. A [restricted key](https://docs.stripe.com/keys#limit-access)
    that can read subscriptions and write meter events is enough for the worker.
  </Step>

  <Step title="Confirm which provider started">
    Each backend process logs `billing provider selected` at startup, with a
    `provider` field (`stripe` or `manual`) and a `self_serve` field.
  </Step>
</Steps>

<Note>
The production Compose file passes `BILLING_PROVIDER` and the `STRIPE_`
variables from your environment file to the `api` and `worker` services, and
to no other. Before 2026-10-13 it passed none of them, and before 2026-11-13
it did not pass them to the worker, so reconciliation never ran there; see
[Production Compose](/installation/production-compose#which-variables-reach-the-containers).
</Note>

### What startup refuses

A half-configured payment provider is a fatal startup error, not a warning.
The failure it prevents is quiet: a deployment that can sell a subscription
and cannot hear about it charges a customer and never upgrades them.

| Configuration | Result |
|---|---|
| `stripe` with no `STRIPE_SECRET_KEY` | Refuses to start |
| `stripe` with no `STRIPE_WEBHOOK_SECRET` | Refuses to start |
| `stripe` with no price set, monthly or yearly | Refuses to start: there is nothing to buy |
| A key beginning `sk_test_` when `ENV` is not `development` | Refuses to start: a test key takes no money |
| `STRIPE_API_BASE` set with a key beginning `sk_live_` | Refuses to start |
| `manual` with `STRIPE_SECRET_KEY` or `STRIPE_WEBHOOK_SECRET` set | Refuses to start |
| Any other `BILLING_PROVIDER` value | Refuses to start |

## How a purchase reaches a plan

1. An organization admin starts checkout from **Settings → Plan**. The API
   answers with a Stripe Checkout URL and the browser goes there. Checkout and
   the portal need the `organization:manage` permission, which an API key
   cannot hold, so a leaked pipeline credential cannot commit a customer to a
   subscription. The body names the plan and `interval` (`month`, the
   default, or `year`); any other interval answers `400`, and a plan with no
   price at that interval answers `402` naming both.
2. The customer pays at Stripe and is sent back to the dashboard's plan tab.
   Returning proves nothing and changes nothing.
3. Stripe posts a signed event to the webhook. TRUSTIVAN verifies it, works
   out which organization and which plan it concerns, and writes the
   subscription. **This is the only step that changes a plan.**

A Stripe subscription maps to a TRUSTIVAN plan by its price: the monthly and
the yearly price of a plan both grant that plan. A subscription on a price
none of the `STRIPE_PRICE_` variables names grants nothing. Stripe's subscription statuses collapse to four:

| Stripe status | TRUSTIVAN status |
|---|---|
| `trialing` | Trialing |
| `active` | Active |
| `past_due`, `unpaid` | Past due |
| Anything else, including `incomplete`, `paused` and `canceled` | Cancelled |

A past-due organization keeps its plan for 14 days, counted from the first
failed payment. Later failed retries do not restart that clock. A subscription
set to cancel at the end of its period stays active until the period ends.

## The webhook endpoint

`POST /api/v1/billing/webhook` is unauthenticated by necessity: Stripe has no
session and no API key. The signature is the authentication.

- **Verification.** The `Stripe-Signature` header is checked against
  `STRIPE_WEBHOOK_SECRET`. An event whose timestamp is more than five minutes
  from the server's clock is refused even when its signature is genuine, so
  keep the host's clock synchronised.
- **Idempotency.** Each event is recorded by its Stripe identifier before it
  is applied. A redelivery is acknowledged and applied once.
- **Logging.** A rejected payload is logged without its body.

| Status | Meaning | What Stripe does |
|---|---|---|
| `200` | Applied, a duplicate, a type TRUSTIVAN does not act on, or an event no organization could be matched to | Stops |
| `400` | The signature did not verify, or this deployment is on the manual provider and accepts no billing events | Stops |
| `500` | TRUSTIVAN failed to apply a verified event | Retries |

An unmatched event is recorded, not dropped, and answered `200` because a
retry would return the same answer. It is the trace of a paying customer who
is not getting what they paid for, so look for it when a customer reports
exactly that.

## Reconciliation

Webhooks are notifications, and notifications are lost. Once an hour, the
process running the scan worker asks Stripe for the current state of the
organizations it has not checked recently, 50 at a time, and writes any
difference through the same path a webhook uses. An organization Stripe has
no record of is skipped.

If your reverse proxy cannot be reached by Stripe for a while, reconciliation
is what brings plans back into line afterwards. It does nothing under the
manual provider.

## AI overage metering

AI credits past a plan's monthly allowance (overage, Team and above, when an
admin turns it on) are charged through a Stripe Billing meter. Once an hour
the worker reports to the meter named by `STRIPE_METER_EVENT_NAME`
(`ai_credits` by default) each organization's overage since its last report,
with the organization's Stripe customer as `stripe_customer_id` and the
credits as `value`.

To charge for it, create the meter in Stripe with the event name you
configure, a metered price on it (the list price is US$0.02 a credit), and
add that price to the subscriptions that may run overage.

- **Only the delta.** What was reported is remembered per organization and
  calendar month (UTC); each report is the difference. The first pass after a
  month ends reports that month's last hour, timestamped inside the month.
- **Never twice.** Each report carries an identifier made of the
  organization, the month and a sequence number, sent as the event's
  `identifier` and as the request's idempotency key, and is written down
  before it is sent. A report whose answer was lost is resent unchanged on the
  next pass, so Stripe counts it once.
- **Never past the cap.** At most the organization's overage cap is reported
  for a month. Credits spent past the allowance while overage was off are not
  overage and are not billed.
- **Skipped**: organizations with no Stripe customer. Under the manual
  provider the task does nothing.

A failed report is logged as `reporting AI overage` with the organization and
month, and retried on the next pass.

## What TRUSTIVAN does not hold

No card data, no invoices and no receipts. Payment methods, invoice history
and cancellation are Stripe's own pages, opened from **Manage billing**. The
only Stripe identifiers TRUSTIVAN stores are the customer and subscription
references it needs to ask Stripe about an organization.

Stripe is the only payment adapter that ships. The integration is written
against a small provider interface, and no second provider is implemented.

## Related

- [Billing and plans](/concepts/billing-and-plans): plans, limits and the
  customer's view.
- [Staff console](/deployment/staff-console): assigning a plan or an override
  by hand.
- [Environment variables](/configuration/environment#billing): the variables
  in the full list.
