Package: hot-recharge
Hot Rechargeperform hot-recharge services with hot-recharge python library programmaticalyℹ Not an official hot-recharge python libraryLibrary installation$pipinstallhot-rechargeor update with$pipinstall-Uhot-rechargeCHANGELOGplease see fullchangelog hereExamplesCheck examples availablehereSign Upneeds a hot recharge co-operate account orcontact hot-recharge for proper accountAuthentication HeaderUse the newHRAuthConfig(fromv2.x.x) class to pass auth header keysimporthotrecharge# create config classconfig=hotrecharge.HRAuthConfig(access_code='acc-email',access_password='acc-pwd',reference='random-ref')# pass config object to api constructorapi=hotrecharge.HotRecharge(config)New inv3.xYou can now return response models rather than dictmodel returned is auto-generated byMunchlibraryTo enable it, flag thereturn_model=True, defaults toFalse# <..>try:# flag return_model -> True in order to return model, (Munch object)api=hotrecharge.HotRecharge(config,return_model=True)# lets get available EVDs (electronic vouchers) as modelsevds=api.getEVDs()# you can now doprint(evds.AgentReference)print(evds.ReplyMsg)x=0# can loop around available evds in stockforevd_pininevds.InStock:print(f'------- EVD Pin [{x}]-------')print('EVD Brand Name:    ',evd_pin.BrandName)print('EVD Pin Value:     ',evd_pin.PinValue)print('EVD Current Stock: ',evd_pin.Stock)print('-----------------------------')x++# can also catch api exceptions# HotRechargeException is the base class for all exceptions# check example folder for moreexcepthotrecharge.HotRechargeExceptionasex:print(f"[HOTRECHARGE ERROR] There was a problem:{ex}")Performing requeststhis shows how to do basic get requests for different servicesimporthotrechargeimportpprinttry:# get wallet balancewallet_bal_response=api.walletBalance()# get data bundlesdata_bundles_resp=api.getDataBundles()print("Wallet Balance: ")pprint.pprint(wallet_bal_response)print("Data Bundles Balance: ")pprint.pprint(data_bundles_resp)exceptExceptionasex:print(f"There was a problem:{ex}")RechargeRecharge data bundlesuse bundle product codean optional customer sms can be send together upon requestPlace holders used include%AMOUNT% 	    $XXX.XX
%COMPANYNAME%	As Defined by Customer on the website www.hot.co.zw
%ACCESSNAME%	Defined by Customer on website – Teller or Trusted User or branch name
%BUNDLE%	    Name of the Data Bundletry:# option message to send to usercustomer_sms=" Amount of %AMOUNT% for data %BUNDLE% recharged! "\" %ACCESSNAME%. The best %COMPANYNAME%!"# need to update reference manually, if `use_random_ref` is set to Falseapi.updateReference('<new-random-string>')response=api.dataBundleRecharge(product_code="<bundle-product-code>",number="077xxxxxxx",mesg=customer_sms)pprint(response)exceptExceptionasex:print(f"There was a problem:{ex}")Recharge pinlesstry:customer_sms="Recharge of %AMOUNT% successful"\"Initial balance $%INITIALBALANCE%"\"Final Balance $%FINALBALANCE%"\"%COMPANYNAME%"response=api.rechargePinless(amount=3.5,number="077xxxxxxx",mesg=customer_sms)print(response)exceptExceptionasex:print(f"There was a problem:{ex}")Zesa Rechargecustom Message place holders to use and their representation on end user for zesa transactions:%AMOUNT% - $xxx.xx%KWH% - Unit in Kilowatt Hours(Kwh)%ACOUNTNAME% - Account holdername of meter number%METERNUMBER% - meter number%COMPANYNAME% - as defined by Customer on the website www.hot.co.zwNote on Zesa RechargesRequirementsA method  for Purchasing ZESA TokensIt is a ZESA requirement that any purchase must beverified. As such please ensure that you use thecheckZesaCustomer()methodtry:customer=api.checkZesaCustomer(meterNumber)print(customer)# prompt user to confirm their details first before performing a rechargeexceptExceptionaserr:print('[ERROR] Error getting zesa customer: ',err)and prompt the customer to confirm the detailsbeforecalling this method (api.rechargeZesa(...)).There is a new transaction state specifically for ZESA that is Pending verification indicated byreply code 4. Transactions in this state can result in successful transactions after a period of time once ZESA complete transaction.You must call Query ZESA methodTBDperiodically until a permanent resolution of the transaction occurs. This polling of a pending transaction should not exceed more that4 request a minute. Resending of transactions that have not yet failed can result in the duplication of transaction and lose of funds.Please note ZESA does not allowrefundsso the cost of any errors cannot be recovered.Query transactionYou can now query a previous transaction by itsagentReferencefor reconciliation.It is reccommended to query within the last 30 days of the transactiontry:response=api.rechargePinless(amount=3.5,number="077xxxxxxx")# save agentReference to query for reconciliationprevTransactionAgentReference=response.get("agentReference")result=api.queryTransactionReference(prevTransactionAgentReference)print(response,result)exceptExceptionasex:print(f"There was a problem:{ex}")Note on ExceptionsHotRechargeExceptionis the base class for all exceptionsAll exceptions are subclasses ofHotRechargeExceptionAll exceptions have amessageproperty that contains the error messageAll exceptions have aresponseproperty that contains the response object(which is aMunch). In some cases this will beNone, so dont get mad if you seeNone😁.One of the best use cases of theresponseproperty is when aPendingZesaTransactionexception gets raised. you can saverechargeID, then you can use it later to query the transaction status.Support 🤿This is not an official hot-recharge python libraryI initiated, develop and maintain this library on my own spare timeA little support can go a long way, i would appreciate it