home / skills / andrelandgraf / fullstackrecipes / stripe-subscriptions

stripe-subscriptions skill

/skills/stripe-subscriptions

This skill helps you implement a complete Stripe subscriptions workflow with webhooks, plan gating via feature flags, and a billing portal for seamless billing.

npx playbooks add skill andrelandgraf/fullstackrecipes --skill stripe-subscriptions

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.9 KB
---
name: stripe-subscriptions
description: Complete subscription billing system with Stripe integration, feature flags for plan gating, webhook handling, and billing portal.
---

# Stripe Subscriptions

Complete subscription billing system with Stripe integration, feature flags for plan gating, webhook handling, and billing portal.

## Prerequisites

Complete these recipes first (in order):

### Type-Safe Environment Configuration

Type-safe environment variable validation using Zod with a Drizzle-like schema API. Supports server/public fields, feature flags, either-or constraints, and client-side protection.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/config-schema-setup
```

### Neon + Drizzle Setup

Connect a Next.js app to Neon Postgres using Drizzle ORM with optimized connection pooling for Vercel serverless functions.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/neon-drizzle-setup
```

### Pino Logging Setup

Configure structured logging with Pino. Outputs human-readable colorized logs in development and structured JSON in production for log aggregation services.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/pino-logging-setup
```

## Cookbook - Complete These Recipes in Order

### Feature Flags with Flags SDK

Implement feature flags using the Vercel Flags SDK with server-side evaluation, environment-based toggles, and Vercel Toolbar integration.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/feature-flags-setup
```

### Stripe Subscriptions DB Sync

Complete subscription system with Stripe, Vercel Flags for plan configuration, webhook handling for syncing subscription state to Postgres, usage tracking, and billing portal integration.

```bash
curl -H "Accept: text/markdown" https://fullstackrecipes.com/api/recipes/stripe-sync
```

Overview

This skill implements a complete subscription billing system integrated with Stripe, including plan gating via feature flags, webhook-driven sync to your database, and a customer billing portal. It bundles production-ready patterns and step-by-step recipes to connect Stripe, Postgres, and feature flagging for reliable recurring billing. The implementation is TypeScript-first and designed for full-stack Next.js apps.

How this skill works

The system wires Stripe checkout, billing portal sessions, and webhook handlers to keep subscription state synchronized with a Postgres database using Drizzle. Feature flags control plan availability and gating logic at runtime, so you can enable or disable plans without code releases. Webhooks from Stripe update subscription and invoice records, while usage tracking and billing portal links let customers manage billing directly.

When to use it

  • You need recurring billing with metered or tiered plans in a Next.js app.
  • You want server-side feature gating for plans without redeploying.
  • You require reliable subscription state in Postgres for product logic.
  • You want a ready-made webhook and billing portal integration.
  • You need production-ready patterns for logging, env validation, and DB pooling.

Best practices

  • Validate environment variables with a type-safe schema before startup.
  • Use server-side feature flag evaluation to enforce plan gating.
  • Verify Stripe webhook signatures and idempotency to avoid duplicate processing.
  • Store minimal Stripe IDs in Postgres and derive state from synced records.
  • Emit structured logs for billing events and webhook processing for auditability.

Example use cases

  • Offer tiered SaaS plans with usage-based billing and a self-serve checkout flow.
  • Gate premium features by checking feature flags on session or API routes.
  • Automatically sync subscription cancellations and renewals from Stripe to your app database.
  • Provide customers a link to Stripe Billing Portal for invoices and payment updates.
  • Track metered feature usage server-side and report it to Stripe for billing.

FAQ

Do I need a specific database or ORM?

No, but the recipes use Postgres with Drizzle ORM and Neon-compatible pooling for serverless environments; you can adapt the syncing logic to other databases.

How are feature flags evaluated?

Feature flags are evaluated server-side using the Flags SDK, allowing environment-based toggles and integration with your plan configuration without client-side exposure.