This commit is contained in:
Lizandro Guarnizo
2026-05-01 13:44:37 -05:00
parent be28fea806
commit 3f6eb7dddc
7 changed files with 191 additions and 12 deletions
+40
View File
@@ -0,0 +1,40 @@
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)
}