python wrapper for the new mpesa daraja api
pip install python-mpesawrapper==1.0.4
The more time you spend contemplating what you should have done... you lose valuable time planning what you can and will do.- lil wayne
This Library Covers
pip install mpesawrapper
after installation
go to the root of your project
cd /your-path/ touch .env
paste and fill the following
======================================
consumer_key=
b2cInitiatorName=
b2cShortcode=
b2cTimeoutUrl=
b2cResultUrl=
b2bInitiator=
b2bShortcode=
b2bTimeoutURL=
b2bResultURL=
MEShortcode=
MECallBackURL=
MEpasskey=
reversalInitiator=
reversalinit_password=
reverseShortcode=
reversResultURL=
reverseQueueTimeOutURL=
sqInitiator=
sqResultURL=
sqQueueTimeOutURL=
sqinit_password=
======================================
mpesa requires a valid public key certificate get this from mpesa portal, save it as pubkey.pem in the root directory of your project
This api facillitates business sending money directly to it's customers, This maybe termed as a withdrawal
from mpesawrapper import B2CHandler
B2CHandler().handle(amount=10,mobile_number='2547********')
This api facillitates business sending money to other busineses
from mpesawrapper import B2bHandler
B2bHandler().handle(amount=10,
command='',senderType='',recieverType='',recipient='')
NOTES:
BusinessPayBill
BusinessBuyGoods
DisburseFundsToBusiness
BusinessToBusinessTransfer
BusinessTransferFromMMFToUtility
BusinessTransferFromUtilityToMMF
MerchantToMerchantTransfer
MerchantTransferFromMerchantToWorking
MerchantServicesMMFAccountTransfer
AgencyFloatAdvance
use 2 for Till Number
use 4 for Organization short code
use 2 for Till Number
use 4 for Organization short code
This is the shortcode/till number recieving the funds
This works as a notification method for payments made to a shortcode via ussd One has to register urls with mpesa for this to work
from mpesawrapper import c2bHandler
c2bHandler().handler(ShortCode='',ConfirmationURL='',ValidationURL='')
from mpesawrapper import MpesaExpressHandler
MpesaExpressHandler().handle(mobile_number='2547********',amount=10)
The result of the above will give CheckoutRequestID in the response object this will fill CheckoutRequestID in the request below
from mpesawrapper import MpesaExpressQueryHandler
MpesaExpressQueryHandler().handle(CheckoutRequestID='')
from mpesawrapper import reversalHandler
reversalHandler().handle(amount=10,remarks='',mpesaTransactionID='')
from mpesawrapper import statusQueryHandler
statusQueryHandler().handle(mpesaTransactionID='',initiator='')
initiator is what platform the transaction happened
use 1 for MSISDN
use 2 for Till Number
use 4 for Organization short code