Access Safaricom's M-Pesa API
This gist describes the processes of allowing us to access the Safaricom's M-Pesa API. At the end of the process
we will obtain all variable needed to start using their API. We will be using the Customer to Business (C2B) API.
This gist has been created as an Appendix to this article (part 1).
Start the Engine
⚡ Start by accessing the M-Pesa Developer Portal and create a new account if you don't already have one. Click the build new app button to scaffold a new testing application.
Create The Application
Now within the Products category of the application creation page, you need to check the two boxes; Lipa na M-Pesa sandbox and M-Pesa sandbox to enable the APIs
After you've successfully created the application, you would be able to see your Consumer Key and Consumer Secret under the keys tab
And TADA 🎉, here are your
MPESA_CONSUMER_SECRET environment variables.
Okay, what are keys for?
M-Pesa APIs are built on REST and to communicate with the API, you will need a Basic Auth over HTTPS authorization token (OAuth token). You use the keys to obtain the token.
Next, we need to get the
Lipa Na Mpesa Online Shortcode and
Lipa Na Mpesa Online Passkey test credentials from the this link.
You now have your
MPESA_PASS_KEY environment variables.