MonPay payment gateway SDK for Python
Project description
mongolian-payment-monpay
MonPay payment gateway SDK for Python. Supports both QR and Deeplink payment flows with synchronous and asynchronous clients.
Installation
pip install mongolian-payment-monpay
QR Payments
Sync
from mongolian_payment_monpay import MonPayQrClient, MonPayQrConfig
client = MonPayQrClient(MonPayQrConfig(
endpoint="https://api.monpay.mn",
username="my-username",
account_id="my-account-id",
callback_url="https://example.com/callback",
))
# Generate a QR code
qr = client.generate_qr(5000)
print(qr.result.qrcode) # base64 QR image
print(qr.result.uuid) # unique payment ID
# Check payment status
status = client.check_qr(qr.result.uuid)
print(status.result.transaction_id)
# Parse a callback URL
callback = MonPayQrClient.parse_callback(
"https://example.com/callback?amount=5000&uuid=abc&status=paid&tnxId=txn-1"
)
print(callback.amount, callback.status)
Async
import asyncio
from mongolian_payment_monpay import AsyncMonPayQrClient, MonPayQrConfig
async def main():
async with AsyncMonPayQrClient(MonPayQrConfig(
endpoint="https://api.monpay.mn",
username="my-username",
account_id="my-account-id",
callback_url="https://example.com/callback",
)) as client:
qr = await client.generate_qr(5000)
print(qr.result.qrcode)
asyncio.run(main())
Deeplink Payments
Sync
from mongolian_payment_monpay import MonPayDeeplinkClient, MonPayDeeplinkConfig
client = MonPayDeeplinkClient(MonPayDeeplinkConfig(
endpoint="https://api.monpay.mn",
client_id="my-client-id",
client_secret="my-client-secret",
grant_type="client_credentials",
webhook_url="https://example.com/webhook",
redirect_url="https://example.com/redirect",
))
# Create a deeplink invoice (authenticates automatically)
invoice = client.create_deeplink(
amount=5000,
invoice_type="P2B",
branch_username="branch1",
description="Order #123",
)
print(invoice.result.id)
print(invoice.result.status)
# Check invoice status
status = client.check_invoice(invoice.result.id)
print(status.result.status)
# Parse a callback URL
callback = MonPayDeeplinkClient.parse_callback(
"https://example.com/webhook?amount=5000&invoiceId=123&status=paid&tnxId=txn-1&info=ok"
)
print(callback.amount, callback.invoice_id, callback.status)
Async
import asyncio
from mongolian_payment_monpay import AsyncMonPayDeeplinkClient, MonPayDeeplinkConfig
async def main():
async with AsyncMonPayDeeplinkClient(MonPayDeeplinkConfig(
endpoint="https://api.monpay.mn",
client_id="my-client-id",
client_secret="my-client-secret",
grant_type="client_credentials",
webhook_url="https://example.com/webhook",
redirect_url="https://example.com/redirect",
)) as client:
invoice = await client.create_deeplink(5000, "P2B", "branch1", "Order #123")
print(invoice.result.id)
asyncio.run(main())
Environment Variables
You can load configuration from environment variables:
from mongolian_payment_monpay import (
MonPayQrClient,
MonPayDeeplinkClient,
load_qr_config_from_env,
load_deeplink_config_from_env,
)
# QR: reads MONPAY_ENDPOINT, MONPAY_USERNAME, MONPAY_ACCOUNT_ID, MONPAY_CALLBACK_URL
qr_client = MonPayQrClient(load_qr_config_from_env())
# Deeplink: reads MONPAY_ENDPOINT, MONPAY_CLIENT_ID, MONPAY_CLIENT_SECRET,
# MONPAY_GRANT_TYPE, MONPAY_WEBHOOK_URL, MONPAY_REDIRECT_URL
dl_client = MonPayDeeplinkClient(load_deeplink_config_from_env())
License
MIT
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 mongolian_payment_monpay-1.0.0.tar.gz.
File metadata
- Download URL: mongolian_payment_monpay-1.0.0.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7813e12e4583c09766454d0e0cde3e24442fbfef6096bc9bdbbe52efd0c546f
|
|
| MD5 |
e301f9426426a87ca29d9d9ee7024c2d
|
|
| BLAKE2b-256 |
67b4a4a3890b999bc5e0780d30c9c0e0f65f532a6ea34efcd3df9c60b17bfd3f
|
File details
Details for the file mongolian_payment_monpay-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mongolian_payment_monpay-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6985f3417409ef2ce571a7d7b27984154b9901db07d03a6290babe22cd0e502
|
|
| MD5 |
cb72de85a71e8d239eb878f8d274e44d
|
|
| BLAKE2b-256 |
0b787b260bd032345fe1e968171994f2d33d5ae6de4b812beed92026500713c2
|