zenopay


Namezenopay JSON
Version 0.0.9 PyPI version JSON
download
home_pagehttps://github.com/jovyinny/zenopay
SummaryA Python wrapper for ZenoPay Payment API.
upload_time2025-02-03 15:36:23
maintainerNone
docs_urlNone
authorJovine Mutelani
requires_python>=3.7
licenseMIT
keywords zenopay zenopay sdk zeno pay sdk zenopay wrapper
VCS
bugtrack_url
requirements annotated-types backports.tarfile certifi cfgv charset-normalizer distlib dnspython docutils email_validator filelock identify idna importlib_metadata jaraco.classes jaraco.context jaraco.functools keyring markdown-it-py mdurl more-itertools nh3 nodeenv packaging phonenumbers pkginfo platformdirs pre_commit pydantic pydantic_core Pygments python-dotenv PyYAML readme_renderer requests requests-toolbelt rfc3986 rich twine typing_extensions urllib3 virtualenv zipp
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # zenopay

Python Wrapper to Zenopay Payment. This wrapper is a simple way to interact with Zenopay Payment API.

You can get you account and API key from [Zenopay](https://zenopay.net/). You will need to have an account to access the API.

## Installation

```bash
pip install zenopay
```

## Usage

This assumes that you keep your credentials in a `.env` file. You can also set the environment variables directly. Let create an instance of the Zenopay class that will be used to interact with the API [It will  be reused in the examples below].

```python
import os
from dotenv import load_dotenv
from zenopay import ZenoPay

load_dotenv()

zenopay_client=ZenoPay(account_id=os.getenv('ZENOPAY_ACCOUNT_ID'))
```

NOTE: Webhook url set should be the endpoint that receives a POST request from Zenopay after a transaction is completed.

### Mobile Checkout

To initiate a mobile checkout, you will need to set client's api_key and sceret_key. You can get these from your Zenopay account.

```python
zenopay_client.api_key=os.getenv('ZENOPAY_API_KEY')
zenopay_client.secret_key=os.getenv('ZENOPAY_SECRET_KEY')

# Data to be sent to Zenopay
data = {
    "buyer_name": "jovine me",
    "buyer_phone": "0718193343",
    "buyer_email": "jovinerobotics@gmail.com",
    "amount": 1000,
    "webhook_url": "https://jovine.me/zenopay/webhook",
    "metadata":{
        "product_id": "12345",
        "color": "blue",
        "size": "L",
        "custom_notes": "Please gift-wrap this item."
    },
}

# Initiate a mobile checkout
checkout=zenopay_client.mobile_checkout(data)

# Print the response
print(checkout)
# {'status': 'success', 'message': 'Wallet payment successful', 'order_id': '6777ad7e327xxx'}
```

### Card Checkout

To initiate a card checkout, you will need to set client's api_key and sceret_key. You can get these from your Zenopay account.

```python
zenopay_client.api_key=os.getenv('ZENOPAY_API_KEY')
zenopay_client.secret_key=os.getenv('ZENOPAY_SECRET_KEY')

# Data to be sent to Zenopay

data = {
    "buyer_name": "jovine me",
    "buyer_phone": "0718193343",
    "buyer_email": "jovinerobotics@gmail.com",
    "amount": 1000,
    "webhook_url": "https://jovine.me/zenopay/webhook",
    "billling_country": "TZ",
    "redirect_url": "https://jovine.me/zenopay/redirect",
    "metadata":{
        "product_id": "12345",
        "color": "blue",
        "size": "L",
        "custom_notes": "Please gift-wrap this item."
    },
}

# Initiate a card checkout
checkout=zenopay_client.card_checkout(data)

# Print the response
print(checkout)
#{'status': 'success', 'message': 'Order created successfully', 'order_id': '6777ad7e327xxx', 'payment_link': 'https://secure.payment.tz/link'}
```

You can keep record of the `order_id` to easily keep track of order and update details in case of a callback as the `order_id` will be sent in the callback.

### Check Order Status

```python
status=zenopay_client.check_order_status(order_id="xxxxx")

# Print the response
print(status)
#{"status": "success","order_id": "6777ad7e327xxx","message": "Order status updated","payment_status": "PENDING"}
```

## Callbacks

As highlighted above, you need to set a webhook url when initiating a mobile checkout. Zenopay will send a POST request to the webhook url with the transaction details. You can use the following code to handle the callback.

Sample callback code using Flask and FastAPI. The callback request JSON sample is as follows:

```json
{
    "order_id": "6777ad7e327xxx",
    "payment_status": "COMPLETED",
    "reference": "0882061614",
    "matadata": {
        "product_id": "12345",
        "color": "blue",
        "size": "L",
        "custom_notes": "Please gift-wrap this item."
    }
}
```

- Flask

    ```python
    from flask import Flask, request, jsonify

    app = Flask(__name__)

    @app.route('/zenopay/webhook', methods=['POST'])
    def webhook():
        data = request.json
        # Do something with the data
        print(data)
        # You can save the data to a database
        return jsonify({"status":"success"})

    ```

- FastAPI

    ```python
    from fastapi import FastAPI, Request
    from fastapi.responses import JSONResponse

    app = FastAPI()

    @app.post("/zenopay/webhook")
    async def webhook(request: Request):
        data = await request.json()
        # Do something with the data
        print(data)
        # You can save the data to a database
        return JSONResponse(content={"status":"success"})

    ```

## Redirects and Cancel URLs

These should be set when initiating a card checkout. The redirect url will be used to redirect the user after a successful payment. The cancel url will be used to redirect the user if the payment is cancelled. A provided url will be loaded when either of the two events occur.

Remember both are optional, so setting non-accessible url will hurt the user experience.

## Issues

If you encounter any issues, please open an issue

## Contributing

1. Fork the repository
2. Create a new branch (git checkout -b feature)
3. Make changes
4. Commit your changes (git commit -am 'Add new feature')
5. Push to the branch (git push origin feature)
6. Create a pull request
7. Wait for the PR to be reviewed

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jovyinny/zenopay",
    "name": "zenopay",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "zenopay, zenopay SDK, zeno pay SDK, ZenoPay Wrapper",
    "author": "Jovine Mutelani",
    "author_email": "jovinerobotics@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/30/0a/acea01385d0220b1254aa424fd0f9977470be9f63a1a1b2339c9dbd82b07/zenopay-0.0.9.tar.gz",
    "platform": null,
    "description": "# zenopay\n\nPython Wrapper to Zenopay Payment. This wrapper is a simple way to interact with Zenopay Payment API.\n\nYou can get you account and API key from [Zenopay](https://zenopay.net/). You will need to have an account to access the API.\n\n## Installation\n\n```bash\npip install zenopay\n```\n\n## Usage\n\nThis assumes that you keep your credentials in a `.env` file. You can also set the environment variables directly. Let create an instance of the Zenopay class that will be used to interact with the API [It will  be reused in the examples below].\n\n```python\nimport os\nfrom dotenv import load_dotenv\nfrom zenopay import ZenoPay\n\nload_dotenv()\n\nzenopay_client=ZenoPay(account_id=os.getenv('ZENOPAY_ACCOUNT_ID'))\n```\n\nNOTE: Webhook url set should be the endpoint that receives a POST request from Zenopay after a transaction is completed.\n\n### Mobile Checkout\n\nTo initiate a mobile checkout, you will need to set client's api_key and sceret_key. You can get these from your Zenopay account.\n\n```python\nzenopay_client.api_key=os.getenv('ZENOPAY_API_KEY')\nzenopay_client.secret_key=os.getenv('ZENOPAY_SECRET_KEY')\n\n# Data to be sent to Zenopay\ndata = {\n    \"buyer_name\": \"jovine me\",\n    \"buyer_phone\": \"0718193343\",\n    \"buyer_email\": \"jovinerobotics@gmail.com\",\n    \"amount\": 1000,\n    \"webhook_url\": \"https://jovine.me/zenopay/webhook\",\n    \"metadata\":{\n        \"product_id\": \"12345\",\n        \"color\": \"blue\",\n        \"size\": \"L\",\n        \"custom_notes\": \"Please gift-wrap this item.\"\n    },\n}\n\n# Initiate a mobile checkout\ncheckout=zenopay_client.mobile_checkout(data)\n\n# Print the response\nprint(checkout)\n# {'status': 'success', 'message': 'Wallet payment successful', 'order_id': '6777ad7e327xxx'}\n```\n\n### Card Checkout\n\nTo initiate a card checkout, you will need to set client's api_key and sceret_key. You can get these from your Zenopay account.\n\n```python\nzenopay_client.api_key=os.getenv('ZENOPAY_API_KEY')\nzenopay_client.secret_key=os.getenv('ZENOPAY_SECRET_KEY')\n\n# Data to be sent to Zenopay\n\ndata = {\n    \"buyer_name\": \"jovine me\",\n    \"buyer_phone\": \"0718193343\",\n    \"buyer_email\": \"jovinerobotics@gmail.com\",\n    \"amount\": 1000,\n    \"webhook_url\": \"https://jovine.me/zenopay/webhook\",\n    \"billling_country\": \"TZ\",\n    \"redirect_url\": \"https://jovine.me/zenopay/redirect\",\n    \"metadata\":{\n        \"product_id\": \"12345\",\n        \"color\": \"blue\",\n        \"size\": \"L\",\n        \"custom_notes\": \"Please gift-wrap this item.\"\n    },\n}\n\n# Initiate a card checkout\ncheckout=zenopay_client.card_checkout(data)\n\n# Print the response\nprint(checkout)\n#{'status': 'success', 'message': 'Order created successfully', 'order_id': '6777ad7e327xxx', 'payment_link': 'https://secure.payment.tz/link'}\n```\n\nYou can keep record of the `order_id` to easily keep track of order and update details in case of a callback as the `order_id` will be sent in the callback.\n\n### Check Order Status\n\n```python\nstatus=zenopay_client.check_order_status(order_id=\"xxxxx\")\n\n# Print the response\nprint(status)\n#{\"status\": \"success\",\"order_id\": \"6777ad7e327xxx\",\"message\": \"Order status updated\",\"payment_status\": \"PENDING\"}\n```\n\n## Callbacks\n\nAs highlighted above, you need to set a webhook url when initiating a mobile checkout. Zenopay will send a POST request to the webhook url with the transaction details. You can use the following code to handle the callback.\n\nSample callback code using Flask and FastAPI. The callback request JSON sample is as follows:\n\n```json\n{\n    \"order_id\": \"6777ad7e327xxx\",\n    \"payment_status\": \"COMPLETED\",\n    \"reference\": \"0882061614\",\n    \"matadata\": {\n        \"product_id\": \"12345\",\n        \"color\": \"blue\",\n        \"size\": \"L\",\n        \"custom_notes\": \"Please gift-wrap this item.\"\n    }\n}\n```\n\n- Flask\n\n    ```python\n    from flask import Flask, request, jsonify\n\n    app = Flask(__name__)\n\n    @app.route('/zenopay/webhook', methods=['POST'])\n    def webhook():\n        data = request.json\n        # Do something with the data\n        print(data)\n        # You can save the data to a database\n        return jsonify({\"status\":\"success\"})\n\n    ```\n\n- FastAPI\n\n    ```python\n    from fastapi import FastAPI, Request\n    from fastapi.responses import JSONResponse\n\n    app = FastAPI()\n\n    @app.post(\"/zenopay/webhook\")\n    async def webhook(request: Request):\n        data = await request.json()\n        # Do something with the data\n        print(data)\n        # You can save the data to a database\n        return JSONResponse(content={\"status\":\"success\"})\n\n    ```\n\n## Redirects and Cancel URLs\n\nThese should be set when initiating a card checkout. The redirect url will be used to redirect the user after a successful payment. The cancel url will be used to redirect the user if the payment is cancelled. A provided url will be loaded when either of the two events occur.\n\nRemember both are optional, so setting non-accessible url will hurt the user experience.\n\n## Issues\n\nIf you encounter any issues, please open an issue\n\n## Contributing\n\n1. Fork the repository\n2. Create a new branch (git checkout -b feature)\n3. Make changes\n4. Commit your changes (git commit -am 'Add new feature')\n5. Push to the branch (git push origin feature)\n6. Create a pull request\n7. Wait for the PR to be reviewed\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python wrapper for ZenoPay Payment API.",
    "version": "0.0.9",
    "project_urls": {
        "Bug Tracker": "https://github.com/jovyinny/zenopay/issues",
        "Documentation": "https://jovyinny.github.io/zenopay/",
        "Homepage": "https://github.com/jovyinny/zenopay",
        "Source Code": "https://github.com/jovyinny/zenopay"
    },
    "split_keywords": [
        "zenopay",
        " zenopay sdk",
        " zeno pay sdk",
        " zenopay wrapper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9f6dc23d23556f74035423543d47c0fa5c9910f1350a22fb1dedda6e719eb757",
                "md5": "6b6b9019f5b41ca58f28aa21a73fcc9c",
                "sha256": "c53f9de1baa28181d257288027c3cd927e9a6f69abecb92069fe4cf9f1d17c4c"
            },
            "downloads": -1,
            "filename": "zenopay-0.0.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6b6b9019f5b41ca58f28aa21a73fcc9c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6603,
            "upload_time": "2025-02-03T15:36:22",
            "upload_time_iso_8601": "2025-02-03T15:36:22.078810Z",
            "url": "https://files.pythonhosted.org/packages/9f/6d/c23d23556f74035423543d47c0fa5c9910f1350a22fb1dedda6e719eb757/zenopay-0.0.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "300aacea01385d0220b1254aa424fd0f9977470be9f63a1a1b2339c9dbd82b07",
                "md5": "af4759b2a3529b808be29eb348d38f00",
                "sha256": "996b250c563c373897130fdd4bf88334627b5957a5e3d1a473633b72480e7d90"
            },
            "downloads": -1,
            "filename": "zenopay-0.0.9.tar.gz",
            "has_sig": false,
            "md5_digest": "af4759b2a3529b808be29eb348d38f00",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 6638,
            "upload_time": "2025-02-03T15:36:23",
            "upload_time_iso_8601": "2025-02-03T15:36:23.273978Z",
            "url": "https://files.pythonhosted.org/packages/30/0a/acea01385d0220b1254aa424fd0f9977470be9f63a1a1b2339c9dbd82b07/zenopay-0.0.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-03 15:36:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jovyinny",
    "github_project": "zenopay",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "annotated-types",
            "specs": [
                [
                    "==",
                    "0.7.0"
                ]
            ]
        },
        {
            "name": "backports.tarfile",
            "specs": [
                [
                    "==",
                    "1.2.0"
                ]
            ]
        },
        {
            "name": "certifi",
            "specs": [
                [
                    "==",
                    "2024.12.14"
                ]
            ]
        },
        {
            "name": "cfgv",
            "specs": [
                [
                    "==",
                    "3.4.0"
                ]
            ]
        },
        {
            "name": "charset-normalizer",
            "specs": [
                [
                    "==",
                    "3.4.1"
                ]
            ]
        },
        {
            "name": "distlib",
            "specs": [
                [
                    "==",
                    "0.3.9"
                ]
            ]
        },
        {
            "name": "dnspython",
            "specs": [
                [
                    "==",
                    "2.7.0"
                ]
            ]
        },
        {
            "name": "docutils",
            "specs": [
                [
                    "==",
                    "0.21.2"
                ]
            ]
        },
        {
            "name": "email_validator",
            "specs": [
                [
                    "==",
                    "2.2.0"
                ]
            ]
        },
        {
            "name": "filelock",
            "specs": [
                [
                    "==",
                    "3.16.1"
                ]
            ]
        },
        {
            "name": "identify",
            "specs": [
                [
                    "==",
                    "2.6.5"
                ]
            ]
        },
        {
            "name": "idna",
            "specs": [
                [
                    "==",
                    "3.10"
                ]
            ]
        },
        {
            "name": "importlib_metadata",
            "specs": [
                [
                    "==",
                    "8.5.0"
                ]
            ]
        },
        {
            "name": "jaraco.classes",
            "specs": [
                [
                    "==",
                    "3.4.0"
                ]
            ]
        },
        {
            "name": "jaraco.context",
            "specs": [
                [
                    "==",
                    "6.0.1"
                ]
            ]
        },
        {
            "name": "jaraco.functools",
            "specs": [
                [
                    "==",
                    "4.1.0"
                ]
            ]
        },
        {
            "name": "keyring",
            "specs": [
                [
                    "==",
                    "25.6.0"
                ]
            ]
        },
        {
            "name": "markdown-it-py",
            "specs": [
                [
                    "==",
                    "3.0.0"
                ]
            ]
        },
        {
            "name": "mdurl",
            "specs": [
                [
                    "==",
                    "0.1.2"
                ]
            ]
        },
        {
            "name": "more-itertools",
            "specs": [
                [
                    "==",
                    "10.5.0"
                ]
            ]
        },
        {
            "name": "nh3",
            "specs": [
                [
                    "==",
                    "0.2.20"
                ]
            ]
        },
        {
            "name": "nodeenv",
            "specs": [
                [
                    "==",
                    "1.9.1"
                ]
            ]
        },
        {
            "name": "packaging",
            "specs": [
                [
                    "==",
                    "24.2"
                ]
            ]
        },
        {
            "name": "phonenumbers",
            "specs": [
                [
                    "==",
                    "8.13.52"
                ]
            ]
        },
        {
            "name": "pkginfo",
            "specs": [
                [
                    "==",
                    "1.12.0"
                ]
            ]
        },
        {
            "name": "platformdirs",
            "specs": [
                [
                    "==",
                    "4.3.6"
                ]
            ]
        },
        {
            "name": "pre_commit",
            "specs": [
                [
                    "==",
                    "4.0.1"
                ]
            ]
        },
        {
            "name": "pydantic",
            "specs": [
                [
                    "==",
                    "2.10.4"
                ]
            ]
        },
        {
            "name": "pydantic_core",
            "specs": [
                [
                    "==",
                    "2.27.2"
                ]
            ]
        },
        {
            "name": "Pygments",
            "specs": [
                [
                    "==",
                    "2.18.0"
                ]
            ]
        },
        {
            "name": "python-dotenv",
            "specs": [
                [
                    "==",
                    "1.0.1"
                ]
            ]
        },
        {
            "name": "PyYAML",
            "specs": [
                [
                    "==",
                    "6.0.2"
                ]
            ]
        },
        {
            "name": "readme_renderer",
            "specs": [
                [
                    "==",
                    "44.0"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.32.3"
                ]
            ]
        },
        {
            "name": "requests-toolbelt",
            "specs": [
                [
                    "==",
                    "1.0.0"
                ]
            ]
        },
        {
            "name": "rfc3986",
            "specs": [
                [
                    "==",
                    "2.0.0"
                ]
            ]
        },
        {
            "name": "rich",
            "specs": [
                [
                    "==",
                    "13.9.4"
                ]
            ]
        },
        {
            "name": "twine",
            "specs": [
                [
                    "==",
                    "6.0.1"
                ]
            ]
        },
        {
            "name": "typing_extensions",
            "specs": [
                [
                    "==",
                    "4.12.2"
                ]
            ]
        },
        {
            "name": "urllib3",
            "specs": [
                [
                    "==",
                    "2.3.0"
                ]
            ]
        },
        {
            "name": "virtualenv",
            "specs": [
                [
                    "==",
                    "20.28.1"
                ]
            ]
        },
        {
            "name": "zipp",
            "specs": [
                [
                    "==",
                    "3.21.0"
                ]
            ]
        }
    ],
    "lcname": "zenopay"
}
        
Elapsed time: 1.53603s