The PlatformBilling module provides SaaS-native billing with subscription lifecycle management, plan catalogs, usage tracking, quota enforcement, and invoice generation.
Endpoints
| Endpoint | Method | Description |
|---|---|---|
/api/billing/plans | GET | List available plans |
/api/billing/subscriptions | POST | Start subscription |
/api/billing/subscriptions | GET | List subscriptions |
/api/billing/subscriptions/{id} | GET | Get subscription details |
/api/billing/usage | POST | Record usage |
/api/billing/invoices | POST | Generate invoice |
/api/billing/invoices | GET | List invoices |
/api/billing/quota | GET | Check quota status |
Architecture
PlatformBillingService │ ├── IPlatformBillingRepository → SqlSugarPlatformBillingRepository ├── QuotaService → EntitlementResolver └── IPlatformBillingEventPublisher → NullPlatformBillingEventPublisher
CatalogService │ ├── ICatalogRepository → SqlSugarCatalogRepository ├── ICatalogEntitlementMappingStore └── ICatalogEventPublisherKey entities
| Entity | Purpose |
|---|---|
PlatformBillingPlanEntity | Plan definition (name, price, features) |
PlatformBillingSubscriptionEntity | Tenant’s active subscription |
PlatformBillingInvoiceEntity | Generated invoices |
PlatformBillingUsageRecordEntity | Usage tracking records |
CatalogItemEntity | Catalog items (plans, add-ons, entitlements) |
Subscription lifecycle
Start │ ▼ Active (trial) │ ▼ Active (paid) │ │ ▼ ▼ Paused Cancelled │ │ ▼ ▼ Resumed ExpiredQuota enforcement
public class QuotaCheckResult{ public bool IsAllowed { get; } public long Remaining { get; } public long Used { get; } public long Limit { get; } public OverQuotaBehavior Behavior { get; }}Entitlement resolution
Tenant → Active Subscription → Plan → Catalog Offerings → EntitlementsEach entitlement maps to a quota key (e.g., storage.files, tickets.open, chat.channels).
Usage recording
Modules record usage through the billing service:
await billingService.RecordUsageAsync( tenantId: "100", entitlementKey: "storage.files", delta: 1);Over-quota behavior
| Policy | Description |
|---|---|
Deny | Block operation with 429/403 |
Warn | Allow with warning notification |
Allow | No enforcement (privileged tenants) |
See also
- Catalog module — Plan definitions
- Quota building block — Quota infrastructure