# Install the nifty client # pip install git+https://github.com/east36/python-nifty-client.git import logging from niftyclient import NiftyClient logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger('STK') class Config: key_id = '<>' secret = '<>' user_id = '<>' api_base = 'https://api.nifty.co.ke/api/v1' WALLET_ID = '<>' def initiate_stk_push( paybill, phone_number, transaction_amount, account_reference ): """ Uses the nifty client to initiate an stk stk_push_status """ logger.info("Initiate the stk push") logger.info( ("Transaction({account_reference}) " "Phone Number: {phone}, " "Amount: {amount} " "Paybill: {paybill}").format( phone=phone_number, amount=transaction_amount, account_reference=account_reference, paybill=paybill ) ) client = NiftyClient(Config(), logger) try: response = client.stkpush.initiate_stk_push( phone_number=phone_number, transaction_amount=float(transaction_amount), account_reference=account_reference, wallet_id=WALLET_ID, paybill=paybill ) except Exception as ex: logger.exception(ex) logger.info("Success %s!!", response) initiate_stk_push(paybill, phone_number, transaction_amount, account_reference)