Backend NestJS/Prisma, application mobile Expo (Tap to Pay Stripe), tableau de bord web Vite et documentation (cadrage en brouillon, décisions d'architecture). Secrets et fichiers locaux exclus par .gitignore. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
292 lines
13 KiB
Text
292 lines
13 KiB
Text
// TapTP — schéma MySQL.
|
|
// Règles : montants en centimes (Int), aucune donnée carte/IBAN complète,
|
|
// uniquement les identifiants fournis par Stripe.
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "mysql"
|
|
url = env("DATABASE_URL")
|
|
// Développement uniquement (prisma migrate dev) ; inutile en production (prisma migrate deploy).
|
|
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
email String @unique @db.VarChar(191)
|
|
passwordHash String @map("password_hash") @db.VarChar(255)
|
|
firstName String @map("first_name") @db.VarChar(100)
|
|
lastName String @map("last_name") @db.VarChar(100)
|
|
phone String? @db.VarChar(30)
|
|
emailVerifiedAt DateTime? @map("email_verified_at")
|
|
termsAcceptedAt DateTime @map("terms_accepted_at")
|
|
termsVersion String @map("terms_version") @db.VarChar(20)
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
business Business?
|
|
sessions Session[]
|
|
passwordResets PasswordReset[]
|
|
auditLogs AuditLog[]
|
|
|
|
@@map("users")
|
|
}
|
|
|
|
// Refresh tokens (hashés) : permet déconnexion et révocation.
|
|
model Session {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
userId String @map("user_id") @db.Char(36)
|
|
tokenHash String @unique @map("token_hash") @db.Char(64)
|
|
userAgent String? @map("user_agent") @db.VarChar(255)
|
|
ip String? @db.VarChar(45)
|
|
expiresAt DateTime @map("expires_at")
|
|
revokedAt DateTime? @map("revoked_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId])
|
|
@@map("sessions")
|
|
}
|
|
|
|
model PasswordReset {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
userId String @map("user_id") @db.Char(36)
|
|
tokenHash String @unique @map("token_hash") @db.Char(64)
|
|
expiresAt DateTime @map("expires_at")
|
|
usedAt DateTime? @map("used_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId])
|
|
@@map("password_resets")
|
|
}
|
|
|
|
model Business {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
userId String @unique @map("user_id") @db.Char(36)
|
|
legalName String @map("legal_name") @db.VarChar(191)
|
|
tradeName String? @map("trade_name") @db.VarChar(191)
|
|
siret String? @db.Char(14)
|
|
legalForm String @map("legal_form") @db.VarChar(30) // individual | company
|
|
mcc String? @db.Char(4)
|
|
description String? @db.VarChar(500) // activité, exigée par Stripe (business_profile.product_description)
|
|
addressLine1 String @map("address_line1") @db.VarChar(191)
|
|
addressLine2 String? @map("address_line2") @db.VarChar(191)
|
|
postalCode String @map("postal_code") @db.VarChar(10)
|
|
city String @db.VarChar(100)
|
|
country String @default("FR") @db.Char(2)
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
paymentAccount PaymentAccount?
|
|
transactions Transaction[]
|
|
subscriptions Subscription[]
|
|
debts MerchantDebt[]
|
|
|
|
@@map("businesses")
|
|
}
|
|
|
|
model PaymentAccount {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
businessId String @unique @map("business_id") @db.Char(36)
|
|
provider String @default("stripe") @db.VarChar(20)
|
|
providerAccountId String @unique @map("provider_account_id") @db.VarChar(64)
|
|
chargesEnabled Boolean @default(false) @map("charges_enabled")
|
|
payoutsEnabled Boolean @default(false) @map("payouts_enabled")
|
|
// KYC, IBAN et acceptation des CGU Stripe sont collectés par Stripe (onboarding intégré).
|
|
requirements Json? // exigences restantes renvoyées par Stripe (sans données personnelles)
|
|
bankLast4 String? @map("bank_last4") @db.Char(4)
|
|
bankName String? @map("bank_name") @db.VarChar(100)
|
|
terminalLocationId String? @map("terminal_location_id") @db.VarChar(64)
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
business Business @relation(fields: [businessId], references: [id], onDelete: Restrict)
|
|
payouts Payout[]
|
|
|
|
@@map("payment_accounts")
|
|
}
|
|
|
|
// Frais TapTP configurables (frais Stripe réels refacturés + fixe par transaction).
|
|
model FeePlan {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
code String @unique @db.VarChar(50) // default | subscriber
|
|
perTransactionCents Int @map("per_transaction_cents")
|
|
monthlyPriceCents Int @default(0) @map("monthly_price_cents") // abonnement (0 = sans abonnement)
|
|
// Frais Tap to Pay Stripe par autorisation (tarif public 0,10 €) s'ils ne figurent pas dans la balance transaction.
|
|
tapToPayFeeCents Int @default(10) @map("tap_to_pay_fee_cents")
|
|
passThroughStripeFees Boolean @default(true) @map("pass_through_stripe_fees")
|
|
active Boolean @default(true)
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@map("fee_plans")
|
|
}
|
|
|
|
model Subscription {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
businessId String @map("business_id") @db.Char(36)
|
|
priceCents Int @map("price_cents")
|
|
status String @db.VarChar(20) // active | past_due | canceled
|
|
currentPeriodStart DateTime @map("current_period_start")
|
|
currentPeriodEnd DateTime @map("current_period_end")
|
|
cancelAtPeriodEnd Boolean @default(false) @map("cancel_at_period_end")
|
|
canceledAt DateTime? @map("canceled_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
business Business @relation(fields: [businessId], references: [id], onDelete: Restrict)
|
|
debts MerchantDebt[]
|
|
|
|
@@index([businessId, status])
|
|
@@map("subscriptions")
|
|
}
|
|
|
|
model Transaction {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
businessId String @map("business_id") @db.Char(36)
|
|
idempotencyKey String @unique @map("idempotency_key") @db.VarChar(64)
|
|
providerPaymentIntentId String? @unique @map("provider_payment_intent_id") @db.VarChar(64)
|
|
providerChargeId String? @unique @map("provider_charge_id") @db.VarChar(64)
|
|
providerTransferId String? @unique @map("provider_transfer_id") @db.VarChar(64)
|
|
amountCents Int @map("amount_cents")
|
|
currency String @default("eur") @db.Char(3)
|
|
providerFeeCents Int? @map("provider_fee_cents") // coût Stripe réel
|
|
platformFeeCents Int? @map("platform_fee_cents") // part fixe TapTP
|
|
netCents Int? @map("net_cents") // reversé au pro
|
|
refundedCents Int @default(0) @map("refunded_cents")
|
|
feePlanCode String? @map("fee_plan_code") @db.VarChar(50) // plan appliqué (default | subscriber)
|
|
debtDeductedCents Int @default(0) @map("debt_deducted_cents") // sommes dues retenues sur cette vente
|
|
note String? @db.VarChar(255)
|
|
status String @db.VarChar(30) // pending | succeeded | failed | canceled | refunded | partially_refunded
|
|
failureReason String? @map("failure_reason") @db.VarChar(255)
|
|
cardBrand String? @map("card_brand") @db.VarChar(20)
|
|
cardLast4 String? @map("card_last4") @db.Char(4)
|
|
walletType String? @map("wallet_type") @db.VarChar(20)
|
|
receiptEmail String? @map("receipt_email") @db.VarChar(191)
|
|
succeededAt DateTime? @map("succeeded_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
business Business @relation(fields: [businessId], references: [id], onDelete: Restrict)
|
|
refunds Refund[]
|
|
debtAllocations DebtAllocation[]
|
|
|
|
@@index([businessId, createdAt])
|
|
@@index([businessId, status])
|
|
@@map("transactions")
|
|
}
|
|
|
|
model Refund {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
transactionId String @map("transaction_id") @db.Char(36)
|
|
idempotencyKey String @unique @map("idempotency_key") @db.VarChar(64)
|
|
providerRefundId String? @unique @map("provider_refund_id") @db.VarChar(64)
|
|
amountCents Int @map("amount_cents")
|
|
reason String? @db.VarChar(50)
|
|
status String @db.VarChar(20) // pending | succeeded | failed | canceled
|
|
requestedBy String @map("requested_by") @db.Char(36)
|
|
// Part reprise au pro sur le reversement de la vente ; le reste devient une dette (frais à sa charge).
|
|
providerReversalId String? @unique @map("provider_reversal_id") @db.VarChar(64)
|
|
reversedCents Int @default(0) @map("reversed_cents")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
transaction Transaction @relation(fields: [transactionId], references: [id], onDelete: Restrict)
|
|
debt MerchantDebt?
|
|
|
|
@@index([transactionId])
|
|
@@map("refunds")
|
|
}
|
|
|
|
// Sommes dues par le pro à TapTP (abonnement, frais d'un remboursement non couverts),
|
|
// retenues automatiquement sur les reversements des ventes suivantes.
|
|
model MerchantDebt {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
businessId String @map("business_id") @db.Char(36)
|
|
kind String @db.VarChar(30) // subscription | refund_shortfall
|
|
amountCents Int @map("amount_cents")
|
|
settledCents Int @default(0) @map("settled_cents")
|
|
status String @default("open") @db.VarChar(20) // open | settled | canceled
|
|
subscriptionId String? @map("subscription_id") @db.Char(36)
|
|
periodStart DateTime? @map("period_start") // abonnement : une dette par période
|
|
refundId String? @unique @map("refund_id") @db.Char(36)
|
|
settledAt DateTime? @map("settled_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
business Business @relation(fields: [businessId], references: [id], onDelete: Restrict)
|
|
subscription Subscription? @relation(fields: [subscriptionId], references: [id], onDelete: Restrict)
|
|
refund Refund? @relation(fields: [refundId], references: [id], onDelete: Restrict)
|
|
allocations DebtAllocation[]
|
|
|
|
@@unique([subscriptionId, periodStart])
|
|
@@index([businessId, status, createdAt])
|
|
@@map("merchant_debts")
|
|
}
|
|
|
|
model DebtAllocation {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
debtId String @map("debt_id") @db.Char(36)
|
|
transactionId String @map("transaction_id") @db.Char(36)
|
|
amountCents Int @map("amount_cents")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
debt MerchantDebt @relation(fields: [debtId], references: [id], onDelete: Restrict)
|
|
transaction Transaction @relation(fields: [transactionId], references: [id], onDelete: Restrict)
|
|
|
|
@@unique([debtId, transactionId])
|
|
@@index([transactionId])
|
|
@@map("debt_allocations")
|
|
}
|
|
|
|
model Payout {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
paymentAccountId String @map("payment_account_id") @db.Char(36)
|
|
providerPayoutId String @unique @map("provider_payout_id") @db.VarChar(64)
|
|
amountCents Int @map("amount_cents")
|
|
currency String @default("eur") @db.Char(3)
|
|
arrivalDate DateTime @map("arrival_date")
|
|
status String @db.VarChar(20) // pending | in_transit | paid | failed | canceled
|
|
bankLast4 String? @map("bank_last4") @db.Char(4)
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
paymentAccount PaymentAccount @relation(fields: [paymentAccountId], references: [id], onDelete: Restrict)
|
|
|
|
@@index([paymentAccountId, arrivalDate])
|
|
@@map("payouts")
|
|
}
|
|
|
|
model WebhookEvent {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
providerEventId String @unique @map("provider_event_id") @db.VarChar(64)
|
|
type String @db.VarChar(100)
|
|
payload Json
|
|
processedAt DateTime? @map("processed_at")
|
|
error String? @db.Text
|
|
attempts Int @default(0)
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
@@index([type])
|
|
@@map("webhook_events")
|
|
}
|
|
|
|
model AuditLog {
|
|
id String @id @default(uuid()) @db.Char(36)
|
|
userId String? @map("user_id") @db.Char(36)
|
|
action String @db.VarChar(100)
|
|
ip String? @db.VarChar(45)
|
|
metadata Json?
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
|
|
|
@@index([userId, createdAt])
|
|
@@map("audit_logs")
|
|
}
|