Sell Digital Products from AI Chatbots Without Holding Funds
Why Payment Collection Matters for AI Agents
AI chatbots are becoming increasingly capable of handling business transactions. However, one critical challenge has limited their real-world utility: accepting payments while managing liability and regulatory compliance.
Traditional payment solutions require chatbots to hold customer funds temporarily, creating security risks, regulatory headaches, and customer trust issues. What if your AI agent could accept payments without ever touching the money?
Enter AgentPay VN—an open-source Python SDK that lets AI agents collect VietQR payments directly into merchant bank accounts, with instant settlement confirmation.
How AgentPay VN Works
AgentPay VN operates on a simple principle: remove the intermediary. Instead of funds flowing through your application, customers pay directly into your bank account via QR code.
Here's the workflow:
- Create a payment request via your AI agent
- Send the checkout URL to the customer
- Await settlement confirmation from the bank feed
No escrow accounts. No fund reconciliation. No compliance nightmares.
Key Benefits
- Zero liability: Your system never holds funds
- MIT licensed: Use freely in commercial projects
- Bank-native: Settlements come directly through your bank feed
- Agent-native: Built specifically for autonomous AI systems
- Vietnamese market: Optimized for VietQR ecosystem
Getting Started with AgentPay VN
Installation
Start by installing the SDK:
pip install agentpay-vn
The package includes both the Python SDK and the MCP (Model Context Protocol) server for seamless AI integration.
Basic Setup
Here's a minimal example showing how to integrate payment collection into your AI chatbot:
from agentpay_vn import PaymentClient
# Initialize the payment client
client = PaymentClient(
merchant_id="your_merchant_id",
api_key="your_api_key",
webhook_secret="your_webhook_secret"
)
# Step 1: Create a payment request
payment_request = client.create_payment_request(
amount=99000, # VND
order_id="digital_product_123",
description="Premium AI Writing Templates Bundle",
return_url="https://yourapp.com/payment/success"
)
print(f"Checkout URL: {payment_request['checkout_url']}")
# Step 2: Send checkout URL to customer via chatbot
# (Implementation depends on your chatbot framework)
# Step 3: Listen for settlement confirmation
def handle_settlement(webhook_payload):
order_id = webhook_payload['order_id']
status = webhook_payload['status']
amount = webhook_payload['amount']
if status == 'settled':
print(f"Payment confirmed! Order {order_id} for {amount} VND settled.")
# Grant access to digital product
grant_product_access(order_id)
return handle_settlement
Using the MCP Server with Claude & Other AI Models
For advanced AI agent integration, AgentPay VN provides an MCP server that exposes payment operations as tools.
MCP Configuration
Add this to your Claude Desktop config (~/.claude_desktop_config.json):
{
"mcpServers": {
"agentpay": {
"command": "python",
"args": ["-m", "agentpay_mcp"],
"env": {
"AGENTPAY_MERCHANT_ID": "your_merchant_id",
"AGENTPAY_API_KEY": "your_api_key",
"AGENTPAY_WEBHOOK_SECRET": "your_webhook_secret"
}
}
}
}
Once configured, Claude gains access to:
- create_payment_request — Generate a payment request
- check_settlement_status — Poll settlement confirmation
- list_recent_orders — Retrieve transaction history
Real-World Example: Digital Product Marketplace
Let's build a realistic scenario: an AI chatbot that sells digital writing templates.
from agentpay_vn import PaymentClient
import asyncio
class DigitalProductAgent:
def __init__(self):
self.client = PaymentClient(
merchant_id="templates_store",
api_key="sk_live_xxx",
webhook_secret="whsec_xxx"
)
self.products = {
"premium_templates": {"price": 99000, "name": "Premium Writing Templates"},
"seo_toolkit": {"price": 149000, "name": "SEO Blog Toolkit"},
}
async def sell_product(self, customer_id, product_key):
product = self.products[product_key]
# Create payment request
payment = self.client.create_payment_request(
amount=product["price"],
order_id=f"{customer_id}_{product_key}",
description=product["name"]
)
# Return checkout URL to chatbot
return {
"message": f"To access {product['name']}, scan this QR code:",
"checkout_url": payment["checkout_url"],
"amount": product["price"]
}
async def confirm_delivery(self, order_id):
status = self.client.check_settlement_status(order_id)
if status["status"] == "settled":
# Deliver the product
return {"success": True, "download_link": f"https://yourapp.com/download/{order_id}"}
else:
return {"success": False, "message": "Payment still processing"}
# Usage
agent = DigitalProductAgent()
checkout_info = asyncio.run(agent.sell_product("cust_123", "premium_templates"))
print(checkout_info)
Security Best Practices
1. Environment Variables
Never hardcode credentials:
export AGENTPAY_MERCHANT_ID="your_id"
export AGENTPAY_API_KEY="your_key"
export AGENTPAY_WEBHOOK_SECRET="your_secret"
2. Webhook Verification
Always verify webhook signatures:
from agentpay_vn import verify_webhook_signature
def webhook_handler(request_body, signature_header):
is_valid = verify_webhook_signature(request_body, signature_header)
if not is_valid:
return {"error": "Invalid signature"}, 401
# Process webhook
3. HTTPS Only
Ensure all communication with AgentPay VN uses HTTPS in production.
Frequently Asked Questions
Q: What happens if a customer doesn't pay? A: Your chatbot simply doesn't grant access. No funds are at risk since nothing was transferred.
Q: How long does settlement take? A: Most VietQR payments settle within 1-2 business days. AgentPay VN will confirm via webhook when settlement occurs.
Q: Can I use this for subscription payments? A: AgentPay VN currently supports one-time payments. For recurring billing, consider combining it with a subscription management layer.
Q: Is my data secure? A: AgentPay VN is open-source (MIT licensed), so you can audit the code. It never stores sensitive payment data—everything flows directly to VietQR.
Q: What if there's a payment dispute? A: Disputes are handled between the customer and their bank, not your application. Your merchant account will be credited/debited accordingly.
Next Steps
Ready to empower your AI agents with frictionless payment collection? Here's what to do:
- Install AgentPay VN:
pip install agentpay-vn - Read the full documentation: https://agentpay.servicesai.vn/v1/docs
- Explore the source code: https://github.com/phuocdu/agentpay-vn
- Start building: Integrate payments into your first chatbot
- Join the community: Contribute improvements or report issues on GitHub
AgentPay VN removes the last barrier to building truly autonomous AI agents that can conduct real business—without the compliance and security headaches. Your customers get instant gratification, you get instant settlements, and everyone wins.
Happy selling! 🚀