up
This commit is contained in:
@@ -91,7 +91,7 @@ function pagoApp() {
|
|||||||
async verificar() {
|
async verificar() {
|
||||||
this.intentos++;
|
this.intentos++;
|
||||||
try {
|
try {
|
||||||
const r = await fetch(`/api/pago-estado?ref=${encodeURIComponent(this.ref)}`);
|
const r = await fetch(`/pago/estado?ref=${encodeURIComponent(this.ref)}`);
|
||||||
const data = await r.json();
|
const data = await r.json();
|
||||||
|
|
||||||
if (data.estado === 'confirmado' || data.confirmado) {
|
if (data.estado === 'confirmado' || data.confirmado) {
|
||||||
|
|||||||
@@ -14,11 +14,16 @@ import (
|
|||||||
func PagoExitosoPage(c *fiber.Ctx) error {
|
func PagoExitosoPage(c *fiber.Ctx) error {
|
||||||
// Recolectar todos los parámetros posibles que Bold puede enviar
|
// Recolectar todos los parámetros posibles que Bold puede enviar
|
||||||
params := map[string]string{}
|
params := map[string]string{}
|
||||||
|
// Parámetros clave que Bold envía en la callback_url
|
||||||
for _, k := range []string{"bold-order-id", "order_id", "payment_link", "reference", "id", "ref"} {
|
for _, k := range []string{"bold-order-id", "order_id", "payment_link", "reference", "id", "ref"} {
|
||||||
if v := c.Query(k, ""); v != "" {
|
if v := c.Query(k, ""); v != "" {
|
||||||
params[k] = v
|
params[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// bold-tx-status: Bold envía el resultado directamente en la URL
|
||||||
|
if v := c.Query("bold-tx-status", ""); v != "" {
|
||||||
|
params["bold-tx-status"] = v
|
||||||
|
}
|
||||||
c.Request().URI().QueryArgs().VisitAll(func(k, v []byte) {
|
c.Request().URI().QueryArgs().VisitAll(func(k, v []byte) {
|
||||||
params[string(k)] = string(v)
|
params[string(k)] = string(v)
|
||||||
})
|
})
|
||||||
@@ -43,6 +48,19 @@ func PagoExitosoPage(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
paramsJSON += "}"
|
paramsJSON += "}"
|
||||||
|
|
||||||
|
// Si Bold ya envía el resultado en la URL (bold-tx-status), usarlo directamente
|
||||||
|
// antes de hacer cualquier llamada a la API externa.
|
||||||
|
boldTxStatus := params["bold-tx-status"]
|
||||||
|
if boldTxStatus == "rejected" || boldTxStatus == "cancelled" || boldTxStatus == "failed" {
|
||||||
|
_ = models.SaveBoldCallbackLog(models.BoldCallbackLog{
|
||||||
|
Referencia: ref, PaymentLink: paymentLink, Params: paramsJSON,
|
||||||
|
Estado: "fallido", IP: c.IP(), UserAgent: string(c.Request().Header.UserAgent()),
|
||||||
|
})
|
||||||
|
return c.Render("pago_exitoso", fiber.Map{
|
||||||
|
"Ref": ref, "Estado": "rechazado", "FechaPago": "",
|
||||||
|
}, "layouts/landing")
|
||||||
|
}
|
||||||
|
|
||||||
// Registrar el intento de pago en la tabla de callbacks
|
// Registrar el intento de pago en la tabla de callbacks
|
||||||
if ref != "" || paymentLink != "" {
|
if ref != "" || paymentLink != "" {
|
||||||
entry := models.BoldCallbackLog{
|
entry := models.BoldCallbackLog{
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ func RutasPublicas(web fiber.Router) {
|
|||||||
|
|
||||||
// ─── Página de confirmación de pago ───────────────────────────────────
|
// ─── Página de confirmación de pago ───────────────────────────────────
|
||||||
web.Get("/pago-exitoso", apiControllers.PagoExitosoPage)
|
web.Get("/pago-exitoso", apiControllers.PagoExitosoPage)
|
||||||
web.Get("/api/pago-estado", apiControllers.PagoEstadoAPI)
|
// Ruta fuera del prefijo /api para evitar que AuthApi() la intercepte
|
||||||
|
web.Get("/pago/estado", apiControllers.PagoEstadoAPI)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user