# Modifier le crontabcrontab -e# Ajouter une ligne pour exécuter toutes les 20 minutes*/20 * * * * /usr/bin/node /path/to/cron-job.js >> /var/log/payment-check.log 2>&1# Ou pour Python*/20 * * * * /usr/bin/python3 /path/to/cron-job.py >> /var/log/payment-check.log 2>&1# Ou pour PHP*/20 * * * * /usr/bin/php /path/to/cron-check-payments.php >> /var/log/payment-check.log 2>&1
Méthode 2 : Vérification manuelle (quand le client consulte sa commande)
Déjà implémenté à l’Étape 2 ! Quand le client arrive sur la page de commande, elle vérifie automatiquement une fois.Optionnel : Ajoutez un bouton pour vérifier à la demande (vérifie au maximum toutes les minutes) :
<!DOCTYPE html><html> <head> <title>Statut de la commande</title> </head> <body> <h1>Statut de la commande</h1> <p>Statut : <span id="status">PENDING</span></p> <button id="checkBtn" onclick="startChecking()"> Check Payment Status </button> <p id="message"></p> <script> let checking = false; let checkInterval = null; const orderId = window.location.pathname.split("/").pop(); async function checkPayment() { const response = await fetch(`/orders/${orderId}/check`, { method: "POST", }); const data = await response.json(); document.getElementById("status").textContent = data.status; if (data.status === "CONFIRMED") { document.getElementById("message").textContent = "✅ Paiement confirmé !"; stopChecking(); setTimeout(() => location.reload(), 2000); } else if (data.status === "FAILED") { document.getElementById("message").textContent = "❌ Paiement échoué"; stopChecking(); } else { document.getElementById("message").textContent = "⏳ Toujours en attente..."; } } function startChecking() { if (checking) return; checking = true; document.getElementById("checkBtn").disabled = true; // Check immediately checkPayment(); // Puis vérifier toutes les minutes checkInterval = setInterval(checkPayment, 60000); // Arrêter après 10 minutes setTimeout(stopChecking, 10 * 60000); } function stopChecking() { checking = false; document.getElementById("checkBtn").disabled = false; if (checkInterval) { clearInterval(checkInterval); checkInterval = null; } } // Vérification automatique au chargement (si en attente) if (document.getElementById("status").textContent === "PENDING") { checkPayment(); } </script> </body></html>