Integrating the Daraja-Api with Python language.
This file contains the consumer key and the consumer secrete key that is provided by Safaricom for test purposes. Safaricom developers site
It initiates payment on behalf of the customer
The datetime module in python returns a date in %Y-%m-%d %H%M%S format. However the Daraja Api Docs dictates the timestamp format be in %Y%m%d%H%M%S format. The function converts the current time according to the Api requirements.
It utilizes the base64 import that that encodes and decodes the password. The password is the combination of a business shortcode, the passkey, and the formated time (Daraja Api Docs).
This function authenticates the request mate through the customer key and the customer secrete through HTTPBasicAuth. The GET request made to the safaricom through the access_token url, gives a response that has the access token and the expiry time. The access token is then filtered out.
This function makes a GET request through the api_url and in relation to our request body, a response is provided by safaricom. Below is a response to a successfull request.
Register validation and confirmation URLs on M-Pesa
Transact between an M-Pesa short code to a phone number registered on M-Pesa
- requests module
- datetime module
- base64 module
This Api has been applied in this library website