API Reference daraja v#0.1.0

Copy Markdown View Source

Modules

Elixir client for the Safaricom Daraja API.

Structured error for :auth_failed, :http_error, and unparsed :request_failed outcomes.

Handles OAuth 2.0 authentication with the Daraja API.

Business to Business (B2B) payments.

Helpers for parsing asynchronous B2B callback payloads posted to ResultURL.

Parsed B2B callback result payload.

Input struct for a B2B payment request.

Response structs for the B2B Payment Request API.

Returned when Safaricom rejects a B2B payment request.

Returned when Safaricom accepts a B2B payment request.

Business to Customer (B2C) payments.

Helpers for parsing asynchronous B2C callback payloads posted to ResultURL.

Parsed B2C callback result payload.

Input struct for a B2C payment request.

Response structs for the B2C Payment Request API.

Returned when Safaricom rejects a B2C payment request.

Returned when Safaricom accepts a B2C payment request.

Customer to Business (C2B) — receive payment notifications for Paybill or Till numbers.

Helpers for parsing inbound C2B callback payloads posted by M-PESA to the merchant's registered validation and confirmation URLs.

Payload received at the ConfirmationURL after M-PESA completes a transaction.

Payload received at the ValidationURL before M-PESA completes a transaction.

Input struct for a C2B Register URL request.

Response structs for the C2B Register URL and Simulate APIs.

Returned when Safaricom rejects a C2B request.

Returned when Safaricom successfully accepts a C2B request.

Input struct for a C2B Simulate transaction request (sandbox only).

Optional idempotency guard for inbound M-PESA callbacks.

Optional verification helpers for inbound M-PESA webhook requests.

Validates callback URLs before they are registered with Safaricom.

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

M-Pesa Express (STK Push) — initiates a payment prompt on a customer's phone.

Helpers for parsing STK Push (M-Pesa Express) callback payloads posted by M-PESA to the merchant's CallBackURL.

Parsed STK Push callback payload.

Input struct for an STK Push request.

Response structs for the STK Push API.

Returned when Safaricom rejects the STK Push request.

Returned when Safaricom successfully accepts the STK Push request.

Opt-in HTTP retry with exponential backoff and jitter.

Behaviour for making HTTP requests.

Security checklist for custom Daraja.HTTPClient implementations.

Default HTTP client implementation using Finch.

Maps HTTP status codes from Safaricom Daraja API responses before JSON parsing.

Utilities for building Daraja security credentials.

Optional supervisor that starts Daraja.TokenCache. Add it to your application's supervision tree to enable token caching across all API calls

ETS-backed GenServer that caches Daraja access tokens to eliminate the network round-trip on every API call.