Stripe Billing Integration
omnibioai-billing lets an organization's billing admin add a credit card and manage billing through Stripe-hosted pages (Checkout, in setup mode, and the Billing Portal). Card numbers never reach OmniBioAI servers, databases, or logs — only the Stripe customer ID and non-sensitive card display fields (brand, last 4, expiry) are stored. This page covers the cross-repository configuration; implementation detail lives in each repository's own source (omnibioai-billing/app/services/stripe_service.py and app/routers/billing.py, omnibioai-studio/docker/nginx-router.conf).
Prerequisites
- A Stripe account. No business/bank verification is required for test mode — only Test mode API keys are needed for any non-production deployment.
- The Stripe CLI for local webhook forwarding (
brew install stripe/stripe-cli/stripe, thenstripe login). manage_billingpermission inomnibioai-auth(granted to theorg_adminrole alongsidemanage_api_keys) to call either of the two mutating endpoints below. Any org member can read payment-method state.
Environment variables
Set on billing-service (omnibioai-studio's .env / docker-compose.yml):
| Variable | Purpose |
|---|---|
STRIPE_SECRET_KEY | Test-mode secret key (sk_test_...) from Stripe's Developers → API keys. Empty = Stripe disabled; the service reports stripe_enabled: false and the two mutating endpoints return 503. |
STRIPE_WEBHOOK_SECRET | Signing secret for POST /billing/stripe/webhook. In production this comes from the registered webhook endpoint (below); for local development, the Stripe CLI prints one each time stripe listen starts. |
BILLING_WEB_BASE_URL | Base URL the service uses to build Checkout/Portal success_url/cancel_url/return_url server-side only — never accepted from the client. |
All three are optional and empty by default; see omnibioai-billing's own README for the full environment-variable reference.
API surface
GET /billing/organizations/{org_id}/payment-method — any org member
POST /billing/organizations/{org_id}/payment-method/setup-session — requires manage_billing
POST /billing/organizations/{org_id}/portal-session — requires manage_billing
POST /billing/stripe/webhook — no user auth; Stripe's signature instead
The webhook route is mounted unauthenticated in nginx-router.conf as an exact-match location ahead of the auth_request-gated /billing prefix that covers every other billing route — Stripe signs each delivery itself, so a session/JWT gate would reject every legitimate one.
Stripe Dashboard setup
- Webhook endpoint (Developers → Webhooks → Add endpoint):
https://<BILLING_WEB_BASE_URL>/billing/stripe/webhook. Subscribe to:checkout.session.completedpayment_method.attachedcustomer.updatedpayment_method.detached
- Customer Portal (Settings → Billing → Customer portal): enable payment-method update, invoice history, and tax ID collection.
- Copy the endpoint's signing secret into
STRIPE_WEBHOOK_SECRET.
Testing locally
Run the Stripe CLI alongside the stack to forward webhooks without registering a public endpoint:
stripe listen \
--events checkout.session.completed,payment_method.attached,customer.updated,payment_method.detached \
--forward-to localhost/billing/stripe/webhook
It prints a whsec_... signing secret — put that in STRIPE_WEBHOOK_SECRET and restart billing-service to pick it up. Then, through the UI (Billing → Overview → Add card), use Stripe's standard test card 4242 4242 4242 4242, any future expiry, any CVC.
A SetupIntent created by a Checkout Session can only be completed by actually submitting that hosted page (a Stripe platform restriction) — it cannot be confirmed directly via the API. For testing the webhook-driven sync logic specifically (without a browser), attach a test payment method straight to an existing Stripe customer instead:
import stripe
stripe.api_key = "sk_test_..."
pm = stripe.PaymentMethod.create(type="card", card={"token": "tok_visa"})
stripe.PaymentMethod.attach(pm["id"], customer=customer_id)
stripe.Customer.modify(customer_id, invoice_settings={"default_payment_method": pm["id"]})
This fires real payment_method.attached / customer.updated webhooks through the same signature-verified pipeline.
Troubleshooting
Invalid mode: setup. Managed Payments... only supports mode: subscription or mode: payment— Stripe's Managed Payments feature is enabled by default on new accounts and rejectsmode=setupCheckout Sessions.create_setup_sessiondisables it explicitly (managed_payments={"enabled": False}) as ofomnibioai-billingPR #29; if this recurs, confirm that fix is deployed.503from either POST endpoint —STRIPE_SECRET_KEYis empty; Stripe is disabled on this deployment.409from the portal-session endpoint — the organization has no Stripe customer yet (no card has ever been added); call the setup-session endpoint first.- Card doesn't appear after completing Checkout — confirm the Stripe CLI (local) or the registered webhook endpoint (deployed) is actually forwarding events, and that
STRIPE_WEBHOOK_SECRETmatches. Illegal instruction(SIGILL) crash onbilling-servicestartup, ARM64 hosts — an unpinnedcryptographyversion resolved to a build incompatible with the Docker Desktop ARM64 VM wheniam_clientimports it. Pinned to46.0.3inomnibioai-billing'srequirements.txtas of PR #29.
Verification state
Verified live end-to-end on 2026-10-03 against a real Stripe test-mode account, through the full real stack (nginx-router → api-gateway → auth-service → billing-service, real MySQL/Redis): customer creation, Checkout setup-session creation, a real test card attached with its webhooks delivered and processed, the card correctly returned by the read endpoint, a real Billing Portal session created, and payment_method.detached correctly clearing the stored card. Not yet verified: a real browser completing the hosted Checkout page itself (the SetupIntent-confirmation restriction above meant that specific step was exercised via direct API calls standing in for the hosted form, not a browser).