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=...).

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"]))

Đọ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.3.0.tar.gz (10.3 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.3.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: monapay-0.3.0.tar.gz
  • Upload date:
  • Size: 10.3 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.3.0.tar.gz
Algorithm Hash digest
SHA256 352a3fb12be3f04d6b5dc8e75f06f15f1c8ea4b7a0bbeaa025779023e80a61ab
MD5 24cb85c3c6d5af1c2322771444cf4d49
BLAKE2b-256 776b794fc8883c6ac676d22dfd7ce8d52ee9fc1e06418c193521a0b5d955dece

See more details on using hashes here.

File details

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

File metadata

  • Download URL: monapay-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e65bb255d7127e2c4483e54617f75b8a19e640261acc754940361b26d305883
MD5 27dfcf1d888806c6365eb4fffd7c3157
BLAKE2b-256 faffc3b813fdd5636aeb3c2757b32ec2b8b73291b8dea5759f4d0493f3908607

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

This release

0.3.0 This release

2 files

0.2.0

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