Skip to content

Subscription payment

Purpose

TBD by human

Identity & key fields

  • Primary key: id (uuid, default gen_random_uuid()).
  • companyId (uuid, FK → companies.company.id).
  • plan (enum subscription_plan) — plan being paid for.
  • period (enum subscription_period: monthly, yearly).
  • amount (text), currency (text, default 'UAH').
  • status (enum subscription_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

  • companyId NOT 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).
  • status defaults to pending (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) — companyIdcompanies.company.id, on-delete cascade. N:1.
  • Company subscription (ENT-001) — implicit, by companyId only (no direct FK on this row to the subscription PK).

API surfaces

SurfaceExposedNotes
clientno
businessyes — billing-admin module routes under /api/business/*Swagger UI
super-adminno

Known gotchas / open questions

  • OPEN: business OpenAPI schemas (as of audit date) do not show explicit DTOs for subscription_payment rows — surface coverage is inferred from libs/features/billing/.
  • OPEN: amount is stored as text (other money fields in the codebase use numeric/decimal). Rationale not yet established — flagged for future investigation; a migration to decimal may be appropriate.