update
This commit is contained in:
+13
-12
@@ -19,18 +19,19 @@ type DlocalApi struct {
|
|||||||
Modo string `gorm:"default:'prod'" json:"modo"`
|
Modo string `gorm:"default:'prod'" json:"modo"`
|
||||||
}
|
}
|
||||||
type PlanRequest struct {
|
type PlanRequest struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name" validate:"required"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description" validate:"required"`
|
||||||
Country string `json:"country"`
|
Currency string `json:"currency" validate:"required"`
|
||||||
Currency string `json:"currency"`
|
Amount float64 `json:"amount" validate:"required"`
|
||||||
Amount float64 `json:"amount"`
|
FrequencyType string `json:"frequency_type" validate:"required"`
|
||||||
FrequencyType string `json:"frequency_type"`
|
|
||||||
FrequencyValue int `json:"frequency_value"`
|
Country string `json:"country,omitempty"`
|
||||||
DayOfMonth int `json:"day_of_month"`
|
FrequencyValue int `json:"frequency_value,omitempty"`
|
||||||
NotificationURL string `json:"notification_url"`
|
DayOfMonth int `json:"day_of_month,omitempty"`
|
||||||
SuccessURL string `json:"success_url"`
|
NotificationURL string `json:"notification_url,omitempty"`
|
||||||
BackURL string `json:"back_url"`
|
SuccessURL string `json:"success_url,omitempty"`
|
||||||
ErrorURL string `json:"error_url"`
|
BackURL string `json:"back_url,omitempty"`
|
||||||
|
ErrorURL string `json:"error_url,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName asegura que GORM use la tabla 'qrvcard'
|
// 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
|
// Devolver la respuesta exitosa
|
||||||
return responseBody, nil
|
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")
|
planID := c.Params("planID")
|
||||||
subscriptionId := c.Params("subscriptionId")
|
subscriptionId := c.Params("subscriptionId")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Obtener la configuración activa de DlocalApi
|
// Obtener la configuración activa de DlocalApi
|
||||||
dlocalConfig, err := models.GetLastActiveDlocalApi()
|
dlocalConfig, err := models.GetLastActiveDlocalApi()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -136,3 +134,28 @@ func DeactivatePlan(c *fiber.Ctx) error {
|
|||||||
"response": string(response),
|
"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.Get("/dlocal/subscription/ver-plan/:planID", apiControllers.SeePlan)
|
||||||
api.Patch("/dlocal/subscription/actualizar-plan/:planID", apiControllers.UpdatedPlan)
|
api.Patch("/dlocal/subscription/actualizar-plan/:planID", apiControllers.UpdatedPlan)
|
||||||
api.Patch("/dlocal/subscription/plan/:planId/subscription/:subscriptionId/deactivate", apiControllers.DeactivatePlan)
|
api.Patch("/dlocal/subscription/plan/:planId/subscription/:subscriptionId/deactivate", apiControllers.DeactivatePlan)
|
||||||
|
api.Get("/dlocal/subscription/plan/all", apiControllers.SeePlanes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func v1Routes(api fiber.Router) {
|
func v1Routes(api fiber.Router) {
|
||||||
|
|||||||
Reference in New Issue
Block a user