Sell Digital Products from AI Chatbots Without Holding Funds

2026-10-07 · AgentPay VN

ai-paymentsvietqrpython-sdkmcp-serverdigital-commerce

The Hidden Risk Nobody Talks About: Why Most AI Payment Systems Fail

You've built an incredible AI chatbot. It recommends products, answers questions, and customers actually want to buy from it. Then reality hits: you need to collect money.

Most developers reach for Stripe or PayPal, but here's the catch—you're now a money intermediary. Your chatbot holds customer funds, even if just for seconds. That means:

What if your AI chatbot could accept VietQR payments and never touch the money? The funds go straight to the merchant's bank account, confirmed by an automated bank feed. No escrow. No holding accounts. No regulatory grey zones.

That's exactly what AgentPay VN enables.

What AgentPay VN Actually Does (And Doesn't)

AgentPay VN is an open-source Python SDK + MCP server (MIT license) that strips payment collection down to three clean steps:

  1. create_payment_request — Your bot generates a unique VietQR code tied to a specific transaction
  2. send checkout_url — The bot sends a link; customers scan and pay directly to your merchant account
  3. await_settlement — The bot confirms payment when it hits your bank

The critical difference: AgentPay VN is not a payment processor. It's plumbing between your AI and Vietnam's banking infrastructure. Your bot initiates the payment flow, but the merchant bank handles the actual money transfer. This is why it works for digital products—no inventory, no shipping delays, instant settlement.

Real Numbers

Why This Matters for Digital Product Creators

Let's say you run an online Vietnamese language course platform. Your AI tutor chatbot recommends premium content to learners. Currently:

With AgentPay VN:

Setting Up AgentPay VN: Step-by-Step

Step 1: Installation

pip install agentpay-vn

This gives you the SDK. For MCP integration (Claude/other AI agents), also install:

pip install agentpay-mcp

Step 2: Create Your First Payment Request

Here's the canonical flow in Python:

from agentpay_vn import create_payment_request, await_settlement

# Step 1: Generate a payment request
# This creates a unique VietQR tied to your merchant bank account
payment = create_payment_request(
    amount=299000,  # VND for a $15 ebook
    description="Premium JavaScript Course Bundle",
    transaction_id="txn_20250115_user42_course",
    merchant_account="0123456789",  # Your bank account
    merchant_bank="970436"  # ACB bank code
)

# payment.checkout_url = "https://vietqr.io/..."
# payment.qr_code = <base64 encoded image>
# payment.expires_in = 3600  # seconds

# Step 2: Send the checkout URL to the customer
print(f"Please complete payment: {payment.checkout_url}")
print(f"QR Code expires in {payment.expires_in} seconds")

# Step 3: Wait for settlement confirmation
# This polls your bank feed every 3 seconds for up to 5 minutes
settlement = await_settlement(
    transaction_id="txn_20250115_user42_course",
    timeout=300  # 5 minute timeout
)

if settlement.confirmed:
    print(f"✅ Payment confirmed! Reference: {settlement.bank_reference}")
    print(f"Settled amount: {settlement.amount} VND")
    # NOW grant access to the digital product
    grant_course_access(user_id=42)
else:
    print(f"❌ Payment timeout or failed")
    # Retry or notify customer

Line-by-line breakdown:

Step 3: Integrate with Your AI Chatbot (Claude via MCP)

If you're using Claude or another AI agent, define the MCP server config:

{
  "mcpServers": {
    "agentpay-vn": {
      "command": "agentpay-mcp",
      "args": [],
      "env": {
        "AGENTPAY_MERCHANT_ACCOUNT": "0123456789",
        "AGENTPAY_MERCHANT_BANK": "970436",
        "AGENTPAY_BANK_FEED_URL": "https://your-bank-api.vn/feeds"
      }
    }
  }
}

Now Claude can call create_payment_request and await_settlement directly from its tools. No code needed—the agent orchestrates the payment flow.

Real-World Walkthrough: Café Subscription Bot

Let's build a concrete example: a coffee subscription chatbot for a Hanoi café.

Scenario: Customer asks for a monthly coffee package. Bot recommends "Premium Bean Box" ($20 USD ≈ 490,000 VND).

The Bot's Conversation Flow

Customer: "I want a coffee subscription."
Bot: "Great! Our Premium Bean Box is 490,000 VND/month. It includes 5 single-origin espresso packs. Ready to pay?"
Customer: "Yes!"

[Bot creates payment request]
Bot: "Perfect! Scan this QR or click: [checkout_url]. You'll get your first shipment this Friday."

[Customer scans, pays from their bank app]
[Bank transfer settles in 8 seconds]

[Bot confirms]
Bot: "✅ Payment confirmed! Your subscription is active. I've sent your first shipment details to your email."

The Backend Code

from agentpay_vn import create_payment_request, await_settlement
import uuid
from datetime import datetime

def handle_subscription_purchase(customer_id, email, subscription_tier="premium"):
    """Handle subscription purchase end-to-end."""

    # Define pricing
    pricing = {
        "standard": 290000,    # VND
        "premium": 490000,
        "elite": 890000
    }

    amount = pricing[subscription_tier]
    transaction_id = f"sub_{customer_id}_{uuid.uuid4().hex[:8]}"

    # Create payment
    payment = create_payment_request(
        amount=amount,
        description=f"Coffee Subscription - {subscription_tier.capitalize()}",
        transaction_id=transaction_id,
        merchant_account="0123456789",
        merchant_bank="970436"
    )

    # Send to customer
    print(f"📲 Sent checkout: {payment.checkout_url}")

    # Wait for settlement (with timeout)
    try:
        settlement = await_settlement(transaction_id, timeout=300)

        if settlement.confirmed:
            # Grant access: activate subscription
            activate_subscription(
                customer_id=customer_id,
                tier=subscription_tier,
                bank_ref=settlement.bank_reference,
                settled_at=datetime.now()
            )

            # Send shipment email
            send_email(
                to=email,
                subject="Your Coffee Subscription is Active!",
                body=f"Your first shipment will arrive {get_next_friday()}."
            )

            return {"status": "success", "subscription_id": customer_id}
        else:
            return {"status": "timeout", "retry_url": payment.checkout_url}

    except Exception as e:
        print(f"Settlement error: {e}")
        return {"status": "error", "message": str(e)}

What's happening:

  1. Bot generates a unique transaction ID tied to the customer
  2. Merchant bank account and code are pre-configured
  3. Payment URL is generated and sent immediately
  4. Bot waits up to 5 minutes for bank confirmation
  5. Once confirmed, subscription is activated (no manual intervention)
  6. Shipment workflow starts automatically

Total time from "yes" to "subscription active": ~30 seconds.

Advanced Tips & Common Pitfalls

✅ Do's

❌ Don'ts

Do's vs. Don'ts Comparison

Practice ✅ Do ❌ Don't
Bank details Use env vars or secrets manager Hardcode in code
Settlement confirmation Poll bank feed; verify confirmed flag Trust QR scan alone
Transaction tracking Log every txn_id + bank_reference Lose track of payments
Timeout handling Retry with exponential backoff Fail silently
Testing Use real merchant account with small amounts Use mock payments; skip integration test
Error recovery Send user a new checkout_url if expired Force manual bank transfer

Frequently Asked Questions

Q: Does AgentPay VN hold my money?

A: No. AgentPay VN is not a payment processor. It orchestrates VietQR payments that go directly to your merchant bank account. We never touch the funds. Your bank's account agreement applies; AgentPay VN is invisible to the transaction.

Q: What banks are supported?

A: Any bank in Vietnam that supports VietQR (NAPAS standard). This includes ACB, VCB, TPB, MB, Techcombank, OCB, and 50+ others. Check your bank's VietQR documentation for your account's 3-digit code.

Q: Can I use this for subscription billing?

A: AgentPay VN handles individual transactions. For recurring subscriptions, you'd create a new payment_request each cycle (e.g., monthly). Consider a wrapper library that handles schedule automation, or integrate with your own subscription management system.

Q: What if the bank feed is down?

A: await_settlement() will timeout after your specified duration (default: 300 seconds). The QR code remains valid for 1 hour, so users can re-scan or you can retry programmatically. Implement exponential backoff and notify the user if settlement takes longer than expected.

Q: Is this production-ready?

A: Yes. AgentPay VN is MIT-licensed open-source with a live MCP server. It's been tested with real VietQR integrations. Follow the do's/don'ts above and test with your actual merchant account in a staging environment first.

Key Takeaways

Get Started Now

You have everything you need to build a payment-aware AI chatbot.

1. Install the SDK:

pip install agentpay-vn

2. Grab your merchant account details from your bank (account number + 3-digit bank code).

3. Run the walkthrough above with a test transaction. Use VND 1,000 or 10,000 first.

4. Deploy to production. Use environment variables for credentials; log every transaction ID and settlement reference.

Need help? - GitHub repo: https://github.com/phuocdu/agentpay-vn - Full docs & API reference: https://agentpay.servicesai.vn/v1/docs - MCP server setup: Check the README for Claude integration examples

Your customers' money goes straight to your bank. Your chatbot handles the orchestration. No intermediaries, no friction, no regulatory grey zones.

That's the AgentPay VN difference.


Have you built a payment-aware AI chatbot? Share your use case in the comments or open an issue on GitHub. We'd love to hear what you're selling.

Get started →

← All posts