Billing HTTP API (Flask, token-auth, fail-closed) #2
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
Flask HTTP API over the billing core from issue #1. Token-auth'd, fail-closed, testable without real Stripe.
Depends on: issue #1 (billing core). Files allowed:
gitea_saas/server.py,gitea_saas/config.py,tests/test_server.py,requirements.txt. Do NOT modify anything else.Spec
create_app(core, api_key)factory.X-API-Keyheader must matchSAAS_API_KEY(env or constructor arg). Missing/wrong key -> 401. No auth on/health.GET /health->{"ok": true}POST /api/clients{name, tier?, meta?}-> client with balanceGET /api/clients/{id}-> client + balance (404 if missing)POST /api/clients/{id}/credits{amount_minor, idempotency_key, ref_type?, ref_id?}-> new balancePOST /api/clients/{id}/debits{amount_minor, idempotency_key, ref_type?, ref_id?}-> new balance; 409 if would go negativePOST /api/clients/{id}/holds{amount_minor, ref_type?, ref_id?, ttl_s?}-> hold id; 409 if insufficientPOST /api/holds/{id}/release-> releasedGET /api/clients/{id}/ledger?from=&to=-> rowsGET /api/clients(list, admin) -> all clients + balanceserrorsas{"error": "...", "code": "..."}.SAAS_PORTenv forapp.run(only whenpython -m gitea_saas.server); tests use Flask test client.Acceptance
/healthpublicVerification:
python -m pytest tests/test_server.py -qpasses.pbwraith referenced this issue2026-08-25 11:36:22 +02:00