
Accepting M-Pesa inside your own website or app is one of the highest-value integrations you can build in Kenya. Customers get a prompt on their phone, enter their PIN, and your system confirms the payment automatically. Here is how it works with Safaricom's Daraja API.
The password is the Base64 of ShortCode + Passkey + Timestamp, and the timestamp is formatted YYYYMMDDHHMMSS.
POST /mpesa/stkpush/v1/processrequest
{
"BusinessShortCode": "174379",
"Password": "<base64(shortcode+passkey+timestamp)>",
"Timestamp": "20260101120000",
"TransactionType": "CustomerPayBillOnline",
"Amount": 1,
"PartyA": "2547XXXXXXXX",
"PartyB": "174379",
"PhoneNumber": "2547XXXXXXXX",
"CallBackURL": "https://yourdomain.com/mpesa/callback/",
"AccountReference": "ORDER-1001",
"TransactionDesc": "Payment"
}Use CustomerBuyGoodsOnline for a Till number. Phone numbers must be in the 2547XXXXXXXX format, not 07XX.
The callback contains a ResultCode. A value of 0 means success and includes the M-Pesa receipt number. Anything else is a failure or cancellation. Store the CheckoutRequestID when you send the request so you can match the callback to the right order.
BlackCodeLabs builds M-Pesa Daraja integrations on Django for shops, ticketing and booking platforms. Get in touch if you want it done right the first time.
Comments (0)
Sign in or create an account to comment.