up
This commit is contained in:
@@ -83,9 +83,26 @@ func BoldWebhook(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
|
||||
// ─── 6. Solo procesar SALE_APPROVED ─────────────────────────────────────
|
||||
// ─── 6. Actualizar estado en callback_log para TODOS los eventos ─────────
|
||||
if referencia != "" {
|
||||
estimado := "pendiente"
|
||||
switch tipo {
|
||||
case "SALE_APPROVED":
|
||||
estimado = "pagado"
|
||||
case "SALE_REJECTED":
|
||||
estimado = "fallido"
|
||||
case "SALE_REVERSED", "CHARGEBACK":
|
||||
estimado = "revertido"
|
||||
}
|
||||
models.UpdateBoldCallbackEstado(referencia, estimado)
|
||||
if paymentID != "" {
|
||||
models.UpdateBoldCallbackEstado(paymentID, estimado)
|
||||
}
|
||||
}
|
||||
|
||||
// Solo continuar lógica de negocio para SALE_APPROVED ─────────────────────
|
||||
if tipo != "SALE_APPROVED" {
|
||||
log.Printf("[BOLD] Webhook: tipo '%s' ignorado", tipo)
|
||||
log.Printf("[BOLD] Webhook: tipo '%s' registrado", tipo)
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
|
||||
|
||||
@@ -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