Add finance app with Stripe provider (invoices, payments, subscription pricing) #21

Closed
opened 2026-07-26 14:26:38 -07:00 by westfarn · 2 comments
Owner

Summary

Introduce a new Django app finance that integrates Stripe as the payment provider. Users complete payment on Stripe Checkout (hosted); we persist invoices and payments locally and drive subscription pricing from Django settings.

Related: #17 (token quotas / usage enforcement) — this ticket covers payment collection and ledger; #17 covers usage limits against paid plans.

Goals

  • New app: finance registered in INSTALLED_APPS
  • Stripe as the (initial) payment provider
  • Track invoices and payments in our DB
  • Subscription pricing values live in settings.py (env-backed)
  • Customer pays on Stripe’s hosted flow (Checkout / Customer Portal as appropriate) — we do not collect card details in our UI

Requirements

App & settings

  • Create finance Django app under the project
  • Add settings for Stripe + subscription pricing, e.g.:
    • STRIPE_SECRET_KEY, STRIPE_PUBLISHABLE_KEY, STRIPE_WEBHOOK_SECRET
    • Subscription price config (amount / currency / interval / Stripe Price ID mapping) in settings.py
  • Document required env vars in .env.example / .env.prod.example

Models

  • Invoice: link to user/company, Stripe invoice/session IDs, status, amounts, period, timestamps
  • Payment: link to invoice (and/or user), Stripe payment intent / charge IDs, amount, status, timestamps
  • Store provider name (e.g. stripe) so we can add other providers later without a rewrite

Stripe flow

  • API to create a Stripe Checkout Session (or equivalent) and return the redirect URL
  • User completes payment on Stripe
  • Webhook endpoint verifies signatures and upserts invoice/payment records on relevant events (checkout.session.completed, invoice.paid, invoice.payment_failed, etc.)
  • Idempotent webhook handling (safe retries)

Admin / API

  • Django admin for invoices and payments
  • Authenticated endpoints to start checkout and list own invoices/payments (as needed by FE)

Acceptance criteria

  • finance app installed and migrated
  • Subscription pricing configurable via settings / env
  • Checkout redirects user to Stripe to enter payment details
  • Webhooks create/update Invoice and Payment rows
  • Admin can inspect invoices and payments
  • Tests cover session creation (mocked Stripe), webhook verification, and model persistence
  • Secrets never committed; examples documented

Out of scope (unless needed for MVP)

  • Full Customer Portal UI for plan changes/cancellations (can follow-on)
  • Token quota enforcement (see #17)
  • Frontend self-serve registration (tracked in chat_web_app)
## Summary Introduce a new Django app `finance` that integrates Stripe as the payment provider. Users complete payment on Stripe Checkout (hosted); we persist invoices and payments locally and drive subscription pricing from Django settings. Related: #17 (token quotas / usage enforcement) — this ticket covers payment collection and ledger; #17 covers usage limits against paid plans. ## Goals - New app: `finance` registered in `INSTALLED_APPS` - Stripe as the (initial) payment provider - Track **invoices** and **payments** in our DB - Subscription pricing values live in `settings.py` (env-backed) - Customer pays on Stripe’s hosted flow (Checkout / Customer Portal as appropriate) — we do **not** collect card details in our UI ## Requirements ### App & settings - Create `finance` Django app under the project - Add settings for Stripe + subscription pricing, e.g.: - `STRIPE_SECRET_KEY`, `STRIPE_PUBLISHABLE_KEY`, `STRIPE_WEBHOOK_SECRET` - Subscription price config (amount / currency / interval / Stripe Price ID mapping) in `settings.py` - Document required env vars in `.env.example` / `.env.prod.example` ### Models - **Invoice**: link to user/company, Stripe invoice/session IDs, status, amounts, period, timestamps - **Payment**: link to invoice (and/or user), Stripe payment intent / charge IDs, amount, status, timestamps - Store provider name (e.g. `stripe`) so we can add other providers later without a rewrite ### Stripe flow - API to create a Stripe Checkout Session (or equivalent) and return the redirect URL - User completes payment on Stripe - Webhook endpoint verifies signatures and upserts invoice/payment records on relevant events (`checkout.session.completed`, `invoice.paid`, `invoice.payment_failed`, etc.) - Idempotent webhook handling (safe retries) ### Admin / API - Django admin for invoices and payments - Authenticated endpoints to start checkout and list own invoices/payments (as needed by FE) ## Acceptance criteria - [ ] `finance` app installed and migrated - [ ] Subscription pricing configurable via settings / env - [ ] Checkout redirects user to Stripe to enter payment details - [ ] Webhooks create/update Invoice and Payment rows - [ ] Admin can inspect invoices and payments - [ ] Tests cover session creation (mocked Stripe), webhook verification, and model persistence - [ ] Secrets never committed; examples documented ## Out of scope (unless needed for MVP) - Full Customer Portal UI for plan changes/cancellations (can follow-on) - Token quota enforcement (see #17) - Frontend self-serve registration (tracked in `chat_web_app`)
Author
Owner

Frontend companion: ai_ml_operations/chat_web_app#31 (self-serve sign-up → Stripe Checkout).

Frontend companion: https://git.aimloperations.com/ai_ml_operations/chat_web_app/issues/31 (self-serve sign-up → Stripe Checkout).
Author
Owner

Follow-on for Customer Portal / Account billing UI: ai_ml_operations/chat_web_app#33

ai_ml_operations/chat_web_app#33

Follow-on for Customer Portal / Account billing UI: ai_ml_operations/chat_web_app#33 https://git.aimloperations.com/ai_ml_operations/chat_web_app/issues/33
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ai_ml_operations/chat_backend#21