up
This commit is contained in:
@@ -321,13 +321,13 @@ func DlocalWebhook(c *fiber.Ctx) error {
|
|||||||
var contratoID uint
|
var contratoID uint
|
||||||
if _, err := fmt.Sscanf(orderID, "contrato-%d", &contratoID); err == nil && contratoID > 0 {
|
if _, err := fmt.Sscanf(orderID, "contrato-%d", &contratoID); err == nil && contratoID > 0 {
|
||||||
if ok, err := models.MarcarContratoPagado(contratoID); err != nil {
|
if ok, err := models.MarcarContratoPagado(contratoID); err != nil {
|
||||||
log.Printf("[DLOCAL] Webhook: error marcando contrato %d como pagado: %v", contratoID, err)
|
log.Printf("[DLOCAL] Webhook: error marcando contrato %d como pagado: %v", contratoID, err)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("[DLOCAL] Webhook: contrato %d marcado como pagado (nuevo=%v)", contratoID, ok)
|
log.Printf("[DLOCAL] Webhook: contrato %d marcado como pagado (nuevo=%v)", contratoID, ok)
|
||||||
if ok {
|
if ok {
|
||||||
go services.DispatchSaasPaymentNotification(contratoID, payerEmail, "dlocal", monto, moneda)
|
go services.DispatchSaasPaymentNotification(contratoID, payerEmail, "dlocal", monto, moneda)
|
||||||
go services.EnviarCorreoConfirmacionPago(contratoID, "dlocal")
|
go services.EnviarCorreoConfirmacionPago(contratoID, "dlocal")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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{
|
||||||
@@ -179,9 +188,11 @@ func verificarPago(ref string) (confirmado bool, fechaPago string) {
|
|||||||
log.Printf("[PAGO-ESTADO] Bold API error para link %s: %v", contrato.EnlacePagoLinkID, boldApiErr)
|
log.Printf("[PAGO-ESTADO] Bold API error para link %s: %v", contrato.EnlacePagoLinkID, boldApiErr)
|
||||||
} else if paid {
|
} else if paid {
|
||||||
log.Printf("[PAGO-ESTADO] Contrato %d confirmado via Bold API (payment_id=%s)", contratoID, paymentID)
|
log.Printf("[PAGO-ESTADO] Contrato %d confirmado via Bold API (payment_id=%s)", contratoID, paymentID)
|
||||||
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,
|
||||||
@@ -206,9 +217,9 @@ func verificarPago(ref string) (confirmado bool, fechaPago string) {
|
|||||||
log.Printf("[PAGO-ESTADO] dLocal API error para order_id %s: %v", ref, dlocalApiErr)
|
log.Printf("[PAGO-ESTADO] dLocal API error para order_id %s: %v", ref, dlocalApiErr)
|
||||||
} else if paid {
|
} else if paid {
|
||||||
log.Printf("[PAGO-ESTADO] Contrato %d confirmado via dLocal API (payment_id=%s)", contratoID, paymentID)
|
log.Printf("[PAGO-ESTADO] Contrato %d confirmado via dLocal API (payment_id=%s)", contratoID, paymentID)
|
||||||
if ok, _ := models.MarcarContratoPagado(contratoID); ok {
|
if ok, _ := models.MarcarContratoPagado(contratoID); ok {
|
||||||
go services.EnviarCorreoConfirmacionPago(contratoID, "dlocal")
|
go services.EnviarCorreoConfirmacionPago(contratoID, "dlocal")
|
||||||
}
|
}
|
||||||
notifID := "api-check-" + ref
|
notifID := "api-check-" + ref
|
||||||
if !models.IsDlocalNotificationDuplicate(notifID) {
|
if !models.IsDlocalNotificationDuplicate(notifID) {
|
||||||
_ = models.SaveDlocalPaymentLog(models.DlocalPaymentLog{
|
_ = models.SaveDlocalPaymentLog(models.DlocalPaymentLog{
|
||||||
|
|||||||
Reference in New Issue
Block a user