Skip to content

M-Pesa Express (STK push) ​

Sends a payment prompt to the customer's phone. The result is posted to callbackUrl; read it with parseStkCallback.

ts
const sent = await mpesa.stkPush.send({
  shortCode: 174379,
  type: 'paybill',
  amount: 100,
  phoneNumber: '0712345678',
  callbackUrl: 'https://example.com/payments/stk',
  accountReference: 'INV-001',
  description: 'Invoice 001',
});

const status = await mpesa.stkPush.query({
  shortCode: 174379,
  checkoutRequestId: sent.checkoutRequestId,
});
if (status.resultCode === 0) console.log('paid');

stkPush.send:

FieldDaraja fieldNotes
shortCodeBusinessShortCodePaybill, or the HO/store number for till payments.
typeTransactionType'paybill' (CustomerPayBillOnline) or 'till' (CustomerBuyGoodsOnline).
amountAmountWhole shillings, at least 1.
phoneNumberPartyA, PhoneNumber07…, 01…, +254… or 254….
partyBPartyBOptional. Defaults to shortCode; set it to the till number for tills.
callbackUrlCallBackURLReceives the result.
accountReferenceAccountReferenceShown to the customer. 1 to 12 characters.
descriptionTransactionDescOptional. 1 to 13 characters; defaults to "Payment".

Password and Timestamp are generated from the configured passkey.

stkPush.query takes shortCode (BusinessShortCode) and checkoutRequestId (CheckoutRequestID), and returns resultCode (0 means paid; 1032 means the customer cancelled, 1037 that they didn't respond). Querying within about 30 seconds of the push can fail with 500.001.1001 "The transaction does not Exist"; retry later, or rely on the callback.

Released under the MIT License.