agentleFS
param087param087/saas-starter-skills/skills/subscription-billing/SKILL.md

subscription-billing

Skill2 starsChanged 6 months agoMITView on GitHub

Use when turning payment state into product behavior — model plans and subscription status in the DB, enforce plan limits and feature entitlements server-side, and gate features with a single typed check.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Call assertCanCreateProject inside the create action — the UI may also read the limit to show a paywall (pairs with billing-and-pricing UI).

    line 55

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Subscription & Billing Logic

Overview

Once payments-stripe syncs subscription state into your database, you need to turn that state into behavior: which features are unlocked, which limits apply, what happens when a plan lapses. Model plans as data, store the org's current plan + status, and expose one entitlement(org) check the whole app uses. Enforce limits on the server, where they can't be bypassed.

When to use

  • Different plans unlock different features or limits (seats, projects, API calls).
  • You need paywalls, usage caps, or "upgrade to continue" gates.
  • Handling trials, past-due, and cancelled states gracefully.

Model plans as data

// src/server/billing/plans.ts
export type PlanId = "free" | "pro" | "scale";

export const PLANS = {
  free:  { name: "Free",  priceId: null,            seats: 1,  projects: 3,   apiCallsPerMonth: 1_000 },
  pro:   { name: "Pro",   priceId: "price_pro",     seats: 10, projects: 50,  apiCallsPerMonth: 100_000 },
  scale: { name: "Scale", priceId: "price_scale",   seats: 50, projects: Infinity, apiCallsPerMonth: 1_000_000 },
} as const satisfies Record<PlanId, { name: string; priceId: string | null; seats: number; projects: number; apiCallsPerMonth: number }>;

Store on the org (synced from Stripe): planId, subscriptionStatus (active | trialing | past_due | canceled), currentPeriodEnd.

Enforce entitlements server-side

import { PLANS } from "@/server/billing/plans";

export function planFor(org: { planId: PlanId; subscriptionStatus: string }) {
  // lapsed subscriptions fall back to free limits
  const active = ["active", "trialing"].includes(org.subscriptionStatus);
  return active ? PLANS[org.planId] : PLANS.free;
}

export async function assertCanCreateProject(org) {
  const limit = planFor(org).projects;
  const count = await countProjects(org.id);
  if (count >= limit) {
    const e = new Error("Project limit reached for your plan");
    (e as any).status = 402; // Payment Required → show upgrade prompt
    throw e;
  }
}

Call assertCanCreateProject inside the create action — the UI may also read the limit to show a paywall (pairs with billing-and-pricing UI).

Pitfalls

  • Enforcing limits only in the UI — disable the button and check on the server; the endpoint is the real gate.
  • Ignoring past_due/canceled — decide the grace policy explicitly; default to downgrading to free limits.
  • Hard-coding plan rules across the app — centralize in PLANS; one edit changes every gate.
  • Counting usage without org_id scope — always count within the tenant.
  • No trial handling — treat trialing as active until currentPeriodEnd.

Hand-off

Typed entitlements enforced server-side. The pricing/paywall UI (billing-and-pricing in saas-ui-skills) reads the same PLANS; payments-stripe keeps the status fresh.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.