feat: Initial Diabetix application commit
- Add authentication with NextAuth v5 (credentials + email verification) - Implement dashboard with glycemia tracking and AI analysis - Add PDF report generation for Premium users - Implement Stripe integration for Premium subscriptions - Add responsive UI with Tailwind CSS and shadcn components - Database schema with Prisma ORM and PostgreSQL support - Real-time glycemia visualization with Recharts - Mobile-optimized entry form - User profile management with medical information - Subscription lifecycle management (create, cancel, webhook) - Email notifications with Resend - Feature gates for Free vs Premium plans Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
88
STRIPE_INTEGRATION.md
Normal file
88
STRIPE_INTEGRATION.md
Normal file
@@ -0,0 +1,88 @@
|
||||
# Intégration Stripe pour Diabetix
|
||||
|
||||
## 📋 Aperçu
|
||||
|
||||
L'intégration Stripe permet aux utilisateurs de passer du plan FREE au plan PREMIUM (4,99 € / mois) avec gestion automatique des abonnements.
|
||||
|
||||
## 🏗️ Architecture
|
||||
|
||||
### Modèles Prisma
|
||||
- **User.stripeId** : ID du client Stripe
|
||||
- **Subscription** : Table pour tracker l'état de l'abonnement
|
||||
- `stripeId` : ID de l'abonnement
|
||||
- `status` : État (active, past_due, unpaid, canceled)
|
||||
- `currentPeriodEnd` : Date d'expiration
|
||||
|
||||
### Routes API
|
||||
|
||||
#### POST `/api/stripe/create-checkout`
|
||||
Crée une session de paiement Stripe
|
||||
- **Auth** : Requis (proxy.ts)
|
||||
- **Response** : `{ sessionId: string }`
|
||||
- **Redirection** : Vers Stripe Checkout → `/dashboard?checkout=success`
|
||||
|
||||
#### POST `/api/stripe/webhook`
|
||||
Reçoit les webhooks Stripe (non protégé)
|
||||
- **Événements gérés** :
|
||||
- `customer.subscription.created` : Nouvel abonnement → plan PREMIUM
|
||||
- `customer.subscription.updated` : Mise à jour
|
||||
- `customer.subscription.deleted` : Annulation → plan FREE
|
||||
- `invoice.payment_failed` : Paiement échoué
|
||||
|
||||
### Composants
|
||||
|
||||
#### `<UpgradeButton />`
|
||||
Bouton pour initier le paiement (client-side)
|
||||
- Charge Stripe.js via CDN
|
||||
- Crée une session de checkout
|
||||
- Redirige vers le formulaire de paiement Stripe
|
||||
|
||||
#### Page `/pricing`
|
||||
- Affiche les deux plans (FREE et PREMIUM)
|
||||
- Bouton "Commencer" pour non-connectés
|
||||
- `<UpgradeButton />` pour utilisateurs connectés
|
||||
- Affiche le statut PREMIUM si applicable
|
||||
|
||||
## 🔧 Configuration
|
||||
|
||||
Voir `STRIPE_SETUP.md` pour les étapes détaillées.
|
||||
|
||||
Variables d'environnement requises :
|
||||
```
|
||||
NEXT_PUBLIC_STRIPE_KEY=pk_test_...
|
||||
STRIPE_SECRET_KEY=sk_test_...
|
||||
STRIPE_PRICE_ID=price_...
|
||||
STRIPE_WEBHOOK_SECRET=whsec_...
|
||||
```
|
||||
|
||||
## 🔄 Flux d'achat
|
||||
|
||||
1. **Utilisateur accède `/pricing`**
|
||||
- S'il est FREE, affiche `<UpgradeButton />`
|
||||
|
||||
2. **Clique sur "Passer à Premium"**
|
||||
- `UpgradeButton` appelle `POST /api/stripe/create-checkout`
|
||||
- Reçoit `sessionId`
|
||||
- Redirige vers Stripe Checkout
|
||||
|
||||
3. **Paiement sur Stripe Checkout**
|
||||
- Succès : Redirige vers `/dashboard?checkout=success`
|
||||
- Annulation : Redirige vers `/pricing`
|
||||
|
||||
4. **Webhook Stripe `customer.subscription.created`**
|
||||
- Crée un `Subscription` en DB
|
||||
- Met à jour `User.plan = "PREMIUM"`
|
||||
|
||||
5. **NextAuth JWT refresh**
|
||||
- JWT callback lit le nouveau plan
|
||||
- Prochains appels utilisent `plan: "PREMIUM"`
|
||||
- ChatBot et features IA activés
|
||||
|
||||
## 🚀 Prochaines étapes
|
||||
|
||||
- [ ] Page de confirmation de paiement
|
||||
- [ ] Email de bienvenue Premium
|
||||
- [ ] Historique des factures
|
||||
- [ ] Gestion du renouvellement / annulation
|
||||
- [ ] Facturation annuelle
|
||||
- [ ] Tests de webhook locaux avec Stripe CLI
|
||||
Reference in New Issue
Block a user