Configuration for a Triple client.
A %Triple.Config{} struct is the client — it's plain data, holds no
open connections or processes, and is passed explicitly to every call
(Triple.enrich_transaction(client, ...), etc). This makes it safe to
build multiple clients (e.g. one per tenant, or one for sandbox + one for
production) in the same application without any global or process-dictionary
state.
Creating a client
client = Triple.Config.new(api_key: "tr_live_xxx")Or, equivalently, via the top-level shortcut:
client = Triple.new(api_key: "tr_live_xxx")Application-wide defaults
Any option can also be set application-wide and will be used whenever it
isn't passed explicitly to new/1:
config :triple,
api_key: System.fetch_env!("TRIPLE_API_KEY"),
receive_timeout: 15_000Options
:api_key(required) — your Triple API key. Keys starting withtr_test_are sandbox keys,tr_live_are production keys.:environment—:productionor:sandbox. If omitted, it's inferred from the:api_keyprefix.:base_url— override the API host. Defaults to Triple's production or sandbox URL based on:environment.:control_base_url— override the control-plane host (currently only used byTriple.TLS). Defaults similarly based on:environment.:receive_timeout— response timeout in ms. Default30_000.:connect_timeout— connection timeout in ms. Default5_000.:retry— retry strategy.:default(the default) retries408/429/500/502/503/504and transport errors with exponential backoff, honoring theretry-afterheader on429s. Also acceptsfalse, Req's own built-in:transient/:safe_transient, or a custom 2-arity function — seeReq's:retryoption for the exact contract.:max_retries— maximum retry attempts. Default3.:rate_limiter— optionally, the name/pid of a runningTriple.RateLimiterto throttle outgoing requests client-side. Defaultnil(disabled).:req_options— a keyword list merged into the underlyingReq.new/1call, for anything not covered above (custom steps, a:plugfor testing, etc). Takes precedence over this module's own defaults.
Summary
Functions
Infers :production or :sandbox from an API key's prefix
(tr_live_ / tr_test_). Raises ArgumentError if the key matches
neither — pass :environment explicitly in that case.
Builds a new client config, raising ArgumentError if no :api_key can
be found (either passed explicitly or set via config :triple, ...).
Types
@type environment() :: :production | :sandbox
@type retry_strategy() :: :default | :transient | :safe_transient | false | (Req.Request.t(), Req.Response.t() | Exception.t() -> boolean() | {:delay, non_neg_integer()})
@type t() :: %Triple.Config{ api_key: String.t(), base_url: String.t(), connect_timeout: pos_integer(), control_base_url: String.t(), environment: environment(), max_retries: non_neg_integer(), rate_limiter: GenServer.name() | pid() | nil, receive_timeout: pos_integer(), req_options: keyword(), retry: retry_strategy() }
Functions
@spec infer_environment!(String.t()) :: environment()
Infers :production or :sandbox from an API key's prefix
(tr_live_ / tr_test_). Raises ArgumentError if the key matches
neither — pass :environment explicitly in that case.
Builds a new client config, raising ArgumentError if no :api_key can
be found (either passed explicitly or set via config :triple, ...).