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.
Summary
Functions
Returns the Safaricom base URL for the client's environment.
Builds a Daraja.Client from options, falling back to the :daraja
application environment for any missing value.
Types
Functions
Returns the Safaricom base URL for the client's environment.
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.