Sell Digital Products from AI Chatbots Without Holding Funds

2026-09-17 · AgentPay VN

agentpayai-agentspayment-processingvietqrpython

The Problem: AI Sales Without the Trust Headache

Imagine you've built an AI chatbot that sells e-books, courses, or design templates. A customer types "I want your $19 UI kit," and your bot responds with a payment link. But here's the friction: to make this seamless, you'd normally need to integrate with a payment processor that holds the cash—at least temporarily—in your merchant account. You're managing refunds, chargebacks, reconciliation, and the regulatory burden of holding customer funds.

Then there's the trust problem. Your customer sees money flowing into your system. If something goes wrong—a delayed delivery, a refund request, a transaction dispute—they're not sure if their money is actually safe.

This is where AgentPay VN changes the game. Instead of your bot (or you) holding funds, payments flow directly into your merchant's bank account, with settlement confirmed by a bank feed. Your AI agent orchestrates the sale, but the money never touches your infrastructure.

What Is AgentPay VN? The Quick Version

AgentPay VN is an open-source Python SDK + MCP server (MIT license) that lets AI agents collect payments via VietQR codes without holding funds. Here's the mental model:

  1. Your AI agent creates a payment request → generates a unique VietQR code
  2. Customer scans & pays → money goes straight to your bank account
  3. Bank feed confirms settlement → agent proceeds with fulfillment (send file, activate account, etc.)

That's it. No escrow. No merchant account juggling. No liability for holding cash. Just three lines of logic: create_payment_request()send_checkout_url()await_settlement().

Why AI Agents + Direct Settlement = Your New Competitive Edge

AI agents are being deployed for customer-facing tasks everywhere: chatbots, email responders, automated support. But most of them can't monetize. They can chat, but they can't close the sale without handing off to a payment widget.

AgentPay VN bridges that gap inside the agent workflow. Your Claude, GPT, or custom LLM can now:

This is especially powerful for: - Subscription chatbots (sell monthly access to AI tools) - Course-selling bots (gated educational content) - Digital storefronts (templates, presets, design files) - Café & small business automation (pre-orders, gift cards)

Installation & Setup: 2 Minutes to Your First Payment

Step 1: Install the SDK

pip install agentpay-vn

That's one command. The SDK is lightweight—it's just Python, no external binaries.

Step 2: Get Your Merchant Info

You'll need: - Your bank account number - Your bank code (e.g., "BIDV", "VIETCOMBANK") - A merchant ID (AgentPay VN docs show how to register)

Step 3: Wire Up Your AI Agent

If you're using Claude or another MCP-compatible agent:

{
  "mcpServers": {
    "agentpay": {
      "command": "agentpay-mcp",
      "env": {
        "AGENTPAY_MERCHANT_ID": "your-merchant-id",
        "AGENTPAY_BANK_ACCOUNT": "0123456789",
        "AGENTPAY_BANK_CODE": "BIDV"
      }
    }
  }
}

Your agent now has direct access to payment functions via MCP. When the agent calls create_payment_request(), it's calling AgentPay VN under the hood.

The Core Workflow: Step-by-Step

Step 1: Create a Payment Request

When a customer decides to buy, your agent creates a payment request:

from agentpay_vn import AgentPayClient

client = AgentPayClient(
    merchant_id="your-merchant-id",
    bank_account="0123456789",
    bank_code="BIDV"
)

# Customer wants to buy a Python course for $24.99
payment = client.create_payment_request(
    amount=2499,  # in VND (24.99 USD ≈ 600,000 VND; adjust to your pricing)
    description="Python Mastery Course",
    customer_email="student@example.com",
    metadata={"product_id": "course_python_001", "user_id": "12345"}
)

print(f"VietQR Code: {payment.qr_code_url}")
print(f"Checkout URL: {payment.checkout_url}")
print(f"Payment ID: {payment.id}")

Line by line: - amount=2499: Price in VND (smallest unit). Always use VND in AgentPay VN. - description: What the customer is buying (shows on their bank app). - customer_email: For receipts & notifications. - metadata: Your internal tracking (product ID, user ID, etc.). Encrypted on the backend.

Step 2: Send the Checkout URL to the Customer

Your agent displays the QR code or sends the checkout URL:

# In your chatbot, after creating the payment:
agent_response = f"""
Great choice! Here's your checkout link:
{payment.checkout_url}

Or scan this QR:
{payment.qr_code_url}

Payment goes straight to my bank. Once confirmed (usually <30 seconds), 
you'll get instant access to the course.
"""

The customer scans the VietQR with their banking app and pays. Money goes directly to your bank account—AgentPay VN never touches it.

Step 3: Wait for Settlement Confirmation

Your agent polls the settlement endpoint to confirm the payment:

import time
from agentpay_vn import AgentPayClient

client = AgentPayClient(
    merchant_id="your-merchant-id",
    bank_account="0123456789",
    bank_code="BIDV"
)

payment_id = "payment_1234567890"  # from step 1

# Wait for settlement (with timeout)
start_time = time.time()
max_wait = 300  # 5 minutes

while time.time() - start_time < max_wait:
    settlement = client.await_settlement(
        payment_id=payment_id,
        timeout=5  # check every 5 seconds
    )

    if settlement.status == "confirmed":
        print(f"✅ Payment confirmed! Amount: {settlement.amount} VND")
        print(f"   Bank ref: {settlement.bank_reference}")

        # Now deliver the product
        deliver_course_access(customer_email=settlement.metadata["customer_email"])
        break

    elif settlement.status == "failed":
        print(f"❌ Payment failed. Tell customer to try again.")
        break

else:
    print("⏱️  Payment timed out. Check your bank account manually.")

Why this is safe: - The bank feed confirms the money arrived in your account. - You only deliver the product once you see status="confirmed". - No refund risk—the customer already paid their bank. - The settlement includes a bank_reference, so you can reconcile with your bank statement.

Real-World Example: An AI Course-Selling Bot

Let's walk through a complete scenario. You've built a chatbot that sells micro-courses on AI prompt engineering. Here's how it flows:

User: "Do you have a course on advanced prompting?"

Bot: "Yes! Our 'Prompt Master' course covers 47 techniques in 6 hours. It's ₫299,000 (~$12 USD). Want it?"

User: "Sure, let's do it."

Bot (backend): 1. Calls create_payment_request(amount=299000, description="Prompt Master Course") 2. Receives QR code and checkout URL 3. Sends to user: "Here's your VietQR. Scan with your banking app to pay."

User: Scans QR, opens their bank app, pays ₫299,000. Money goes directly to your Vietcombank account.

Bot (backend): 1. Calls await_settlement(payment_id, timeout=5) in a loop 2. Receives status="confirmed" + bank_reference="TRX202412311245" 3. Triggers send_course_access(user_email) → email with course link + login token 4. Responds to user: "✅ Access granted! Check your email for the course link."

You (merchant): - See ₫299,000 in your bank account (already there) - Log into your bank dashboard, see the transaction - Reconcile in your accounting system using the bank_reference - Zero chargeback risk - Zero fund-holding liability

The entire payment → settlement → fulfillment cycle takes <2 minutes, all orchestrated by the AI agent.

Advanced Tips: Scaling & Reliability

Tip 1: Batch Requests for High Volume

If you have multiple agents or services hitting AgentPay VN, batch your create_payment_request() calls:

from agentpay_vn import AgentPayClient

client = AgentPayClient(...)

# Create 10 payment requests in one call (faster, fewer network round-trips)
payments = client.create_payment_requests([
    {"amount": 299000, "description": "Course A", "customer_email": "user1@ex.com"},
    {"amount": 399000, "description": "Course B", "customer_email": "user2@ex.com"},
    # ... up to 100 per batch
])

Tip 2: Webhook Listeners for Real-Time Settlement

Instead of polling await_settlement(), register a webhook:

client.register_webhook(
    url="https://your-domain.com/agentpay/webhook",
    events=["settlement.confirmed", "settlement.failed"]
)

When settlement happens, AgentPay VN POSTs to your endpoint. You can then trigger fulfillment instantly, rather than polling.

Tip 3: Reconciliation Automation

Store the bank_reference from every settlement:

if settlement.status == "confirmed":
    db.save_transaction({
        "payment_id": payment_id,
        "amount": settlement.amount,
        "bank_reference": settlement.bank_reference,  # e.g., "TRX202412311245"
        "timestamp": settlement.timestamp,
        "product_id": settlement.metadata["product_id"]
    })

At month-end, download your bank statement as CSV and match each transaction by bank_reference. Full audit trail.

Tip 4: Error Handling & Retry Logic

Network hiccups happen. Always retry with exponential backoff:

import time

def await_settlement_with_retry(client, payment_id, max_retries=3):
    for attempt in range(max_retries):
        try:
            return client.await_settlement(payment_id, timeout=10)
        except ConnectionError:
            if attempt < max_retries - 1:
                time.sleep(2 ** attempt)  # 1s, 2s, 4s
            else:
                raise

Do's & Don'ts

Do Don't
Store bank_reference for reconciliation Assume settlement is instant (usually <30s, but use a timeout)
Use VND for all amounts (AgentPay VN standard) Try to handle payment refunds yourself—customer goes back to their bank
Test in sandbox mode first (docs show how) Share your AGENTPAY_MERCHANT_ID in client-side code—keep it server-only
Monitor webhook delivery (implement retries) Deliver the product before status="confirmed"
Encrypt metadata with sensitive user IDs Rely on polling alone for mission-critical flows (use webhooks)

FAQ

Q: What happens if a customer disputes the payment? A: The customer disputes it with their bank (Vietcombank, BIDV, etc.), not with you. The bank handles chargeback. Since you didn't hold the funds, your liability is minimal. Always keep the bank_reference for the bank's investigation.

Q: Can I refund a customer? A: No—AgentPay VN doesn't hold funds, so you can't refund through the platform. The customer refunds through their bank (if the merchant disputes is resolved) or you send them a separate payment via bank transfer. For digital products (courses, e-books), refunds are rare if you offer a money-back guarantee upfront.

Q: Does AgentPay VN charge transaction fees? A: Check the official docs at https://agentpay.servicesai.vn/v1/docs. Fees vary by deployment (self-hosted vs. cloud). The open-source SDK has no license fees (MIT license).

Q: Can I use this outside Vietnam? A: AgentPay VN is designed for VietQR (Vietnamese bank transfers). It works for merchants with Vietnamese bank accounts. Customers can be anywhere if they have access to a Vietnamese bank app (many do via expat banking).

Key Takeaways

Get Started Now

Your AI agents are ready to sell. Here's what to do:

  1. Install the SDK: bash pip install agentpay-vn

  2. Read the docs: https://agentpay.servicesai.vn/v1/docs

  3. Explore the code: https://github.com/phuocdu/agentpay-vn

  4. Integrate into your agent (Claude, GPT, or custom LLM) using the MCP server.

  5. Test with sandbox mode before going live.

Then deploy. Your first agent-powered sale is waiting.

Get started →

← All posts