Stripe
Configure Stripe for billing, subscriptions, and the customer billing portal.
This page covers the legacy Stripe integration. Per ADR 2026-09-26, card payments worldwide moved to Creem — a merchant of record that collects and remits sales tax/VAT itself. Stripe is retired from new work; its code stays only for subscriptions, the billing portal, the licence webhook, and checkouts opened before the switch. Nothing new should be built on it. For the current card rail, see Creem.
Prerequisites
- Stripe CLI installed:
npm install -g stripe
Step 1: Set environment variables
STRIPE_SECRET_KEY=sk_live_xxxxxxxxxxxxxxxxxxxx
STRIPE_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxxxxxxUse sk_test_ keys during development.
Step 2: Create products in Stripe
Nebutra's billing model maps to three Stripe products:
# Create products
stripe products create --name="Nebutra FREE" --description="Free tier"
stripe products create --name="Nebutra PRO" --description="$29/month"
stripe products create --name="Nebutra ENTERPRISE" --description="Custom pricing"
# Create prices
stripe prices create \
--product=prod_xxx \
--unit-amount=2900 \
--currency=usd \
--recurring[interval]=monthStep 3: Configure webhook endpoint
In your Stripe Dashboard: Developers → Webhooks → Add endpoint
- URL:
https://api.nebutra.com/api/webhooks/stripe - Events to listen for:
checkout.session.completedcustomer.subscription.createdcustomer.subscription.updatedcustomer.subscription.deletedinvoice.paidinvoice.payment_failed
Test webhooks locally
stripe listen --forward-to localhost:3000/api/webhooks/stripeStep 4: Webhook handler
The Stripe webhook handler is pre-built in the monorepo — as a Hono route on the API gateway, not a Next.js route handler:
const stripeWebhookRoute = createRoute({ method: "post", path: "/stripe" /* … */ });
stripeWebhookRoutes.openapi(stripeWebhookRoute, async (c) => {
const body = await c.req.text();
const sig = c.req.header("stripe-signature");
const event = stripe.webhooks.constructEvent(body, sig!, process.env.STRIPE_WEBHOOK_SECRET!);
await handleStripeEvent(event, stripe, prisma);
return c.json({ received: true });
});Mounted at app.route("/api/webhooks", stripeWebhookRoutes) in backends/gateway/src/app.ts, so the public path is POST /api/webhooks/stripe. There is no @nebutra/billing/stripe webhook-handling export — application code does not call into this route; it only reads what it wrote (subscription status, payment orders).
Step 5: Billing portal
Customers can manage their subscription via the Stripe customer portal, using createBillingPortalSession from @nebutra/billing:
import { createBillingPortalSession } from "@nebutra/billing";
const session = await createBillingPortalSession(
org.stripeCustomerId,
`${process.env.WEB_URL}/settings/billing`,
);
redirect(session.url);Stripe test cards
| Card number | Scenario |
|---|---|
4242 4242 4242 4242 | Successful payment |
4000 0000 0000 9995 | Insufficient funds |
4000 0025 0000 3155 | 3D Secure authentication |
Use any future expiry date and any 3-digit CVC.
Related
How is this guide?
Last updated on