mpesa-api demo

node v10.24.1
version: 2.0.0
endpointsharetweet
const Mpesa = require("mpesa-api").Mpesa; //import { Mpesa } from "mpesa-api"; const mpesa = new Mpesa( { client_key: process.env.mpesaClientKey, client_secret: process.env.mpesaClientSecret, initiator_password: process.env.mpesaInitiatorPassword, certificatepath: null, }, "sandbox" ); mpesa .lipaNaMpesaOnline({ BusinessShortCode: 174379, // Lipa Na Mpesa Online Shortcode on test credentials page Amount: 1 /* 1000 is an example amount */, PartyA: "254...", // use your real phone number PartyB: 174379, // LiAccount Referencepa Na Mpesa Online Shortcode on test credentials page PhoneNumber: "254...", // use your real phone number CallBackURL: "Enter a callback url", // this is where the api sends a callback. It must a hosted endpoint with public access. AccountReference: "account", // This is what the customer would have put as account number if they used normal mpesa passKey: process.env.lnmPassKey, // Lipa na mpesa passkey in test credentials page TransactionType: "CustomerPayBillOnline" /* OPTIONAL */, TransactionDesc: "Sending Money" /* OPTIONAL */, }) .then((response) => { //Do something with the response //eg console.log("res"); console.log(response); }) .catch((error) => { //Do something with the error; //eg console.log("error"); console.error(error); }); // mpesa // .b2c({ // Initiator: "testapi113", // Amount: 1 /* 1000 is an example amount */, // PartyB: "254...", // use your real phone number // PartyA: 174379, // LiAccount Referencepa Na Mpesa Online Shortcode on test credentials page // CommandID: "BusinessPayment", // QueueTimeOutURL: // "Enter a callback url", // ResultURL: // "Enter a callback url" // }) // .then(response => { // //Do something with the response // //eg // console.log("res"); // console.log(response); // }) // .catch(error => { // //Do something with the error; // //eg // console.log("error"); // console.error(error); // });
Loading…

1 comment

  • posted 4 years ago by newtonmunene99
    Please remember to change callback and result URLs as well as PhoneNumber and Party

sign in to comment