agentpay-vn
AgentPay VN — an MCP server that lets your AI agent collect real (fiat) payments over VietQR
README
AgentPay VN
<!-- mcp-name: io.github.phuocdu/agentpay-vn -->
VietQR payment infrastructure for AI agents — collect money inside any conversation.
AgentPay VN lets AI agents (Claude, GPT, custom bots) generate payment QR codes, send them to users, and automatically confirm when the money arrives — all without ever holding or touching funds. Money flows directly from the payer's bank account into the merchant's account; AgentPay only reads the bank transaction feed to confirm settlement.
Status: Early access / self-hosted — running on the same swarm as Sổ Nợ AI.
How it works
AI Agent AgentPay API Bank feed (SePay)
| | |
|-- create_payment_request ->| |
|<- { qr_image_url, id } ----| |
| | |
|-- send QR to user -------->| |
| | user scans & pays |
| |<-- webhook (bank txn) ----|
| |-- match AP* pay_code |
| |-- status → settled |
|<-- await_settlement done --| |
| | |
|-- deliver order / unlock ->| |
- Create — agent calls
POST /v1/payment-requests→ gets a VietQR image URL and a checkout page. - Send — agent embeds the QR image or sends the checkout link to the user in chat.
- Await — agent calls
await_settlement()(or the MCP tool) to poll untilstatus = settled. - Deliver — only after confirmed settlement does the agent release the goods/service.
AgentPay never holds money. The QR points directly at the merchant's bank account number. The platform only monitors the bank transaction feed to detect matching transfers.
Quick start
1. Install
pip install agentpay-vn
2. Set your API key
export AGENTPAY_API_KEY=ap_test_xxx # sandbox key for testing
Get a key from the admin dashboard (self-hosted) or contact the platform operator.
3. Collect a payment (3 lines)
from agentpay.client import AsyncAgentPayClient, await_settlement
import asyncio
async def main():
async with AsyncAgentPayClient("ap_test_xxx") as client:
pr = await client.create_payment_request(amount=50_000, description="Order #1")
print(pr["checkout_url"]) # send this link to your user
result = await await_settlement(client, pr["id"], timeout=120)
assert result["status"] == "settled"
asyncio.run(main())
See examples/quickstart.py for the full runnable version.
MCP server setup
AgentPay ships an MCP server so any MCP-compatible AI agent can call it as a tool — no extra code needed.
Claude Desktop / Claude Code
Add to claude_desktop_config.json (or use examples/claude_desktop_config.json):
{
"mcpServers": {
"agentpay": {
"command": "python",
"args": ["-m", "agentpay.mcp_server"],
"env": {
"AGENTPAY_API_KEY": "ap_test_xxx",
"AGENTPAY_BASE_URL": "https://agentpay.servicesai.vn/v1"
}
}
}
}
Or use the installed console script:
{
"mcpServers": {
"agentpay": {
"command": "agentpay-mcp",
"env": { "AGENTPAY_API_KEY": "ap_live_xxx" }
}
}
}
Available MCP tools
| Tool | Description |
|---|---|
create_payment_request |
Generate a VietQR code for a given amount |
check_payment |
Get current status of a payment request |
await_settlement |
Poll until payment arrives or timeout (max 600 s) |
list_recent_payments |
List last N settled transactions |
Python SDK
Synchronous
from agentpay.client import AgentPayClient
with AgentPayClient("ap_live_xxx") as client:
# Create
pr = client.create_payment_request(
amount=150_000,
description="Consulting session 30 min",
ttl_minutes=30,
idempotency_key="session-abc-123",
)
# Poll manually
import time
for _ in range(60):
pr = client.get_payment_request(pr["id"])
if pr["status"] != "pending":
break
time.sleep(5)
# Reconcile
txns = client.list_transactions(limit=10)
Asynchronous
from agentpay.client import AsyncAgentPayClient, await_settlement
async with AsyncAgentPayClient("ap_live_xxx") as client:
pr = await client.create_payment_request(amount=75_000, description="eBook download")
result = await await_settlement(client, pr["id"], timeout=300)
if result["status"] == "settled":
send_download_link(result["metadata"].get("email"))
Webhook verification
import hashlib, hmac
def verify_webhook(raw_body: bytes, signature_header: str, secret: str) -> bool:
expected = hmac.new(secret.encode(), raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, signature_header)
Register a webhook endpoint:
ep = client.register_webhook(
url="https://your-server.com/webhooks/agentpay",
events=["payment.settled", "payment.expired"],
)
print(ep["secret"]) # store this — shown only once
API reference
- OpenAPI spec:
agentpay-openapi.yaml - Base URL:
https://agentpay.servicesai.vn/v1 - Authentication:
Authorization: Bearer ap_live_xxx(orap_test_xxxfor sandbox)
Key endpoints
| Method | Path | Description |
|---|---|---|
POST |
/v1/payment-requests |
Create payment request |
GET |
/v1/payment-requests/{id} |
Get status |
POST |
/v1/payment-requests/{id}/cancel |
Cancel pending request |
GET |
/v1/transactions |
List settled transactions |
POST |
/v1/webhook-endpoints |
Register webhook URL |
POST |
/v1/sandbox/simulate-settlement |
Simulate payment (sandbox only) |
GET |
/pay/{pay_code} |
Public checkout page (HTML, mobile-friendly) |
Self-hosting
AgentPay runs as part of the Sổ Nợ AI FastAPI backend.
Requirements
- Docker Swarm cluster (same as Sono)
- MongoDB (shared with Sono)
- SePay bank feed account (for live payments)
- Nginx with an
agentpay.servicesai.vnvhost
Environment variables
| Variable | Default | Description |
|---|---|---|
AGENTPAY_BASE_URL |
https://agentpay.servicesai.vn |
Public base URL for checkout links |
MONGO_URI |
mongodb://localhost:27017 |
Inherited from Sono |
BILLING_WEBHOOK_TOKEN |
— | SePay webhook token (inherited) |
Create an API key (admin)
curl -X POST https://sono.servicesai.vn/api/admin/agentpay/keys \
-H "Authorization: Bearer <admin-jwt>" \
-H "Content-Type: application/json" \
-d '{"org_id": "<shop-user-id>", "name": "My bot", "livemode": true}'
The response includes the full key — store it immediately; it is shown only once.
Rate limits
| Tier | Settled payments/month | Requests/minute |
|---|---|---|
| Free | 50 | 120 |
Design principles
-
No money held — QR codes point directly at the merchant's bank account. AgentPay only reads the transaction feed; it never touches the money.
-
Idempotency — pass an
Idempotency-Keyheader onPOST /payment-requeststo safely retry without creating duplicates (24-hour deduplication window). -
HMAC webhook verification — every outbound webhook is signed with
HMAC-SHA256(whsec_..., raw_body)in theAgentPay-Signatureheader. Always verify before processing. -
Sandbox — use
ap_test_*keys andPOST /v1/sandbox/simulate-settlementto develop and test without real transactions. -
Minimal trust surface — the MCP server is a thin REST client with no local secrets beyond the API key. Compromising an agent key only exposes one tenant's payment-request creation ability.
License
MIT © 2026 ServicesAI — see LICENSE.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。