An interaction of the Safaricom Daraja Api with Python
Project description
Mpesa Rest Api
A special interaction with the Safaricom daraja Api using python suitable for business payment integration. create your consumer key and consumer secret from the safaricom daraja developer's portal
Installation
pip3 install MpesaRest
Usage
Instantiate Business to client Lipa na Mpesa Stk Push
Prompt user to Accept Payment for your service using lipa na mpesa
from MpesaRest.mpesarest import StartService as Mpesa
config = {
'consumer_key': "YOUR_CONSUMER_KEY",
'consumer_secret': "YOUR_CONSUMER_SECRET",
'business_code': "YOUR_BUSINESS_CODE"
}
app = Mpesa(**config)
app.prompt_payment_for_service({
'name': 'lumuli',
'phone': '254794784462',
'amount': 3000
})
# One Can prompt for payment from multiple clients
app.prompt_payment_for_service(
[
{
'name': 'lumuli',
'phone': '254794784462',
'amount': 3000
},
{
'name': 'test',
'phone': '254794784462',
'amount': 6000
}
]
)
Reverse Mpesa Transaction
from MpesaRest.mpesarest import StartService as Mpesa
config = {
'consumer_key': "YOUR_CONSUMER_KEY",
'consumer_secret': "YOUR_CONSUMER_SECRET",
'business_code': "YOUR_BUSINESS_CODE"
}
app = Mpesa(**config)
app.prompt_payment_for_service({
'name': 'lumuli',
'phone': '+254794784462',
'amount': 3000
})
app.reverse_transaction(3000, 'transaction_code', 'reversal for purchase of goods worth 300')
Request payment from clients
from MpesaRest.mpesarest import StartService as Mpesa
config = {
'consumer_key': "YOUR_CONSUMER_KEY",
'consumer_secret': "YOUR_CONSUMER_SECRET",
'business_code': "YOUR_BUSINESS_CODE"
}
app = Mpesa(**config)
app.request_payment()
Check Account Balance status
from MpesaRest.mpesarest import StartService as Mpesa
config = {
'consumer_key': "YOUR_CONSUMER_KEY",
'consumer_secret': "YOUR_CONSUMER_SECRET",
'business_code': "YOUR_BUSINESS_CODE"
}
mpesa = Mpesa(**config)
mpesa.check_account_balance()
Contribution
Contribute by creating pull request
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
MpesaRest-0.0.4.tar.gz
(5.3 kB
view details)
Built Distribution
File details
Details for the file MpesaRest-0.0.4.tar.gz
.
File metadata
- Download URL: MpesaRest-0.0.4.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fc1f53ebfee9be3b93c6d43469e807cd0359919be80cea814e3b0d3ba557cf6 |
|
MD5 | 4981d26b4a8d5a5df79c84b54bcf58d0 |
|
BLAKE2b-256 | 0a2a9cd50ff8a84552d99d4d919ed129e0307ba6740ec16b70e899a94d09a1e6 |
Provenance
File details
Details for the file MpesaRest-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: MpesaRest-0.0.4-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 546b289ba744b021ca55b9567cffa5c27d55c1593c0a36aad2756b8213239c6c |
|
MD5 | 926108d707d38e71f08bd7d069c846e5 |
|
BLAKE2b-256 | ada6c02d1c3df42cf066bef6335b061557fd23d077a2c1ed7aaeba4679dbbcc6 |