chore: add crypto payment

This commit is contained in:
2026-03-18 19:20:37 +01:00
parent adf68201fd
commit a00dd475f3
8 changed files with 471 additions and 254 deletions
@@ -76,6 +76,7 @@ func IPNWebhook(c *gin.Context) {
// GetCommandPaymentStatus - GET /api/v1/commands/:id/payment-status
// Retourne le statut du paiement crypto d'une commande (polling côté client)
// Effectue un refresh temps réel depuis NowPayments si le paiement est encore en attente
func GetCommandPaymentStatus(c *gin.Context) {
database := c.MustGet("database").(*db.Database)
@@ -95,6 +96,30 @@ func GetCommandPaymentStatus(c *gin.Context) {
return
}
// Refresh temps réel depuis NowPayments pour les statuts intermédiaires (comme la référence)
switch payment.Status {
case "waiting", "confirming", "confirmed", "sending":
np, npOk := c.Get("nowpayments")
if npOk && np != nil {
npClient := np.(*services.NowPaymentsClient)
npStatus, err := npClient.GetPaymentStatus(payment.NowPaymentID)
if err == nil && npStatus.PaymentStatus != payment.Status {
payAmount, _ := npStatus.PayAmount.Float64()
if updateErr := database.UpdateCryptoPaymentStatus(payment.ID, npStatus.PaymentStatus, payAmount); updateErr == nil {
payment.Status = npStatus.PaymentStatus
payment.PayAmount = payAmount
log.Printf("[PAYMENT-STATUS] cmd %d: %s → %s (refresh temps réel)", commandID, payment.Status, npStatus.PaymentStatus)
}
switch npStatus.PaymentStatus {
case "finished", "confirmed":
_ = database.ActivateCryptoCommand(commandID)
case "failed", "expired":
_ = database.CancelCryptoCommand(commandID)
}
}
}
}
c.JSON(http.StatusOK, gin.H{
"command_id": payment.CommandID,
"payment_status": payment.Status,