Skip to content

Stripe Payments for NestJS SaaS — Subscriptions, Metering & Billing

Integrating Stripe properly takes 2-3 weeks — checkout sessions, webhook signature verification, subscription lifecycle, failed payment retries, proration logic, and customer portal configuration. One missed webhook and your billing state drifts out of sync.

The Cloudrix SaaS Starter Kit ships with a complete Stripe integration built on the official Stripe Node.js SDK. Every webhook event is verified, every subscription state change is handled, and the customer portal is pre-configured. You get checkout, billing, metering, invoices, and plan management — all wired into your NestJS backend and Angular frontend from day one.

Stripe Checkout

Hosted checkout sessions with automatic tax calculation and promo code support. Supports both one-time payments and recurring subscriptions. The session is created server-side with full type safety and redirects the user to Stripe's PCI-compliant payment page.

Webhook Handling

Verified webhook endpoints for subscription lifecycle, payment failures, and disputes. Every event is validated using Stripe's signature verification to prevent spoofing. Idempotent handlers ensure that replayed webhooks never corrupt your billing state.

Customer Portal

Self-service portal for plan changes, payment method updates, and invoice history. Pre-configured with your branding and plan options. Users can upgrade, downgrade, or cancel without contacting support — reducing churn and support tickets.

Usage-Based Billing

Metered billing with usage records. Track API calls, storage, or any custom metric. Usage is reported to Stripe in real-time and aggregated on the invoice at the end of each billing period. Perfect for API-first SaaS products with variable consumption.

Invoices

Automatic invoice generation with PDF downloads and email delivery via Stripe. Invoices include line items, tax breakdowns, and payment status. Hosted invoice pages let customers pay outstanding invoices directly from their email.

Subscriptions

Multi-tier plans with trial periods, upgrades, downgrades, and cancellation flows. Proration is handled automatically when switching plans mid-cycle. Failed payments trigger a retry schedule with dunning emails before the subscription is paused.

How It Works in Code

The Stripe module wraps the official SDK with NestJS dependency injection. Here's how a checkout session is created and a webhook is handled:

// Create a Stripe Checkout session
@Post('checkout')
@UseGuards(JwtAuthGuard)
async createCheckout(@CurrentUser() user: User) {
  const session = await this.stripe.checkout.sessions.create({
    customer: user.stripeCustomerId,
    mode: 'subscription',
    line_items: [{ price: 'price_pro_monthly', quantity: 1 }],
    success_url: '{{FRONTEND_URL}}/billing?success=true',
  });
  return { url: session.url };
}

// Handle webhook events
@Post('webhook')
async handleWebhook(@Req() req: RawBodyRequest) {
  const event = this.stripe.webhooks.constructEvent(
    req.rawBody, req.headers['stripe-signature'], WEBHOOK_SECRET
  );
  await this.billingService.handleEvent(event);
}

What's Included

Stripe Checkout with hosted payment page
Subscription management (create, update, cancel)
Usage-based metering with real-time reporting
Automatic invoice generation with PDF
Customer portal (self-service)
Webhook handling with signature verification
Plan upgrades and downgrades
Proration on mid-cycle plan changes
Failed payment handling with retry logic
Stripe CLI testing setup
Get SaaS Starter Pro — $249

One-time purchase. 14-day money-back guarantee.