Skip to content
Error normalization

Unified Error Enums Across Heterogeneous Provider Specs

While iyzico returns '12', Garanti emits '0051', and PayTR outputs '1004', Better Payment unifies them all into INSUFFICIENT_FUNDS with localized user guidance.

Error normalization
  • iyzico10051
  • akbank51
  • paytrfailed_reason_code 6
  • ziraatProcReturnCode 51
error.code === "INSUFFICIENT_FUNDS"
Why it matters

Why this earns its place in your stack

1

Unified Error Enums

Standard enums for card declines, invalid inputs, 3D auth failures, and timeouts.

2

User-Friendly Messages

Actionable, localized error messages guiding shoppers how to resolve declines.

3

Raw Provider Transparency

Normalized errors retain the raw provider code and raw payload for debug audit logs.

4

Double-Charge Immunity

Network dropouts yield clear NETWORK_ERROR states preventing accidental repeat charges.

Simple, readable, direct.

Without Better Payment

Manually scouring bank PDF manuals to map cryptic 4-digit bank return codes.

With Better Payment

Predictable TypeScript enum switches that make frontend decline handling trivial.

error-handling.tsTypeScript
try {
  await payment.createPayment({ ... });
} catch (error) {
  if (error instanceof BetterPaymentError) {
    switch (error.code) {
      case "INSUFFICIENT_FUNDS":
        return showToast("Kartınızın bakiyesi yetersiz.");
      case "EXPIRED_CARD":
        return showToast("Kartınızın son kullanma tarihi geçmiş.");
      case "3D_AUTH_FAILED":
        return showToast("SMS doğrulama kodu hatalı veya onaylanmadı.");
      default:
        return showToast("Ödeme alınamadı: " + error.message);
    }
  }
}