# v347 Platform Subscription Stripe Test Subscription Note

- Super Admin platform subscriptions now support a controlled Stripe test-mode subscription creation scaffold.
- The Stripe platform path can create a test customer first, then create a test subscription only when a `cus_` customer ID and `price_` monthly plan price ID are present.
- This remains separate from the future Workspace Admin dispatcher-service Stripe path for billing carriers.
- Carrier/company billing to brokers and shippers remains factoring or Net 30 based and does not use this platform subscription Stripe path.
- Live charging, checkout, payment method collection, and customer portal workflows remain intentionally disabled until later controlled billing tracks.

CURRENT CANONICAL BASELINE
Version: v39
Status: documentation expansion package
Next planned package: v40

# Subscriptions and Entitlements Plan

## Current phase note
- v39.1 formalizes workspace subscriptions, billing control, entitlements, seat governance, and plan-based feature access.

## Purpose
This document defines how Dispatch Spot should model subscriptions and entitlements so workspace billing, feature access, seat limits, plan upgrades, and platform overrides remain consistent and extensible.

## Core Principle
Subscriptions belong to the workspace account, not to individual users.
Users inherit entitlements through workspace membership and role policy.

## Planned Billing Objects
- billing account
- plan
- price
- subscription
- subscription item
- invoice
- payment event
- billing adjustment
- add-on
- workspace entitlement
- workspace usage counter

## Plan Types to Support
- free or internal development plan
- trial plan
- monthly plan
- annual plan
- enterprise custom plan
- add-on expansions

## Example Entitlement Dimensions
A plan may govern:
- maximum users
- maximum active drivers
- maximum active loads
- document storage limits
- CRM access
- invoicing access
- analytics access
- automation access
- API access
- SMS notification access
- support tier

## Self-Service Billing Responsibilities
Workspace Owner or Billing Admin should be able to:
- start trial
- select plan
- upgrade
- downgrade
- cancel
- resume
- update billing details
- view invoices
- view payment failures
- manage seat count
- purchase add-ons
- view current entitlements

## Super Admin Billing Responsibilities
Super Admin should additionally be able to:
- override plan
- extend trial
- grant credits
- comp a workspace
- pause billing
- force-cancel subscription
- flag delinquency
- attach support notes
- restore access after resolution

## Entitlement Engine Direction
Feature checks should resolve through a dedicated entitlement layer rather than random conditional logic in pages.

Examples:
- hasFeature(workspaceId, "crm")
- hasFeature(workspaceId, "analytics")
- hasCapacity(workspaceId, "users")
- hasCapacity(workspaceId, "drivers")

## Entitlement Sources
Workspace entitlements may derive from:
- active subscription plan
- add-ons
- support overrides
- grandfathered rights
- promotional grants
- enterprise custom contracts

## Seat Governance Direction
The platform should support:
- active licensed users
- invited but unaccepted users
- deactivated users no longer consuming seats when policy allows
- seat threshold notifications
- seat overage logic by plan

## Subscription Event Examples
- trial started
- trial ending soon
- subscription activated
- payment failed
- subscription renewed
- subscription downgraded
- add-on purchased
- seat threshold reached

## Recommended Admin and Workspace Billing Surfaces
### Workspace Billing Center
- current plan
- included features
- seat usage
- renewal date
- invoices
- payment status
- add-ons
- upgrade and downgrade actions

### Super Admin Billing Console
- workspace subscription search
- failed payment queue
- trial management
- custom pricing support
- credits and manual adjustments
- subscription override history

## Build Rule Going Forward
Plan enforcement and capacity checks must be centralized through an entitlement service so pricing and packaging can evolve without widespread code rewrites.

## v336 update — Super Admin subscription plan foundation
The subscription plan foundation has moved from planning-only documentation into the Super Admin UI.

Implemented foundation:
- `/admin/subscriptions` page.
- Staged plan list and plan editor.
- CRUD-ready browser-side controls for creating, editing, duplicating, and deleting staged plans.
- Plan limits for users, trucks, and business phone numbers.
- Add-on price preparation for extra users/seats and extra business phone numbers.
- Feature access preparation for dispatch, documents, billing, notifications, business phone, route planning, load board, reports, and CORI.

Not yet implemented:
- Database persistence for plans.
- Workspace subscription assignment.
- Stripe or billing provider integration.
- Hard enforcement against workspace usage.
- Invoice/payment lifecycle.

Next recommended subscription steps:
1. Add workspace subscription assignment to Super Admin workspace pages.
2. Add a shared entitlement checker used by Workspace Admin pages.
3. Add soft warnings when a workspace exceeds included limits.
4. Add plan upgrade/add-on prompts only where useful and not cluttering daily workflow.

## v337 Staged Workspace Assignment Visibility
The staged subscription plan foundation is now connected to Super Admin workspace review. Super Admin can inspect the staged plan for each workspace, included versus over-limit usage, and included/locked feature access before database-backed persistence is introduced.

Current staged signals:
- users/seats
- trucks
- business phone numbers
- Dispatch
- Documents
- Billing
- Notifications
- Business phone
- Route planning
- Load board
- Reports
- CORI

The next required subscription step is persistence: subscription plan tables, workspace subscription assignment, add-on records, billing status, and shared enforcement helpers for Workspace Admin pages.


## v338-v343 update — persisted subscriptions, entitlements, add-ons, and Stripe-ready billing

The subscription system has moved from staged planning into the core SaaS architecture.

Implemented through v343:
- Persisted `SubscriptionPlan` and `WorkspaceSubscription` Prisma models.
- Super Admin saved plan CRUD at `/admin/subscriptions`.
- Super Admin workspace plan assignment at `/admin/workspaces/subscriptions`.
- Shared entitlement evaluation for feature access, locked states, over-limit states, billing holds, and enforcement readiness.
- Clean Workspace Admin feature gating for selected modules without exposing Super Admin-level billing detail.
- Plan limit checks for users/seats, trucks, and business phone numbers.
- Add-on readiness review for extra users/seats, extra trucks, extra business phone numbers, and future feature add-ons.
- Stripe-ready billing provider fields on subscription plans and workspace subscriptions.

Billing architecture now separates:
- Super Admin platform subscriptions: future Stripe integration for Dispatch Spot SaaS billing.
- Workspace Admin dispatcher-service billing: a separate future Stripe path for dispatchers billing carriers for their service.
- Carrier/company billing to brokers or shippers: factoring or Net 30 flows, not Stripe.

Important current limitation:
- v343 prepares Stripe identifiers and billing mode/status fields but does not enable live Stripe charging, webhooks, checkout, customer portal, or invoice sync yet.

Next recommended subscription steps:
1. Harden editable add-on assignments inside Super Admin.
2. Add provider-sync readiness checks before real Stripe API calls.
3. Add Stripe test-mode integration for Super Admin platform subscriptions only.
4. Keep Workspace Admin clean and show only simple upgrade or plan-limit messages when needed.

## v345 update — Stripe test-mode customer/subscription scaffold

- Added a Super Admin-only `/admin/stripe-scaffold` page for safe platform billing preparation.
- The scaffold validates whether Stripe appears to be in test mode, whether the selected plan has a monthly Stripe price ID, and whether the selected workspace has a test customer ID staged.
- Super Admin can preview the future Stripe customer and subscription payload shape before any Stripe SDK/API call is enabled.
- Super Admin can manually store confirmed test-mode customer, subscription, and subscription item IDs on the workspace subscription.
- This remains a scaffold only: it does not create Stripe customers, checkout sessions, portal sessions, subscriptions, invoices, payment methods, or charges.
- Workspace Admin remains clean. No Stripe controls are exposed to normal workspace users.
- Platform subscription billing remains separate from the future Workspace Admin dispatcher-service Stripe path for billing carriers. Carrier/company billing to brokers and shippers continues to rely on factoring or Net 30 workflows.

## v346 Platform Stripe customer creation note

v346 adds controlled Stripe SDK test-mode customer creation for Super Admin platform subscriptions.

This is intentionally limited to test customer creation only. It does not create Stripe subscriptions, invoices, checkout sessions, customer portal sessions, payment methods, or charges.

The platform billing path remains separate from Workspace Admin dispatcher-service billing. Dispatcher-service Stripe billing for carrier customers will be added later as a separate billing path.


## v349 Stripe webhook test-event handling note

Dispatch Spot now has a Super Admin-only Stripe test webhook handling foundation for platform subscriptions. The webhook endpoint is `/api/subscriptions/stripe-test/webhook`. It is limited to safe test-mode provider sync updates and does not enable checkout, customer portal, live billing, add-ons, payment method collection, or charges. Workspace Admin dispatcher-service Stripe billing remains a separate future path.

## v417 plan-family visibility cleanup controls

v417 adds Super Admin plan-family visibility cleanup controls to `/admin/subscriptions` before registration/workspace-type plan-selection staging begins.

Current behavior:

- Super Admin can review plan family, plan visibility, and visible workspace type lists directly inside the saved plan manager.
- Super Admin can apply a recommended visibility/type-list helper to the selected plan draft and then save the plan.
- Visibility review counts identify plans with missing type lists, public staged visibility, and family/type-list mismatch warnings.
- Clearing a visible workspace type list is now persisted intentionally instead of leaving an older list unchanged.

Important limitation:

- These fields remain metadata only. Registration plan selection, Stripe checkout, hard billing gates, broker distribution limits, owned portal rules, and internal load-board access are still not activated.

## v418 Super Admin registration readiness checklist

v418 adds a Super Admin-only registration readiness checklist to `/admin/subscriptions` before registration/workspace-type plan-selection staging begins.

Current behavior:

- Super Admin can review whether active workspaces have stored workspace type/account class values.
- Super Admin can see whether saved plans have usable plan family, plan visibility, and visible workspace type metadata.
- Super Admin can see whether any Public or Invite only customer plans are staged as future registration choices.
- Super Admin can identify paid workspace subscription gaps, assigned plan/workspace-type mismatches, and trial records missing trial end dates.
- Super Admin can see guarded Stripe/billing and broker/marketplace policy warnings before any registration work relies on these values.

Important limitation:

- This is review-only readiness visibility. It does not activate signup plan selection, Stripe checkout, billing enforcement, broker distribution limits, owned portal rules, or internal load-board access.

## v419 registration workspace-type plan-selection staging

v419 activates the first public signup staging step for workspace type and plan selection, but keeps the workflow review-only.

Current behavior:

- `/sign-up` now asks the registrant to select a workspace type before entering company/admin details.
- The public workspace type choices are limited to paid workspace candidates: Dispatcher, Company / Fleet, Carrier / Owner-Operator, and Freight Broker.
- `/sign-up` reads `/api/auth/sign-up/options` for sanitized staged plan options.
- The signup options endpoint only returns non-retired Public or Invite only customer plans that are visible for paid workspace types.
- The endpoint does not expose Stripe product IDs, Stripe price IDs, provider sync state, internal billing notes, private plans, internal plans, driver-interface plans, platform marketplace plans, or internal operations plans.
- When a user creates a workspace, the selected workspace type is stored on `Organization.workspaceType` and the account class is stored as `PAID_WORKSPACE`.
- When a valid staged plan is selected, the new workspace trial subscription uses that plan.
- When no staged plan exists for the selected type, workspace creation falls back to the existing safe default plan so registration does not fail.

Important limitation:

- This is a review-only trial signup step. It does not collect payment, create Stripe checkout sessions, create customer portal sessions, enforce hard billing gates, activate broker distribution limits, change owned portal rules, or open internal load-board access.


## v419.1 registration workspace-type plan-selection build fix

v419.1 fixes the v419 WHM build error without changing product behavior.

Current behavior:

- Public registration still supports only paid workspace candidates: Dispatcher, Company / Fleet, Carrier / Owner-Operator, and Freight Broker.
- The allowed public registration workspace types are now stored in a typed `readonly WorkspaceType[]` constant so TypeScript can safely check the full enum value.
- Shipper/customer portals, driver-interface records, platform marketplace layers, and internal operations workspaces remain unavailable from public registration.

Important limitation:

- This is a build fix only. It does not activate Stripe checkout, payment collection, hard billing gates, broker distribution limits, owned portal rules, or internal load-board access.