update
This commit is contained in:
+13
-12
@@ -19,18 +19,19 @@ type DlocalApi struct {
|
||||
Modo string `gorm:"default:'prod'" json:"modo"`
|
||||
}
|
||||
type PlanRequest struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Country string `json:"country"`
|
||||
Currency string `json:"currency"`
|
||||
Amount float64 `json:"amount"`
|
||||
FrequencyType string `json:"frequency_type"`
|
||||
FrequencyValue int `json:"frequency_value"`
|
||||
DayOfMonth int `json:"day_of_month"`
|
||||
NotificationURL string `json:"notification_url"`
|
||||
SuccessURL string `json:"success_url"`
|
||||
BackURL string `json:"back_url"`
|
||||
ErrorURL string `json:"error_url"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
Description string `json:"description" validate:"required"`
|
||||
Currency string `json:"currency" validate:"required"`
|
||||
Amount float64 `json:"amount" validate:"required"`
|
||||
FrequencyType string `json:"frequency_type" validate:"required"`
|
||||
|
||||
Country string `json:"country,omitempty"`
|
||||
FrequencyValue int `json:"frequency_value,omitempty"`
|
||||
DayOfMonth int `json:"day_of_month,omitempty"`
|
||||
NotificationURL string `json:"notification_url,omitempty"`
|
||||
SuccessURL string `json:"success_url,omitempty"`
|
||||
BackURL string `json:"back_url,omitempty"`
|
||||
ErrorURL string `json:"error_url,omitempty"`
|
||||
}
|
||||
|
||||
// TableName asegura que GORM use la tabla 'qrvcard'
|
||||
|
||||
@@ -355,3 +355,59 @@ func DeactivatePlan(cfg models.DlocalApi, planID string, subscriptionId string)
|
||||
// Devolver la respuesta exitosa
|
||||
return responseBody, nil
|
||||
}
|
||||
|
||||
func SeePlanes(cfg models.DlocalApi) ([]byte, error) {
|
||||
// Determinar la URL base según el modo
|
||||
baseURL := cfg.UrlDev
|
||||
accessKeyID := cfg.AccessKeyIDdev
|
||||
accessKeySecret := cfg.AccessKeySecretdev
|
||||
|
||||
if cfg.Modo == "prod" {
|
||||
baseURL = cfg.UrlProd
|
||||
accessKeyID = cfg.AccessKeyID
|
||||
accessKeySecret = cfg.AccessKeySecret
|
||||
}
|
||||
|
||||
|
||||
// Construir la URL completa para el endpoint
|
||||
url := fmt.Sprintf("%s/v1/subscription/planes", baseURL)
|
||||
|
||||
// Construir el token de autorización
|
||||
authToken := fmt.Sprintf("Bearer %s:%s", accessKeyID, accessKeySecret)
|
||||
|
||||
// Crear la solicitud HTTP
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error al crear la solicitud: %v", err)
|
||||
}
|
||||
|
||||
// Agregar los encabezados a la solicitud
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", authToken)
|
||||
|
||||
// Configurar el cliente HTTP
|
||||
client := &http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
}
|
||||
|
||||
// Ejecutar la solicitud
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error al enviar la solicitud: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Leer la respuesta
|
||||
responseBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error al leer la respuesta: %v", err)
|
||||
}
|
||||
|
||||
// Si la respuesta no es exitosa, devolver un error
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("error en la respuesta de DLocal (%d): %s", resp.StatusCode, string(responseBody))
|
||||
}
|
||||
|
||||
// Devolver la respuesta exitosa
|
||||
return responseBody, nil
|
||||
}
|
||||
|
||||
@@ -112,8 +112,6 @@ func DeactivatePlan(c *fiber.Ctx) error {
|
||||
planID := c.Params("planID")
|
||||
subscriptionId := c.Params("subscriptionId")
|
||||
|
||||
|
||||
|
||||
// Obtener la configuración activa de DlocalApi
|
||||
dlocalConfig, err := models.GetLastActiveDlocalApi()
|
||||
if err != nil {
|
||||
@@ -136,3 +134,28 @@ func DeactivatePlan(c *fiber.Ctx) error {
|
||||
"response": string(response),
|
||||
})
|
||||
}
|
||||
|
||||
func SeePlanes(c *fiber.Ctx) error {
|
||||
|
||||
// Obtener la configuración activa de DlocalApi
|
||||
dlocalConfig, err := models.GetLastActiveDlocalApi()
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": "Error al obtener la configuración activa de DlocalApi.",
|
||||
})
|
||||
}
|
||||
|
||||
// Llamar al servicio para ver el plan
|
||||
response, err := services.SeePlanes(*dlocalConfig)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": fmt.Sprintf("Error al obtener los planes", err),
|
||||
})
|
||||
}
|
||||
|
||||
// Devolver la respuesta exitosa
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"message": "Planes obtenido exitosamente.",
|
||||
"response": string(response),
|
||||
})
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ func v1AuthRoutes(api fiber.Router) {
|
||||
api.Get("/dlocal/subscription/ver-plan/:planID", apiControllers.SeePlan)
|
||||
api.Patch("/dlocal/subscription/actualizar-plan/:planID", apiControllers.UpdatedPlan)
|
||||
api.Patch("/dlocal/subscription/plan/:planId/subscription/:subscriptionId/deactivate", apiControllers.DeactivatePlan)
|
||||
|
||||
api.Get("/dlocal/subscription/plan/all", apiControllers.SeePlanes)
|
||||
}
|
||||
|
||||
func v1Routes(api fiber.Router) {
|
||||
|
||||
Reference in New Issue
Block a user