Skip to main content

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, then stripe login).
  • manage_billing permission in omnibioai-auth (granted to the org_admin role alongside manage_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):

VariablePurpose
STRIPE_SECRET_KEYTest-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_SECRETSigning 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_URLBase 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​

  1. Webhook endpoint (Developers → Webhooks → Add endpoint): https://<BILLING_WEB_BASE_URL>/billing/stripe/webhook. Subscribe to:
    • checkout.session.completed
    • payment_method.attached
    • customer.updated
    • payment_method.detached
  2. Customer Portal (Settings → Billing → Customer portal): enable payment-method update, invoice history, and tax ID collection.
  3. 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 rejects mode=setup Checkout Sessions. create_setup_session disables it explicitly (managed_payments={"enabled": False}) as of omnibioai-billing PR #29; if this recurs, confirm that fix is deployed.
  • 503 from either POST endpoint — STRIPE_SECRET_KEY is empty; Stripe is disabled on this deployment.
  • 409 from 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_SECRET matches.
  • Illegal instruction (SIGILL) crash on billing-service startup, ARM64 hosts — an unpinned cryptography version resolved to a build incompatible with the Docker Desktop ARM64 VM when iam_client imports it. Pinned to 46.0.3 in omnibioai-billing's requirements.txt as 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).