- Lien Checkout d'abonnement 10 €/mois (carte ou SEPA) créé depuis l'admin et envoyé au contact du magasin - Webhook Stripe signé : suivi de l'abonnement, suspension automatique des magasins actifs en cas d'impayé, réactivation au paiement (uniquement si la suspension venait de la facturation) - Factures MEP-AAAA-NNNNNN à numérotation continue, PDF avec mentions légales (art. 293 B, pénalités, indemnité 40 €), envoyées par e-mail - Onglet Facturation dans l'admin, page /abonnement/merci/ sur le site - Migration SQL manuelle prisma/manual-migrations/2026-10-06-facturation.sql Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
239 lines
8.4 KiB
Text
239 lines
8.4 KiB
Text
// ─────────────────────────────────────────────────────────────
|
|
// MonEspacePro (MEP) — carte de fidélité dématérialisée
|
|
// Prisma + MySQL, base « mep » (séparée de GoSortir).
|
|
// ─────────────────────────────────────────────────────────────
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "mysql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
// ── Administration (moi) ──────────────────────────────────────
|
|
model Admin {
|
|
id String @id @default(cuid())
|
|
email String @unique
|
|
passwordHash String
|
|
createdAt DateTime @default(now())
|
|
}
|
|
|
|
// ── Magasins ──────────────────────────────────────────────────
|
|
enum StoreStatus {
|
|
DRAFT /// créé, carte pas encore conçue / abonnement pas encore actif
|
|
ACTIVE
|
|
SUSPENDED /// paiement échoué : scans et inscriptions refusés
|
|
CLOSED
|
|
}
|
|
|
|
model Store {
|
|
id String @id @default(cuid())
|
|
/// Identifiant public court utilisé dans les URL d'inscription (/c/<slug>).
|
|
slug String @unique
|
|
name String
|
|
addressLine String
|
|
postalCode String
|
|
city String
|
|
siret String @db.Char(14)
|
|
contactName String
|
|
contactEmail String
|
|
contactPhone String
|
|
status StoreStatus @default(DRAFT)
|
|
/// Suspendu automatiquement pour impayé (réactivé automatiquement au paiement).
|
|
billingSuspended Boolean @default(false)
|
|
|
|
// Anti-triche : réglages par magasin
|
|
maxAmountCents Int @default(50000) /// plafond d'un montant saisi
|
|
minScanIntervalSec Int @default(300) /// délai minimum entre deux crédits d'un même client
|
|
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
cardDesign CardDesign?
|
|
staff StaffUser[]
|
|
cards LoyaltyCard[]
|
|
transactions Transaction[]
|
|
subscription Subscription?
|
|
invoices Invoice[]
|
|
}
|
|
|
|
enum PointsMode {
|
|
AMOUNT /// points proportionnels au montant (pointsPerEuro)
|
|
STAMP /// un tampon par passage
|
|
}
|
|
|
|
model CardDesign {
|
|
id String @id @default(cuid())
|
|
storeId String @unique
|
|
store Store @relation(fields: [storeId], references: [id], onDelete: Cascade)
|
|
programName String
|
|
logoPath String?
|
|
stripPath String? /// bandeau
|
|
backgroundColor String @default("#1F2937")
|
|
foregroundColor String @default("#FFFFFF")
|
|
labelColor String @default("#D1D5DB")
|
|
pointsMode PointsMode @default(AMOUNT)
|
|
pointsPerEuro Decimal @default(1) @db.Decimal(6, 2)
|
|
rewards Reward[]
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model Reward {
|
|
id String @id @default(cuid())
|
|
cardDesignId String
|
|
cardDesign CardDesign @relation(fields: [cardDesignId], references: [id], onDelete: Cascade)
|
|
label String
|
|
cost Int /// points ou tampons nécessaires
|
|
active Boolean @default(true)
|
|
transactions Transaction[]
|
|
}
|
|
|
|
// ── Personnel du magasin (app Pro) ────────────────────────────
|
|
enum StaffRole {
|
|
MANAGER
|
|
EMPLOYEE
|
|
}
|
|
|
|
model StaffUser {
|
|
id String @id @default(cuid())
|
|
storeId String
|
|
store Store @relation(fields: [storeId], references: [id], onDelete: Cascade)
|
|
email String @unique
|
|
displayName String
|
|
passwordHash String
|
|
role StaffRole @default(EMPLOYEE)
|
|
active Boolean @default(true)
|
|
/// Incrémenté pour révoquer tous les jetons de rafraîchissement.
|
|
tokenVersion Int @default(0)
|
|
createdAt DateTime @default(now())
|
|
transactions Transaction[]
|
|
}
|
|
|
|
// ── Clients finaux ────────────────────────────────────────────
|
|
model Customer {
|
|
id String @id @default(cuid())
|
|
firstName String
|
|
email String
|
|
consentAt DateTime /// consentement RGPD horodaté
|
|
createdAt DateTime @default(now())
|
|
cards LoyaltyCard[]
|
|
}
|
|
|
|
model LoyaltyCard {
|
|
id String @id @default(cuid())
|
|
storeId String
|
|
store Store @relation(fields: [storeId], references: [id], onDelete: Cascade)
|
|
customerId String
|
|
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
|
|
/// Numéro de série du pass Wallet ; contenu du QR (non devinable).
|
|
serial String @unique
|
|
/// Jeton d'authentification du service web Apple Wallet.
|
|
authToken String
|
|
/// Clé secrète des liens client (page de la carte, téléchargement du pass).
|
|
accessKey String @unique
|
|
balance Int @default(0)
|
|
lastCreditAt DateTime?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
transactions Transaction[]
|
|
devices AppleRegistration[]
|
|
|
|
@@unique([storeId, customerId])
|
|
}
|
|
|
|
enum TransactionType {
|
|
CREDIT
|
|
REDEEM
|
|
ADJUST /// correction manuelle (gérant)
|
|
REJECTED /// tentative refusée par l'anti-triche (0 point), visible dans les opérations
|
|
}
|
|
|
|
enum RejectReason {
|
|
AMOUNT_OVER_LIMIT
|
|
TOO_SOON
|
|
INSUFFICIENT_BALANCE
|
|
}
|
|
|
|
/// Journal immuable : chaque scan est enregistré avec l'employé.
|
|
model Transaction {
|
|
id String @id @default(cuid())
|
|
storeId String
|
|
store Store @relation(fields: [storeId], references: [id], onDelete: Cascade)
|
|
cardId String
|
|
card LoyaltyCard @relation(fields: [cardId], references: [id], onDelete: Cascade)
|
|
staffId String
|
|
staff StaffUser @relation(fields: [staffId], references: [id])
|
|
type TransactionType
|
|
amountCents Int?
|
|
points Int /// positif (crédit) ou négatif (récompense)
|
|
/// Solde de la carte après l'opération (lecture de l'historique sans recalcul).
|
|
balanceAfter Int
|
|
rejectReason RejectReason?
|
|
rewardId String?
|
|
reward Reward? @relation(fields: [rewardId], references: [id])
|
|
createdAt DateTime @default(now())
|
|
|
|
@@index([storeId, createdAt])
|
|
@@index([cardId, createdAt])
|
|
@@index([staffId, createdAt])
|
|
}
|
|
|
|
// ── Apple Wallet (service web PassKit) ────────────────────────
|
|
model AppleDevice {
|
|
id String @id @default(cuid())
|
|
deviceLibraryId String @unique
|
|
pushToken String
|
|
registrations AppleRegistration[]
|
|
}
|
|
|
|
model AppleRegistration {
|
|
deviceId String
|
|
device AppleDevice @relation(fields: [deviceId], references: [id], onDelete: Cascade)
|
|
cardId String
|
|
card LoyaltyCard @relation(fields: [cardId], references: [id], onDelete: Cascade)
|
|
createdAt DateTime @default(now())
|
|
|
|
@@id([deviceId, cardId])
|
|
}
|
|
|
|
// ── Facturation ───────────────────────────────────────────────
|
|
enum SubscriptionStatus {
|
|
INCOMPLETE
|
|
ACTIVE
|
|
PAST_DUE
|
|
CANCELED
|
|
}
|
|
|
|
model Subscription {
|
|
id String @id @default(cuid())
|
|
storeId String @unique
|
|
store Store @relation(fields: [storeId], references: [id], onDelete: Cascade)
|
|
stripeCustomerId String? @unique
|
|
stripeSubscriptionId String? @unique
|
|
status SubscriptionStatus @default(INCOMPLETE)
|
|
currentPeriodEnd DateTime?
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model Invoice {
|
|
id String @id @default(cuid())
|
|
/// Numérotation continue, sans trou : MEP-2026-000001
|
|
number String @unique
|
|
sequence Int @unique
|
|
storeId String
|
|
store Store @relation(fields: [storeId], references: [id])
|
|
stripeInvoiceId String? @unique
|
|
amountCents Int
|
|
/// Identité du client figée à l'émission (une facture ne change plus).
|
|
clientName String
|
|
clientAddress String @db.Text
|
|
clientSiret String
|
|
clientEmail String
|
|
periodStart DateTime
|
|
periodEnd DateTime
|
|
issuedAt DateTime @default(now())
|
|
paidAt DateTime?
|
|
pdfPath String?
|
|
}
|