Skip to content
bitzorcas
EN

Reference

Billing module

Platform billing — subscription management, plan catalog, usage recording, quota enforcement, invoice generation, and entitlement resolution.

Last updated

The PlatformBilling module provides SaaS-native billing with subscription lifecycle management, plan catalogs, usage tracking, quota enforcement, and invoice generation.

Endpoints

EndpointMethodDescription
/api/billing/plansGETList available plans
/api/billing/subscriptionsPOSTStart subscription
/api/billing/subscriptionsGETList subscriptions
/api/billing/subscriptions/{id}GETGet subscription details
/api/billing/usagePOSTRecord usage
/api/billing/invoicesPOSTGenerate invoice
/api/billing/invoicesGETList invoices
/api/billing/quotaGETCheck quota status

Architecture

PlatformBillingService
├── IPlatformBillingRepository → SqlSugarPlatformBillingRepository
├── QuotaService → EntitlementResolver
└── IPlatformBillingEventPublisher → NullPlatformBillingEventPublisher
CatalogService
├── ICatalogRepository → SqlSugarCatalogRepository
├── ICatalogEntitlementMappingStore
└── ICatalogEventPublisher

Key entities

EntityPurpose
PlatformBillingPlanEntityPlan definition (name, price, features)
PlatformBillingSubscriptionEntityTenant’s active subscription
PlatformBillingInvoiceEntityGenerated invoices
PlatformBillingUsageRecordEntityUsage tracking records
CatalogItemEntityCatalog items (plans, add-ons, entitlements)

Subscription lifecycle

Start
Active (trial)
Active (paid)
│ │
▼ ▼
Paused Cancelled
│ │
▼ ▼
Resumed Expired

Quota 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 → Entitlements

Each 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

PolicyDescription
DenyBlock operation with 429/403
WarnAllow with warning notification
AllowNo enforcement (privileged tenants)

See also