Mpesa API SDK
Project description
MPESA REST API Python SDK
Simple to use helper sdk for Python developers seeking to integrate MPESA API without much hustle. Supports Python 2 & 3.
Urls are found on urls.py and depending on the environment set sandbox or production urls are used.
To generate access token use your client and secret from M-Pesa api account and use oauth_generate_token method.
Installation
$ pip install mpesa-api-sdk
Usage
from mpesa.gateway import Mpesa
access_token = oauth_generate_token(consumer_key="Consumer Key", consumer_secret="Consumer Secret", grant_type="client_credentials", env="sandbox")
mpesa = Mpesa(access_token)
C2B Register Url
data = {
"ShortCode": " " ,
"ResponseType": " ",
"ConfirmationURL": " ",
"ValidationURL": " "
}
mpesa.c2b_register_url(data)
C2B Simulate Transaction
data = {
"ShortCode": "",
"CommandID": "CustomerPayBillOnline",
"Amount": "",
"Msisdn": "",
"BillRefNumber": ""
}
mpesa.c2b_simulate_transaction(data)
B2B Payment Request
data = {
"Initiator": "",
"SecurityCredential": "",
"CommandID": "",
"SenderIdentifierType": "",
"RecieverIdentifierType": "",
"Amount": "",
"PartyA": "",
"PartyB": "",
"AccountReference": "",
"Remarks": "",
"QueueTimeOutURL": "",
"ResultURL": ""
}
mpesa.b2b_payment_request(data)
B2C Payment Request
data = {
"InitiatorName": "",
"SecurityCredential": "",
"CommandID": "",
"Amount": "",
"PartyA": "",
"PartyB": "",
"Remarks": "",
"QueueTimeOutURL": "" ,
"ResultURL": "",
"Occassion": ""
}
mpesa.b2c_payment_request(data)
Transaction Status
data = {
"Initiator": "",
"SecurityCredential": "",
"CommandID": "TransactionStatusQuery",
"TransactionID": "",
"PartyA": "",
"IdentifierType": "1",
"ResultURL": "",
"QueueTimeOutURL": "",
"Remarks": " ",
"Occasion": " "
}
mpesa.transation_status_request(data)
Account Balance
data = {
"Initiator": "",
"SecurityCredential": "",
"CommandID": "AccountBalance",
"PartyA": "",
"IdentifierType": "4",
"Remarks": "",
"QueueTimeOutURL": "",
"ResultURL": ""
}
mpesa.account_balance_request(data)
Reversal Request
data = {
"Initiator": "",
"SecurityCredential": "",
"CommandID":"TransactionReversal",
"TransactionID": "",
"Amount": "",
"ReceiverParty": "",
"RecieverIdentifierType":"11",
"ResultURL": "",
"QueueTimeOutURL": "",
"Remarks": "",
"Occasion": ""
}
mpesa.reversal_request(data)
NOTE: Access token generated from M-Pesa API expires after 3599 seconds
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mpesa-sdk-1.0.0.tar.gz
(5.4 kB
view hashes)
Built Distribution
Close
Hashes for mpesa_sdk-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ec0c97805b2c83fb0289461908f709e46490eb5547efbfe1d7b9cd599b5042b |
|
MD5 | aa141e571937495fcb235c319845047b |
|
BLAKE2b-256 | e07007d24cd8c10faad87a7879d1a8a055bbc0fc6c928971dba9eb18a0a71d91 |