up
This commit is contained in:
@@ -81,17 +81,26 @@ func PagoExitosoPage(c *fiber.Ctx) error {
|
|||||||
if ok, _ := models.MarcarContratoPagado(contratoID); ok {
|
if ok, _ := models.MarcarContratoPagado(contratoID); ok {
|
||||||
go services.EnviarCorreoConfirmacionPago(contratoID, "bold")
|
go services.EnviarCorreoConfirmacionPago(contratoID, "bold")
|
||||||
}
|
}
|
||||||
// Intentar enriquecer con datos del webhook log si ya llegó
|
// Enriquecer callback log: primero webhook log, luego Bold API directa
|
||||||
go func() {
|
go func(linkID string) {
|
||||||
|
// 1. Si el webhook ya llegó, usar esos datos
|
||||||
if wLogs, err := models.GetBoldWebhookLogsByRef(ref); err == nil {
|
if wLogs, err := models.GetBoldWebhookLogsByRef(ref); err == nil {
|
||||||
for _, wl := range wLogs {
|
for _, wl := range wLogs {
|
||||||
if wl.PayerEmail != "" || wl.Monto > 0 {
|
if wl.PayerEmail != "" || wl.Monto > 0 {
|
||||||
models.EnrichBoldCallbackLog(ref, wl.PayerEmail, wl.Monto)
|
models.EnrichBoldCallbackLog(ref, wl.PayerEmail, wl.Monto)
|
||||||
break
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
// 2. Fallback: consultar Bold API directamente para obtener el monto
|
||||||
|
if linkID != "" {
|
||||||
|
if boldCfg, err := models.GetBoldConfig(); err == nil {
|
||||||
|
if _, _, monto, err := services.CheckBoldLinkStatus(boldCfg, linkID); err == nil && monto > 0 {
|
||||||
|
models.EnrichBoldCallbackLog(ref, "", monto)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}(paymentLink)
|
||||||
}
|
}
|
||||||
estado, fechaPago := verificarPago(ref)
|
estado, fechaPago := verificarPago(ref)
|
||||||
return c.Render("pago_exitoso", fiber.Map{
|
return c.Render("pago_exitoso", fiber.Map{
|
||||||
@@ -182,6 +191,8 @@ func verificarPago(ref string) (confirmado bool, fechaPago string) {
|
|||||||
if ok, _ := models.MarcarContratoPagado(contratoID); ok {
|
if ok, _ := models.MarcarContratoPagado(contratoID); ok {
|
||||||
go services.EnviarCorreoConfirmacionPago(contratoID, "bold")
|
go services.EnviarCorreoConfirmacionPago(contratoID, "bold")
|
||||||
}
|
}
|
||||||
|
// Enriquecer callback log con monto y email del cliente
|
||||||
|
go models.EnrichBoldCallbackLog(ref, contrato.Cliente.Email, monto)
|
||||||
if paymentID != "" && !models.IsBoldNotificationDuplicate("api-check-"+paymentID) {
|
if paymentID != "" && !models.IsBoldNotificationDuplicate("api-check-"+paymentID) {
|
||||||
_ = models.SaveBoldWebhookLog(models.BoldWebhookLog{
|
_ = models.SaveBoldWebhookLog(models.BoldWebhookLog{
|
||||||
NotificationID: "api-check-" + paymentID,
|
NotificationID: "api-check-" + paymentID,
|
||||||
|
|||||||
Reference in New Issue
Block a user