Skip to main content

core-billing-service

Handles Stripe integration for checkout sessions, subscription management, and billing builders used during onboarding. Receives Stripe webhooks for payment event processing.

Worker name: crow-core-billing-service Domain (prod): internal.billing.crowai.dev Domain (dev): dev.internal.billing.crowai.dev

Schema​

billing_builder​

Used during onboarding to accumulate billing preferences before creating a Stripe subscription.

ColumnTypeNotes
idtext PK
organizationIdtext
modulestextJSON {"web":false,"cctv":false,"social":false}
payAsYouGobooleandefault false
billingPeriodtextdefault monthly, also annual
stripeCustomerIdtextnullable, set after checkout
stripeSubscriptionIdtextnullable, set after checkout
statustextdefault draft, also active
onboardingIdtextnullable
createdAtintegerepoch ms

subscription​

ColumnTypeNotes
idtext PK
organizationIdtextunique (one subscription per org)
stripeCustomerIdtext
stripeSubscriptionIdtext
modulestextJSON {"web":true,"cctv":false,"social":false}
payAsYouGoboolean
billingPeriodtextmonthly or annual
statustextdefault active, also cancelled, past_due
currentPeriodStartintegerepoch ms
currentPeriodEndintegerepoch ms
createdAtintegerepoch ms
updatedAtintegerepoch ms

Routes​

MethodPathDescription
POST/api/v1/billing/billing-buildersCreate billing builder
GET/api/v1/billing/billing-builders/{id}Get billing builder
PATCH/api/v1/billing/billing-builders/{id}Update modules/period/payAsYouGo
POST/api/v1/billing/checkout/sessionCreate Stripe checkout session
GET/api/v1/billing/plansList available plans and pricing
POST/api/v1/billing/subscriptionsCreate subscription record
GET/api/v1/billing/subscriptions/{organizationId}Get subscription for org
POST/api/v1/billing/webhookStripe webhook endpoint (public, signature-verified)

Environment Variables​

VariableExample
ENVIRONMENTdev
AUTH_SERVICE_URLhttps://dev.internal.auth-api.crowai.dev
NOTIFICATION_SERVICE_URLhttps://dev.internal.notifications.crowai.dev
AUTH_CLIENT_URLhttps://dev.auth.crowai.dev
STRIPE_PRICE_ID_PROStripe price ID
STRIPE_PRICE_ID_ENTERPRISEStripe price ID

Secrets​

SecretPurpose
BETTER_AUTH_SECRETJWT verification
INTERNAL_GATEWAY_KEYGateway trust validation
STRIPE_SECRET_KEYStripe API authentication
STRIPE_WEBHOOK_SECRETStripe webhook signature verification

Bindings​

BindingTypeName
DBD1crow-core-billing-service-db
R2_BUCKETR2crow-core-billing-service-store

Dependencies​

  • Inbound: gateway (billing operations), auth service (onboarding flow)
  • Outbound: auth service (JWT verification), notification service (payment confirmations)

Key Behaviors​

  • INTERNAL_GATEWAY_KEY guard: Applied on /api/v1/billing/* middleware, runs before JWT verification
  • Checkout BOLA: Checkout route requires X-Organization-Id header and validates it against the billing builder's org
  • Webhook bypass: POST /api/v1/billing/webhook is public (no auth, no internal key) -- Stripe provides authentication via Stripe-Signature header
  • ZodError sanitization: Validation errors return generic messages without schema details
  • Modules: Three toggleable components -- web, cctv, social