Architecture et flux des paiements locatifs (Stripe, fallback, webhook)
rental_transactions| Colonne | Type | Description |
|---|---|---|
id |
UUID | ClΓ© primaire |
lease_id |
UUID | FK vers leases |
period_month |
INTEGER | Mois de la pΓ©riode (1-12) |
period_year |
INTEGER | AnnΓ©e de la pΓ©riode |
amount_due |
DECIMAL | Montant dΓ» |
amount_paid |
INTEGER | Montant payΓ© |
status |
TEXT | pending, paid, overdue |
paid_at |
TIMESTAMPTZ | Date de paiement |
payment_method |
TEXT | stripe, manual, transfer |
payment_ref |
TEXT | ID Stripe session/transaction |
team_id |
UUID | FK pour multi-tenant |
owner_id |
UUID | FK vers profiles |
meta |
JSONB | MΓ©tadonnΓ©es (provider, timestamps) |
βββββββββββββββ ββββββββββββββββββββββ ββββββββββββββββββββ
β /locataire ββββββΆβ Stripe Checkout ββββββΆβ Webhook β
β Payer β β createRentSession β β /api/stripe/ β
βββββββββββββββ ββββββββββββββββββββββ β webhook β
ββββββββββ¬ββββββββββ
β
ββββββββββββββββββββββ β
β /paiement-succes ββββββββββββββββ
β saveRentPayment β
β Fallback β
ββββββββββββββββββββββ
| Fichier | RΓ΄le |
|---|---|
app/api/stripe/webhook/route.ts |
Webhook Stripe - marque paiement "paid" |
app/locataire/paiement-succes/page.tsx |
Page succès + fallback si webhook échoue |
lib/stripe-rent.ts |
CrΓ©ation session Stripe pour loyer |
saveRentPaymentFallbackLocalisation: app/locataire/paiement-succes/page.tsx
Cette fonction est idempotente et sert de filet de sΓ©curitΓ© si le webhook Stripe n'a pas traitΓ© le paiement :
team_id et owner_id depuis le bail// Colonnes OBLIGATOIRES pour insert/update
{
status: 'paid',
paid_at: new Date().toISOString(),
payment_method: 'stripe',
payment_ref: sessionId,
amount_paid: amountFcfa,
team_id: teamId, // Pour visibilitΓ© dashboard /gestion
owner_id: ownerId,
meta: { provider: 'stripe', ... }
}
PGRST204, vΓ©rifier que les colonnes existent en DBteam_id, les transactions n'apparaissent pas dans /gestioncreateAdminClient() pour bypass RLS dans les webhooksALTER TABLE rental_transactions
ADD COLUMN IF NOT EXISTS payment_method TEXT,
ADD COLUMN IF NOT EXISTS payment_ref TEXT,
ADD COLUMN IF NOT EXISTS amount_paid INTEGER,
ADD COLUMN IF NOT EXISTS owner_id UUID,
ADD COLUMN IF NOT EXISTS meta JSONB DEFAULT '{}'::jsonb;
Script pour vΓ©rifier les paiements d'un bail :
npx tsx scripts/check-lease.ts
Logs Γ surveiller :
β
Rent payment updated (fallback) - Transaction pending mise Γ jourβ
Rent payment created (fallback) - Nouvelle transaction crééeβ Failed to insert/update payment - Erreur DB (vΓ©rifier colonnes)