Dumu Pay lets your website or app collect M-Pesa payments with a single API call. You send a phone number and an amount, the customer receives an M-Pesa STK prompt on their phone, and we tell your server the result with a signed webhook. Collected money builds up in your Dumu Pay balance, which you withdraw to M-Pesa or a bank account from the dashboard.
Base URL https://pay.dumutech.co.ke/api/v1
All requests and responses are JSON. Amounts are whole Kenyan shillings (KES). Timestamps are UTC, ISO 8601.
Your server --POST /payments--> Dumu Pay --STK push--> Customer's phone Your server <--webhook---------- Dumu Pay <--result----- M-Pesa
Create an account to get two keys from the API keys page. Send the key in the X-API-Key header (or Authorization: Bearer KEY).
| Key | What it does |
|---|---|
dp_test_... | Simulated payments. Succeed after about 4 seconds. No real money, no fees, no balance. |
dp_live_... | Real M-Pesa prompts. Successful payments are credited to your balance. |
Keys are shown once when created, so store them in an environment variable on your server. Never put a key in browser or mobile app code: anyone who finds it can create payment prompts as you. If a key leaks, roll it on the API keys page and the old one stops working immediately. Requests are limited to 120 per minute per key.
Dumu Pay charges a flat 2.0% commission on every successful payment. There is no setup fee, no monthly fee, and failed, cancelled or timed-out prompts cost nothing.
| Payment | Commission (2.0%) | Credited to you |
|---|---|---|
| KES 100 | KES 2 | KES 98 |
| KES 500 | KES 10 | KES 490 |
| KES 1,000 | KES 20 | KES 980 |
| KES 5,000 | KES 100 | KES 4,900 |
| KES 20,000 | KES 400 | KES 19,600 |
The commission is calculated when you create the payment and shown in the response as fee and net. Commission is rounded to the nearest shilling. Withdrawals: KES 25 to M-Pesa, KES 100 to a bank account, minimum KES 200, deducted from the amount you withdraw.
POST/payments
Sends an M-Pesa prompt to the customer's phone and returns immediately with status pending. The final result arrives by webhook.
| Field | Type | Description |
|---|---|---|
phone * | string | Safaricom number: 0712345678 or 254712345678. |
amount * | integer | KES, from 1 to 150,000. |
reference | string | Your own order or invoice id, up to 80 characters. Idempotent: reusing a reference that is pending or already paid returns that payment (with "duplicate": true) instead of charging twice. Use it. |
description | string | Up to 40 characters, shown to the customer where M-Pesa allows. |
callback_url | string | Public https URL for this payment's webhook. Overrides your default URL in Settings. |
curl -X POST https://pay.dumutech.co.ke/api/v1/payments \
-H "X-API-Key: $DUMUPAY_KEY" \
-H "Content-Type: application/json" \
-d '{"phone":"0712345678","amount":500,"reference":"ORDER-1042","description":"Order 1042"}'
<?php
$ch = curl_init('https://pay.dumutech.co.ke/api/v1/payments');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('DUMUPAY_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode(['phone' => '0712345678', 'amount' => 500, 'reference' => 'ORDER-1042']),
]);
$res = json_decode(curl_exec($ch), true);
if ($res['success']) { $paymentId = $res['data']['id']; }
import os, requests
r = requests.post("https://pay.dumutech.co.ke/api/v1/payments",
headers={"X-API-Key": os.environ["DUMUPAY_KEY"]},
json={"phone": "0712345678", "amount": 500, "reference": "ORDER-1042"}, timeout=30)
data = r.json()
if data["success"]:
payment_id = data["data"]["id"]
const r = await fetch("https://pay.dumutech.co.ke/api/v1/payments", {
method: "POST",
headers: { "X-API-Key": process.env.DUMUPAY_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ phone: "0712345678", amount: 500, reference: "ORDER-1042" }),
});
const { success, data, error } = await r.json();201{
"success": true,
"message": "Payment prompt sent to the customer's phone.",
"data": {
"id": "dp_9f3c1a07be42d5e1a8c3",
"status": "pending",
"amount": 500,
"fee": 10,
"net": 490,
"currency": "KES",
"phone": "254712345678",
"reference": "ORDER-1042",
"description": "Order 1042",
"mpesa_receipt": null,
"failure_reason": null,
"mode": "live",
"created_at": "2026-12-04T10:15:00Z",
"completed_at": null
}
}GET/payments/{id} The {id} can be our dp_... id or your own reference. Returns the same payment object. Rely on webhooks, and use this only as a fallback, for example when the customer returns to your site and you want to confirm the result.
GET/payments?limit=25&status=failed Newest first. limit is 1 to 100; status is pending, success or failed. Returns {"success": true, "data": [ ...payments ]}.
GET/balance {"success": true, "data": {"currency": "KES", "available": 12450}}. This is what you can withdraw: successful live payments minus commission, minus withdrawals that are pending or paid.
When a payment succeeds or fails we send a POST to your webhook URL (set it in Settings, or per payment with callback_url):
{ "event": "payment.success", "data": { ...the payment object... } }
Events: payment.success and payment.failed. Reply with any 2xx status within 10 seconds. If we do not get one we retry up to 4 times: immediately, then after 10 seconds, 1 minute and 5 minutes. You can see every delivery on the payment's page in the dashboard and resend it with one click.
Every webhook has an X-DumuPay-Signature header: sha256= followed by the HMAC-SHA256 of the raw request body using your webhook secret (Settings). Check it before you trust anything in the body, otherwise anyone could send your server a fake “paid” message.
<?php
$raw = file_get_contents('php://input');
$expect = 'sha256=' . hash_hmac('sha256', $raw, getenv('DUMUPAY_WEBHOOK_SECRET'));
if (!hash_equals($expect, $_SERVER['HTTP_X_DUMUPAY_SIGNATURE'] ?? '')) { http_response_code(403); exit; }
$event = json_decode($raw, true);
$p = $event['data'];
if ($event['event'] === 'payment.success') {
// find your order by $p['reference'], check $p['amount'] matches, mark it paid once
}
http_response_code(200);
import hmac, hashlib, os
from flask import Flask, request, abort
app = Flask(__name__)
@app.post("/dumupay/webhook")
def webhook():
raw = request.get_data()
expect = "sha256=" + hmac.new(os.environ["DUMUPAY_WEBHOOK_SECRET"].encode(), raw, hashlib.sha256).hexdigest()
if not hmac.compare_digest(expect, request.headers.get("X-DumuPay-Signature", "")):
abort(403)
event = request.get_json()
p = event["data"]
if event["event"] == "payment.success":
pass # look up order by p["reference"], verify p["amount"], mark paid once
return "", 200
const crypto = require("crypto");
app.post("/dumupay/webhook", express.raw({ type: "application/json" }), (req, res) => {
const expect = "sha256=" + crypto.createHmac("sha256", process.env.DUMUPAY_WEBHOOK_SECRET).update(req.body).digest("hex");
const got = req.get("X-DumuPay-Signature") || "";
if (got.length !== expect.length || !crypto.timingSafeEqual(Buffer.from(got), Buffer.from(expect))) return res.sendStatus(403);
const event = JSON.parse(req.body);
if (event.event === "payment.success") { /* find order by event.data.reference, verify amount, mark paid once */ }
res.sendStatus(200);
});| Status | Meaning |
|---|---|
pending | Prompt sent, waiting for the customer to enter their PIN. |
success | Paid. mpesa_receipt is set and the net amount is in your balance. |
failed | Cancelled, wrong PIN, insufficient funds, or no response. failure_reason says why. No commission is charged. |
If the customer ignores the prompt, the payment is marked failed after about 3 minutes. M-Pesa can occasionally confirm late, so a payment.success may arrive after a payment.failed for the same payment. Treat the latest event as the truth.
Always check that data.amount matches what you expected for the order before you deliver goods.
Use your dp_test_ key. Every test payment is created as pending and turns success after about 4 seconds, with a receipt starting TEST. Webhooks fire exactly as in live mode, so you can build and verify your whole flow without spending money. Test payments appear under the Test toggle in the dashboard and never affect your balance.
Failed requests return a non-2xx status and:
{ "success": false, "error": { "code": "invalid_phone", "message": "phone must be a Safaricom number..." } }
| HTTP | Code | Meaning |
|---|---|---|
| 401 | missing_api_key, invalid_api_key | No key sent, or it is wrong or revoked. |
| 403 | account_pending, account_suspended | Live mode not approved yet, or account suspended. |
| 404 | not_found | No payment with that id or reference. |
| 422 | invalid_phone, invalid_amount, invalid_callback_url | Fix the field named in message. |
| 429 | rate_limited | Over 120 requests per minute. Back off and retry. |
| 502 | gateway_error | The prompt could not be sent. The response includes the failed payment in data; safe to retry with a new reference. |
| 1 | Payments work end to end with your test key, including the webhook. |
| 2 | Your webhook verifies X-DumuPay-Signature and is idempotent. |
| 3 | Your API key and webhook secret live in server environment variables, not in front-end code or git. |
| 4 | You check amount and reference before fulfilling an order. |
| 5 | You send a unique reference per order. |
| 6 | Swap in your dp_live_ key, make one small real payment, then add your payout details under Settings. |