This commit is contained in:
Lizandro Guarnizo
2026-05-01 17:36:17 -05:00
parent 52c3d7ebe2
commit c9024274f0
10 changed files with 437 additions and 0 deletions
+30
View File
@@ -157,3 +157,33 @@ func ParseBoldWebhookEvent(rawBody []byte) (*BoldWebhookEvent, error) {
}
return &event, nil
}
// ─── Consulta directa de estado de link ──────────────────────────────────────
// BoldLinkStatus refleja el campo status del payload de la API de Bold.
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"`
}
// 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) {
raw, err := GetBoldPaymentLinkStatus(cfg, linkID)
if err != nil {
return false, "", err
}
var result BoldLinkStatus
if err := json.Unmarshal(raw, &result); err != nil {
return false, "", fmt.Errorf("bold: parse link status: %w", err)
}
paid := result.Payload.Status == "PAID" || result.Payload.Status == "APPROVED"
return paid, result.Payload.PaymentID, nil
}