daraja library
Classes
- Daraja
- Entry point for the daraja package.
- DarajaConfig
- Configuration for a Daraja instance.
- DisbursementFailed
- Safaricom rejected or was unable to complete the disbursement.
- DisbursementInitiating
- The B2C request is being sent to Safaricom.
- DisbursementPending
- Safaricom accepted the B2C request. Waiting for the async result callback.
- DisbursementState
- Sealed state type for the B2C disbursement lifecycle.
- DisbursementSuccess
- Safaricom processed the disbursement and the funds were sent.
- DisbursementTimeout
- The B2C request expired in Safaricom's queue without processing.
- PaymentCancelled
- The customer dismissed or cancelled the M-Pesa PIN prompt.
- PaymentError
- An error occurred before or during payment initiation. The STK Push did not reach the customer's phone. Check the message for details.
- PaymentFailed
- The payment could not be completed. See resultCode and message for the reason, or use the convenience getters for the most common failure modes.
- PaymentIdle
- No payment is currently active.
- PaymentInitiating
- The STK Push request is being sent to Safaricom.
- PaymentPending
- Safaricom accepted the STK Push. The customer has been prompted to enter their M-Pesa PIN. Waiting for the async callback.
- PaymentState
- Sealed state type for the STK Push payment lifecycle.
- PaymentSuccess
- The customer entered their PIN and the payment was processed successfully.
- PaymentTimeout
- The T+90s timeout elapsed with no callback received.
- SecurityCredential
- Generates the SecurityCredential required by Safaricom B2C, Account Balance, Transaction Status, and Reversal APIs.
Enums
- B2cCommandId
- The B2C transaction type sent to Safaricom.
- DarajaEnvironment
- Selects the Safaricom API environment.
Exceptions / Errors
- B2cRejectedError
-
Thrown when the B2C request is accepted at the HTTP level (200) but
Safaricom's
ResponseCodeis non-zero — meaning the request was rejected before entering the processing queue. - DarajaAuthError
- Thrown when OAuth token acquisition returns HTTP 401 or 403.
- DarajaException
- Base exception for all daraja errors.
- StkPushRejectedError
-
Thrown when the STK Push request is accepted at the HTTP level (200) but
Safaricom's
ResponseCodeis non-zero — meaning the business logic rejected the request before a push was sent to the customer's phone.