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
This commit was merged in pull request #69.
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from monetization.models import Invoice, Payment, SubscriptionPlan
|
||||
|
||||
|
||||
class InvoiceSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Invoice
|
||||
fields = [
|
||||
"id",
|
||||
"provider",
|
||||
"status",
|
||||
"currency",
|
||||
"amount_due",
|
||||
"amount_paid",
|
||||
"period_start",
|
||||
"period_end",
|
||||
"stripe_invoice_id",
|
||||
"stripe_checkout_session_id",
|
||||
"stripe_subscription_id",
|
||||
"revenuecat_event_id",
|
||||
"revenuecat_store",
|
||||
"hosted_invoice_url",
|
||||
"description",
|
||||
"created",
|
||||
"last_modified",
|
||||
]
|
||||
read_only_fields = fields
|
||||
|
||||
|
||||
class PaymentSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Payment
|
||||
fields = [
|
||||
"id",
|
||||
"invoice",
|
||||
"provider",
|
||||
"status",
|
||||
"currency",
|
||||
"amount",
|
||||
"stripe_payment_intent_id",
|
||||
"stripe_charge_id",
|
||||
"revenuecat_transaction_id",
|
||||
"paid_at",
|
||||
"failure_message",
|
||||
"created",
|
||||
"last_modified",
|
||||
]
|
||||
read_only_fields = fields
|
||||
|
||||
|
||||
class CheckoutSessionSerializer(serializers.Serializer):
|
||||
success_url = serializers.URLField(required=False, allow_blank=False)
|
||||
cancel_url = serializers.URLField(required=False, allow_blank=False)
|
||||
plan_slug = serializers.SlugField(required=False, allow_blank=False)
|
||||
|
||||
|
||||
class PortalSessionSerializer(serializers.Serializer):
|
||||
return_url = serializers.URLField(required=False, allow_blank=False)
|
||||
|
||||
|
||||
class SubscriptionPlanSerializer(serializers.ModelSerializer):
|
||||
features = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = SubscriptionPlan
|
||||
fields = [
|
||||
"slug",
|
||||
"name",
|
||||
"description",
|
||||
"price_cents",
|
||||
"currency",
|
||||
"interval",
|
||||
"is_public",
|
||||
"is_selectable",
|
||||
"features",
|
||||
"prompt_quota_per_window",
|
||||
"prompt_window_hours",
|
||||
"monthly_token_quota",
|
||||
"sort_order",
|
||||
]
|
||||
read_only_fields = fields
|
||||
|
||||
def get_features(self, obj):
|
||||
return {
|
||||
"text_generation": obj.allows_feature("text_generation"),
|
||||
"image_generation": obj.allows_feature("image_generation"),
|
||||
"rag": obj.allows_feature("rag"),
|
||||
"all_future_features": obj.allows_all_future_features,
|
||||
}
|
||||
Reference in New Issue
Block a user