Trustline Payments API

APIs for Mobile Money Payment Collections (STK Push) and Instant B2C Payouts

Authentication

All API requests require an API key sent via the Authorization header.


Authorization: Bearer YOUR_API_KEY
Accept: application/json
    

1️⃣ MPESA STK Push (Payment Collections)

Request payments from customers via MPESA STK Push.

Endpoint


POST https://trustline.co.ke/api/v1/mpesa/express
        

Request Parameters

Field Type Required Description
amountintYesAmount to charge
phone_numberstringYesCustomer phone
payment_idintYesPayment channel ID
orderNostringYesOrder reference
user_referencestringNoInternal reference
callback_urlstringYesHTTPS callback URL

Example – cURL


curl -X POST https://trustline.co.ke/api/v1/mpesa/express \
-H "Authorization: Bearer YOUR_API_KEY" \
-d "amount=100" \
-d "phone_number=0787677676" \
-d "payment_id=133" \
-d "orderNo=001" \
-d "user_reference=INV-009" \
-d "callback_url=https://example.com/callback"
        

Example – JavaScript


fetch('https://trustline.co.ke/api/v1/mpesa/express', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    amount: 100,
    phone_number: '0787677676',
    payment_id: 133,
    orderNo: '001',
    user_reference: 'INV-009',
    callback_url: 'https://example.com/callback'
  })
}).then(res => res.json()).then(console.log);
        

STK Callback Response


{
  "message": "Payment initiated successfully",
  "data": {
    "MerchantRequestID": "9096-...",
    "CheckoutRequestID": "ws_CO_...",
    "ResponseCode": "0",
    "ResponseDescription": "Success. Request accepted for processing",
    "CustomerMessage": "Success. Request accepted for processing"
  }
}
        

Use CheckoutRequestID to track the transaction.

2️⃣ B2C Withdrawals (Send Money to Mobile)

Endpoint


POST https://app.m-pay.cfd/api/v1/b2c/withdraw
        

Example – cURL


curl -X POST https://app.m-pay.cfd/api/v1/b2c/withdraw \
-H "Authorization: Bearer YOUR_API_KEY" \
-d "Amount=500" \
-d "ReceiverNumber=0712345678" \
-d "ChannelCode=63902" \
-d "PaymentReference=PAYOUT_1001" \
-d "CallbackURL=https://example.com/b2c-callback"
        

Success Response


{
  "success": true,
  "status": "QUEUED",
  "reference": "PAYOUT_1001",
  "amount": 500
}