Authed users can now request a Stripe-hosted Customer Portal URL for card
updates and cancellation via GET /api/v1/billing/portal-session. The path is
already in both _SUBSCRIPTION_GUARD_ALLOWLIST and _EMAIL_VERIFICATION_ALLOWLIST
so canceled or unverified-past-grace users can still update billing.
- Returns 503 with {"error": "stripe_not_configured"} when STRIPE_SECRET_KEY unset.
- Returns 400 with {"error": "no_stripe_customer"} when account has no
stripe_customer_id (must complete checkout first).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
from typing import Literal, Optional, Dict, Any
|
|
from datetime import datetime
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class CheckoutSessionCreate(BaseModel):
|
|
plan: Literal["pro", "starter", "team", "enterprise"]
|
|
seats: int
|
|
billing_interval: Literal["monthly", "annual"] = "monthly"
|
|
|
|
|
|
class CheckoutSessionResponse(BaseModel):
|
|
url: str
|
|
|
|
|
|
class BillingPortalSessionResponse(BaseModel):
|
|
url: str
|
|
|
|
|
|
class SubscriptionState(BaseModel):
|
|
status: str
|
|
plan: str
|
|
current_period_start: Optional[datetime]
|
|
current_period_end: Optional[datetime]
|
|
cancel_at_period_end: bool
|
|
seat_limit: Optional[int]
|
|
has_pro_entitlement: bool
|
|
is_paid: bool
|
|
|
|
|
|
class PlanBillingState(BaseModel):
|
|
display_name: str
|
|
description: Optional[str] = None
|
|
monthly_price_cents: Optional[int] = None
|
|
annual_price_cents: Optional[int] = None
|
|
|
|
model_config = {"from_attributes": True}
|
|
|
|
|
|
class BillingStateResponse(BaseModel):
|
|
subscription: SubscriptionState
|
|
plan_billing: Optional[PlanBillingState]
|
|
plan_limits: Dict[str, Any]
|
|
enabled_features: Dict[str, bool]
|