azampay-sdk-anga


Nameazampay-sdk-anga JSON
Version 0.1.12 PyPI version JSON
download
home_pagehttps://github.com/tbwahacker/azampay-sdk-anga
SummaryA dynamic Python SDK for AzamPay (AzamPay Python SDK used for native python, Django, Flask, FastApi e.t.c)
upload_time2025-08-10 07:53:26
maintainerNone
docs_urlNone
authorAnganile Adam (Anga)
requires_python>=3.6
licenseMIT
keywords sdk api client payments integration python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # AzamPay Python SDK for python developers (Pure/Native python, Django,Flask, FastApi et..c)

This SDK allows integration with AzamPay payment services.
whereby Initially the versions below 0.1.8 were only having MNO payments (Mobile Paymments) only. Much thanks to "Wadau" even Bank payments service is now working in released version 0.1.8 +

[![PyPI Downloads](https://static.pepy.tech/badge/azampay-sdk-anga/week)](https://pepy.tech/projects/azampay-sdk-anga)
[![PyPI Downloads](https://static.pepy.tech/badge/azampay-sdk-anga/month)](https://pepy.tech/projects/azampay-sdk-anga)
[![PyPI Downloads](https://static.pepy.tech/badge/azampay-sdk-anga)](https://pepy.tech/projects/azampay-sdk-anga)
![PyPI version](https://img.shields.io/pypi/v/azampay-sdk-anga)

<p align="start">
    <img src="/screenshots/azampay-logo.png" width="300" title="Azampay Logo" alt="Azampay Logo">
</p>

# ## Supported Banks

- Mpesa
- Airtel Money
- Halopesa
- Mix by yas
- Azampesa
- CRDB
- NMB


## Installation

```bash
pip install azampay-sdk-anga
```

## Usage
    try:
        # Generate a unique external ID
        external_id = str(uuid.uuid4())

        # Sample transaction details
        mobile_number = "0712345678"
        amount = 5000
        currency = "TZS"
        provider = "TIGO" # Mpesa, Airtel, Halotel, Azampesa, Tigo

        print("Initiating MNO Checkout...")
        response, ref = AzamPay.mno_checkout(  # For mobile payments
            mobile_number=mobile_number,
            amount=amount,
            currency=currency,
            provider=provider,
            external_id=external_id
        )

        print(f"Transaction Reference: {ref}")
        print("Response:")
        print(response)

    except Exception as e:
        print("Transaction failed:")
        print(str(e))
## So, what you have to do
is to create the callback(webhook) url (paste its path to azampay portal) and file in your project to accept and receive payment status && transactionId from Azampay

example callback_url.py (I will use flask for showcase) 'if status is rejected or success it will go update your payment/transaction database table. my example is ==> update_custom_o custom table'

```
from flask import Flask, request
from main import Main
from db import conn  # your DB connection file (pymysql or similar)

app = Flask(__name__)

@app.route('/callback', methods=['POST'])
def callback():
    if request.method != 'POST':
        return "Invalid method", 405

    try:
        main = Main(conn)
        data = request.get_json()
    except Exception:
        return "Server error", 500

    if not data or 'utilityref' not in data or 'transactionstatus' not in data:
        return "Invalid payload", 400

    utility_ref = data['utilityref']
    status = 'success' if data['transactionstatus'].lower() == 'success' else 'rejected'

    # Query and update transaction if it's still pending
    count, result = main.all_query_nolimit_s(
        'transactions',
        'AND status="pending" LIMIT 1',
        'reference',
        utility_ref
    )

    if count > 0:
        update = main.update_custom_o(
            'transactions', 'status', status, 'reference', utility_ref, 'AND status="pending"'
        )
        return "Transaction updated", 200
    else:
        return "Transaction not found", 404

```
## Optional 
Create a check.py (Elsewhere not in callback file) file to retrive your payment table and check if status has been changed, if yes or no then the redirect page will notify user as follows through the file 

templates/redirect.html
```
<!-- templates/redirect.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Transaction Status</title>
    <link href="{{ url_for('static', filename='bootstrap/css/bootstrap.min.css') }}" rel="stylesheet">
</head>
<body class="bg-light d-flex justify-content-center align-items-center" style="height: 100vh;">
    <div class="container text-center">
        {% if status == 'approved' %}
            <div class="alert alert-success shadow p-4 rounded" role="alert">
                <h1 class="mb-3">🎉 Transaction Approved</h1>
                <p class="lead">Your transaction was successfully completed.</p>
                <a href="/" class="btn btn-success mt-3">Go Home</a>
            </div>
        {% else %}
            <div class="alert alert-danger shadow p-4 rounded" role="alert">
                <h1 class="mb-3">❌ Transaction Failed</h1>
                <p class="lead">Sorry, something went wrong. Please try again.</p>
                <a href="/" class="btn btn-danger mt-3">Try Again</a>
            </div>
        {% endif %}
    </div>

    <script src="{{ url_for('static', filename='bootstrap/js/bootstrap.bundle.min.js') }}"></script>
</body>
</html>
```

## Remind you makesure that your .env in your root project folder must contains keys you got from azampay portal
```
AZAMPAY_ENVIRONMENT=sandbox  #production  (if u wanna change it to live then replace that sandbox to production)
AZAMPAY_APP_NAME=your-azam-app-name-here
AZAMPAY_CLIENT_ID=your-client-id-here
AZAMPAY_CLIENT_SECRET=your-secret-here
```
AzamPay Success Message Example
![AzamPay Success Message Example](screenshots/success_request.png)

## Credits and Inspiration
1. [Anganile Adam (Anga)](https://github.com/tbwahacker)
2. Thanks much to AzamPay for this support [Azampay Documentation](https://developerdocs.azampay.co.tz/redoc).
3. Tanzania Developers you are now free using the AzamPay python api
4. [All Contributors](../../contributors)

## Issues
Please open an issue here [**GITHUB**](https://github.com/tbwahacker/azampay-sdk-anga/)

## HAPPY ENJOY MAKING PAYMENTS. DON'T FORGET BUYING ME A ☕COFEE 😂😂😂
## 0685750593 / 0768571150 or gmail : twaloadam@gmail.com / anganileadam87@gmail.com

If you find this package useful, you can support us by starring this repository and sharing it with others.

## Licence
The MIT License (MIT).

## Contribute
""""  Feel Free to contribute by forking the Repo """"

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/tbwahacker/azampay-sdk-anga",
    "name": "azampay-sdk-anga",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "sdk, api client, payments, integration, python",
    "author": "Anganile Adam (Anga)",
    "author_email": "\"Anganile Adam (Anga)\" <twaloadam@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/fe/1a/a8fdede558080f84622b47eee00b3d549e40134f073479cb5ea667ad222d/azampay_sdk_anga-0.1.12.tar.gz",
    "platform": null,
    "description": "# AzamPay Python SDK for python developers (Pure/Native python, Django,Flask, FastApi et..c)\r\n\r\nThis SDK allows integration with AzamPay payment services.\r\nwhereby Initially the versions below 0.1.8 were only having MNO payments (Mobile Paymments) only. Much thanks to \"Wadau\" even Bank payments service is now working in released version 0.1.8 +\r\n\r\n[![PyPI Downloads](https://static.pepy.tech/badge/azampay-sdk-anga/week)](https://pepy.tech/projects/azampay-sdk-anga)\r\n[![PyPI Downloads](https://static.pepy.tech/badge/azampay-sdk-anga/month)](https://pepy.tech/projects/azampay-sdk-anga)\r\n[![PyPI Downloads](https://static.pepy.tech/badge/azampay-sdk-anga)](https://pepy.tech/projects/azampay-sdk-anga)\r\n![PyPI version](https://img.shields.io/pypi/v/azampay-sdk-anga)\r\n\r\n<p align=\"start\">\r\n    <img src=\"/screenshots/azampay-logo.png\" width=\"300\" title=\"Azampay Logo\" alt=\"Azampay Logo\">\r\n</p>\r\n\r\n# ## Supported Banks\r\n\r\n- Mpesa\r\n- Airtel Money\r\n- Halopesa\r\n- Mix by yas\r\n- Azampesa\r\n- CRDB\r\n- NMB\r\n\r\n\r\n## Installation\r\n\r\n```bash\r\npip install azampay-sdk-anga\r\n```\r\n\r\n## Usage\r\n    try:\r\n        # Generate a unique external ID\r\n        external_id = str(uuid.uuid4())\r\n\r\n        # Sample transaction details\r\n        mobile_number = \"0712345678\"\r\n        amount = 5000\r\n        currency = \"TZS\"\r\n        provider = \"TIGO\" # Mpesa, Airtel, Halotel, Azampesa, Tigo\r\n\r\n        print(\"Initiating MNO Checkout...\")\r\n        response, ref = AzamPay.mno_checkout(  # For mobile payments\r\n            mobile_number=mobile_number,\r\n            amount=amount,\r\n            currency=currency,\r\n            provider=provider,\r\n            external_id=external_id\r\n        )\r\n\r\n        print(f\"Transaction Reference: {ref}\")\r\n        print(\"Response:\")\r\n        print(response)\r\n\r\n    except Exception as e:\r\n        print(\"Transaction failed:\")\r\n        print(str(e))\r\n## So, what you have to do\r\nis to create the callback(webhook) url (paste its path to azampay portal) and file in your project to accept and receive payment status && transactionId from Azampay\r\n\r\nexample callback_url.py (I will use flask for showcase) 'if status is rejected or success it will go update your payment/transaction database table. my example is ==> update_custom_o custom table'\r\n\r\n```\r\nfrom flask import Flask, request\r\nfrom main import Main\r\nfrom db import conn  # your DB connection file (pymysql or similar)\r\n\r\napp = Flask(__name__)\r\n\r\n@app.route('/callback', methods=['POST'])\r\ndef callback():\r\n    if request.method != 'POST':\r\n        return \"Invalid method\", 405\r\n\r\n    try:\r\n        main = Main(conn)\r\n        data = request.get_json()\r\n    except Exception:\r\n        return \"Server error\", 500\r\n\r\n    if not data or 'utilityref' not in data or 'transactionstatus' not in data:\r\n        return \"Invalid payload\", 400\r\n\r\n    utility_ref = data['utilityref']\r\n    status = 'success' if data['transactionstatus'].lower() == 'success' else 'rejected'\r\n\r\n    # Query and update transaction if it's still pending\r\n    count, result = main.all_query_nolimit_s(\r\n        'transactions',\r\n        'AND status=\"pending\" LIMIT 1',\r\n        'reference',\r\n        utility_ref\r\n    )\r\n\r\n    if count > 0:\r\n        update = main.update_custom_o(\r\n            'transactions', 'status', status, 'reference', utility_ref, 'AND status=\"pending\"'\r\n        )\r\n        return \"Transaction updated\", 200\r\n    else:\r\n        return \"Transaction not found\", 404\r\n\r\n```\r\n## Optional \r\nCreate a check.py (Elsewhere not in callback file) file to retrive your payment table and check if status has been changed, if yes or no then the redirect page will notify user as follows through the file \r\n\r\ntemplates/redirect.html\r\n```\r\n<!-- templates/redirect.html -->\r\n<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n    <meta charset=\"UTF-8\">\r\n    <title>Transaction Status</title>\r\n    <link href=\"{{ url_for('static', filename='bootstrap/css/bootstrap.min.css') }}\" rel=\"stylesheet\">\r\n</head>\r\n<body class=\"bg-light d-flex justify-content-center align-items-center\" style=\"height: 100vh;\">\r\n    <div class=\"container text-center\">\r\n        {% if status == 'approved' %}\r\n            <div class=\"alert alert-success shadow p-4 rounded\" role=\"alert\">\r\n                <h1 class=\"mb-3\">\ud83c\udf89 Transaction Approved</h1>\r\n                <p class=\"lead\">Your transaction was successfully completed.</p>\r\n                <a href=\"/\" class=\"btn btn-success mt-3\">Go Home</a>\r\n            </div>\r\n        {% else %}\r\n            <div class=\"alert alert-danger shadow p-4 rounded\" role=\"alert\">\r\n                <h1 class=\"mb-3\">\u274c Transaction Failed</h1>\r\n                <p class=\"lead\">Sorry, something went wrong. Please try again.</p>\r\n                <a href=\"/\" class=\"btn btn-danger mt-3\">Try Again</a>\r\n            </div>\r\n        {% endif %}\r\n    </div>\r\n\r\n    <script src=\"{{ url_for('static', filename='bootstrap/js/bootstrap.bundle.min.js') }}\"></script>\r\n</body>\r\n</html>\r\n```\r\n\r\n## Remind you makesure that your .env in your root project folder must contains keys you got from azampay portal\r\n```\r\nAZAMPAY_ENVIRONMENT=sandbox  #production  (if u wanna change it to live then replace that sandbox to production)\r\nAZAMPAY_APP_NAME=your-azam-app-name-here\r\nAZAMPAY_CLIENT_ID=your-client-id-here\r\nAZAMPAY_CLIENT_SECRET=your-secret-here\r\n```\r\nAzamPay Success Message Example\r\n![AzamPay Success Message Example](screenshots/success_request.png)\r\n\r\n## Credits and Inspiration\r\n1. [Anganile Adam (Anga)](https://github.com/tbwahacker)\r\n2. Thanks much to AzamPay for this support [Azampay Documentation](https://developerdocs.azampay.co.tz/redoc).\r\n3. Tanzania Developers you are now free using the AzamPay python api\r\n4. [All Contributors](../../contributors)\r\n\r\n## Issues\r\nPlease open an issue here [**GITHUB**](https://github.com/tbwahacker/azampay-sdk-anga/)\r\n\r\n## HAPPY ENJOY MAKING PAYMENTS. DON'T FORGET BUYING ME A \u2615COFEE \ud83d\ude02\ud83d\ude02\ud83d\ude02\r\n## 0685750593 / 0768571150 or gmail : twaloadam@gmail.com / anganileadam87@gmail.com\r\n\r\nIf you find this package useful, you can support us by starring this repository and sharing it with others.\r\n\r\n## Licence\r\nThe MIT License (MIT).\r\n\r\n## Contribute\r\n\"\"\"\"  Feel Free to contribute by forking the Repo \"\"\"\"\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A dynamic Python SDK for AzamPay (AzamPay Python SDK used for native python, Django, Flask, FastApi e.t.c)",
    "version": "0.1.12",
    "project_urls": {
        "Homepage": "https://github.com/tbwahacker/azampay-sdk-anga",
        "Repository": "https://github.com/tbwahacker/azampay-sdk-anga"
    },
    "split_keywords": [
        "sdk",
        " api client",
        " payments",
        " integration",
        " python"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2d7a8e606f3376058da9e4bff25eff4417c864184b2424385070927b2a8e8349",
                "md5": "c4f5ae0c64eaf084cdaf7c6718c4125a",
                "sha256": "5d5d03584b0bf67e2ca6b663fdb9e80ec52ac9ea105f7e64b1f0d59249d0fbaa"
            },
            "downloads": -1,
            "filename": "azampay_sdk_anga-0.1.12-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c4f5ae0c64eaf084cdaf7c6718c4125a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 8275,
            "upload_time": "2025-08-10T07:53:25",
            "upload_time_iso_8601": "2025-08-10T07:53:25.332653Z",
            "url": "https://files.pythonhosted.org/packages/2d/7a/8e606f3376058da9e4bff25eff4417c864184b2424385070927b2a8e8349/azampay_sdk_anga-0.1.12-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "fe1aa8fdede558080f84622b47eee00b3d549e40134f073479cb5ea667ad222d",
                "md5": "3e3c33efd35591d715b6086900903ee6",
                "sha256": "f5b6fd34f891e7923c184a548b880915a6a31f0417c0f2dd7fdab8d3910db2f1"
            },
            "downloads": -1,
            "filename": "azampay_sdk_anga-0.1.12.tar.gz",
            "has_sig": false,
            "md5_digest": "3e3c33efd35591d715b6086900903ee6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 7457,
            "upload_time": "2025-08-10T07:53:26",
            "upload_time_iso_8601": "2025-08-10T07:53:26.767852Z",
            "url": "https://files.pythonhosted.org/packages/fe/1a/a8fdede558080f84622b47eee00b3d549e40134f073479cb5ea667ad222d/azampay_sdk_anga-0.1.12.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-10 07:53:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tbwahacker",
    "github_project": "azampay-sdk-anga",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "azampay-sdk-anga"
}
        
Elapsed time: 0.54254s