Skip to main content
Version: 1.0

Billing Service

Repo: o-apps/billing-service

Handles subscription plans, usage-based billing, and Stripe integration for tenant billing.

Key Capabilities​

  • Plans — public plan catalog, plus admin-only plan creation
  • Subscriptions — per-tenant subscription state, upgrade requests, and admin visibility across all tenant subscriptions
  • Usage tracking — GetUsage reports metered usage against the tenant's current plan
  • Stripe integration — webhook endpoint validates the Stripe-Signature header before processing checkout/subscription events; checkout session creation and billing-portal link generation
  • Invoices — list a tenant's invoice history

Auth​

Unlike most services in this monorepo, billing-service ships its own bearer-auth middleware (internal/adapters/primary/http/middleware/auth.go) rather than the shared pkg/authmiddleware package — it predates that extraction. Tenant-facing routes require a valid token; admin routes (/api/v1/admin/billing/*) require an admin role on top of that. The Stripe webhook route is intentionally unauthenticated by bearer token — it's verified instead via Stripe's own request signature.

REST API​

MethodPathDescription
GET/api/v1/billing/plansPublic plan catalog
GET/api/v1/billing/usageCurrent tenant's usage against their plan
GET/api/v1/billing/subscriptionCurrent tenant's subscription
POST/api/v1/billing/checkoutCreate a Stripe checkout session
GET/api/v1/billing/portalGet a Stripe billing-portal link
POST/api/v1/billing/upgrade-requestRequest a plan upgrade
GET/api/v1/billing/invoicesList invoices
POST/api/v1/webhooks/stripeStripe webhook receiver (signature-verified, not bearer-authed)
GET/api/v1/admin/billing/plansAdmin: list all plans
POST/api/v1/admin/billing/plansAdmin: create a plan
GET/api/v1/admin/billing/subscriptionsAdmin: list all tenant subscriptions
GET/healthHealth check

Environment Variables​

VariableDescription
DATABASE_URLPostgreSQL connection
STRIPE_SECRET_KEYStripe API key
STRIPE_WEBHOOK_SECRETUsed to verify the Stripe-Signature header
STRIPE_SUCCESS_URL / STRIPE_CANCEL_URLRedirect targets after Stripe checkout
PORTHTTP port