monapay
MONA Pay là cổng thanh toán và API ngân hàng của The MONA Group, giúp doanh nghiệp Việt Nam nhận và xác nhận tiền chuyển khoản theo thời gian thực qua tài khoản ảo (VA), VietQR, webhook, Telegram và email, thiết kế để cả lập trình viên lẫn AI agent tích hợp trong vài phút.
SDK Python đồng bộ, chỉ dùng standard library. MONA Pay miễn phí hoàn toàn.
Cài đặt
pip install monapay
Bắt đầu nhanh
import os
from monapay import MonaPay
mona = MonaPay(
client_id=os.environ["MONAPAY_CLIENT_ID"],
client_secret=os.environ["MONAPAY_CLIENT_SECRET"],
)
# Hoặc: mona = MonaPay.from_env()
# Tự lấy OAuth token và cache tới gần hạn.
print(mona.me())
mona.webhooks.create({
"name": "Web ban hang",
"webhook_url": "https://shop.vn/webhooks/monapay",
"auth_type": "HMAC_SHA256",
"secret_key": os.environ["MONA_WEBHOOK_SECRET"],
"payload_format": "application/json",
})
qr = mona.qr.generate({
"ownerNumber": "123456789", "ownerType": "ORG",
"merchantId": "MC00012345", "terminalId": "TM0001", "orderId": "DH10234",
"virtualAccountPrefix": "MONA", "beneficiaryName": "CONG TY ABC",
"amount": 2500000, "description": "Thanh toan DH10234",
})
print(qr["qr_data_url"])
MonaPay.from_env() ưu tiên MONAPAY_CLIENT_ID + MONAPAY_CLIENT_SECRET. Cách cũ MonaPay(username, password) hoặc MONAPAY_USERNAME + MONAPAY_PASSWORD vẫn được hỗ trợ, nhưng tài khoản bật 2FA không login bằng mật khẩu được. Client cache token theo expires_in (làm mới sớm 60 giây) và thử request đúng một lần khi gặp HTTP 401. Các method trả trực tiếp trường data; ApiError có status và body.
Các nhóm method: keys, va, bank_accounts, qr, transactions, webhooks, webhook_logs, email_configs, email_logs, email_suppressions. Tên method dùng snake_case, ví dụ va.register_notification(...) và email_configs.resend_verification(...).
Nối ngân hàng bằng OTP (4 bước)
OTP do ACB gửi về số điện thoại đăng ký của chủ tài khoản. Ứng dụng phải hỏi người dùng ở bước 2 và 4, không tự tạo hoặc lưu OTP.
registration = mona.register_virtual_account({
"customer_type": "PERS",
"account_number": 123456789,
"phone_number": "0901234567",
"virtual_account_info": {
"virtual_account_prefix_code": "LOC",
"virtual_account_content": "DH10234",
"virtual_account_explain": "Don hang 10234",
},
"user_agreement": True,
})
va = mona.verify_virtual_account(registration["acb_request"]["id"], otp_nguoi_dung_nhap)
notification = mona.register_notification(va["id"])
mona.verify_notification(notification["acb_request"]["id"], otp_lan_hai)
print(mona.notification_detail(va["id"]))
Thông báo qua email
MONA Pay gửi mã 6 số tới từng địa chỉ mới. Ứng dụng phải hỏi người dùng mã trong hộp thư rồi xác minh, không tự đoán mã.
config = mona.email_configs.create({"name": "Kế toán", "recipients": ["kt@shop.vn"]})
email = config["pending_verification"][0]
code = ask_user_for_code(email)
mona.email_configs.verify(config["id"], email, code)
mona.email_configs.test(config["id"])
print(mona.email_logs.list(config_id=config["id"], status="sent"))
Địa chỉ bounce hoặc khiếu nại nằm trong email_suppressions.list(); chỉ gọi email_suppressions.remove(email) sau khi đã sửa nguyên nhân.
Đọc hết các trang giao dịch:
for tx in mona.iter_transactions("MONA0000010234", limit=100):
print(tx["transaction_code"], tx["amount"])
Xác thực webhook
Luôn truyền đúng request.body dạng bytes, không parse rồi encode lại.
from monapay import verify_webhook
result = verify_webhook(raw_body, headers, os.environ["MONA_WEBHOOK_SECRET"])
if not result.ok:
return {"reason": result.reason}, 401
save_once(result.payload["transaction_code"], result.payload)
Ví dụ nhận webhook cho Flask, FastAPI và Django nằm trong examples/. Dùng transaction_code làm unique key để chống xử lý trùng.
Tài liệu: https://monapay.vn/docs · AI/LLM: https://monapay.vn/llms.txt · Hotline 1900 636 648 · info@themona.global
Test
Từ thư mục gói:
python -m pytest tests
License MIT.
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 monapay-0.4.0.tar.gz.
File metadata
- Download URL: monapay-0.4.0.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.10 {"installer":{"name":"uv","version":"0.11.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e4741fe5b106bca5f4f688fd8ce69f6f2edfcc1a32075144c2be05a0c9361ae
|
|
| MD5 |
e095d9441ba869a52c4e56003a40aa9c
|
|
| BLAKE2b-256 |
1e5c59381a3c5bcc546ed717640218c8ccb43023601170783ccb5c5f1efe3054
|
File details
Details for the file monapay-0.4.0-py3-none-any.whl.
File metadata
- Download URL: monapay-0.4.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.10 {"installer":{"name":"uv","version":"0.11.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63a459fafa692bad1c04bcc91f60c7df107df7adb4f78db2be7645f563261c90
|
|
| MD5 |
b07a0b06c591fbedbf92a11f9a11a935
|
|
| BLAKE2b-256 |
2e5463079aec42332212bfffe4b05af18378f146dc6ed2f86f7a76bd4b3a49cd
|