QPay Integration made easy (async & sync, typed schemas, auto token refresh)
Project description
QPay API Integration client
QPay API integration made simpler and safer with data validation and auto token refresh.
This python package includes async and sync client. You can choose which ever suits your project.
Visit links:
Package document
QPay document
Features
- Client manages the access & refresh tokens
- Both sync and async/await support
- Pydantic data validation
- Retries for payment check
- Retries on server error >=500
- Retries on network error
- Clear QPay error code and details
API coverage
Authentication
QPay Client authenticates and manages access and refresh token for you.
- ✅ token
- ✅ refresh
Invoice
- ✅ Get invoice
- ✅ Create simple invoice
- ✅ Create detailed invoice
- ✅ Create subscription invoice
- ✅ Cancel invoice
Payment
- ✅ get
- ✅ list
- ✅ check
- ✅ cancel
- ✅ refund
Ebarimt
- ✅ get
- ✅ create
Subscription
- ✅ Get subscription
- ✅ Cancel subscription
Installation
Using pip:
pip install qpay-client
Using poetry:
poetry add qpay-client
Using uv:
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 for the example just to create a simple callback API.
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.
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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qpay_client-0.3.1.tar.gz.
File metadata
- Download URL: qpay_client-0.3.1.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33ed80ffc11e64b8039371ff2af677c49369eec35dc9022a0cb642df928a8eae
|
|
| MD5 |
7619e1027889cfc0823824d3fc41b9a9
|
|
| BLAKE2b-256 |
16d9094cfa7906bf860ca0b8754fd2ee5cd78f24084d49fe853db6bb3d0c04fb
|
Provenance
The following attestation bundles were made for qpay_client-0.3.1.tar.gz:
Publisher:
release.yml on Amraa1/qpay_client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qpay_client-0.3.1.tar.gz -
Subject digest:
33ed80ffc11e64b8039371ff2af677c49369eec35dc9022a0cb642df928a8eae - Sigstore transparency entry: 655646013
- Sigstore integration time:
-
Permalink:
Amraa1/qpay_client@e32f6cd248736fdd45fbd99a514f732ccb44eb4e -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/Amraa1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e32f6cd248736fdd45fbd99a514f732ccb44eb4e -
Trigger Event:
release
-
Statement type:
File details
Details for the file qpay_client-0.3.1-py3-none-any.whl.
File metadata
- Download URL: qpay_client-0.3.1-py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cd025e8ed9166050a8d2817f0701494ce40c8d87e663c56a7263b99405315bb
|
|
| MD5 |
44011d78452ac2f7d010be1989f09298
|
|
| BLAKE2b-256 |
7008d6dc276f56d1f608de8183453959d81342c1fb97be1a6f82056d20e61dfd
|
Provenance
The following attestation bundles were made for qpay_client-0.3.1-py3-none-any.whl:
Publisher:
release.yml on Amraa1/qpay_client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qpay_client-0.3.1-py3-none-any.whl -
Subject digest:
6cd025e8ed9166050a8d2817f0701494ce40c8d87e663c56a7263b99405315bb - Sigstore transparency entry: 655646038
- Sigstore integration time:
-
Permalink:
Amraa1/qpay_client@e32f6cd248736fdd45fbd99a514f732ccb44eb4e -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/Amraa1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e32f6cd248736fdd45fbd99a514f732ccb44eb4e -
Trigger Event:
release
-
Statement type: