Build an AI Agent That Takes Payments via Stripe
How to build an OpenClaw chatbot that collects payments through Stripe — including payment links, subscription sign-ups, and invoice creation. Perfect for coaches and freelancers.
An AI agent that can take payments is genuinely useful. Imagine a coaching chatbot that books a session and charges the card in the same conversation, or a freelance proposal bot that sends an invoice and gets paid before you even check your email.
This guide shows you how to build a payment-capable OpenClaw agent using Stripe. No custom checkout page needed.
What You're Building
An AI agent that can:
- Collect customer name and email
- Present pricing options
- Create a Stripe payment link on the fly
- Send the payment link in the conversation
- Detect when payment is completed (via Stripe webhook)
- Trigger a follow-up action (send confirmation, book calendar slot, etc.)
Stripe Setup
You'll need:
- A Stripe account (free to create, standard processing fees apply)
- Stripe API keys (Publishable + Secret Key)
- Products/Prices already created in Stripe, or created dynamically via API
For simple use cases (fixed service packages), pre-create your products in the Stripe dashboard and note the Price IDs. They look like price_1OqXYZ....
Creating Payment Links via Stripe API
The cleanest approach for chatbot payments is Stripe Payment Links — single-use or reusable links that Stripe hosts.
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
async function createPaymentLink(priceId, customerEmail, metadata) {
const paymentLink = await stripe.paymentLinks.create({
line_items: [
{
price: priceId,
quantity: 1,
},
],
after_completion: {
type: 'redirect',
redirect: {
url: 'https://yoursite.com/thank-you',
},
},
customer_creation: 'always',
metadata: {
...metadata,
customer_email: customerEmail,
},
});
return paymentLink.url;
}
Then expose this as an OpenClaw tool:
tools:
- name: "create_payment_link"
description: "Create a Stripe payment link for a service package"
parameters:
price_id:
type: string
description: "Stripe Price ID for the service"
customer_email:
type: string
description: "Customer's email address"
handler: "tools/create_payment_link.js"
Teaching the Agent to Use Payments
In your SOUL.md:
## Services and Pricing
You offer three coaching packages:
- **Discovery Call** (30 min, free): Schedule via Calendly
- **Strategy Session** (90 min, $297): price_strategy_session
- **Growth Package** (3-month, $1,497): price_growth_package
## Payment Flow
When a user wants to book a paid session:
1. Confirm what they want to book
2. Ask for their email address (needed for Stripe)
3. Use create_payment_link tool with their email and the correct price_id
4. Send them the payment link: "Here's your secure payment link: [URL]"
5. Let them know what to expect after payment
Do not ask for card details directly. Always use the payment link.
Always confirm the booking details before creating the link.
Example Conversation Flow
User: I'd like to book a strategy session with you.
Agent: Great! The 90-minute Strategy Session is $297. Before I
create your booking link, can I get your email address so Stripe
can send you a receipt?
User: [email protected]
Agent: Perfect. Here's your secure payment link:
https://buy.stripe.com/abc123...
Once you complete payment, you'll get a confirmation email with
the scheduling link. The whole thing takes about 2 minutes.
User: Just paid!
Agent: Excellent! You should have a confirmation email from Stripe,
plus a separate email from me with the Calendly link to pick your
time. Let me know if anything doesn't arrive within 5 minutes.
Detecting Payment Completion
Set up a Stripe webhook to detect when payment is complete:
// Your webhook endpoint
app.post('/webhooks/stripe', express.raw({type: 'application/json'}), async (req, res) => {
const sig = req.headers['stripe-signature'];
let event;
try {
event = stripe.webhooks.constructEvent(
req.body,
sig,
process.env.STRIPE_WEBHOOK_SECRET
);
} catch (err) {
return res.status(400).json({ error: 'Invalid signature' });
}
if (event.type === 'checkout.session.completed') {
const session = event.data.object;
const customerEmail = session.customer_details.email;
const metadata = session.metadata;
// Trigger follow-up actions
await onPaymentCompleted({
email: customerEmail,
conversationId: metadata.conversation_id,
product: metadata.product_name,
});
}
res.json({ received: true });
});
async function onPaymentCompleted({ email, conversationId, product }) {
// 1. Send confirmation email
await sendConfirmationEmail(email, product);
// 2. Send Calendly link (or calendar booking)
await sendCalendlyLink(email);
// 3. Notify yourself
await notifySlack(`Payment received: ${email} booked ${product}`);
// 4. Optionally: send a message back in the conversation
await openClaw.sendMessage(conversationId,
"Your payment went through! Check your email for next steps."
);
}
Handling Subscriptions
For recurring payments (monthly retainers, memberships):
async function createSubscriptionLink(priceId, customerEmail) {
// Create a customer first for better tracking
const customer = await stripe.customers.create({
email: customerEmail,
metadata: { source: 'openclaw_chatbot' }
});
// Create a subscription checkout session
const session = await stripe.checkout.sessions.create({
customer: customer.id,
mode: 'subscription',
line_items: [{ price: priceId, quantity: 1 }],
success_url: 'https://yoursite.com/welcome',
cancel_url: 'https://yoursite.com/pricing',
});
return session.url;
}
Custom Invoice Generation
For freelancers who need invoice-based payments:
async function createAndSendInvoice(customerEmail, items, dueDate) {
// Create or find customer
const customers = await stripe.customers.list({ email: customerEmail });
let customer;
if (customers.data.length > 0) {
customer = customers.data[0];
} else {
customer = await stripe.customers.create({ email: customerEmail });
}
// Create invoice items
for (const item of items) {
await stripe.invoiceItems.create({
customer: customer.id,
amount: item.amount, // in cents
currency: 'usd',
description: item.description,
});
}
// Create and finalize invoice
const invoice = await stripe.invoices.create({
customer: customer.id,
collection_method: 'send_invoice',
days_until_due: dueDate || 14,
auto_advance: true,
});
const finalizedInvoice = await stripe.invoices.finalizeInvoice(invoice.id);
// Send it
await stripe.invoices.sendInvoice(finalizedInvoice.id);
return finalizedInvoice.hosted_invoice_url;
}
Security Considerations
- Never handle raw card data in your agent — always use Stripe-hosted payment links
- Validate all inputs before creating payment links — sanitize email addresses
- Set metadata on Stripe objects for traceability back to conversations
- Use Stripe's fraud tools — Radar is included in standard Stripe pricing
- Test thoroughly with Stripe's test card numbers before going live
Test cards:
4242 4242 4242 4242 — Always succeeds
4000 0000 0000 0002 — Always declines
4000 0025 0000 3155 — Requires 3D Secure
Deployment Considerations
This setup requires a server that can:
- Handle incoming Stripe webhooks (HTTPS required)
- Make outbound Stripe API calls
- Store conversation-to-payment metadata
If you're self-hosting OpenClaw, you need to configure all of this yourself — SSL certificates, webhook receiver, API key management, and the glue code between all the pieces.
The ClawPort Approach
ClawPort hosts your OpenClaw agent and handles the HTTPS endpoint, environment variable management (including your STRIPE_SECRET_KEY), and webhook receipt. You write the tool handlers and payment logic; ClawPort handles the deployment.
The $10/month hosting cost versus the engineering time to set up secure SSL webhook handling yourself is an easy calculation. Seven-day free trial at clawport.io.
What to Build Next
Once payments work:
- Connect to your calendar to book sessions automatically after payment
- Build a refund workflow into the agent for customer service scenarios
- Add upsell logic: after a strategy session, offer the growth package at a discount
Ready to deploy your AI agent?
Get started with ClawPort in 60 seconds. No credit card required.
Get Started FreeRelated Articles
Add an AI Chatbot to Your Shopify Store (Without Apps)
How to connect an OpenClaw agent to your Shopify store for product recommendations, order tracking, and FAQ automation — without paying $50/month for a chatbot app.
How to Migrate From ChatGPT Assistants API to OpenClaw
Why developers are moving away from the OpenAI Assistants API, a full feature comparison, and step-by-step migration guide — including conversation history, file search, and function calling.
Build an AI Appointment Booking Agent (Google Calendar + OpenClaw)
How to build an AI agent that checks availability, books appointments, and sends confirmations using Google Calendar — ideal for service businesses, coaches, and consultants.
How to Build a Discord Bot With OpenClaw
A complete guide to building and deploying a Discord bot using OpenClaw — covering gateway setup, slash commands, conversation memory, and how it compares to Telegram.