Chiude la decisione "payment provider" aperta in CLAUDE.md. **Modello**: free 30gg post-signup (no carta richiesta) → Pro mensile €9,90 / annuale €89. Allinea il paywall al confine fra fase INTENSIVE e TRANSITION (PRD §5.1), quando l'utente ha già visto i primi risultati. Dopo la scadenza l'app non si "spegne": storico restano consultabili (sola lettura), ma generazione piani / nuove pesate / digiuni / foto / export richiedono abbonamento attivo. **Schema**: nuova tabella `subscriptions` (1:1 con users) con stati TRIALING/ACTIVE/PAST_DUE/CANCEL_AT_PERIOD_END/CANCELED/EXPIRED + `billing_webhook_events` per idempotenza dei retry Stripe. **Backend** (`apps/api/src/modules/billing/`): - `GET /me/billing/status` — snapshot + derived (kind, isPro, trialDaysRemaining) - `POST /me/billing/checkout` — crea Stripe Checkout Session (subscription mode + Stripe Tax + tax_id_collection) - `POST /me/billing/portal` — Customer Portal Session - `POST /webhooks/stripe` — raw body, firma HMAC, idempotenza per `event.id`, dispatch su `customer.subscription.*`, `checkout.session.completed`, `invoice.payment_failed` - Plugin `requirePro()` (402 payment_required) applicato a 9 rotte: meal-plans CRUD, weight-entries POST, check-ins POST, fast-events POST/PATCH, fasting/pause POST, export.pdf (plan+tracking) **Shared** (`@ketopath/shared/billing/pro-status`): - `isProActive(snap)` — verifica live (gestisce anche TRIALING con `trialEndsAt` passato in caso di cron in ritardo) - `deriveProStatus(snap)` — kind + isPro + trialDaysRemaining + accessEndsAt per l'UI - `computeTrialEndsAt(signupAt, days=30)` - 11 unit test **Frontend** (`apps/web/src/app/[locale]/billing/`): - Pagina `/billing` editoriale (capitolo VIII) con StatusBlock per ogni kind, BillingActionsBar client (transitions, redirect a Stripe), 3 benefits - `<TrialBanner>` in SignedInDashboard (3 stati: trial in corso oro / scaduto pomodoro / past_due pomodoro) - Nav item "Abbonamento" (chapter VI) nel grid asimmetrico - i18n IT completo (`Billing` namespace) **Soft-degradation**: env Stripe (`STRIPE_SECRET_KEY`, `STRIPE_WEBHOOK_SECRET`, `STRIPE_PRICE_ID_*`, `BILLING_RETURN_URL`) sono tutte opzionali. Senza configurazione i route billing rispondono 503 e il banner trial mostra "pagamenti non ancora attivati" — utenti in trial continuano a usare l'app. 99/99 test verdi, lint pulito su tutto il monorepo. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
42 lines
1.1 KiB
JSON
42 lines
1.1 KiB
JSON
{
|
|
"name": "@ketopath/api",
|
|
"version": "0.0.0",
|
|
"private": true,
|
|
"type": "module",
|
|
"scripts": {
|
|
"dev": "tsx watch --env-file=.env src/server.ts",
|
|
"build": "tsc",
|
|
"start": "node dist/server.js",
|
|
"typecheck": "tsc --noEmit",
|
|
"lint": "eslint src --max-warnings=0"
|
|
},
|
|
"dependencies": {
|
|
"@fastify/cors": "^9.0.1",
|
|
"@fastify/helmet": "^11.1.1",
|
|
"@fastify/rate-limit": "^9.1.0",
|
|
"@fastify/sensible": "^5.6.0",
|
|
"@ketopath/auth": "workspace:*",
|
|
"@ketopath/db": "workspace:*",
|
|
"@ketopath/shared": "workspace:*",
|
|
"@sentry/node": "^8.30.0",
|
|
"better-auth": "^1.0.21",
|
|
"fastify": "^4.28.1",
|
|
"fastify-plugin": "^4.5.1",
|
|
"node-cron": "^3.0",
|
|
"pdfkit": "^0.15",
|
|
"stripe": "^22.1.1",
|
|
"web-push": "^3.6",
|
|
"zod": "^3.23.8"
|
|
},
|
|
"devDependencies": {
|
|
"@ketopath/eslint-config": "workspace:*",
|
|
"@ketopath/tsconfig": "workspace:*",
|
|
"@types/node": "^20.12.7",
|
|
"@types/node-cron": "^3.0",
|
|
"@types/pdfkit": "^0.13",
|
|
"@types/web-push": "^3.6",
|
|
"pino-pretty": "^11.2.1",
|
|
"tsx": "^4.16.2"
|
|
}
|
|
}
|