This commit is contained in:
Lizandro Guarnizo
2026-05-12 21:15:53 -05:00
parent 217e1b550f
commit 553fc25473
5 changed files with 578 additions and 7 deletions
+27 -1
View File
@@ -106,11 +106,17 @@ func GetBoldWebhookLogs(limit int) ([]BoldWebhookLog, error) {
}
// GetBoldWebhookLogsPaginated devuelve los logs con paginación y filtro por tipo.
// El valor especial "APROBADOS" incluye tanto SALE_APPROVED como API_CHECK.
func GetBoldWebhookLogsPaginated(page, limit int, tipo string) ([]BoldWebhookLog, int64, error) {
var logs []BoldWebhookLog
var total int64
db := app.Http.Database.DB.Model(&BoldWebhookLog{})
if tipo != "" && tipo != "TODOS" {
switch tipo {
case "", "TODOS":
// sin filtro
case "APROBADOS":
db = db.Where("tipo IN ?", []string{"SALE_APPROVED", "API_CHECK"})
default:
db = db.Where("tipo = ?", tipo)
}
db.Count(&total)
@@ -121,6 +127,26 @@ func GetBoldWebhookLogsPaginated(page, limit int, tipo string) ([]BoldWebhookLog
return logs, total, nil
}
// UpdateBoldWebhookLogDatos actualiza email y monto de un log existente (para rellenar datos faltantes en API_CHECK).
func UpdateBoldWebhookLogDatos(id uint, payerEmail string, monto int64) error {
updates := map[string]interface{}{}
if payerEmail != "" {
updates["payer_email"] = payerEmail
}
if monto > 0 {
updates["monto"] = monto
}
if len(updates) == 0 {
return nil
}
return app.Http.Database.DB.Model(&BoldWebhookLog{}).Where("id = ?", id).Updates(updates).Error
}
// GetBoldWebhookLogByID carga un registro por su PK.
func GetBoldWebhookLogByID(id uint, out *BoldWebhookLog) error {
return app.Http.Database.DB.First(out, id).Error
}
// ─── Callback log (intentos de pago) ─────────────────────────────────────────
// BoldCallbackLog registra cada visita a la URL de retorno de Bold.