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
pip3 install MpesaRest
Prompt user to Accept Payment for your service using lipa na mpesa
from MpesaRest import 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
}
]
)from MpesaRest import 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')from MpesaRest import Mpesa
config = {
'consumer_key': "YOUR_CONSUMER_KEY",
'consumer_secret': "YOUR_CONSUMER_SECRET",
'business_code': "YOUR_BUSINESS_CODE"
}
app = Mpesa(**config)
app.request_payment()from MpesaRest import Mpesa
config = {
'consumer_key': "YOUR_CONSUMER_KEY",
'consumer_secret': "YOUR_CONSUMER_SECRET",
'business_code': "YOUR_BUSINESS_CODE"
}
mpesa = Mpesa(**config)
mpesa.check_account_balance()Contribute by creating pull request