Skip to main content

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 và Telegram — 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; ApiErrorstatusbody.

Các nhóm method: keys, va, bank_accounts, qr, transactions, webhooks, webhook_logs. Tên method dùng snake_case, ví dụ va.register_notification(...)transactions.retry(id, target_type="WEBHOOK", target_id=...).

Đọ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

monapay-0.2.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

monapay-0.2.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file monapay-0.2.0.tar.gz.

File metadata

  • Download URL: monapay-0.2.0.tar.gz
  • Upload date:
  • Size: 9.5 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

Hashes for monapay-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a894774bc57d4e6584724b6d1f26836dcdc5473b6c96478bf015bdf42b874ba0
MD5 bab4b03f216e285de1dcca29c0b2645c
BLAKE2b-256 ee87d02e407d3a80ed1c360702500d70641f4f62f431f8f5f6baf47d9e4a0dea

See more details on using hashes here.

File details

Details for the file monapay-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: monapay-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.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

Hashes for monapay-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7755d5260e99f06107510d60242eddcacff5b9e98504d0424834ee87ecbb1792
MD5 971c7c2d0c0feacfc24a00d37a6efead
BLAKE2b-256 8847e8cb104c50f30131e69997c3cefe0b76e247f39cc02fc68ea708257b7993

See more details on using hashes here.

Release history Release notifications | RSS feed

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page