A daraja STK push (M-PESA Express) demo with node and express server
- Create an account on Safaricom developers portal (Daraja)
- Create a new app under My Apps section ensuring to check all the fields. You will be able to see consumer key and consumer secret under each app
- Have
node.js
installed (or reuse the implementation in your favorite programming language or framework) - (Optional) Have
ngrok
installed - Use this to simulate https on our localhost server. If you already havenode.js
then you can install it by runningnpm install -g ngrok
or run it directly onnpx
. Otherwise, download it from ngrok download page. - Have Postman or any other API testing tool installed
- Run
ngrok http 5000
in a terminal in the project root - Fill in the
.env
with the necessary information. Replace theCALLBACK_URL
with the https version of the link provided on the ngrok terminal in step 1 - Start the project by running
node index.js
- In Postman, create a
POST
request with the body containing thephone
andamount
- Press send and “fingers crossed” you should receive a push on your phone
- On the
node.js
terminal, you should see a console logging once you either accept or decline the push.