✨ From vibe coding to vibe deployment. UBOS MCP turns ideas into infra with one message.

Learn more
Andrii Bidochko
  • Updated: March 23, 2026
  • 6 min read

Step‑by‑Step Stripe Integration Guide for OpenClaw

Integrating Stripe with OpenClaw lets developers add both one‑time and metered billing to their SaaS products, providing a seamless payment experience that scales from early‑stage startups to enterprise deployments.

Introduction

OpenClaw is a powerful boilerplate that accelerates SaaS development by handling authentication, multi‑tenant architecture, and API scaffolding out of the box. Pairing it with Stripe’s robust payment platform completes the stack, enabling you to monetize features instantly. In this guide we walk through every step—from setting up credentials to handling metered usage—so you can ship a production‑ready billing system in minutes.

Prerequisites

OpenClaw setup

Before touching Stripe, ensure you have a running OpenClaw instance. If you need a quick start, the UBOS platform overview explains how OpenClaw fits into the broader UBOS ecosystem, and the UBOS templates for quick start provide ready‑made project scaffolds.

Stripe account

Sign up for a Stripe account (or log in to an existing one) and activate the Payments and Billing products. You’ll need the Publishable key and Secret key later in the OpenClaw configuration. For a cost‑effective plan, review the UBOS pricing plans to see how UBOS pricing aligns with your Stripe fees.

Setting up Stripe credentials in OpenClaw

OpenClaw stores third‑party secrets in its .env file. Add the following variables, replacing the placeholders with your actual keys:

# .env
STRIPE_PUBLISHABLE_KEY=pk_live_XXXXXXXXXXXXXXXX
STRIPE_SECRET_KEY=sk_live_XXXXXXXXXXXXXXXX
STRIPE_WEBHOOK_SECRET=whsec_XXXXXXXXXXXXXXXX

After updating .env, restart the OpenClaw server so the new environment variables are loaded. For a deeper dive into environment management, check the Web app editor on UBOS.

Implementing one‑time payments

Create product and price in Stripe

In the Stripe Dashboard, navigate to Products → Add product. Give it a name (e.g., “Pro Feature Pack”), a description, and click Save product. Then create a price:

  • Currency: USD
  • Amount: 1999 (represents $19.99)
  • Pricing model: One‑time

Note the generated price_XXXXXXXXXXXX ID; you’ll need it in the checkout code.

Checkout session code

Add a new route in OpenClaw (e.g., /api/checkout) that creates a Stripe Checkout Session. Below is a minimal Node.js example using the Stripe SDK:

// routes/checkout.js
const express = require('express');
const router = express.Router();
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);

router.post('/', async (req, res) => {
  const { customerId } = req.body; // OpenClaw tenant ID
  try {
    const session = await stripe.checkout.sessions.create({
      payment_method_types: ['card'],
      line_items: [{
        price: 'price_XXXXXXXXXXXX', // replace with your price ID
        quantity: 1,
      }],
      mode: 'payment',
      success_url: `${process.env.APP_URL}/billing/success?session_id={CHECKOUT_SESSION_ID}`,
      cancel_url: `${process.env.APP_URL}/billing/cancel`,
      client_reference_id: customerId,
    });
    res.json({ url: session.url });
  } catch (err) {
    console.error(err);
    res.status(500).json({ error: 'Stripe checkout failed' });
  }
});

module.exports = router;

Register the route in app.js and protect it with OpenClaw’s authentication middleware. When the frontend calls this endpoint, redirect the user to session.url. For UI components, the Workflow automation studio can help you build a no‑code button that triggers the API call.

Implementing metered billing

Usage records API

Metered billing in Stripe relies on usage records attached to a subscription item. First, create a product with a “metered” price:

  • Pricing model: Metered usage
  • Billing period: Monthly
  • Unit amount: 0.05 (5¢ per unit)

When a tenant consumes a billable action (e.g., API call, generated image), record the usage:

// utils/usageRecorder.js
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);

async function recordUsage(subscriptionItemId, quantity) {
  await stripe.subscriptionItems.createUsageRecord(
    subscriptionItemId,
    {
      quantity,
      timestamp: Math.floor(Date.now() / 1000),
      action: 'increment',
    }
  );
}

module.exports = { recordUsage };

Call recordUsage wherever the billable event occurs. Stripe aggregates usage over the billing period and automatically invoices the customer.

Subscription handling

Create a subscription endpoint that attaches the metered price to the tenant’s Stripe customer:

// routes/subscription.js
router.post('/create', async (req, res) => {
  const { customerId } = req.body;
  try {
    const subscription = await stripe.subscriptions.create({
      customer: customerId,
      items: [{ price: 'price_YYYYYYYYYYYY' }], // metered price ID
      expand: ['latest_invoice.payment_intent'],
    });
    res.json({ subscriptionId: subscription.id });
  } catch (e) {
    console.error(e);
    res.status(500).json({ error: 'Subscription creation failed' });
  }
});

Store subscription.id in OpenClaw’s tenant record so you can reference the subscriptionItemId when recording usage. For a visual overview of subscription lifecycle, see the Enterprise AI platform by UBOS.

Testing the integration

Stripe provides a Test mode with special card numbers (e.g., 4242 4242 4242 4242). Follow these steps:

  1. Set STRIPE_PUBLISHABLE_KEY and STRIPE_SECRET_KEY to the test keys from the Dashboard.
  2. Run the OpenClaw server locally (e.g., npm run dev).
  3. Trigger a one‑time checkout and complete the payment with the test card.
  4. Invoke a metered event and verify the usage record appears in Developers → Usage Records on Stripe.
  5. Check the generated invoice in Billing → Invoices.

For automated testing, you can mock Stripe’s SDK using stripe-mock. Detailed instructions are available in Stripe’s official docs (Stripe Testing Guide).

Deploying to production

When you’re ready to go live, swap the test keys for the live ones and enable webhook signing. Add the following webhook endpoint in OpenClaw to listen for invoice.paid and customer.subscription.deleted events:

// routes/webhook.js
router.post('/', express.raw({type: 'application/json'}), (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) {
    console.log(`⚠️ Webhook signature verification failed.`, err.message);
    return res.sendStatus(400);
  }

  // Handle the event
  switch (event.type) {
    case 'invoice.paid':
      // Mark tenant as active
      break;
    case 'customer.subscription.deleted':
      // Downgrade or suspend tenant
      break;
    default:
      console.log(`Unhandled event type ${event.type}`);
  }

  res.json({received: true});
});

Deploy your OpenClaw app using UBOS’s managed hosting. The host OpenClaw on UBOS page walks you through containerizing the app and connecting it to a production‑grade PostgreSQL instance.

After deployment, monitor payment health via Stripe’s Radar and set up email alerts for failed payments. For a holistic view of your SaaS metrics, consider integrating the AI marketing agents to automate churn analysis.

Conclusion and next steps

By following this guide you now have a fully functional Stripe integration that supports both instant one‑time purchases and scalable metered billing. Your OpenClaw‑based SaaS can start generating revenue immediately while retaining the flexibility to evolve pricing models as your product matures.

Next steps you might explore:

  • Implementing discount coupons via Stripe’s PromotionCode API.
  • Adding a self‑service portal for customers to manage subscriptions.
  • Leveraging the UBOS partner program to co‑sell your solution.
  • Showcasing your implementation in the UBOS portfolio examples to attract new clients.

For any questions, the UBOS community forum and the About UBOS page are great places to start.

Source: Original news article


Andrii Bidochko

CTO UBOS

Andrii Bidochko is an AI entrepreneur and researcher focused on AI agents, reinforcement learning, and autonomous systems. He writes about the technologies shaping the future of machine intelligence, from frontier models and agent architectures to real-world AI applications.

Sign up for our newsletter

Stay up to date with the roadmap progress, announcements and exclusive discounts feel free to sign up with your email.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.