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 —
GetUsagereports metered usage against the tenant's current plan - Stripe integration — webhook endpoint validates the
Stripe-Signatureheader 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
| Method | Path | Description |
|---|---|---|
GET | /api/v1/billing/plans | Public plan catalog |
GET | /api/v1/billing/usage | Current tenant's usage against their plan |
GET | /api/v1/billing/subscription | Current tenant's subscription |
POST | /api/v1/billing/checkout | Create a Stripe checkout session |
GET | /api/v1/billing/portal | Get a Stripe billing-portal link |
POST | /api/v1/billing/upgrade-request | Request a plan upgrade |
GET | /api/v1/billing/invoices | List invoices |
POST | /api/v1/webhooks/stripe | Stripe webhook receiver (signature-verified, not bearer-authed) |
GET | /api/v1/admin/billing/plans | Admin: list all plans |
POST | /api/v1/admin/billing/plans | Admin: create a plan |
GET | /api/v1/admin/billing/subscriptions | Admin: list all tenant subscriptions |
GET | /health | Health check |
Environment Variables
| Variable | Description |
|---|---|
DATABASE_URL | PostgreSQL connection |
STRIPE_SECRET_KEY | Stripe API key |
STRIPE_WEBHOOK_SECRET | Used to verify the Stripe-Signature header |
STRIPE_SUCCESS_URL / STRIPE_CANCEL_URL | Redirect targets after Stripe checkout |
PORT | HTTP port |