TreasuryPrime.Client (TreasuryPrime v1.0.0)

Copy Markdown View Source

Holds everything needed to talk to the Treasury Prime API: credentials, which environment to call, and HTTP transport configuration.

A Client is just a plain struct — there's no process, no GenServer, no global/application config required to use it (though TreasuryPrime.Config is available if you'd like to configure a default client via config.exs/environment variables instead of passing one around explicitly).

Build one with new/1 and pass it as the first argument to every resource function, e.g. TreasuryPrime.Account.get(client, "acct_123").

Options

  • :api_key_id (required) - your API key ID, used as the HTTP Basic Auth username.
  • :api_key_value (required) - your API key value/secret, used as the HTTP Basic Auth password.
  • :environment - :sandbox (default) or :production. Controls which base URL is used. Sandbox requests never touch real banking rails.
  • :base_url - override the computed base URL entirely. Mostly useful for testing against a local proxy/mock server.
  • :http_client - module implementing TreasuryPrime.HTTPClient. Defaults to TreasuryPrime.HTTPClient.Httpc, a zero-dependency adapter built on Erlang's :httpc.
  • :connect_timeout - milliseconds, default 10_000.
  • :receive_timeout - milliseconds, default 30_000.
  • :max_retries - automatic retries for 429 and 5xx responses, with exponential backoff + jitter. Default 2. Set to 0 to disable.
  • :retry_base_delay - base delay in milliseconds for the backoff schedule. Default 500.

Examples

client = TreasuryPrime.Client.new(
  api_key_id: System.fetch_env!("TREASURY_PRIME_KEY_ID"),
  api_key_value: System.fetch_env!("TREASURY_PRIME_KEY_VALUE"),
  environment: :sandbox
)

{:ok, account} = TreasuryPrime.Account.get(client, "acct_123")

Summary

Functions

Builds a new client. Raises TreasuryPrime.Error if required credentials are missing.

Returns true if the client is configured to hit the sandbox environment.

Types

environment()

@type environment() :: :sandbox | :production

t()

@type t() :: %TreasuryPrime.Client{
  api_key_id: String.t(),
  api_key_value: String.t(),
  base_url: String.t(),
  connect_timeout: pos_integer(),
  environment: environment(),
  http_client: module(),
  max_retries: non_neg_integer(),
  receive_timeout: pos_integer(),
  retry_base_delay: pos_integer()
}

Functions

new(opts)

@spec new(keyword()) :: t()

Builds a new client. Raises TreasuryPrime.Error if required credentials are missing.

See the module docs for available options.

sandbox?(client)

@spec sandbox?(t()) :: boolean()

Returns true if the client is configured to hit the sandbox environment.