Skip to main content

An unofficial python sdk for the QosIc platform.

Project description

qosic-sdk

https://img.shields.io/pypi/v/qosic-sdk.svg https://api.travis-ci.com/Tobi-De/qosic-sdk.svg Documentation Status

An unofficial python sdk for the QosIC platform. This platform provides an api to enable mobile money payments for businesses in Africa.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qosic-sdk-1.1.3.tar.gz (24.6 kB view hashes)

Uploaded Source

Built Distribution

qosic_sdk-1.1.3-py2.py3-none-any.whl (10.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page