up
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -150,6 +150,48 @@ func GetDlocalPaymentLogs(limit int) ([]DlocalPaymentLog, error) {
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
// GetDlocalPaymentLogsPaginated devuelve los logs con paginación y filtro por estado.
|
||||
// El valor especial "APROBADOS" agrupa PAID + AUTHORIZED.
|
||||
func GetDlocalPaymentLogsPaginated(page, limit int, estado string) ([]DlocalPaymentLog, int64, error) {
|
||||
var logs []DlocalPaymentLog
|
||||
var total int64
|
||||
db := app.Http.Database.DB.Model(&DlocalPaymentLog{})
|
||||
switch estado {
|
||||
case "", "TODOS":
|
||||
// sin filtro
|
||||
case "APROBADOS":
|
||||
db = db.Where("estado IN ?", []string{"PAID", "AUTHORIZED"})
|
||||
default:
|
||||
db = db.Where("estado = ?", estado)
|
||||
}
|
||||
db.Count(&total)
|
||||
offset := (page - 1) * limit
|
||||
if err := db.Order("id DESC").Limit(limit).Offset(offset).Find(&logs).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return logs, total, nil
|
||||
}
|
||||
|
||||
// GetDlocalPaymentLogByID carga un registro por su PK.
|
||||
func GetDlocalPaymentLogByID(id uint, out *DlocalPaymentLog) error {
|
||||
return app.Http.Database.DB.First(out, id).Error
|
||||
}
|
||||
|
||||
// UpdateDlocalPaymentLogDatos actualiza email y monto de un log existente.
|
||||
func UpdateDlocalPaymentLogDatos(id uint, payerEmail string, monto float64) 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(&DlocalPaymentLog{}).Where("id = ?", id).Updates(updates).Error
|
||||
}
|
||||
|
||||
// GetDlocalPaymentLogsByRef devuelve todos los registros que coinciden con una referencia/order_id.
|
||||
func GetDlocalPaymentLogsByRef(ref string) ([]DlocalPaymentLog, error) {
|
||||
var logs []DlocalPaymentLog
|
||||
|
||||
Reference in New Issue
Block a user