Skip to content

Instantly share code, notes, and snippets.

@manuthu
Created April 19, 2022 14:14
Show Gist options
  • Save manuthu/52df4866299de3298e2cb004166f4acd to your computer and use it in GitHub Desktop.
Save manuthu/52df4866299de3298e2cb004166f4acd to your computer and use it in GitHub Desktop.
# 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment