# `Stripe.Client`
[🔗](https://github.com/jeffhuen/tiger_stripe/blob/main/lib/stripe/client.ex#L1)

Stripe API client. Holds configuration and executes HTTP requests.

Create a client via `Stripe.client/2`:

    client = Stripe.client("sk_test_...")
    {:ok, data} = Stripe.Client.request(client, :get, "/v1/charges")

# `t`

```elixir
@type t() :: %Stripe.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()
}
```

# `raw_request`

```elixir
@spec raw_request(t(), atom(), String.t(), keyword()) ::
  {:ok, %{status: integer(), headers: list(), body: binary()}}
  | {:error, Stripe.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.

# `request`

```elixir
@spec request(t(), atom(), String.t(), keyword()) ::
  {:ok, struct() | map()} | {:error, Stripe.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

# `stream_request`

```elixir
@spec stream_request(t(), atom(), String.t(), (term(), acc -&gt; acc), acc, keyword()) ::
  {:ok, acc} | {:error, Stripe.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

    Stripe.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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
