BluePayAPI
Ask AI
BluePay
API Keys Support Dashboard

Webhooks

BluePay posts a signed JSON body to your callback URL.

Webhooks

Account → Callback URL (HTTPS, or http:// on localhost) receives each event. callback_url on an STK, or callbackUrl on a B2C payout, is used for that request only.

HeaderValue
X-BluePay-Eventmpesa.payment.received · mpesa.payment.failed · mpesa.wallet_topup.received · mpesa.b2c.success · mpesa.b2c.failed · mpesa.b2c_wallet_topup.received
X-BluePay-Signaturev1= + hex HMAC-SHA256(raw body, API secret from API Keys). HTTP 401 on your endpoint usually means signature mismatch.
Idempotency-KeyDedupe key per delivery.

Payload example & verification code

livemode mirrors production. Key data fields: account_reference, checkout_request_id, mpesa_receipt_number, amount, phone, status.

{
  "event": "mpesa.payment.received",
  "api_version": "1",
  "livemode": true,
  "data": {
    "payment_id": 1,
    "amount": 100,
    "currency": "KES",
    "mpesa_receipt_number": "ABC123XYZ",
    "phone": "254712345678",
    "account_reference": "BPINV-001",
    "checkout_request_id": "ws_CO_...",
    "stk_request_id": 42,
    "channel_id": "BP23356",
    "transaction_time": "2026-04-19 09:50:00",
    "status": "success"
  }
}

Failures: mpesa.payment.failed. Wallet top-ups: mpesa.wallet_topup.received.

$raw = file_get_contents('php://input');
$sigHeader = $_SERVER['HTTP_X_BLUEPAY_SIGNATURE'] ?? '';
if (!preg_match('/^v1=([a-f0-9]{64})$/', $sigHeader, $m)) { http_response_code(400); exit; }
$expected = hash_hmac('sha256', $raw, 'YOUR_SECRET_API_KEY');
if (!hash_equals($expected, $m[1])) { http_response_code(401); exit; }
$payload = json_decode($raw, true);
const raw = req.body;
const sig = req.get("X-BluePay-Signature") || "";
const m = /^v1=([a-f0-9]{64})$/.exec(sig);
const expected = crypto.createHmac("sha256", secret).update(raw).digest("hex");
if (!crypto.timingSafeEqual(Buffer.from(expected, "hex"), Buffer.from(m[1], "hex")))
  return res.sendStatus(401);
Return 2xx quickly. No automatic webhook retries — use payment status as backup.