- Updated: March 22, 2026
- 6 min read
Integrating Automated Billing into Your OpenClaw‑Powered SaaS with UBOS
Answer: To add automated subscription billing to an OpenClaw‑powered multi‑tenant SaaS, you integrate Stripe or Paddle via UBOS, extend the tenant model to store subscription data, configure webhooks for real‑time events, and adjust the boilerplate to handle upgrades, downgrades, and cancellations—all while leveraging UBOS’s workflow automation studio for seamless revenue generation.
1. Introduction
Building a SaaS product on top of OpenClaw gives you a robust multi‑tenant foundation, but without a reliable billing layer you’ll never monetize your effort. This guide walks developers and technical founders through a step‑by‑step integration of Stripe and Paddle using the UBOS platform overview. By the end, you’ll have a production‑ready revenue‑generation workflow that scales with your user base.
2. Prerequisites
OpenClaw‑powered SaaS setup
- OpenClaw repository cloned and running locally.
- Multi‑tenant architecture already in place (tenant identification via sub‑domains or headers).
- Access to the UBOS Web app editor on UBOS for quick UI tweaks.
UBOS environment
- UBOS CLI installed (
npm i -g ubos-cli). - Connected to your UBOS partner program account for deployment.
- Node.js ≥ 18 and a PostgreSQL instance (UBOS default).
Stripe/Paddle accounts
- Live or test Stripe account with API keys.
- Live or test Paddle account with vendor ID and API secret.
- At least one subscription product created in each platform.
3. Overview of the Revenue‑Generation Workflow
The billing flow can be visualized in four stages:
- Plan selection: Tenant UI presents Stripe/Paddle pricing tiers.
- Checkout & subscription creation: UBOS calls the provider SDK, stores the subscription ID.
- Webhook processing: Provider notifies UBOS of events (payment succeeded, trial ending, cancellation).
- Access control: Tenant middleware checks subscription status before granting premium features.
UBOS’s Workflow automation studio can orchestrate webhook handling, reducing custom code and ensuring reliability.
4. Setting up Stripe Integration
4.1 Installing Stripe SDK
npm install stripe@latestImport the client in your UBOS service layer:
import Stripe from "stripe";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
apiVersion: "2023-10-16",
});4.2 Configuring Webhooks
Expose a webhook endpoint in /api/webhooks/stripe. Register the URL in the Stripe Dashboard (Stripe webhook docs).
app.post("/api/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).send(`Webhook Error: ${err.message}`);
}
// Pass event to UBOS workflow
await handleStripeEvent(event);
res.json({received: true});
});4.3 Creating Subscription Plans
Define plans in the Stripe Dashboard or via API. Example for a “Pro” tier:
const product = await stripe.products.create({
name: "Pro Plan",
});
const price = await stripe.prices.create({
unit_amount: 1999,
currency: "usd",
recurring: {interval: "month"},
product: product.id,
});Store price.id in a UBOS Plan table for lookup during checkout.
5. Setting up Paddle Integration
5.1 Installing Paddle SDK
npm install @paddle/paddle-nodeInitialize the client:
import Paddle from "@paddle/paddle-node";
const paddle = new Paddle({
vendorId: process.env.PADDLE_VENDOR_ID,
apiKey: process.env.PADDLE_API_KEY,
});5.2 Configuring Webhooks
Set up a webhook endpoint at /api/webhooks/paddle and register it in the Paddle dashboard (Paddle webhook docs).
app.post("/api/webhooks/paddle", async (req, res) => {
const {alert_name, subscription_id, status} = req.body;
await handlePaddleEvent({alert_name, subscription_id, status});
res.sendStatus(200);
});5.3 Creating Subscription Plans
Paddle plans are created in the vendor dashboard. Capture the plan_id and store it alongside the Stripe price IDs for unified lookup.
6. Modifying the Multi‑Tenant Boilerplate for Billing
6.1 Tenant Identification
UBOS already injects a tenantId into each request via middleware. Ensure the billing service reads this value:
const tenantId = req.headers["x-tenant-id"];6.2 Storing Subscription Data
Add a subscriptions table (PostgreSQL) with the following columns:
| Column | Type | Description |
|---|---|---|
| id | UUID | Primary key |
| tenant_id | UUID | FK to tenants table |
| provider | VARCHAR | “stripe” or “paddle” |
| subscription_id | VARCHAR | Provider‑specific ID |
| status | VARCHAR | active, past_due, canceled, etc. |
| current_period_end | TIMESTAMP | When the billing cycle ends |
6.3 Handling Upgrades, Downgrades, and Cancellations
Expose API endpoints that call the provider SDK and update the subscriptions table. Example for a Stripe upgrade:
async function upgradePlan(tenantId, newPriceId) {
const sub = await db.subscriptions.findOne({tenant_id: tenantId, provider: "stripe"});
await stripe.subscriptions.update(sub.subscription_id, {
items: [{price: newPriceId}],
proration_behavior: "create_prorations",
});
// Update local record
await db.subscriptions.update({id: sub.id}, {status: "active"});
}Similar logic applies to Paddle using paddle.subscription.update. For cancellations, set the subscription to cancel at period end and mark the local status as canceled.
7. Testing the Billing Flow
UBOS provides a UBOS templates for quick start that include mock tenant data. Follow these steps:
- Run
npm run devand use Stripe’s test cards (e.g., 4242 4242 4242 4242). - Trigger a webhook event using
stripe trigger invoice.payment_succeeded. - Verify that the
subscriptionstable reflects the new status. - Repeat for Paddle using the sandbox environment.
Automate these checks in CI with the Enterprise AI platform by UBOS to catch regressions before release.
8. Deploying to Production
When you’re confident the flow works locally, push the changes to your UBOS repository and run:
ubos deploy --env=productionUBOS will provision the necessary environment variables (Stripe secret keys, Paddle credentials) securely. Review the UBOS pricing plans to ensure your chosen tier supports the required number of webhook calls.
9. Conclusion and Next Steps
Integrating automated billing into an OpenClaw‑powered SaaS is now a repeatable process:
- Set up provider SDKs (Stripe or Paddle).
- Configure secure webhooks via UBOS workflow automation.
- Extend the tenant model to persist subscription state.
- Implement upgrade/downgrade/cancel endpoints.
- Test thoroughly with sandbox environments before production deployment.
With the billing layer in place, you can focus on delivering value‑added features. Consider exploring UBOS’s AI marketing agents to automate onboarding emails, or the Web app editor on UBOS to build a custom subscription dashboard for your tenants.
10. Related UBOS Guide
For a deeper dive into hosting OpenClaw on UBOS, see the dedicated guide on hosting OpenClaw with UBOS. It covers container orchestration, scaling strategies, and best practices for multi‑tenant isolation.