Subscription payment
Purpose
TBD by human
Identity & key fields
- Primary key:
id(uuid, defaultgen_random_uuid()). companyId(uuid, FK →companies.company.id).plan(enumsubscription_plan) — plan being paid for.period(enumsubscription_period:monthly,yearly).amount(text),currency(text, default'UAH').status(enumsubscription_payment_status:pending,succeeded,failed).externalId(nullable text) — external billing gateway reference.isAutoRenewal(boolean, default false) — distinguishes manual purchases from cron-driven renewals.failureReason(nullable text).
business meaning: TBD by human
Invariants
companyIdNOT NULL with ON DELETE CASCADE — payment history is scrubbed with the company (enforced in tktspace-backend/libs/shared/data-access-db/src/lib/schema/companies.schema.ts).statusdefaults topending(enforced in tktspace-backend/libs/shared/data-access-db/src/lib/schema/companies.schema.ts).
business invariants: TBD by human
Lifecycle
Status enum values: pending, succeeded, failed.
transitions: TBD by human
Relationships
- Company (ENT-016) —
companyId→companies.company.id, on-delete cascade. N:1. - Company subscription (ENT-001) — implicit, by
companyIdonly (no direct FK on this row to the subscription PK).
API surfaces
| Surface | Exposed | Notes |
|---|---|---|
| client | no | — |
| business | yes — billing-admin module routes under /api/business/* | Swagger UI |
| super-admin | no | — |
Known gotchas / open questions
- OPEN: business OpenAPI schemas (as of audit date) do not show explicit DTOs for
subscription_paymentrows — surface coverage is inferred fromlibs/features/billing/. - OPEN:
amountis stored astext(other money fields in the codebase usenumeric/decimal). Rationale not yet established — flagged for future investigation; a migration todecimalmay be appropriate.