up
This commit is contained in:
@@ -179,3 +179,15 @@ func GetEstadoPago(contratoID uint) (bool, *time.Time, error) {
|
||||
}
|
||||
return c.PagoConfirmado, c.FechaPago, nil
|
||||
}
|
||||
|
||||
// GetContratoParaVerificacion devuelve los campos necesarios para verificar el pago directamente
|
||||
// con la pasarela (pago_confirmado, enlace_pago_link_id).
|
||||
func GetContratoParaVerificacion(contratoID uint) (*Contrato, error) {
|
||||
var c Contrato
|
||||
if err := app.Http.Database.DB.
|
||||
Select("id", "pago_confirmado", "fecha_pago", "enlace_pago_link_id").
|
||||
First(&c, contratoID).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
@@ -96,3 +96,56 @@ func GetLastActiveDlocalApi() (*DlocalApi, error) {
|
||||
}
|
||||
return &dlocalConfig, nil
|
||||
}
|
||||
|
||||
// ─── DlocalPaymentLog ─────────────────────────────────────────────────────────
|
||||
|
||||
// DlocalPaymentLog registra cada pago/notificación de dLocal.
|
||||
// Cubre webhooks automáticos y registros manuales del backoffice.
|
||||
type DlocalPaymentLog struct {
|
||||
gorm.Model
|
||||
// notification_id único; para entradas manuales se genera con prefijo "manual-"
|
||||
NotificationID string `json:"notification_id" gorm:"column:notification_id;uniqueIndex;type:varchar(128);not null"`
|
||||
Fuente string `json:"fuente" gorm:"column:fuente;type:varchar(20)"` // "webhook" | "manual"
|
||||
Tipo string `json:"tipo" gorm:"column:tipo;type:varchar(50)"` // PAYMENT, SUBSCRIPTION_CHARGE, …
|
||||
Estado string `json:"estado" gorm:"column:estado;type:varchar(30)"` // PAID, PENDING, REJECTED, CANCELLED, EXPIRED
|
||||
PaymentID string `json:"payment_id" gorm:"column:payment_id;type:varchar(64)"`
|
||||
OrderID string `json:"order_id" gorm:"column:order_id;type:varchar(120)"`
|
||||
Referencia string `json:"referencia" gorm:"column:referencia;type:varchar(120)"`
|
||||
PayerEmail string `json:"payer_email" gorm:"column:payer_email;type:varchar(255)"`
|
||||
Monto float64 `json:"monto" gorm:"column:monto"`
|
||||
Moneda string `json:"moneda" gorm:"column:moneda;type:varchar(10)"`
|
||||
Procesado bool `json:"procesado" gorm:"column:procesado;default:false"`
|
||||
Nota string `json:"nota" gorm:"column:nota;type:text"`
|
||||
Raw string `json:"raw" gorm:"column:raw;type:text"`
|
||||
}
|
||||
|
||||
func (DlocalPaymentLog) TableName() string { return "dlocal_payment_log" }
|
||||
|
||||
// IsDlocalNotificationDuplicate devuelve true si el notification_id ya existe.
|
||||
func IsDlocalNotificationDuplicate(notificationID string) bool {
|
||||
result := app.Http.Database.DB.
|
||||
Where("notification_id = ?", notificationID).
|
||||
First(&DlocalPaymentLog{})
|
||||
return result.Error == nil
|
||||
}
|
||||
|
||||
// SaveDlocalPaymentLog inserta un nuevo registro de pago.
|
||||
func SaveDlocalPaymentLog(entry DlocalPaymentLog) error {
|
||||
return app.Http.Database.DB.Create(&entry).Error
|
||||
}
|
||||
|
||||
// MarkDlocalPaymentProcessed marca el registro como procesado.
|
||||
func MarkDlocalPaymentProcessed(notificationID string) {
|
||||
app.Http.Database.DB.Model(&DlocalPaymentLog{}).
|
||||
Where("notification_id = ?", notificationID).
|
||||
Update("procesado", true)
|
||||
}
|
||||
|
||||
// GetDlocalPaymentLogs devuelve los últimos N registros ordenados por fecha.
|
||||
func GetDlocalPaymentLogs(limit int) ([]DlocalPaymentLog, error) {
|
||||
var logs []DlocalPaymentLog
|
||||
if err := app.Http.Database.DB.Order("id DESC").Limit(limit).Find(&logs).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user