An unofficial python sdk for the QosIc platform.
Project description
qosic-sdk
An unofficial python sdk for the QosIC platform. This platform provides an api to enable mobile money payments for businesses in Africa.
Free software: MIT license
Documentation: https://qosic-sdk.readthedocs.io.
Supported Python versions
This library was tested with the following Python implementations, but it should work for all python 3.6 and above.
python 3.6
Python 3.7
Python 3.8
Features
Simple synchronous client to make your payment requests
Clean and meaningful exceptions
100 % test coverage
Configurable timeouts
Enable Logging for debug purpose
TODOS
Async Client
Quickstart
For those of you in a hurry, here’s a sample code to get you started.
pip install qosic-sdk
from dotenv import dotenv_values
from qosic import Client, MtnConfig, MTN, MOOV, OPERATION_CONFIRMED
from qosic.exceptions import (
InvalidCredentialsError,
InvalidClientIdError,
ServerError,
RequestError,
)
config = dotenv_values(".env")
moov_client_id = config.get("MOOV_CLIENT_ID")
mtn_client_id = config.get("MTN_CLIENT_ID")
server_login = config.get("SERVER_LOGIN")
server_pass = config.get("SERVER_PASS")
# This is just for test purpose, you should directly pass the phone number
phone = config.get("PHONE_NUMBER")
def main():
providers = [
MTN(client_id=mtn_client_id, config=MtnConfig(step=30, timeout=60 * 2)),
MOOV(client_id=moov_client_id),
]
try:
client = Client(
providers=providers,
login=server_login,
password=server_pass,
active_logging=True,
)
result = client.request_payment(
phone=phone, amount=1000, first_name="User", last_name="TEST"
)
except (
InvalidCredentialsError,
InvalidClientIdError,
ServerError,
RequestError,
) as e:
print(e)
else:
if result.state == OPERATION_CONFIRMED:
print(
f"TransRef: {result.trans_ref} -> Your requested payment to {result.phone} for an amount "
f"of {result.amount} has been successfully validated "
)
else:
print(f"Payment rejected: {result}")
print(client.collected_responses)
# If you need to make a refund : (remember that refund are only available for MTN phone number right now)
# result = client.request_refund(trans_ref=result.trans_ref, phone=phone)
if __name__ == "__main__":
main()
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
1.0.0 (2021-05-13)
First release on PyPI.
1.0.1 (2021-05-14)
Write some tests.
The internal http client handles non-json responses better.
1.0.2 (2021-05-16)
Change timeout defaults.
Update docs.
1.1.0 (2021-05-19)
Change MtnConfig step default and minimal value.
Add exception list to the docs.
Remove PollRuntimeError, now the poll function fails while raising the right exception.
When active_logging is set to True, the client now collect responses in the client property collected_responses.
1.1.1 (2021-05-20)
Update MTN and MOOV prefixes
1.1.2 (2021-05-20)
Add more prefixes to MTN and MOOV prefixes
Update docs
1.1.3 (2021-05-22)
Add more prefixes to MTN and MOOV prefixes
Update docs
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for qosic_sdk-1.1.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ea5c18f817c106779b7588d833c97450b897f29bf7a4937858a6b1f0a849d71 |
|
MD5 | 4af8b8f321d1b0da8feebcfe08f778cd |
|
BLAKE2b-256 | 60b0b557aba0654bcde9f8bf7003e55b490047a4a471b3243c24b8b74e85d995 |