In this topic, learners will understand the process of registering for the Mpesa Daraja API. This includes creating an account on the Safaricom Developer Portal, generating the necessary API credentials (Consumer Key and Consumer Secret), and setting up the application for API access. Learners will also explore the importance of correctly configuring API settings for a successful integration.
-
Create an Account on the Safaricom Developer Portal
- Go to the Safaricom Developer Portal:
https://developer.safaricom.co.ke - Click Sign Up to create a new account or Log In if you already have an account.
- Provide the required information:
- Email Address
- Phone Number
- Password (make sure it’s strong)
- After signing up, confirm your registration via email.
- Go to the Safaricom Developer Portal:
-
Create a New Application
- After logging in, navigate to the My Apps section.
- Click on Create New App.
- Fill in the following fields:
- App Name: This should be a unique and meaningful name (e.g., “MpesaIntegrationApp”).
- App Description: A short description of what the app will do (e.g., “Mpesa payment integration for online store”).
- API(s) to Use: Select the appropriate APIs based on the features you need, such as:
- STK Push (for payment requests).
- C2B (for customer-to-business payments).
- Lipa na Mpesa Online (for online payments).
- Transaction Status (to check the status of a transaction).
- Save the app once all the details are filled.
-
Generate Your API Credentials
- After creating the app, go to the App Details page.
- Under the Credentials section, you will find:
- Consumer Key
- Consumer Secret
- These credentials are essential for authenticating your API requests, so make sure to store them securely.
-
Set Up Callback URL and Shortcode
- When using certain Mpesa APIs, you will need to provide a Callback URL, which is where Mpesa sends transaction responses.
- For example, when initiating STK Push, Mpesa will send a response to this URL.
- You will also need to obtain a Shortcode, which is used for services like C2B and STK Push.
-
Testing in the Sandbox Environment
- The Daraja Portal provides a Sandbox environment where you can test your integration before going live.
- Ensure that your API requests are directed to the Sandbox environment URLs:
Sandbox API URL: https://sandbox.safaricom.co.ke
- You can simulate payments, transaction statuses, and more to verify that your integration works as expected.
Summary
In this topic, you learned how to register for the Mpesa Daraja API. This process involves creating an account on the Safaricom Developer Portal, creating a new app, generating the required API credentials (Consumer Key and Consumer Secret), setting up callback URLs, and testing in the Sandbox environment. By following these steps, you ensure that your integration with Mpesa is ready for real-world use.