up
This commit is contained in:
@@ -105,6 +105,18 @@ func GetBoldWebhookLogs(limit int) ([]BoldWebhookLog, error) {
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
// GetBoldWebhookLogsByRef devuelve los webhooks recibidos para una referencia dada.
|
||||
func GetBoldWebhookLogsByRef(referencia string) ([]BoldWebhookLog, error) {
|
||||
var logs []BoldWebhookLog
|
||||
if err := app.Http.Database.DB.
|
||||
Where("referencia = ?", referencia).
|
||||
Order("id DESC").
|
||||
Find(&logs).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@@ -161,8 +173,9 @@ type BoldCallbackLog struct {
|
||||
Params string `json:"params" gorm:"column:params;type:text"`
|
||||
// Estado: pendiente | pagado | fallido | revertido
|
||||
Estado string `json:"estado" gorm:"column:estado;type:varchar(20);default:'pendiente'"`
|
||||
// Datos del cliente si están disponibles
|
||||
// Datos del pago (enriquecidos desde el webhook cuando llega)
|
||||
PayerEmail string `json:"payer_email" gorm:"column:payer_email;type:varchar(255)"`
|
||||
Monto int64 `json:"monto" gorm:"column:monto;default:0"`
|
||||
// Datos de red (para análisis)
|
||||
IP string `json:"ip" gorm:"column:ip;type:varchar(45)"`
|
||||
UserAgent string `json:"user_agent" gorm:"column:user_agent;type:text"`
|
||||
@@ -186,6 +199,27 @@ func UpdateBoldCallbackEstado(referencia, estado string) {
|
||||
Update("estado", estado)
|
||||
}
|
||||
|
||||
// EnrichBoldCallbackLog enriquece los intentos de pago con email y monto del webhook.
|
||||
// Se llama cuando llega SALE_APPROVED que sí tiene esos datos.
|
||||
func EnrichBoldCallbackLog(referencia, payerEmail string, monto int64) {
|
||||
if referencia == "" {
|
||||
return
|
||||
}
|
||||
updates := map[string]interface{}{}
|
||||
if payerEmail != "" {
|
||||
updates["payer_email"] = payerEmail
|
||||
}
|
||||
if monto > 0 {
|
||||
updates["monto"] = monto
|
||||
}
|
||||
if len(updates) == 0 {
|
||||
return
|
||||
}
|
||||
app.Http.Database.DB.Model(&BoldCallbackLog{}).
|
||||
Where("referencia = ?", referencia).
|
||||
Updates(updates)
|
||||
}
|
||||
|
||||
// GetBoldCallbackLogByID carga un intento de pago por su PK.
|
||||
func GetBoldCallbackLogByID(id uint, out *BoldCallbackLog) error {
|
||||
return app.Http.Database.DB.First(out, id).Error
|
||||
|
||||
Reference in New Issue
Block a user