# `Daraja.Client`
[🔗](https://github.com/okothkongo/daraja/blob/v0.1.1/lib/daraja/client.ex#L1)

Connection-level handle holding Daraja credentials, merchant defaults, and the
target environment.

Use `new/1` to build a client. Per-call options override values pulled from
the `:daraja` application environment.

## Examples

Build a client from application configuration:

    client = Daraja.Client.new()

Override individual fields (handy for multi-tenant scenarios):

    client =
      Daraja.Client.new(
        consumer_key: merchant.consumer_key,
        consumer_secret: merchant.consumer_secret
      )

Pass the client to an endpoint module:

    Daraja.Express.request(client, %{
      amount: 100,
      phone_number: "254712345678",
      account_reference: "Order-001"
    })

## Required vs. optional fields

`consumer_key` and `consumer_secret` are always required. `new/1` raises if
they are absent from both options and the application environment.

`business_short_code`, `passkey`, and `callback_url` are STK Push-only and
default to `nil`. `Daraja.Express.request/2` validates that they are set
before sending a request.

# `env`

```elixir
@type env() :: :sandbox | :production
```

# `t`

```elixir
@type t() :: %Daraja.Client{
  business_short_code: String.t() | nil,
  callback_url: String.t() | nil,
  consumer_key: String.t(),
  consumer_secret: String.t(),
  environment: env(),
  passkey: String.t() | nil
}
```

# `base_url`

```elixir
@spec base_url(t()) :: String.t()
```

Returns the Safaricom base URL for the client's `environment`.

# `new`

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

Builds a `Daraja.Client` from options, falling back to the `:daraja`
application environment for any missing value.

Raises if `consumer_key` or `consumer_secret` cannot be resolved.

---

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