up
This commit is contained in:
@@ -10,9 +10,52 @@ import (
|
||||
)
|
||||
|
||||
// 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}.
|
||||
// Bold redirige al cliente aquí tras el pago. Registra el intento en bold_callback_log.
|
||||
func PagoExitosoPage(c *fiber.Ctx) error {
|
||||
ref := c.Query("ref", "")
|
||||
// Recolectar todos los parámetros posibles que Bold puede enviar
|
||||
params := map[string]string{}
|
||||
for _, k := range []string{"bold-order-id", "order_id", "payment_link", "reference", "id", "ref"} {
|
||||
if v := c.Query(k, ""); v != "" {
|
||||
params[k] = v
|
||||
}
|
||||
}
|
||||
c.Request().URI().QueryArgs().VisitAll(func(k, v []byte) {
|
||||
params[string(k)] = string(v)
|
||||
})
|
||||
|
||||
// Resolver la referencia principal (orden de prioridad)
|
||||
ref := ""
|
||||
for _, k := range []string{"ref", "reference", "bold-order-id", "payment_link", "order_id", "id"} {
|
||||
if v := params[k]; v != "" {
|
||||
ref = v
|
||||
break
|
||||
}
|
||||
}
|
||||
paymentLink := params["payment_link"]
|
||||
|
||||
// Serializar todos los params para auditoría
|
||||
paramsJSON := "{"
|
||||
for k, v := range params {
|
||||
paramsJSON += `"` + k + `":"` + v + `",`
|
||||
}
|
||||
if len(paramsJSON) > 1 {
|
||||
paramsJSON = paramsJSON[:len(paramsJSON)-1]
|
||||
}
|
||||
paramsJSON += "}"
|
||||
|
||||
// Registrar el intento de pago en la tabla de callbacks
|
||||
if ref != "" || paymentLink != "" {
|
||||
entry := models.BoldCallbackLog{
|
||||
Referencia: ref,
|
||||
PaymentLink: paymentLink,
|
||||
Params: paramsJSON,
|
||||
Estado: "pendiente",
|
||||
IP: c.IP(),
|
||||
UserAgent: string(c.Request().Header.UserAgent()),
|
||||
}
|
||||
_ = models.SaveBoldCallbackLog(entry)
|
||||
}
|
||||
|
||||
return c.Render("pago_exitoso", fiber.Map{"Ref": ref}, "layouts/landing")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user