Skip to content

Customer to Business (C2B) ​

ts
await mpesa.c2b.registerUrls({
  shortCode: 600984,
  confirmationUrl: 'https://example.com/payments/c2b/confirmation',
  validationUrl: 'https://example.com/payments/c2b/validation',
  defaultAction: 'Completed',
});

// Sandbox only.
await mpesa.c2b.simulate({
  shortCode: 600984,
  type: 'paybill',
  amount: 100,
  phoneNumber: '0708374149',
  billRefNumber: 'ACC-001',
});

c2b.registerUrls:

FieldDaraja fieldNotes
shortCodeShortCodePaybill or till number.
confirmationUrlConfirmationURLReceives payment confirmations.
validationUrlValidationURLReceives validation requests, if Safaricom enabled external validation.
defaultActionResponseType'Completed' or 'Cancelled': what happens if validation times out.

In production, URLs must use https and must not contain words such as "mpesa", "safaricom", "exec", "cmd", "sql" or "query". Registration is a one-time call there; delete existing URLs in the portal before registering new ones.

c2b.simulate (sandbox only): shortCode (ShortCode), type (CommandID: 'paybill' or 'till'), amount (Amount), phoneNumber (Msisdn) and billRefNumber (BillRefNumber, required for paybill).

Released under the MIT License.