DodoPayments.Client (dodo_payments v0.1.0)

Copy Markdown View Source

Explicit, immutable configuration for Dodo Payments calls.

Clients are ordinary values: there is no global API key, tenant registry, or client-specific process. The SDK application owns a small root supervisor for deadline isolation. The default transport is DodoPayments.ReqClient; pass client: {module, state} to use any conforming DodoPayments.ClientModule.

The default environment is :test, making accidental live charges less likely.

client =
  DodoPayments.Client.new!(
    api_key: System.fetch_env!("DODO_PAYMENTS_API_KEY")
  )

API keys can also be supplied by a zero-arity function for runtime secret rotation. The function is resolved once per logical SDK call.

Summary

Functions

Creates a client, returning configuration errors as data.

Returns a new client using a different key or zero-arity key provider.

Types

credential()

@type credential() :: String.t() | (-> String.t() | nil)

environment()

@type environment() :: :test | :live | :custom

environment_input()

@type environment_input() :: environment() | :test_mode | :live_mode | String.t()

t()

@type t() :: %DodoPayments.Client{
  api_key: DodoPayments.Secret.t() | nil,
  base_url: String.t(),
  client_module: module(),
  client_state: term(),
  environment: environment(),
  max_attempts: pos_integer(),
  max_response_bytes: pos_integer() | :infinity,
  retry_base_delay: non_neg_integer(),
  retry_max_delay: non_neg_integer(),
  timeout: pos_integer()
}

Functions

new(opts \\ [])

@spec new(keyword()) ::
  {:ok, t()} | {:error, DodoPayments.Error.ConfigurationError.t()}

Creates a client, returning configuration errors as data.

new!(opts \\ [])

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

Creates a client or raises DodoPayments.Error.ConfigurationError.

with_api_key(client, api_key)

@spec with_api_key(t(), credential() | nil) :: t()

Returns a new client using a different key or zero-arity key provider.

Direct keys are validated immediately and invalid values raise DodoPayments.Error.ConfigurationError. A provider's returned value is necessarily validated when the provider is resolved for a request.