Hot Recharge
perform hot-recharge services with hot-recharge python library programmaticaly
- ℹ Not an official hot-recharge python library
Library installation
$ pip install hot-recharge
or update with
$ pip install -U hot-recharge
CHANGELOG
please see full changelog here
Examples
Check examples available here
Sign Up
- needs a hot recharge co-operate account or
contact hot-recharge for proper account
Authentication Header
Use the new HRAuthConfig (from v2.x.x) class to pass auth header keys
import hotrecharge
# create config class
config = hotrecharge.HRAuthConfig(
access_code='acc-email',
access_password='acc-pwd',
reference='random-ref'
)
# pass config object to api constructor
api = hotrecharge.HotRecharge(config)
New in v3.x
You can now return response models rather than dict
- model returned is auto-generated by
Munchlibrary - To enable it, flag the
return_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 models
evds = api.getEVDs()
# you can now do
print(evds.AgentReference)
print(evds.ReplyMsg)
x = 0
# can loop around available evds in stock
for evd_pin in evds.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 more
except hotrecharge.HotRechargeException as ex:
print(f"[HOTRECHARGE ERROR] There was a problem: {ex}")
Performing requests
- this shows how to do basic get requests for different services
import hotrecharge
import pprint
try:
# get wallet balance
wallet_bal_response = api.walletBalance()
# get data bundles
data_bundles_resp = api.getDataBundles()
print("Wallet Balance: ")
pprint.pprint(wallet_bal_response)
print("Data Bundles Balance: ")
pprint.pprint(data_bundles_resp)
except Exception as ex:
print(f"There was a problem: {ex}")
Recharge
Recharge data bundles
- use bundle product code
- an optional customer sms can be send together upon request
- Place 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 Bundle
try:
# option message to send to user
customer_sms = " Amount of %AMOUNT% for data %BUNDLE% recharged! " \
" %ACCESSNAME%. The best %COMPANYNAME%!"
# need to update reference manually, if `use_random_ref` is set to False
api.updateReference('<new-random-string>')
response = api.dataBundleRecharge(product_code="<bundle-product-code>", number="077xxxxxxx", mesg=customer_sms)
pprint(response)
except Exception as ex:
print(f"There was a problem: {ex}")
Recharge pinless
try:
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)
except Exception as ex:
print(f"There was a problem: {ex}")
Zesa Recharge
custom 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.zw
Note on Zesa Recharges
Requirements
- A method for Purchasing ZESA Tokens
- It is a ZESA requirement that any purchase must be verified. As such please ensure that you use the
checkZesaCustomer()method
try:
customer = api.checkZesaCustomer(meterNumber)
print(customer)
# prompt user to confirm their details first before performing a recharge
except Exception as err:
print('[ERROR] Error getting zesa customer: ', err)
- and prompt the customer to confirm the details before calling this method (
api.rechargeZesa(...)). - There is a new transaction state specifically for ZESA that is Pending verification indicated by reply 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 method
TBDperiodically until a permanent resolution of the transaction occurs. This polling of a pending transaction should not exceed more that 4 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 allow refunds so the cost of any errors cannot be recovered.
Query transaction
- You can now query a previous transaction by its
agentReferencefor reconciliation. - It is reccommended to query within the last 30 days of the transaction
try:
response = api.rechargePinless(amount=3.5, number="077xxxxxxx")
# save agentReference to query for reconciliation
prevTransactionAgentReference = response.get("agentReference")
result = api.queryTransactionReference(prevTransactionAgentReference)
print(response, result)
except Exception as ex:
print(f"There was a problem: {ex}")
Note on Exceptions
HotRechargeExceptionis the base class for all exceptions- All exceptions are subclasses of
HotRechargeException - All exceptions have a
messageproperty that contains the error message - All exceptions have a
responseproperty 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 the
responseproperty 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 library
- I initiated, develop and maintain this library on my own spare time
- A little support can go a long way, i would appreciate it
Metadata
Release files for hot-recharge 4.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hot-recharge-4.0.0.tar.gz | 10.8 kB | Without provenance | Details for hot-recharge-4.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hot_recharge-4.0.0-py3-none-any.whl | Python 3 | none | any | Details for hot_recharge-4.0.0-py3-none-any.whl |
Total release size: 23.4 kB
Release files / hot-recharge-4.0.0.tar.gz
| Download URL | hot-recharge-4.0.0.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c9128542861172b9871442ec91db0776fa6232bde59766ffe4bd2e51c6a3f31
|
|
BLAKE2b-256 checksum How to use checksums |
86f194dbe322d245edd4cdc078dc629f6c78cfd6a60ec56fcbb5dfc18994188f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11
|
Release files / hot_recharge-4.0.0-py3-none-any.whl
| Download URL | hot_recharge-4.0.0-py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ea3cd55120ded6c82cd6fd78bc4662cae7e72c5f3ae4f8481241005d0040e499
|
|
BLAKE2b-256 checksum How to use checksums |
ac9509fe01c414507259faca3ca64d342a5c041e1af02b26741d538447dc2f81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11
|
Security for hot-recharge 4.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.