Skip to main content

Overview

The PlansClient provides read-only access to billing plans. It’s used by merchants’ frontends to render pricing pages and plan selectors. Plan mutations are handled via revstack.admin.plans.

Methods

list()

List plans with optional filters.
const response = await revstack.plans.list(params);
params
ListPlansParams
Filter and pagination parameters.
response
PaginatedResponse<Plan>
A paginated list of plans.
Example:
// Fetch all public plans for the pricing page
const { data: plans } = await revstack.plans.list({
  status: "active",
});

for (const plan of plans) {
  console.log(`${plan.name}: ${plan.slug}`);
}

get()

Retrieve a single plan by ID, including its nested prices and entitlements.
const plan = await revstack.plans.get(planId);
planId
string
required
The plan’s unique identifier.Example: "plan_pro" or "plan_abc123"
plan
Plan
The plan with populated prices[] and entitlements[].
Example:
// Get a specific plan with prices and entitlements
const proPlan = await revstack.plans.get("plan_pro");

console.log(proPlan.name); // "Pro"
console.log(proPlan.prices); // [{ amount: 4900, billingInterval: "month" }]
console.log(proPlan.entitlements); // [{ entitlementId: "ent_api", valueLimit: 10000 }]

Common Use Cases

Pricing Page

// Fetch all active plans for a pricing page
async function getPricingPlans() {
  const { data: plans } = await revstack.plans.list({
    status: "active",
  });
  
  return plans.map(plan => ({
    name: plan.name,
    slug: plan.slug,
    description: plan.description,
    prices: plan.prices?.map(price => ({
      amount: price.amount / 100, // Convert cents to dollars
      currency: price.currency,
      interval: price.billingInterval,
    })),
  }));
}

Plan Comparison Table

// Build a feature comparison matrix
async function buildComparisonMatrix() {
  const { data: plans } = await revstack.plans.list({
    status: "active",
  });
  
  // Get detailed plan info with entitlements
  const detailedPlans = await Promise.all(
    plans.map(p => revstack.plans.get(p.id))
  );
  
  return detailedPlans.map(plan => ({
    name: plan.name,
    features: plan.entitlements?.map(ent => ({
      id: ent.entitlementId,
      limit: ent.valueLimit,
      enabled: ent.valueBool,
    })),
  }));
}

Plan Selector UI

// Generate plan options for a dropdown
async function getPlanOptions() {
  const { data: plans } = await revstack.plans.list({
    status: "active",
  });
  
  return plans.map(plan => ({
    value: plan.id,
    label: plan.name,
    monthlyPrice: plan.prices?.find(
      p => p.billingInterval === "month"
    )?.amount,
  }));
}

Find Default Plan

// Get the default plan for new customers
async function getDefaultPlan() {
  const { data: plans } = await revstack.plans.list();
  return plans.find(plan => plan.isDefault);
}

Check Plan Features

// Check if a plan includes a specific feature
async function planHasFeature(
  planId: string,
  featureSlug: string
): Promise<boolean> {
  const plan = await revstack.plans.get(planId);
  
  return plan.entitlements?.some(
    ent => ent.entitlementId === featureSlug
  ) ?? false;
}

Build docs developers (and LLMs) love