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.

The two providers

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: 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

1

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.
2

Register the webhook endpoint

Point a Stripe webhook endpoint at:
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.
3

Set the variables and restart

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 that can read subscriptions and write meter events is enough for the worker.
4

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.
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.

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.

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: 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.
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.