REST API · Version 1

API Documentation

Integrate M-Pesa STK Push or Paystack card/bank payments into any website with a single API call.

Overview

The E-Payments API lets you initiate M-Pesa STK Push or Paystack card/bank payments, query transaction status, and list transactions. All requests are authenticated via an API key in the X-API-Key header.

Base URLhttps://yourdomain.com/api/v1

STK Push

Trigger M-Pesa payments

Webhooks

Real-time event notifications

Sandbox

Test without going live

Authentication

Required

All /api/v1/* endpoints require an API key. Generate keys in your API Keys dashboard.

Include in every requestjavascript
fetch('https://yourapp.com/api/v1/payment', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'mpesa_test_xxxxxxxxxxxxxxxxxxxxxxxx'
  }
})

Sandbox keys

mpesa_test_...

Production keys

mpesa_live_...
Server-side only: your API key must never appear in browser JavaScript, a mobile app bundle, or any other client-side code — treat it like a password. Call /api/v1/* from your own backend, then have your backend talk to your frontend. A key leaked in client-side code can be used by anyone to trigger payments against your account.

Initiate Payment

Defaults to an M-Pesa STK Push. Pass provider: "paystack" on the same endpoint to collect by card or bank transfer instead.

POST/api/v1/paymentM-Pesa (default) — sends an STK Push prompt to the customer's phone
Request Bodyjson
{
  "phoneNumber": "0712345678",        // Required — Kenyan format or 254...
  "amount": 500,                       // Required — integer, min 1 KES
  "accountReference": "ORDER-123",    // Optional — max 12 chars, shown in M-Pesa
  "description": "Payment for order", // Optional
  "metadata": { "orderId": "abc" }    // Optional — stored with transaction
}
Responsejson
{
  "success": true,
  "transactionId": "3f2e8a1b-...",
  "checkoutRequestId": "ws_CO_...",
  "status": "pending",
  "message": "Payment request sent to customer's phone"
}
Note: The customer receives a PIN prompt within seconds. Poll /api/v1/transaction/:id or use webhooks for the final status.
POST/api/v1/paymentPaystack — card or bank transfer via Paystack's hosted checkout
Request Bodyjson
{
  "provider": "paystack",
  "email": "customer@example.com",            // Required for Paystack
  "amount": 500,                               // Required — integer, min 1 KES
  "accountReference": "ORDER-123",            // Optional
  "description": "Payment for order",         // Optional
  "redirectUrl": "https://yoursite.com/paid", // Where the customer returns after checkout
  "metadata": { "orderId": "abc" }            // Optional — stored with transaction
}
Responsejson
{
  "success": true,
  "transactionId": "3f2e8a1b-...",
  "provider": "paystack",
  "checkoutUrl": "https://checkout.paystack.com/...",
  "status": "pending",
  "message": "Redirect the customer to checkoutUrl to complete payment"
}
Note: Redirect the customer's browser to checkoutUrl — Paystack's own hosted checkout page handles card entry, 3-D Secure, and (if enabled on your Paystack account) bank transfer. Poll /api/v1/transaction/:id or use webhooks for the final status, same as M-Pesa.
Itemized receipts (optional): pass a metadata.items array (on either the M-Pesa or Paystack request above) to show a line-item breakdown on the merchant's payment-received email, instead of just the total. Two shapes are accepted — use whichever is more natural for your own checkout: { name, quantity, price } (the line total is computed as price × quantity), or { name, qty, total } (a precomputed line total, used as-is). Example: { "name": "Aveeno Shampoo", "quantity": 1, "price": 1795 }.

Transaction Status

GET/api/v1/transaction/:idGet the current status of a transaction
Responsejson
{
  "transaction": {
    "id": "3f2e8a1b-...",
    "status": "completed",           // pending | completed | failed | cancelled
    "amount": "500.00",
    "phone_number": "254712345678",
    "mpesa_receipt_number": "RKL23X...",
    "account_reference": "ORDER-123",
    "created_at": "2024-01-15T10:30:00Z"
  }
}

List Transactions

GET/api/v1/transactions?page=1&limit=20&status=completedPaginated list of all transactions
Responsejson
{
  "transactions": [ { "id": "...", "status": "completed", "amount": "500.00", ... } ],
  "pagination": { "page": 1, "limit": 20, "total": 145, "pages": 8 }
}

Query Parameters

pagePage number (default: 1)
limitResults per page, max 100 (default: 20)
statusFilter: pending | completed | failed | cancelled

Webhooks

Configure endpoints in your dashboard. E-Payments sends a signed POST when these events occur.

payment.completed
payment.failed
invoice.paid
refund.completed
customer.created
Webhook Payloadjson
{
  "event": "payment.completed",
  "timestamp": "2024-01-15T10:32:00Z",
  "data": {
    "id": "3f2e8a1b-...",
    "status": "completed",
    "amount": "500.00",
    "phone_number": "254712345678",
    "mpesa_receipt_number": "RKL23X..."
  }
}

Verify the X-Epayments-Signature header:

Signature Verificationjavascript
const crypto = require('crypto');

app.post('/webhooks/epayments', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = req.headers['x-epayments-signature'];
  const expected  = crypto.createHmac('sha256', process.env.WEBHOOK_SECRET)
                          .update(req.body).digest('hex');

  if (!crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signature))) {
    return res.status(401).send('Unauthorized');
  }

  const { event, data } = JSON.parse(req.body);
  // Handle: 'payment.completed' | 'payment.failed' |
  //         'invoice.paid' | 'refund.completed' | 'customer.created'
  // 'data' is the raw invoice/refund/customer/transaction row.
  res.sendStatus(200);
});
© 2026 E-Payments · Powered by NJWBack to Dashboard →