Payzum.Client (Payzum v0.1.0)

Copy Markdown View Source

HTTP client for the Payzum API: auth, retries, backoff, typed errors.

Only three of the sixteen error codes are retryable. QUOTA_EXCEEDED arrives as a 429 and is NOT one of them — it means too many invoices are open, so retrying makes the situation worse. Treating every 429 as retryable is the obvious mistake.

More importantly, an unsafe request is never retried automatically: invoice creation accepts an Idempotency-Key, but the API documents that as best-effort with roughly 60 seconds of eventual consistency, and it does not enforce order_id uniqueness. A blind retry can create a second real invoice and charge twice.

Every function returns {:ok, value} or {:error, exception}, which is how Elixir reports a failure a caller may want to handle.

Summary

Functions

Seconds to wait before the first safe retry of a create call.

Query GET /v1/status, unauthenticated.

Create a client for production.

Create a client for staging, which has isolated data and separate keys.

A webhook verifier for the given signing secret.

Types

t()

@type t() :: %Payzum.Client{
  config: Payzum.Config.t(),
  sleeper: (non_neg_integer() -> any()),
  transport: (Payzum.Request.t() ->
                {:ok, Payzum.Response.t()} | {:error, Exception.t()})
}

Functions

consistency_window_seconds()

Seconds to wait before the first safe retry of a create call.

health(client)

@spec health(t()) :: {:ok, map()} | {:error, Exception.t()}

Query GET /v1/status, unauthenticated.

Useful as a connectivity probe before blaming your own network.

new(api_key, opts \\ [])

@spec new(String.t(), keyword()) ::
  {:ok, t()} | {:error, Payzum.Errors.Validation.t()}

Create a client for production.

sandbox(api_key, opts \\ [])

@spec sandbox(String.t(), keyword()) ::
  {:ok, t()} | {:error, Payzum.Errors.Validation.t()}

Create a client for staging, which has isolated data and separate keys.

webhooks(secret, opts \\ [])

@spec webhooks(String.t(), keyword()) ::
  {:ok, Payzum.Webhooks.t()} | {:error, Payzum.Errors.Signature.t()}

A webhook verifier for the given signing secret.