Platform Billing — Code Map
API — apps/api/src/platform-billing/
platform-billing.module.tsplatform-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—@PublicPOST /webhooks/platform-billing/cardcom.platform-billing.service.int.spec.ts— integration tests.platform-billing-recurring.service.unit.spec.tsplatform-billing-reconciler.service.unit.spec.tsdto/create-checkout.dto.tsverify-checkout.dto.ts
API — apps/api/src/platform-tiers/
platform-tiers.module.tsplatform-tier.guard.ts—@RequiresFeature(...)enforcement.platform-tiers.service.ts—getTier,updateTier,getUsage(counts members/coaches/locations).platform-tiers.controller.ts—@Controller('organizations/:orgId/tier')— get, usage, patch. Patch routes throughPlatformBillingService.cancelSubscriptionfor paid → lite downgrades.requires-feature.decorator.ts—SetMetadata('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; callsverify-checkout.- Tier upgrade UI: typically rendered inside settings + an
upgrade-cardpattern that links into the checkout endpoint.
Shared
libs/shared/src/lib/constants/platform-tiers.ts—PLATFORM_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.ts—platform_billing_subscriptions,platform_billing_transactions.libs/db/src/lib/schema/enums.ts—platformTier,platformBillingStatus.libs/db/src/lib/schema/organizations.ts—platform_tiercolumn lives here (consulted by the guard, mutated by the service).
Provider
apps/api/src/payments/providers/cardcom.provider.ts— same adapter as per-org payments; called with platform credentials from env (platform-billing.service.ts:118).LowProfile/CreatewithChargeAndCreateToken,GetLpResultfor verification,ChargeWithTokenfor recurring.
Env (apps/api/.env)
| Var | Purpose |
|---|---|
PLATFORM_BILLING_TERMINAL_NUMBER | Cardcom terminal id (shared for all FitKit platform fees). |
PLATFORM_BILLING_API_NAME | Cardcom API name. |
PLATFORM_BILLING_API_PASSWORD | Cardcom API password. |
FRONTEND_URL | Success/cancel URL base for hosted page. |
API_BASE_URL | Used to build the webhook URL (/webhooks/platform-billing/cardcom). |
PAYMENT_CREDENTIALS_ENCRYPTION_KEY | Reused 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_tierflips here are the source of truth for the guard.docs/_archive/plans/cardcom-production-terminal.md— original rollout plan, kept for historical context.