Add finance app with Stripe Checkout subscriptions (#21) (#23)
Unit Tests / test (push) Successful in 10s
Unit Tests / test (push) Successful in 10s
## Summary - Closes #21 — new Django `finance` app with Stripe as payment provider - Subscription price defaults to **$10 USD / month** via `SUBSCRIPTION_PRICE_AMOUNT_CENTS = 1000` in `settings.py` (env-overridable) - Persists **Invoice** and **Payment** rows; both registered in Django admin (with payment inline on invoices) - Checkout Session API redirects users to Stripe hosted payment; webhook verifies signatures and upserts ledger idempotently ## API - `POST /api/finance/checkout/` — JWT auth → `{ checkout_url, session_id }` - `GET /api/finance/invoices/` / `GET /api/finance/payments/` — own records - `POST /api/finance/webhooks/stripe/` — Stripe signature-verified webhook ## Config Documented in `.env.example` / `.env.prod.example`: `STRIPE_SECRET_KEY`, `STRIPE_PUBLISHABLE_KEY`, `STRIPE_WEBHOOK_SECRET`, optional `STRIPE_PRICE_ID`, `FRONTEND_BASE_URL` ## Test plan - [x] `uv run python manage.py test finance` (17 tests) - [ ] Set Stripe test keys locally; create checkout session; complete payment in Stripe test mode - [ ] Confirm Invoice/Payment appear in `/admin/` - [ ] Point Stripe webhook to `/api/finance/webhooks/stripe/` and verify `checkout.session.completed` / `invoice.paid`Reviewed-on: #23
This commit was merged in pull request #23.
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from finance.models import Invoice, Payment
|
||||
|
||||
|
||||
class PaymentInline(admin.TabularInline):
|
||||
model = Payment
|
||||
extra = 0
|
||||
readonly_fields = (
|
||||
"provider",
|
||||
"status",
|
||||
"amount",
|
||||
"currency",
|
||||
"stripe_payment_intent_id",
|
||||
"stripe_charge_id",
|
||||
"paid_at",
|
||||
"failure_message",
|
||||
"created",
|
||||
"last_modified",
|
||||
)
|
||||
can_delete = False
|
||||
show_change_link = True
|
||||
|
||||
|
||||
@admin.register(Invoice)
|
||||
class InvoiceAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
"id",
|
||||
"user",
|
||||
"company",
|
||||
"provider",
|
||||
"status",
|
||||
"amount_due",
|
||||
"amount_paid",
|
||||
"currency",
|
||||
"period_start",
|
||||
"period_end",
|
||||
"stripe_invoice_id",
|
||||
"stripe_checkout_session_id",
|
||||
"created",
|
||||
)
|
||||
list_filter = ("provider", "status", "currency")
|
||||
search_fields = (
|
||||
"user__email",
|
||||
"user__username",
|
||||
"company__name",
|
||||
"stripe_invoice_id",
|
||||
"stripe_checkout_session_id",
|
||||
"stripe_subscription_id",
|
||||
"stripe_customer_id",
|
||||
"description",
|
||||
)
|
||||
readonly_fields = ("created", "last_modified")
|
||||
raw_id_fields = ("user", "company")
|
||||
inlines = [PaymentInline]
|
||||
date_hierarchy = "created"
|
||||
|
||||
|
||||
@admin.register(Payment)
|
||||
class PaymentAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
"id",
|
||||
"user",
|
||||
"company",
|
||||
"invoice",
|
||||
"provider",
|
||||
"status",
|
||||
"amount",
|
||||
"currency",
|
||||
"stripe_payment_intent_id",
|
||||
"stripe_charge_id",
|
||||
"paid_at",
|
||||
"created",
|
||||
)
|
||||
list_filter = ("provider", "status", "currency")
|
||||
search_fields = (
|
||||
"user__email",
|
||||
"user__username",
|
||||
"company__name",
|
||||
"stripe_payment_intent_id",
|
||||
"stripe_charge_id",
|
||||
"invoice__stripe_invoice_id",
|
||||
)
|
||||
readonly_fields = ("created", "last_modified")
|
||||
raw_id_fields = ("user", "company", "invoice")
|
||||
date_hierarchy = "created"
|
||||
Reference in New Issue
Block a user