Paysafe.Error (Paysafe v1.0.0)

Copy Markdown View Source

Structured error type returned by all Paysafe API operations.

All public functions in this library return {:ok, result} or {:error, %Paysafe.Error{}}.

Error kinds

  • :api_error — Paysafe returned a non-2xx response with an error body.
  • :http_error — The HTTP request failed at the transport level.
  • :rate_limited — The rate limiter rejected the request before sending.
  • :timeout — The request timed out.
  • :invalid_config — Configuration validation failed.
  • :invalid_params — Request parameter validation failed.
  • :webhook_signature_mismatch — Webhook HMAC signature verification failed.
  • :decode_error — Response body could not be parsed.

Paysafe API error codes

The most common API error codes are documented here for reference:

  • 3001 — Invalid credentials.
  • 3002 — Invalid account.
  • 3004 — Invalid card number.
  • 3005 — Invalid card expiry.
  • 3007 — Invalid amount.
  • 3009 — Invalid payment type.
  • 3011 — Invalid payment handle token.
  • 3022 — Insufficient funds (trigggers PAS if enabled).
  • 3028 — External gateway system error (retryable).
  • 5000 — Internal server error (retryable).
  • 5068 — Either you submitted a request that requires an action not included
          in your merchant account, or the account is not configured.
  • 5107 — Payment Hub risk rule failed.

Summary

Functions

Build an error from a Paysafe API response body.

Types

field_error()

@type field_error() :: %{field: String.t(), error: String.t()}

kind()

@type kind() ::
  :api_error
  | :http_error
  | :rate_limited
  | :timeout
  | :invalid_config
  | :invalid_params
  | :webhook_signature_mismatch
  | :decode_error

t()

@type t() :: %Paysafe.Error{
  code: String.t() | nil,
  details: map() | nil,
  field_errors: [field_error()] | [],
  http_status: non_neg_integer() | nil,
  kind: kind(),
  message: String.t(),
  retryable?: boolean()
}

Functions

from_response(body, http_status)

@spec from_response(map(), non_neg_integer()) :: t()

Build an error from a Paysafe API response body.