Result callbacks
KiPay posts each STK result to your CallBackURL in Daraja's stkCallback shape.
Delivery
When a transaction reaches a final result, KiPay sends a POST with a JSON body to the CallBackURL you supplied. Respond with any 2xx status to acknowledge. A non-2xx response or a timeout is retried automatically.
Your CallBackURL must use https and resolve to a public address. Private, local and otherwise unsafe addresses are rejected when you send the STK Push.
Successful payment
JSON
{
"Body": {
"stkCallback": {
"MerchantRequestID": "29115-34620561-1",
"CheckoutRequestID": "ws_CO_191220191020363925",
"ResultCode": 0,
"ResultDesc": "The service request is processed successfully.",
"CallbackMetadata": {
"Item": [
{ "Name": "Amount", "Value": 1500 },
{ "Name": "MpesaReceiptNumber", "Value": "NLJ7RT61SV" },
{ "Name": "TransactionDate", "Value": 20261123120512 },
{ "Name": "PhoneNumber", "Value": 254712345678 }
]
}
}
}
}Failed or cancelled payment
Unsuccessful results carry a non-zero ResultCode and a ResultDesc, with no CallbackMetadata.
JSON
{
"Body": {
"stkCallback": {
"MerchantRequestID": "29115-34620561-1",
"CheckoutRequestID": "ws_CO_191220191020363925",
"ResultCode": 1032,
"ResultDesc": "Request cancelled by user"
}
}
}Handling callbacks
- Match the callback to your order using CheckoutRequestID.
- Treat ResultCode 0 as paid. Any other value is not paid.
- Make your handler idempotent. A callback can arrive more than once, for example after a replay.
- Callbacks are delivered to your endpoint but are not individually authenticated. Before fulfilling high-value orders, confirm the payment with STK Query, treat ResultCode 0 as paid, and dedupe on CheckoutRequestID.