Skip to content

Integrating the Daraja-Api with Python 🐍πŸ”₯. Integreations dealt with include Authorization, Mpesa express, Customer to Business (C2B api), etc.

License

Notifications You must be signed in to change notification settings

Morvin-Ian/mpesa-daraja-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Mpesa-Daraja-Api

Integrating the Daraja-Api with Python language.

Credentials.py file

This file contains the consumer key and the consumer secrete key that is provided by Safaricom for test purposes. Safaricom developers site

Mpesa Express

It initiates payment on behalf of the customer

format_time()

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.

decode_password()

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).

generate_access_token()

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.

mpesa()

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.

Screenshot at 2021-10-25 21-26-04

Mpesa Customer to Busineess

Register validation and confirmation URLs on M-Pesa

Mpesa Business to Customer

Transact between an M-Pesa short code to a phone number registered on M-Pesa

Requirements

  1. requests module
  2. datetime module
  3. base64 module

This Api has been applied in this library website

About

Integrating the Daraja-Api with Python 🐍πŸ”₯. Integreations dealt with include Authorization, Mpesa express, Customer to Business (C2B api), etc.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages