Aller au contenu

Test des Webhooks Stripe

Problème résolu

Correction du webhook: Le payload est maintenant correctement récupéré en format brut pour la vérification de signature Stripe.

Comment tester les webhooks Stripe en développement

Option 1: Stripe CLI (Recommandée)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Installer Stripe CLI
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg
echo "deb [signed-by=/usr/share/keyrings/stripe.gpg] https://packages.stripe.dev/stripe-cli-debian-local stable main" | sudo tee -a /etc/apt/sources.list.d/stripe.list
sudo apt update
sudo apt install stripe

# Connecter à votre compte Stripe
stripe login

# Rediriger les webhooks vers votre localhost
stripe listen --forward-to localhost:8001/api/souscriptions/webhook/stripe

Option 2: ngrok (Alternative)

1
2
3
4
5
6
7
8
# Installer ngrok
npm install -g ngrok

# Exposer votre localhost
ngrok http 8001

# Utiliser l'URL ngrok dans la configuration webhook Stripe
# Ex: https://abc123.ngrok.io/api/souscriptions/webhook/stripe

Option 3: Test sur serveur de production

Configurer le webhook directement sur https://api-housing.boaz-study.tech/api/souscriptions/webhook/stripe

Configuration Stripe Dashboard

Dans votre tableau de bord Stripe (https://dashboard.stripe.com/test/webhooks):

  1. Créer un endpoint webhook
  2. URL: https://api-housing.boaz-study.tech/api/souscriptions/webhook/stripe (production) ou l'URL ngrok/Stripe CLI
  3. Événements à écouter:
    • checkout.session.completed
    • payment_intent.payment_failed
  4. Copier le secret de signature et le mettre dans STRIPE_WEBHOOK_SECRET

Variables d'environnement actuelles

  • STRIPE_SECRET_KEY: ✅ Configuré
  • STRIPE_PUBLISHABLE_KEY: ✅ Configuré
  • STRIPE_WEBHOOK_SECRET: ✅ Configuré
  • FRONTEND_URL: ✅ Configuré (https://housing.boaz-study.tech)

Test de paiement

  1. Créer un paiement: ✅ Fonctionne
  2. Redirection Stripe: ✅ Fonctionne
  3. Webhook de confirmation: ⚠️ Nécessite Stripe CLI ou serveur accessible

Cartes de test Stripe

  • Succès: 4242424242424242
  • Échec: 4000000000000002
  • 3D Secure: 4000000000003220