feat(billing): extract Billing Service (Step 4)
- stripe_service: checkout sessions, webhook handling, subscription CRUD
- tier_manager: feature matrix (4 tiers), quota enforcement, rate limits
- routes: checkout, webhook (no auth), subscription, tier query, features
- Traefik header auth (X-User-Id) replaces get_current_user dependency
- /tier/{user_id} endpoint for internal service-to-service lookups
- /features and /features/{tier} for feature matrix queries
- Dockerfile: single worker, 30s timeout (lightweight service)
This commit is contained in:
46
services/billing/app/main.py
Normal file
46
services/billing/app/main.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""Billing Service — FastAPI application.
|
||||
|
||||
Owns: Stripe checkout/webhook, subscription management, tier feature matrix,
|
||||
quota enforcement.
|
||||
|
||||
Downstream services query this service (or read the user's tier from
|
||||
the X-User-Tier header injected by Traefik) for billing decisions.
|
||||
The webhook endpoint is exposed WITHOUT ForwardAuth so Stripe can reach it.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import AsyncGenerator
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.routes import router
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
logger.info("billing: service started")
|
||||
yield
|
||||
logger.info("billing: service stopped")
|
||||
|
||||
|
||||
app = FastAPI(title="Adiuva Billing Service", lifespan=lifespan)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_methods=["GET", "POST", "DELETE"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
app.include_router(router)
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health() -> dict[str, str]:
|
||||
return {"status": "ok", "service": "billing"}
|
||||
Reference in New Issue
Block a user