up
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user