diff --git a/pkg/services/bold_service.go b/pkg/services/bold_service.go index ca0639f..72bdba9 100644 --- a/pkg/services/bold_service.go +++ b/pkg/services/bold_service.go @@ -160,30 +160,35 @@ func ParseBoldWebhookEvent(rawBody []byte) (*BoldWebhookEvent, error) { // ─── Consulta directa de estado de link ────────────────────────────────────── -// BoldLinkStatus refleja el campo status del payload de la API de Bold. +// BoldLinkStatus refleja la respuesta de GET /online/link/v1/{payment_link}. +// La API de Bold devuelve los campos directamente en el root del JSON (no dentro de "payload"). type BoldLinkStatus struct { - Payload struct { - Status string `json:"status"` // ACTIVE | PAID | EXPIRED | CANCELLED - PaymentID string `json:"payment_id"` // presente cuando está pagado - Amount struct { - Total int64 `json:"total_amount"` - Currency string `json:"currency"` - } `json:"amount"` - Reference string `json:"reference"` - } `json:"payload"` + ID string `json:"id"` + Status string `json:"status"` // ACTIVE | PROCESSING | PAID | REJECTED | CANCELLED | EXPIRED + TransactionID string `json:"transaction_id"` // ID de la transacción cuando está pagado + Reference string `json:"reference"` + Total int64 `json:"total"` } -// CheckBoldLinkPaid consulta la API de Bold para saber si un link ya fue pagado. -// Devuelve (pagado bool, paymentID string, error). -func CheckBoldLinkPaid(cfg *models.BoldConfig, linkID string) (bool, string, error) { +// CheckBoldLinkStatus consulta la API de Bold y devuelve el status del link. +// Posibles valores: ACTIVE, PROCESSING, PAID, REJECTED, CANCELLED, EXPIRED. +func CheckBoldLinkStatus(cfg *models.BoldConfig, linkID string) (status string, transactionID string, err error) { raw, err := GetBoldPaymentLinkStatus(cfg, linkID) if err != nil { - return false, "", err + return "", "", err } var result BoldLinkStatus if err := json.Unmarshal(raw, &result); err != nil { - return false, "", fmt.Errorf("bold: parse link status: %w", err) + return "", "", fmt.Errorf("bold: parse link status: %w", err) } - paid := result.Payload.Status == "PAID" || result.Payload.Status == "APPROVED" - return paid, result.Payload.PaymentID, nil + return result.Status, result.TransactionID, nil +} + +// CheckBoldLinkPaid es un wrapper de compatibilidad sobre CheckBoldLinkStatus. +func CheckBoldLinkPaid(cfg *models.BoldConfig, linkID string) (bool, string, error) { + st, txID, err := CheckBoldLinkStatus(cfg, linkID) + if err != nil { + return false, "", err + } + return st == "PAID" || st == "APPROVED", txID, nil } diff --git a/resources/views/pago_exitoso.html b/resources/views/pago_exitoso.html index eb95322..3494d48 100644 --- a/resources/views/pago_exitoso.html +++ b/resources/views/pago_exitoso.html @@ -26,7 +26,22 @@ - + +
Tu pago fue rechazado o cancelado por la pasarela de pago.
+Puedes intentarlo nuevamente o contactar a soporte si el problema persiste.
+ + Volver al inicio + +