Add multi-plan subscriptions, quotas, and token usage APIs
Implements #16/#17/#36: Founders/Standard/Pro/Business/Backer catalog, Backer email whitelist, prompt-window + token-period gates, and tokens_in/out on conversation/prompt + subscription usage APIs.
This commit is contained in:
@@ -11,6 +11,7 @@ from django.db import transaction
|
||||
from django.utils import timezone
|
||||
|
||||
from finance.models import Invoice, Payment
|
||||
from finance.services.plans import assign_founders_from_stripe
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
User = get_user_model()
|
||||
@@ -211,6 +212,11 @@ def handle_checkout_session_completed(session: dict[str, Any]) -> Invoice | None
|
||||
),
|
||||
paid_at=timezone.now(),
|
||||
)
|
||||
if session.get("payment_status") == "paid" or session.get("subscription"):
|
||||
assign_founders_from_stripe(
|
||||
user,
|
||||
stripe_subscription_id=session.get("subscription") or "",
|
||||
)
|
||||
return invoice
|
||||
|
||||
|
||||
@@ -270,6 +276,10 @@ def handle_invoice_paid(stripe_invoice: dict[str, Any]) -> Invoice | None:
|
||||
stripe_charge_id=charge if isinstance(charge, str) else None,
|
||||
paid_at=paid_at,
|
||||
)
|
||||
assign_founders_from_stripe(
|
||||
user,
|
||||
stripe_subscription_id=stripe_invoice.get("subscription") or "",
|
||||
)
|
||||
return invoice
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user