Files
westfarn e1e086a474
Deploy Beta / unit-tests (push) Successful in 11s
Unit Tests / test (push) Successful in 11s
Deploy Beta / docker (push) Successful in 21s
Deploy Beta / deploy-beta (push) Successful in 50s
Monetization app + RevenueCat webhooks (store IAP ledger) (#69)
## Summary
- Rename `finance` → **`monetization`** Django app (keep `finance_*` tables via `label = "finance"`)
- Add `services/stripe.py` + `services/revenuecat.py`; RevenueCat webhook upserts **subscription + Invoice/Payment** (billing history parity with Stripe)
- Mount `/api/monetization/` + keep `/api/finance/` alias
- Extend `Source`/`Provider` with `revenuecat`; product→plan mapping via `revenuecat_product_id` / `REVENUECAT_PRODUCT_PLAN_MAP`

Closes #68. Companion to [chat_web_app#100](ai_ml_operations/chat_web_app#100).

## Test plan
- [x] `manage.py test monetization.tests` (54 OK)
- [x] Smoke `chat_backend.tests.test_views_documents` + `test_oauth`
- [ ] Deploy: set `REVENUECAT_WEBHOOK_SECRET`; point RC webhook at `/api/finance/webhooks/revenuecat/`
- [ ] Map store product IDs on `SubscriptionPlan.revenuecat_product_id` (or env JSON map)
- [ ] Sandbox INITIAL_PURCHASE → subscription `source=revenuecat` + invoice in `/finance/invoices/`Reviewed-on: #69
2026-08-04 03:40:15 -07:00

238 lines
8.3 KiB
Python

# Generated by Django 6.0 on 2026-07-27 00:16
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
("chat_backend", "0023_promptmetric_tokens_in_promptmetric_tokens_out"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="Invoice",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created", models.DateTimeField(default=django.utils.timezone.now)),
(
"last_modified",
models.DateTimeField(default=django.utils.timezone.now),
),
(
"provider",
models.CharField(
choices=[("stripe", "Stripe")], default="stripe", max_length=32
),
),
(
"status",
models.CharField(
choices=[
("draft", "Draft"),
("open", "Open"),
("paid", "Paid"),
("void", "Void"),
("uncollectible", "Uncollectible"),
("payment_failed", "Payment failed"),
],
db_index=True,
default="open",
max_length=32,
),
),
("currency", models.CharField(default="usd", max_length=8)),
(
"amount_due",
models.PositiveIntegerField(
default=0,
help_text="Amount due in the smallest currency unit (e.g. cents).",
),
),
(
"amount_paid",
models.PositiveIntegerField(
default=0,
help_text="Amount paid in the smallest currency unit (e.g. cents).",
),
),
("period_start", models.DateTimeField(blank=True, null=True)),
("period_end", models.DateTimeField(blank=True, null=True)),
(
"stripe_invoice_id",
models.CharField(
blank=True,
db_index=True,
max_length=255,
null=True,
unique=True,
),
),
(
"stripe_checkout_session_id",
models.CharField(
blank=True,
db_index=True,
max_length=255,
null=True,
unique=True,
),
),
(
"stripe_subscription_id",
models.CharField(
blank=True, db_index=True, max_length=255, null=True
),
),
(
"stripe_customer_id",
models.CharField(blank=True, default="", max_length=255),
),
("hosted_invoice_url", models.URLField(blank=True, default="")),
(
"description",
models.CharField(blank=True, default="", max_length=512),
),
(
"company",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="invoices",
to="chat_backend.company",
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="invoices",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"ordering": ["-created"],
},
),
migrations.CreateModel(
name="Payment",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created", models.DateTimeField(default=django.utils.timezone.now)),
(
"last_modified",
models.DateTimeField(default=django.utils.timezone.now),
),
(
"provider",
models.CharField(
choices=[("stripe", "Stripe")], default="stripe", max_length=32
),
),
(
"status",
models.CharField(
choices=[
("pending", "Pending"),
("succeeded", "Succeeded"),
("failed", "Failed"),
("canceled", "Canceled"),
("requires_action", "Requires action"),
],
db_index=True,
default="pending",
max_length=32,
),
),
("currency", models.CharField(default="usd", max_length=8)),
(
"amount",
models.PositiveIntegerField(
default=0,
help_text="Amount in the smallest currency unit (e.g. cents).",
),
),
(
"stripe_payment_intent_id",
models.CharField(
blank=True,
db_index=True,
max_length=255,
null=True,
unique=True,
),
),
(
"stripe_charge_id",
models.CharField(
blank=True,
db_index=True,
max_length=255,
null=True,
unique=True,
),
),
("paid_at", models.DateTimeField(blank=True, null=True)),
(
"failure_message",
models.CharField(blank=True, default="", max_length=512),
),
(
"company",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="payments",
to="chat_backend.company",
),
),
(
"invoice",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="payments",
to="finance.invoice",
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="payments",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"ordering": ["-created"],
},
),
]