Enterprise Billing
Enterprise Billing allows platform administrators to manually manage workspace plans, billing periods, and invoices — independently of Stripe subscriptions.
Overview
EW-FLOW supports two billing models that can coexist:
| Model | Managed by | Billing period source | Invoice source |
|---|---|---|---|
| Stripe | Self-service | Stripe subscription (current_period_start/end) | Stripe webhooks |
| Enterprise | Platform admin | enterprise_plan table (BillingPeriodStart/End) | Manual invoices via admin UI |
When a workspace is marked as Enterprise Managed, an EnterprisePlan record is created with a custom billing period, cycle length, auto-renew flag, and contact details. The admin can assign any plan tier and manage invoices directly.
Architecture
Data Model
Key Relationships
- Workspace → EnterprisePlan: One-to-one. Created when admin enables enterprise. Deactivated (not deleted) when enterprise is removed.
- Workspace → WorkspaceInvoice: One-to-many. Manual invoices created by admin.
- Workspace → StripeSubscription → StripeInvoice: Stripe-managed billing chain. Coexists with enterprise — when a Stripe subscription is created, the enterprise plan is automatically deactivated.
Admin Workflow
Single-Form Management
The admin manages each workspace through a single dialog that combines all settings:
Invoice Management
Metrics & Cron Service
The BillingPeriodMetricsCronService runs every 5 minutes and computes workspace metrics using the correct billing period source.
Cron Execution Flow
Billing Period Resolution
The cron service determines which billing period to use for execution counters and limits:
Dashboard Display
The dashboard subscription header card renders based on billing source priority:
Metrics Hydration
When the dashboard loads, the StatsRepository ensures enterprise info is always available — even if the cron hasn't run yet:
Auto-Renewal Flow
Stripe and Enterprise Interaction
When a Stripe subscription is created for an enterprise workspace, the enterprise plan is automatically deactivated to prevent double billing:
File Reference
| Component | Path | Role |
|---|---|---|
| Admin UI | Client/Pages/AdminEnterprise.razor | Single-form workspace management |
| Admin API | Server/Controllers/AdminEnterpriseController.cs | CRUD endpoints for plans, invoices, settings |
| Dashboard | Client/Pages/Dashboard.razor | Subscription header card rendering |
| Metrics API | Server/Controllers/Workspace/MetricsController.cs | Billing period metrics endpoint |
| Stats Repo | Server/Repositories/Implementations/StatsRepository.cs | Metrics retrieval + enterprise hydration |
| Invoice Repo | Server/Repositories/Implementations/InvoiceRepository.cs | All-invoices query (Stripe + manual) |
| Cron Service | Server/Services/Implementations/BillingPeriodMetricsCronService.cs | Metrics computation, auto-renew, archiving |
| Shared Models | Shared/Models/EnterpriseModels.cs | Request/response DTOs |
| Metrics Model | Shared/Models/BillingPeriodMetrics.cs | Dashboard metrics model with EnterprisePlanInfo |
| Entity | WorkflowEngineLibrary/Core/Models/EnterprisePlan.cs | EF Core entity |
| DB Context | WorkflowDatabase/WilsonCoreContext.cs | EnterprisePlan mapping |
| SQL Migration | WorkflowDatabase/Design/create_enterprise_plan.sql | Table DDL |