Name | qpay-client JSON |
Version |
0.2.3
JSON |
| download |
home_page | None |
Summary | QPay Integration made easy with ❤️ (async & sync, typed schemas, auto token refresh) |
upload_time | 2025-09-16 09:53:46 |
maintainer | None |
docs_url | None |
author | Amraa1 |
requires_python | >=3.12 |
license | MIT License Copyright (c) 2025 Amarsanaa Ganbaatar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
qpay
payment
qpay v2
mongolian payment
mongolia
httpx
pydantic
asyncio
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# QPay API Integration client
QPay API integration made simpler and safer with data validation and auto token refresh.
Visit links:
[Package document](https://pypi.org/project/qpay-client/)
[QPay document](https://developer.qpay.mn)
Made with ❤️
## Features
- Client manages the access & refresh tokens 🤖
- Both sync and async/await support 🙈🙉
- Pydantic data validation ✅
- Retries for payment check 🔁
- QPay error support 🔍
## Installation
Using pip:
```bash
pip install qpay-client
```
Using poetry:
```bash
poetry add qpay-client
```
Using uv:
```bash
uv add qpay-client
```
## Usage
### Basic Example
Lets implement basic payment flow described in QPay developer document.

**Important to note:**
> You are _free to implement the callback API's URI and query/params_ in anyway you want. But the callback you implement must return `Response(status_code = 200, body="SUCCESS")`.
### How to implement (Async example)
You don't have to worry about authentication and managing tokens. QPay client manages this behind the scene so you can focus on the important parts.
You can use any web framework. I am using [Fastapi](https://fastapi.tiangolo.com/) for the example just to create a simple callback API.
```python
import asyncio
from decimal import Decimal
from fastapi import FastAPI, status
from qpay_client.v2 import QPayClient
from qpay_client.v2.enums import ObjectTypeNum
from qpay_client.v2.schemas import InvoiceCreateSimpleRequest, PaymentCheckRequest
client = QPayClient(
username="TEST_MERCHANT", # or use your username
password="123456", # or use your password
is_sandbox=True, # or false for production
)
app = FastAPI()
# Just a dummy db
payment_database = {}
async def create_invoice():
response = await client.invoice_create(
InvoiceCreateSimpleRequest(
invoice_code="TEST_INVOICE",
sender_invoice_no="1234567",
invoice_receiver_code="terminal",
invoice_description="test",
sender_branch_code="SALBAR1",
amount=Decimal(1500),
callback_url="https://api.your-domain.mn/payments?payment_id=1234567",
)
)
# keep the qpay invoice_id in database, used for checking payment later!
payment_database["1234567"] = {
"id": "1234567",
"invoice_id": response.invoice_id,
"amount": Decimal(1500),
}
# Showing QPay invoice to the user ...
print(response.qPay_shortUrl)
# You define the uri and query/param of your callback
# Your callback API must return
# Response(status_code=200, body="SUCCESS")
@app.get("/payments", status_code=status.HTTP_200_OK)
async def qpay_callback(payment_id: str):
data = payment_database.get(payment_id)
if not data:
raise ValueError("Payment not found")
invoice_id = str(data["invoice_id"])
response = await client.payment_check(
PaymentCheckRequest(
object_type=ObjectTypeNum.invoice,
object_id=invoice_id,
)
)
# do something with payment ...
print(response)
# This is important !
return "SUCCESS"
asyncio.run(create_invoice())
```
### Sync client
There is also sync flavour of the client which you can simply use as follows. All the implementation in Async client is also in the Sync client.
```python
from qpay_client.v2 import QPayClientSync
client = QPayClientSync()
...
```
### Run it
`fastapi dev main.py`
### Methods
#### Invoice methods
`invoice_create` Used to create QPay invoice.
`invoice_cancel` Used to cancel a created invoice
#### Payment methods
`payment_get` Used to get payment details
`payment_check` Used to check payment after the callback invocation
`payment_cancel` Used to cancel payment (Use with caution ⚠️)
`payment_refund` Used to refund the payment back to the user
`payment_list` Used to list payments (e.g: for subscription 🔁)
#### Ebarimt methods
`ebarimt_create` Used to create Ebarimt (must be registered in Ebarimt platform first)
`ebarimt_get` Used to get Ebarimt (must be registered in Ebarimt platform first)
### Schemas
Request/response payloads are strongly typed via Pydantic.
See `qpay_client.v2.schemas` for models such as:
- InvoiceCreateSimpleRequest
- InvoiceCreateRequest
- PaymentCheckRequest
- EbarimtCreateRequest
## License
MIT License
Raw data
{
"_id": null,
"home_page": null,
"name": "qpay-client",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "qpay, payment, qpay v2, mongolian payment, mongolia, httpx, pydantic, asyncio",
"author": "Amraa1",
"author_email": "Amraa1 <amarsanaaganbaatar0409@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a4/fe/a8d157264c6b05fe129764acbea44af0dab80911247a2de68bd68f9d971b/qpay_client-0.2.3.tar.gz",
"platform": null,
"description": "# QPay API Integration client\n\nQPay API integration made simpler and safer with data validation and auto token refresh.\n\nVisit links: \n[Package document](https://pypi.org/project/qpay-client/) \n[QPay document](https://developer.qpay.mn)\n\nMade with \u2764\ufe0f\n\n## Features\n\n- Client manages the access & refresh tokens \ud83e\udd16\n- Both sync and async/await support \ud83d\ude48\ud83d\ude49\n- Pydantic data validation \u2705\n- Retries for payment check \ud83d\udd01\n- QPay error support \ud83d\udd0d\n\n## Installation\n\nUsing pip:\n\n```bash\npip install qpay-client\n```\n\nUsing poetry:\n\n```bash\npoetry add qpay-client\n```\n\nUsing uv:\n\n```bash\nuv add qpay-client\n```\n\n## Usage\n\n### Basic Example\n\nLets implement basic payment flow described in QPay developer document.\n\n\n\n**Important to note:**\n\n> You are _free to implement the callback API's URI and query/params_ in anyway you want. But the callback you implement must return `Response(status_code = 200, body=\"SUCCESS\")`.\n\n### How to implement (Async example)\n\nYou don't have to worry about authentication and managing tokens. QPay client manages this behind the scene so you can focus on the important parts.\n\nYou can use any web framework. I am using [Fastapi](https://fastapi.tiangolo.com/) for the example just to create a simple callback API.\n\n```python\nimport asyncio\nfrom decimal import Decimal\n\nfrom fastapi import FastAPI, status\n\nfrom qpay_client.v2 import QPayClient\nfrom qpay_client.v2.enums import ObjectTypeNum\nfrom qpay_client.v2.schemas import InvoiceCreateSimpleRequest, PaymentCheckRequest\n\nclient = QPayClient(\n username=\"TEST_MERCHANT\", # or use your username\n password=\"123456\", # or use your password\n is_sandbox=True, # or false for production\n)\n\napp = FastAPI()\n\n# Just a dummy db\npayment_database = {}\n\n\nasync def create_invoice():\n response = await client.invoice_create(\n InvoiceCreateSimpleRequest(\n invoice_code=\"TEST_INVOICE\",\n sender_invoice_no=\"1234567\",\n invoice_receiver_code=\"terminal\",\n invoice_description=\"test\",\n sender_branch_code=\"SALBAR1\",\n amount=Decimal(1500),\n callback_url=\"https://api.your-domain.mn/payments?payment_id=1234567\",\n )\n )\n\n # keep the qpay invoice_id in database, used for checking payment later!\n payment_database[\"1234567\"] = {\n \"id\": \"1234567\",\n \"invoice_id\": response.invoice_id,\n \"amount\": Decimal(1500),\n }\n\n # Showing QPay invoice to the user ...\n print(response.qPay_shortUrl)\n\n\n# You define the uri and query/param of your callback\n# Your callback API must return\n# Response(status_code=200, body=\"SUCCESS\")\n@app.get(\"/payments\", status_code=status.HTTP_200_OK)\nasync def qpay_callback(payment_id: str):\n data = payment_database.get(payment_id)\n if not data:\n raise ValueError(\"Payment not found\")\n invoice_id = str(data[\"invoice_id\"])\n response = await client.payment_check(\n PaymentCheckRequest(\n object_type=ObjectTypeNum.invoice,\n object_id=invoice_id,\n )\n )\n\n # do something with payment ...\n\n print(response)\n\n # This is important !\n return \"SUCCESS\"\n\n\nasyncio.run(create_invoice())\n\n```\n\n### Sync client\n\nThere is also sync flavour of the client which you can simply use as follows. All the implementation in Async client is also in the Sync client.\n\n```python\nfrom qpay_client.v2 import QPayClientSync\n\nclient = QPayClientSync()\n\n...\n```\n\n### Run it\n\n`fastapi dev main.py`\n\n### Methods\n\n#### Invoice methods\n\n`invoice_create` Used to create QPay invoice.\n\n`invoice_cancel` Used to cancel a created invoice\n\n#### Payment methods\n\n`payment_get` Used to get payment details\n\n`payment_check` Used to check payment after the callback invocation\n\n`payment_cancel` Used to cancel payment (Use with caution \u26a0\ufe0f)\n\n`payment_refund` Used to refund the payment back to the user\n\n`payment_list` Used to list payments (e.g: for subscription \ud83d\udd01)\n\n#### Ebarimt methods\n\n`ebarimt_create` Used to create Ebarimt (must be registered in Ebarimt platform first)\n\n`ebarimt_get` Used to get Ebarimt (must be registered in Ebarimt platform first)\n\n### Schemas\n\nRequest/response payloads are strongly typed via Pydantic.\nSee `qpay_client.v2.schemas` for models such as:\n\n- InvoiceCreateSimpleRequest\n- InvoiceCreateRequest\n- PaymentCheckRequest\n- EbarimtCreateRequest\n\n## License\n\nMIT License\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2025 Amarsanaa Ganbaatar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "QPay Integration made easy with \u2764\ufe0f (async & sync, typed schemas, auto token refresh)",
"version": "0.2.3",
"project_urls": {
"Documentation": "https://pypi.org/project/qpay-client/",
"Homepage": "https://pypi.org/project/qpay-client/",
"Issues": "https://github.com/Amraa1/qpay_client/issues",
"Source": "https://github.com/Amraa1/qpay_client"
},
"split_keywords": [
"qpay",
" payment",
" qpay v2",
" mongolian payment",
" mongolia",
" httpx",
" pydantic",
" asyncio"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "321b2bb0ede8de17ba530cdad3276abb06a91da0ea56022d5383dfd45fc8b9bf",
"md5": "950de25003768dd055042b373d4b9193",
"sha256": "3c12bc5289884d530852e578dde4b6969ad7f372cd3cb7c36fc67858049ae9a4"
},
"downloads": -1,
"filename": "qpay_client-0.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "950de25003768dd055042b373d4b9193",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 12893,
"upload_time": "2025-09-16T09:53:45",
"upload_time_iso_8601": "2025-09-16T09:53:45.700240Z",
"url": "https://files.pythonhosted.org/packages/32/1b/2bb0ede8de17ba530cdad3276abb06a91da0ea56022d5383dfd45fc8b9bf/qpay_client-0.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "a4fea8d157264c6b05fe129764acbea44af0dab80911247a2de68bd68f9d971b",
"md5": "3051089c13fdf0152cd74bee0d693570",
"sha256": "0c80bec4946f34437d3f4ebb0ba331f42b68da9bc9998f5cd9d832491aadcda1"
},
"downloads": -1,
"filename": "qpay_client-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "3051089c13fdf0152cd74bee0d693570",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 9059,
"upload_time": "2025-09-16T09:53:46",
"upload_time_iso_8601": "2025-09-16T09:53:46.684613Z",
"url": "https://files.pythonhosted.org/packages/a4/fe/a8d157264c6b05fe129764acbea44af0dab80911247a2de68bd68f9d971b/qpay_client-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-16 09:53:46",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Amraa1",
"github_project": "qpay_client",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "qpay-client"
}