This commit is contained in:
Lizandro Guarnizo
2026-05-12 22:07:31 -05:00
parent f07ac623eb
commit aead156ba8
5 changed files with 70 additions and 5 deletions
+4
View File
@@ -98,6 +98,10 @@ func BoldWebhook(c *fiber.Ctx) error {
if paymentID != "" {
models.UpdateBoldCallbackEstado(paymentID, estimado)
}
// Enriquecer con email y monto del webhook (solo cuando hay datos reales)
if estimado == "pagado" {
models.EnrichBoldCallbackLog(referencia, payerEmail, monto)
}
}
// Solo continuar lógica de negocio para SALE_APPROVED ─────────────────────
+28 -2
View File
@@ -63,15 +63,34 @@ func PagoExitosoPage(c *fiber.Ctx) error {
// Bold confirmó el pago directamente en la URL de retorno
if boldTxStatus == "approved" {
// IP real (detrás de nginx)
ip := c.Get("X-Real-IP")
if ip == "" {
ip = c.Get("X-Forwarded-For")
}
if ip == "" {
ip = c.IP()
}
_ = models.SaveBoldCallbackLog(models.BoldCallbackLog{
Referencia: ref, PaymentLink: paymentLink, Params: paramsJSON,
Estado: "pagado", IP: c.IP(), UserAgent: string(c.Request().Header.UserAgent()),
Estado: "pagado", IP: ip, UserAgent: string(c.Request().Header.UserAgent()),
})
// 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")
// Intentar enriquecer con datos del webhook log si ya llegó
go func() {
if wLogs, err := models.GetBoldWebhookLogsByRef(ref); err == nil {
for _, wl := range wLogs {
if wl.PayerEmail != "" || wl.Monto > 0 {
models.EnrichBoldCallbackLog(ref, wl.PayerEmail, wl.Monto)
break
}
}
}
}()
}
estado, fechaPago := verificarPago(ref)
return c.Render("pago_exitoso", fiber.Map{
@@ -81,12 +100,19 @@ func PagoExitosoPage(c *fiber.Ctx) error {
// Registrar el intento de pago en la tabla de callbacks
if ref != "" || paymentLink != "" {
ip := c.Get("X-Real-IP")
if ip == "" {
ip = c.Get("X-Forwarded-For")
}
if ip == "" {
ip = c.IP()
}
entry := models.BoldCallbackLog{
Referencia: ref,
PaymentLink: paymentLink,
Params: paramsJSON,
Estado: "pendiente",
IP: c.IP(),
IP: ip,
UserAgent: string(c.Request().Header.UserAgent()),
}
_ = models.SaveBoldCallbackLog(entry)