Backend:
- Prisma: add stripeSubscriptionId, subscriptionStatus, priceId,
currentPeriodEnd to User + migration SQL
- plugins/stripe.ts: getPlans catalog with env-based price IDs
- server.ts: raw body JSON parser for webhook signature verification,
skip rate limit on /stripe/webhook
- types/fastify.d.ts: declare rawBody on FastifyRequest
- routes/stripe.ts (new):
- GET /stripe/plans public
- GET /stripe/subscription user status
- POST /stripe/checkout hosted Checkout Session, lazy-creates
customer, dynamic payment methods, promo codes enabled
- POST /stripe/portal Billing Portal session
- POST /stripe/webhook signature verified, handles
checkout.session.completed, customer.subscription.*,
invoice.payment_failed. Resolves user by clientReferenceId,
metadata.userId, or stripeId fallback
- .env.example + README: Stripe setup, stripe CLI, test cards
Frontend:
- api/stripe.ts typed client (getPlans, getSubscription,
startCheckout, openPortal)
- pages/Pricing.tsx: 3-card grid (free/essentiel/premium) with
popular badge, current plan indicator, gradient popular card
- pages/CheckoutSuccess.tsx: animated confirmation with polling on
/stripe/subscription until webhook activates plan
- pages/Profile.tsx: SubscriptionCard above tabs — free users see an
upgrade banner, paid users see plan + status + next billing date
+ 'Gérer l'abonnement' button opening Customer Portal
- components/header.tsx: 'Tarifs' link in nav
- App.tsx: /pricing (public) and /checkout/success (protected) routes
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
58 lines
2.0 KiB
Plaintext
58 lines
2.0 KiB
Plaintext
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "sqlite"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(uuid())
|
|
email String @unique
|
|
password String? // Optionnel pour les utilisateurs Google
|
|
name String
|
|
googleId String? @unique
|
|
resetToken String?
|
|
resetTokenExpiry DateTime?
|
|
|
|
// ---- Stripe / Abonnement ----
|
|
stripeId String? @unique // Customer ID Stripe
|
|
subscription String? // 'free' | 'essential' | 'premium'
|
|
stripeSubscriptionId String? @unique
|
|
subscriptionStatus String? // active | trialing | past_due | canceled | incomplete
|
|
subscriptionPriceId String?
|
|
subscriptionCurrentPeriodEnd DateTime?
|
|
|
|
// Préférences culinaires injectées dans le prompt IA
|
|
dietaryPreference String? // 'vegetarian' | 'vegan' | 'pescatarian' | 'none'
|
|
allergies String? // Liste séparée par des virgules : "arachides,gluten"
|
|
maxCookingTime Int? // Temps total max (prépa + cuisson) en minutes
|
|
equipment String? // JSON array : '["four","plaque","micro-ondes"]'
|
|
cuisinePreference String? // "française", "italienne", "asiatique"... ou null
|
|
servingsDefault Int? // Nombre de portions par défaut
|
|
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
recipes Recipe[]
|
|
}
|
|
|
|
model Recipe {
|
|
id String @id @default(uuid())
|
|
title String
|
|
ingredients String
|
|
userPrompt String
|
|
generatedRecipe String
|
|
audioUrl String?
|
|
imageUrl String?
|
|
preparationTime Int?
|
|
cookingTime Int?
|
|
servings Int?
|
|
difficulty String?
|
|
steps String?
|
|
tips String?
|
|
userId String
|
|
user User @relation(fields: [userId], references: [id])
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
} |