feat: complete subscription billing system phases 6-10

Phase 6 - Database-driven tiers:
- Update subscription_service to query database first with legacy fallback
- Add get_tier_info() db parameter and _get_tier_from_legacy() method

Phase 7 - Platform health integration:
- Add get_subscription_capacity() for theoretical vs actual capacity
- Include subscription capacity in full health report

Phase 8 - Background subscription tasks:
- Add reset_period_counters() for billing period resets
- Add check_trial_expirations() for trial management
- Add sync_stripe_status() for Stripe synchronization
- Add cleanup_stale_subscriptions() for maintenance
- Add capture_capacity_snapshot() for daily metrics

Phase 10 - Capacity planning & forecasting:
- Add CapacitySnapshot model for historical tracking
- Create capacity_forecast_service with growth trends
- Add /subscription-capacity, /trends, /recommendations endpoints
- Add /snapshot endpoint for manual captures

Also includes billing API enhancements from phase 4:
- Add upcoming-invoice, change-tier, addon purchase/cancel endpoints
- Add UsageSummary schema for billing page
- Enhance billing.js with addon management functions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-26 20:51:13 +01:00
parent b717c23787
commit c6e7f4087f
20 changed files with 1895 additions and 29 deletions

View File

@@ -146,6 +146,10 @@ class VendorSubscriptionWithVendor(VendorSubscriptionResponse):
vendor_name: str
vendor_code: str
# Usage counts (for admin display)
products_count: int | None = None
team_count: int | None = None
class VendorSubscriptionListResponse(BaseModel):
"""Response for listing vendor subscriptions."""
@@ -157,6 +161,15 @@ class VendorSubscriptionListResponse(BaseModel):
pages: int
class VendorSubscriptionCreate(BaseModel):
"""Schema for admin creating a vendor subscription."""
tier: str = "essential"
status: str = "trial"
trial_days: int = 14
is_annual: bool = False
class VendorSubscriptionUpdate(BaseModel):
"""Schema for admin updating a vendor subscription."""

View File

@@ -134,6 +134,22 @@ class SubscriptionUsage(BaseModel):
team_members_percent_used: float | None
class UsageSummary(BaseModel):
"""Usage summary for billing page display."""
orders_this_period: int
orders_limit: int | None
orders_remaining: int | None
products_count: int
products_limit: int | None
products_remaining: int | None
team_count: int
team_limit: int | None
team_remaining: int | None
class SubscriptionStatusResponse(BaseModel):
"""Subscription status with usage and limits."""