Mpesa
Defined in: src/clients/mpesa-client.ts:61
M-Pesa SDK client.
Single entry point for all Daraja API operations. OAuth is handled automatically; tokens are cached and refreshed before expiry.
Example
Section titled “Example”// With env vars (MPESA_CONSUMER_KEY, MPESA_CONSUMER_SECRET, etc. set):const mpesa = new Mpesa({});
// Or with explicit config:const mpesa = new Mpesa({ consumerKey: "...", consumerSecret: "...", environment: "sandbox", shortCode: "174379", passKey: "...",});
const res = await mpesa.stkPush({ phoneNumber: "254708374149", amount: 10, callbackUrl: "https://example.com/callback", accountReference: "order-123", transactionDesc: "Payment",});console.log(res.CheckoutRequestID);Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Mpesa(
config?):Mpesa
Defined in: src/clients/mpesa-client.ts:72
Parameters
Section titled “Parameters”config?
Section titled “config?”MpesaConfig = {}
Returns
Section titled “Returns”Mpesa
Properties
Section titled “Properties”account
Section titled “account”
readonlyaccount:AccountModule
Defined in: src/clients/mpesa-client.ts:64
readonlyb2c:B2CModule
Defined in: src/clients/mpesa-client.ts:63
readonlyc2b:C2BModule
Defined in: src/clients/mpesa-client.ts:62
readonlypull:PullModule
Defined in: src/clients/mpesa-client.ts:68
readonlyqr:QrModule
Defined in: src/clients/mpesa-client.ts:67
reversal
Section titled “reversal”
readonlyreversal:ReversalModule
Defined in: src/clients/mpesa-client.ts:66
transaction
Section titled “transaction”
readonlytransaction:TransactionModule
Defined in: src/clients/mpesa-client.ts:65
Methods
Section titled “Methods”stkPush()
Section titled “stkPush()”stkPush(
input):Promise<StkPushResult>
Defined in: src/clients/mpesa-client.ts:130
Initiate STK Push (Lipa Na M-Pesa Online). Sends a prompt to the customer’s phone; use the returned CheckoutRequestID with stkQuery().
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<StkPushResult>
stkQuery()
Section titled “stkQuery()”stkQuery(
input):Promise<StkQueryResponse>
Defined in: src/clients/mpesa-client.ts:137
Query STK Push status using CheckoutRequestID from stkPush() response.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<StkQueryResponse>