41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package controllers
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/sujit-baniya/fiber-boilerplate/pkg/models"
|
|
)
|
|
|
|
// PagoExitosoPage renderiza la página pública de confirmación de pago.
|
|
// Bold redirige al cliente aquí tras el pago. La URL puede incluir ?ref=contrato-{id}.
|
|
func PagoExitosoPage(c *fiber.Ctx) error {
|
|
ref := c.Query("ref", "")
|
|
return c.Render("pago_exitoso", fiber.Map{"Ref": ref}, "layouts/landing")
|
|
}
|
|
|
|
// PagoEstadoAPI devuelve el estado de pago de un contrato para polling desde el frontend.
|
|
// GET /api/pago-estado?ref=contrato-{id}
|
|
func PagoEstadoAPI(c *fiber.Ctx) error {
|
|
ref := c.Query("ref", "")
|
|
if ref == "" {
|
|
return c.JSON(fiber.Map{"confirmado": false, "error": "ref requerido"})
|
|
}
|
|
|
|
var contratoID uint
|
|
if _, err := fmt.Sscanf(ref, "contrato-%d", &contratoID); err != nil || contratoID == 0 {
|
|
return c.JSON(fiber.Map{"confirmado": false, "error": "ref inválido"})
|
|
}
|
|
|
|
confirmado, fechaPago, err := models.GetEstadoPago(contratoID)
|
|
if err != nil {
|
|
return c.JSON(fiber.Map{"confirmado": false, "error": "contrato no encontrado"})
|
|
}
|
|
|
|
resp := fiber.Map{"confirmado": confirmado}
|
|
if confirmado && fechaPago != nil {
|
|
resp["fecha_pago"] = fechaPago.Format("02/01/2006 15:04")
|
|
}
|
|
return c.JSON(resp)
|
|
}
|