Add a Checkout Tool to Your LLM Agent in 10 Minutes
Why Your AI Agent Needs Payment Collection
AI agents are becoming increasingly autonomous—handling customer inquiries, processing orders, and closing deals. But when it comes to payments, many developers hit a wall. Building a secure, compliant payment system from scratch takes weeks. That's where AgentPay VN changes the game.
AgentPay VN is an open-source Python SDK and MCP server that lets your LLM agent collect VietQR payments in minutes. The best part? Your agent never touches the money. Payments go directly to your merchant bank account, and a bank feed confirms settlement automatically.
What Makes AgentPay VN Different
Unlike payment gateways that require your agent to manage funds or complex webhook integrations, AgentPay VN follows a three-step flow:
- Create a payment request – Your agent generates a unique request
- Send the checkout URL – Customer receives a QR code or payment link
- Await settlement – Bank feed confirms payment automatically
No intermediary. No escrow. Direct to bank.
Getting Started: Installation
Install the SDK with a single command:
pip install agentpay-vn
If you're using AgentPay as an MCP server (for tools like Claude, Anthropic's Codebase agents, or other MCP-compatible clients):
pip install agentpay-mcp
Build Your First Payment Checkout in 3 Steps
Step 1: Initialize the SDK
Create a Python file (e.g., agent_payment.py) and initialize AgentPay:
from agentpay_vn import PaymentClient
# Initialize with your merchant credentials
client = PaymentClient(
merchant_id="your_merchant_id",
api_key="your_api_key"
)
Step 2: Create a Payment Request
Your agent logic might look like this:
from agentpay_vn import PaymentClient
import asyncio
client = PaymentClient(
merchant_id="your_merchant_id",
api_key="your_api_key"
)
async def process_order_payment(order_id: str, amount: int, customer_email: str):
"""Create a payment request for an order."""
# Step 1: Create payment request
payment_request = await client.create_payment_request(
order_id=order_id,
amount=amount, # in VND
description=f"Payment for order {order_id}",
customer_email=customer_email
)
print(f"Payment request created: {payment_request.id}")
# Step 2: Get checkout URL with VietQR code
checkout_url = payment_request.checkout_url
print(f"Send this link to customer: {checkout_url}")
# Step 3: Wait for settlement confirmation
settlement = await client.await_settlement(
payment_request_id=payment_request.id,
timeout_seconds=3600 # 1 hour timeout
)
if settlement.confirmed:
print(f"Payment confirmed! Amount: {settlement.amount} VND")
return True
else:
print("Payment failed or expired")
return False
# Usage in your agent
asyncio.run(process_order_payment(
order_id="ORD-12345",
amount=500000,
customer_email="customer@example.com"
))
Step 3: Integrate with Your LLM Agent
If you're using AgentPay with Claude or another LLM agent framework, define the payment tool:
from agentpay_vn import PaymentClient
import json
client = PaymentClient(
merchant_id="your_merchant_id",
api_key="your_api_key"
)
def checkout_tool(order_id: str, amount: int, customer_email: str) -> dict:
"""
Tool for LLM agents to create payment requests.
The agent calls this when a customer is ready to pay.
"""
try:
# Create payment request synchronously
payment_request = client.create_payment_request(
order_id=order_id,
amount=amount,
customer_email=customer_email,
description=f"Payment for {order_id}"
)
return {
"success": True,
"checkout_url": payment_request.checkout_url,
"payment_id": payment_request.id,
"message": f"Customer should scan the QR code at {payment_request.checkout_url}"
}
except Exception as e:
return {
"success": False,
"error": str(e)
}
Setting Up AgentPay as an MCP Server
If you want your agent to use AgentPay via the Model Context Protocol, configure it in your mcp.json or environment:
{
"mcpServers": {
"agentpay": {
"command": "agentpay-mcp",
"env": {
"AGENTPAY_MERCHANT_ID": "your_merchant_id",
"AGENTPAY_API_KEY": "your_api_key"
}
}
}
}
Your agent can now call:
- agentpay/create_payment_request – Generate a checkout link
- agentpay/check_settlement – Poll payment status
- agentpay/get_payment_request – Retrieve request details
Key Security & Design Principles
No Money Storage: AgentPay never holds customer funds. Payments route directly to your bank account via VietQR.
Automatic Settlement Confirmation: Bank feeds verify deposits automatically—no manual reconciliation.
Open Source: Audit the code yourself at GitHub.
MIT Licensed: Use it freely in commercial and personal projects.
Common Questions
Q: How long does settlement take?
A: Settlement times depend on your bank, typically 1-2 business days. AgentPay polls your bank feed for confirmation automatically.
Q: Can I use AgentPay in production?
A: Yes. AgentPay is production-ready with bank-grade security. Review the docs and test in staging first.
Q: What's the difference between the SDK and MCP server?
A: The SDK is for direct Python integration in your agent code. The MCP server exposes AgentPay tools via the Model Context Protocol, so any MCP-compatible client (Claude, etc.) can call it.
Q: Does AgentPay support multiple currencies?
A: Currently, AgentPay supports VND (Vietnamese Dong) via VietQR. International currency support is planned.
Q: Is there a fee?
A: AgentPay is MIT-licensed open source—no subscription. VietQR transactions follow your bank's standard rates.
Next Steps
- Install AgentPay:
pip install agentpay-vn - Get your credentials: Sign up and create a merchant account at agentpay.servicesai.vn
- Read the full docs: Check API documentation for advanced features
- Join the community: Star the GitHub repo and contribute
That's it—your LLM agent can now collect payments in under 10 minutes. Questions? Open an issue on GitHub or check the docs. Happy building! 🚀