Skip to Content
Living documentation — last reviewed 2026-05-28
FeaturesPlatform BillingPlatform Billing — Code Map

Platform Billing — Code Map

API — apps/api/src/platform-billing/

  • platform-billing.module.ts
  • platform-billing.service.ts — checkout creation, webhook handlers (handlePaymentCompleted, handlePaymentFailed), verifyCheckout, cancel/resume, cancelSubscriptionInternal, billing-status reads.
  • platform-billing-recurring.service.ts — daily renewal cron (@Cron('0 2 * * *')), stale-pending sweep (@Cron('30 2 * * *')), chargeOne, markCharged, markFailed, expireToLite.
  • platform-billing-reconciler.service.ts@Cron('*/5 * * * *') — sweeps pending rows, re-fetches Cardcom truth, fires hang alerts.
  • platform-billing.controller.ts@Controller('organizations/:orgId/billing') — checkout, status, history, cancel, resume, verify-checkout.
  • platform-billing-webhook.controller.ts@Public POST /webhooks/platform-billing/cardcom.
  • platform-billing.service.int.spec.ts — integration tests.
  • platform-billing-recurring.service.unit.spec.ts
  • platform-billing-reconciler.service.unit.spec.ts
  • dto/
    • create-checkout.dto.ts
    • verify-checkout.dto.ts

API — apps/api/src/platform-tiers/

  • platform-tiers.module.ts
  • platform-tier.guard.ts@RequiresFeature(...) enforcement.
  • platform-tiers.service.tsgetTier, updateTier, getUsage (counts members/coaches/locations).
  • platform-tiers.controller.ts@Controller('organizations/:orgId/tier') — get, usage, patch. Patch routes through PlatformBillingService.cancelSubscription for paid → lite downgrades.
  • requires-feature.decorator.tsSetMetadata('requiresFeatures', features).
  • index.ts — re-exports.
  • dto/
    • update-tier.dto.ts

Web — apps/web/src/

  • app/[lang]/(protected)/dashboard/settings/billing/page.tsx — billing status + invoice history.
  • app/[lang]/(protected)/dashboard/settings/checkout-return/page.tsx — Cardcom return page; calls verify-checkout.
  • Tier upgrade UI: typically rendered inside settings + an upgrade-card pattern that links into the checkout endpoint.

Shared

  • libs/shared/src/lib/constants/platform-tiers.tsPLATFORM_TIERS, PLATFORM_FEATURES, PLATFORM_TIER_MAP, tierHasFeature, checkTierLimit, requiredTierForFeature, TIER_DISPLAY.
  • libs/shared/src/lib/schemas/platform-billing.schema.ts — Zod schemas for billing status / history responses.

DB

  • libs/db/src/lib/schema/platform-billing.tsplatform_billing_subscriptions, platform_billing_transactions.
  • libs/db/src/lib/schema/enums.tsplatformTier, platformBillingStatus.
  • libs/db/src/lib/schema/organizations.tsplatform_tier column lives here (consulted by the guard, mutated by the service).

Provider

  • apps/api/src/payments/providers/cardcom.provider.tssame adapter as per-org payments; called with platform credentials from env (platform-billing.service.ts:118). LowProfile/Create with ChargeAndCreateToken, GetLpResult for verification, ChargeWithToken for recurring.

Env (apps/api/.env)

VarPurpose
PLATFORM_BILLING_TERMINAL_NUMBERCardcom terminal id (shared for all FitKit platform fees).
PLATFORM_BILLING_API_NAMECardcom API name.
PLATFORM_BILLING_API_PASSWORDCardcom API password.
FRONTEND_URLSuccess/cancel URL base for hosted page.
API_BASE_URLUsed to build the webhook URL (/webhooks/platform-billing/cardcom).
PAYMENT_CREDENTIALS_ENCRYPTION_KEYReused via CredentialEncryptionService (no per-org credentials on this rail, but the service is imported transitively).

Cross-references

  • apps/api/src/admin/ — admin endpoints can force-cancel and inspect any org’s platform billing.
  • apps/api/src/organizations/organizations.platform_tier flips here are the source of truth for the guard.
  • docs/_archive/plans/cardcom-production-terminal.md — original rollout plan, kept for historical context.