update
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/sujit-baniya/fiber-boilerplate/pkg/services"
|
||||
)
|
||||
|
||||
// Estructuras definidas por el cliente (ya están bien)
|
||||
type Address struct {
|
||||
Name string `json:"name"`
|
||||
Line1 string `json:"line_1"`
|
||||
Line2 string `json:"line_2"`
|
||||
Line3 string `json:"line_3"`
|
||||
City string `json:"city"`
|
||||
State string `json:"state"`
|
||||
Country string `json:"country"`
|
||||
Zip string `json:"zip"`
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
Canton string `json:"canton"`
|
||||
District string `json:"district"`
|
||||
}
|
||||
|
||||
type Contact struct {
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
Email string `json:"email"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
MothersName string `json:"mothers_name"`
|
||||
ContactType string `json:"contact_type"`
|
||||
Address Address `json:"address"`
|
||||
IdentificationType string `json:"identification_type"`
|
||||
IdentificationNumber string `json:"identification_number"`
|
||||
DateOfBirth string `json:"date_of_birth"`
|
||||
Country string `json:"country"`
|
||||
Nationality string `json:"nationality"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
}
|
||||
|
||||
type WalletRequest struct {
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
EwalletReferenceID string `json:"ewallet_reference_id"`
|
||||
Metadata map[string]interface{} `json:"metadata"`
|
||||
Type string `json:"type"`
|
||||
Contact Contact `json:"contact"`
|
||||
}
|
||||
|
||||
func MakeWallet(c *fiber.Ctx) error {
|
||||
var body WalletRequest
|
||||
|
||||
// 1. Parsear el cuerpo de la solicitud
|
||||
if err := c.BodyParser(&body); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"error": "Error al parsear el cuerpo de la solicitud: " + err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
// 2. Imprimir cuerpo recibido para debug
|
||||
bodyBytes, _ := json.MarshalIndent(body, "", " ")
|
||||
fmt.Println("Cuerpo recibido:\n", string(bodyBytes))
|
||||
|
||||
// 3. Enviar solicitud a Rapyd
|
||||
response, err := services.MakeRequest("post", "/v1/ewallets", body)
|
||||
if err != nil {
|
||||
fmt.Println("Error al hacer la solicitud a Rapyd:", err)
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": "Error al comunicarse con Rapyd",
|
||||
"details": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
// 4. Formatear y devolver la respuesta de Rapyd
|
||||
prettyJSON, _ := json.MarshalIndent(response, "", " ")
|
||||
|
||||
|
||||
fmt.Println("Respuesta de Rapyd:\n", string(prettyJSON))
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
Reference in New Issue
Block a user