Initiating an STK Push Transaction
To initiate an STK push transaction using the Mpesa API, you can use the mpesa.sendSTKPush()
method. This allows you to send payment requests to customers' mobile wallets.
mpesa.sendSTKPush({
amount: 1,
sender: process.env.SENDER_NUMBER,
reference: "test",
callbackUrl: process.env.CALLBACK_URL,
description: "test",
})
.then((response) => {
// STK push transaction initiated successfully
console.log(response);
})
.catch((error) => {
// Error occurred while initiating the STK push transaction
console.log(error);
});