Stripe API client. Holds configuration and executes HTTP requests.
Create a client via StripeElixir.client/2:
client = StripeElixir.client("sk_test_...")
{:ok, data} = StripeElixir.Client.request(client, :get, "/v1/charges")
Summary
Functions
Execute an API request and return the raw response without deserialization.
Execute an API request.
Execute a streaming API request.
Types
@type t() :: %StripeElixir.Client{ api_base: String.t(), api_key: String.t(), api_version: String.t() | nil, client_id: String.t() | nil, connect_base: String.t(), finch: atom(), max_retries: non_neg_integer(), meter_events_base: String.t(), open_timeout: pos_integer(), read_timeout: pos_integer(), stripe_account: String.t() | nil, stripe_context: String.t() | nil, uploads_base: String.t() }
Functions
@spec raw_request(t(), atom(), String.t(), keyword()) :: {:ok, %{status: integer(), headers: list(), body: binary()}} | {:error, StripeElixir.Error.t()}
Execute an API request and return the raw response without deserialization.
Returns {:ok, %{status: integer, headers: list, body: binary}} on success,
or {:error, Error.t()} on failure.
@spec request(t(), atom(), String.t(), keyword()) :: {:ok, struct() | map()} | {:error, StripeElixir.Error.t()}
Execute an API request.
Options
:params- Request parameters (map):base_address-:api|:connect|:files|:meter_events(default:api):api_mode-:v1|:v2(default:v1):api_version- Override API version for this request:stripe_account- Override connected account for this request:stripe_context- Override Stripe context for this request:idempotency_key- Idempotency key for POST/DELETE requests:expand- List of fields to expand
@spec stream_request(t(), atom(), String.t(), (term(), acc -> acc), acc, keyword()) :: {:ok, acc} | {:error, StripeElixir.Error.t()} when acc: term()
Execute a streaming API request.
Streams the response body through fun, which receives chunks as they arrive.
The function signature is (chunk, acc -> acc) where chunk is one of:
{:status, integer()}— HTTP status code{:headers, [{String.t(), String.t()}]}— response headers{:data, binary()}— body chunk
Returns {:ok, acc} with the final accumulator, or {:error, Error.t()}.
Example
StripeElixir.Client.stream_request(client, :post, "/v2/billing/meter_event_stream",
params: %{events: [...]},
api_mode: :v2
) do
fn
{:data, chunk}, acc -> [chunk | acc]
_other, acc -> acc
end, []
end