up
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/sujit-baniya/fiber-boilerplate/app"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// PaypalConfig almacena las credenciales de PayPal.
|
||||
// Solo un registro activo a la vez.
|
||||
type PaypalConfig struct {
|
||||
gorm.Model
|
||||
// Credenciales Sandbox
|
||||
ClientIDSandbox string `json:"client_id_sandbox" gorm:"column:client_id_sandbox;type:text"`
|
||||
ClientSecretSandbox string `json:"client_secret_sandbox" gorm:"column:client_secret_sandbox;type:text"`
|
||||
// Credenciales Producción
|
||||
ClientIDProd string `json:"client_id_prod" gorm:"column:client_id_prod;type:text"`
|
||||
ClientSecretProd string `json:"client_secret_prod" gorm:"column:client_secret_prod;type:text"`
|
||||
// Modo activo: "sandbox" | "live"
|
||||
Modo string `json:"modo" gorm:"column:modo;default:'sandbox'"`
|
||||
// Webhook ID para verificación de firmas
|
||||
WebhookID string `json:"webhook_id" gorm:"column:webhook_id;type:text"`
|
||||
// URLs de retorno
|
||||
ReturnURL string `json:"return_url" gorm:"column:return_url;type:text"`
|
||||
CancelURL string `json:"cancel_url" gorm:"column:cancel_url;type:text"`
|
||||
// Nota interna
|
||||
Nota string `json:"nota" gorm:"column:nota;type:text"`
|
||||
Activo bool `json:"activo" gorm:"column:activo;default:true"`
|
||||
}
|
||||
|
||||
func (PaypalConfig) TableName() string { return "paypal_config" }
|
||||
|
||||
// GetPaypalConfig retorna la configuración activa.
|
||||
func GetPaypalConfig() (*PaypalConfig, error) {
|
||||
var item PaypalConfig
|
||||
if err := app.Http.Database.DB.Where("activo = ?", true).Order("id DESC").First(&item).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
// SavePaypalConfig desactiva la config previa y guarda la nueva (o actualiza si ya tiene ID).
|
||||
func SavePaypalConfig(s PaypalConfig) error {
|
||||
app.Http.Database.DB.Model(&PaypalConfig{}).
|
||||
Where("activo = ?", true).
|
||||
Update("activo", false)
|
||||
s.Activo = true
|
||||
if s.ID > 0 {
|
||||
return app.Http.Database.DB.Model(&s).Updates(map[string]interface{}{
|
||||
"client_id_sandbox": s.ClientIDSandbox,
|
||||
"client_secret_sandbox": s.ClientSecretSandbox,
|
||||
"client_id_prod": s.ClientIDProd,
|
||||
"client_secret_prod": s.ClientSecretProd,
|
||||
"modo": s.Modo,
|
||||
"webhook_id": s.WebhookID,
|
||||
"return_url": s.ReturnURL,
|
||||
"cancel_url": s.CancelURL,
|
||||
"nota": s.Nota,
|
||||
"activo": true,
|
||||
}).Error
|
||||
}
|
||||
return app.Http.Database.DB.Create(&s).Error
|
||||
}
|
||||
Reference in New Issue
Block a user