ip
This commit is contained in:
@@ -118,13 +118,15 @@ func BoldWebhook(c *fiber.Ctx) error {
|
||||
if referencia != "" {
|
||||
var contratoID uint
|
||||
if _, err := fmt.Sscanf(referencia, "contrato-%d", &contratoID); err == nil && contratoID > 0 {
|
||||
if err := models.MarcarContratoPagado(contratoID); err != nil {
|
||||
if ok, err := models.MarcarContratoPagado(contratoID); err != nil {
|
||||
log.Printf("[BOLD] Webhook: error marcando contrato %d como pagado: %v", contratoID, err)
|
||||
} else {
|
||||
log.Printf("[BOLD] Webhook: contrato %d marcado como pagado", contratoID)
|
||||
// Notificar SaaS externos + enviar correo de confirmación (goroutine, no bloquea respuesta)
|
||||
go services.DispatchSaasPaymentNotification(contratoID, payerEmail, "bold", float64(monto), "COP")
|
||||
go services.EnviarCorreoConfirmacionPago(contratoID, "bold")
|
||||
log.Printf("[BOLD] Webhook: contrato %d marcado como pagado (nuevo=%v)", contratoID, ok)
|
||||
if ok {
|
||||
// Primer registro del pago: notificar SaaS + enviar correo
|
||||
go services.DispatchSaasPaymentNotification(contratoID, payerEmail, "bold", float64(monto), "COP")
|
||||
go services.EnviarCorreoConfirmacionPago(contratoID, "bold")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,13 +320,14 @@ func DlocalWebhook(c *fiber.Ctx) error {
|
||||
if orderID != "" {
|
||||
var contratoID uint
|
||||
if _, err := fmt.Sscanf(orderID, "contrato-%d", &contratoID); err == nil && contratoID > 0 {
|
||||
if err := models.MarcarContratoPagado(contratoID); err != nil {
|
||||
log.Printf("[DLOCAL] Webhook: error marcando contrato %d como pagado: %v", contratoID, err)
|
||||
} else {
|
||||
log.Printf("[DLOCAL] Webhook: contrato %d marcado como pagado", contratoID)
|
||||
// Notificar SaaS externos + enviar correo de confirmación (goroutine, no bloquea respuesta)
|
||||
go services.DispatchSaasPaymentNotification(contratoID, payerEmail, "dlocal", monto, moneda)
|
||||
go services.EnviarCorreoConfirmacionPago(contratoID, "dlocal")
|
||||
if ok, err := models.MarcarContratoPagado(contratoID); err != nil {
|
||||
log.Printf("[DLOCAL] Webhook: error marcando contrato %d como pagado: %v", contratoID, err)
|
||||
} else {
|
||||
log.Printf("[DLOCAL] Webhook: contrato %d marcado como pagado (nuevo=%v)", contratoID, ok)
|
||||
if ok {
|
||||
go services.DispatchSaasPaymentNotification(contratoID, payerEmail, "dlocal", monto, moneda)
|
||||
go services.EnviarCorreoConfirmacionPago(contratoID, "dlocal")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -405,8 +406,8 @@ func DlocalRegistrarPago(c *fiber.Ctx) error {
|
||||
if b.Estado == "PAID" && referencia != "" {
|
||||
var contratoID uint
|
||||
if _, err := fmt.Sscanf(referencia, "contrato-%d", &contratoID); err == nil && contratoID > 0 {
|
||||
if err := models.MarcarContratoPagado(contratoID); err != nil {
|
||||
log.Printf("[DLOCAL] Registro manual: error marcando contrato %d: %v", contratoID, err)
|
||||
if _, markErr := models.MarcarContratoPagado(contratoID); markErr != nil {
|
||||
log.Printf("[DLOCAL] Registro manual: error marcando contrato %d: %v", contratoID, markErr)
|
||||
} else {
|
||||
log.Printf("[DLOCAL] Registro manual: contrato %d marcado como pagado", contratoID)
|
||||
}
|
||||
|
||||
@@ -78,8 +78,9 @@ func PagoExitosoPage(c *fiber.Ctx) error {
|
||||
// Marcar contrato si aún no está confirmado
|
||||
var contratoID uint
|
||||
if _, err := fmt.Sscanf(ref, "contrato-%d", &contratoID); err == nil && contratoID > 0 {
|
||||
_ = models.MarcarContratoPagado(contratoID)
|
||||
go services.EnviarCorreoConfirmacionPago(contratoID, "bold")
|
||||
if ok, _ := models.MarcarContratoPagado(contratoID); ok {
|
||||
go services.EnviarCorreoConfirmacionPago(contratoID, "bold")
|
||||
}
|
||||
// Intentar enriquecer con datos del webhook log si ya llegó
|
||||
go func() {
|
||||
if wLogs, err := models.GetBoldWebhookLogsByRef(ref); err == nil {
|
||||
@@ -161,8 +162,9 @@ func verificarPago(ref string) (confirmado bool, fechaPago string) {
|
||||
for _, l := range dlocalLogs {
|
||||
if l.Estado == "PAID" || l.Estado == "AUTHORIZED" {
|
||||
log.Printf("[PAGO-ESTADO] Contrato %d confirmado via dlocal_payment_log (id=%d)", contratoID, l.ID)
|
||||
_ = models.MarcarContratoPagado(contratoID)
|
||||
if ok, _ := models.MarcarContratoPagado(contratoID); ok {
|
||||
go services.EnviarCorreoConfirmacionPago(contratoID, "dlocal")
|
||||
}
|
||||
return true, l.CreatedAt.Format("02/01/2006 15:04")
|
||||
}
|
||||
}
|
||||
@@ -177,8 +179,9 @@ func verificarPago(ref string) (confirmado bool, fechaPago string) {
|
||||
log.Printf("[PAGO-ESTADO] Bold API error para link %s: %v", contrato.EnlacePagoLinkID, boldApiErr)
|
||||
} else if paid {
|
||||
log.Printf("[PAGO-ESTADO] Contrato %d confirmado via Bold API (payment_id=%s)", contratoID, paymentID)
|
||||
_ = models.MarcarContratoPagado(contratoID)
|
||||
go services.EnviarCorreoConfirmacionPago(contratoID, "bold")
|
||||
if ok, _ := models.MarcarContratoPagado(contratoID); ok {
|
||||
go services.EnviarCorreoConfirmacionPago(contratoID, "bold")
|
||||
}
|
||||
if paymentID != "" && !models.IsBoldNotificationDuplicate("api-check-"+paymentID) {
|
||||
_ = models.SaveBoldWebhookLog(models.BoldWebhookLog{
|
||||
NotificationID: "api-check-" + paymentID,
|
||||
@@ -203,8 +206,9 @@ func verificarPago(ref string) (confirmado bool, fechaPago string) {
|
||||
log.Printf("[PAGO-ESTADO] dLocal API error para order_id %s: %v", ref, dlocalApiErr)
|
||||
} else if paid {
|
||||
log.Printf("[PAGO-ESTADO] Contrato %d confirmado via dLocal API (payment_id=%s)", contratoID, paymentID)
|
||||
_ = models.MarcarContratoPagado(contratoID)
|
||||
go services.EnviarCorreoConfirmacionPago(contratoID, "dlocal")
|
||||
if ok, _ := models.MarcarContratoPagado(contratoID); ok {
|
||||
go services.EnviarCorreoConfirmacionPago(contratoID, "dlocal")
|
||||
}
|
||||
notifID := "api-check-" + ref
|
||||
if !models.IsDlocalNotificationDuplicate(notifID) {
|
||||
_ = models.SaveDlocalPaymentLog(models.DlocalPaymentLog{
|
||||
|
||||
Reference in New Issue
Block a user