Aller au contenu principal

Monétisation — Flux Stripe

Endpoints implémentés

1) Création paiement

  • Route: POST /api/payments/create
  • Fichier: apps/frontend/app/api/payments/create/route.ts

Responsabilités:

  • Vérifie session utilisateur
  • Vérifie propriété annonce
  • Crée orders (status pending)
  • Crée payments (status pending)
  • Crée la session Stripe (checkout) ou payment_intent
  • Enrichit payments.provider_transaction_id + metadata

Comportement retour:

  • flow=checkout -> retourne checkoutUrl
  • flow=payment_intent -> retourne clientSecret

2) Webhook Stripe idempotent

  • Route: POST /api/webhooks/stripe
  • Fichier: apps/frontend/app/api/webhooks/stripe/route.ts

Responsabilités:

  • Vérifie signature (STRIPE_WEBHOOK_SECRET)
  • Insère l’événement dans webhooks_log (event_id unique)
  • Si doublon: ignore proprement
  • Gère:
    • checkout.session.completed
    • payment_intent.succeeded
    • payment_intent.payment_failed
  • Met à jour:
    • payments.status
    • orders.status
    • car_listings.isFeatured et featuredUntil (si succès)

3) Polling statut retour checkout

  • Route: GET /api/payments/status?order_id=...
  • Fichier: apps/frontend/app/api/payments/status/route.ts

Responsabilités:

  • Vérifie session
  • Vérifie ownership de la commande
  • Retourne statut normalisé:
    • processing
    • success
    • failed

Frontend impliqué

  • Bouton paiement: apps/frontend/app/(protected)/mes-annonces/featured-button.tsx
  • Bandeau statut: apps/frontend/app/(protected)/mes-annonces/payment-status-banner.tsx

Retour UX actuel

  • Stripe success URL -> ?payment=processing&order_id=...
  • Le bandeau lance le polling toutes les 3s
  • Arrêt auto après statut terminal
  • Timeout UX à 60s: message “toujours en vérification, actualisez”