Skip to main content

Overview

The SubscriptionsClient handles creating, retrieving, canceling, and upgrading/downgrading customer subscriptions.

Methods

create()

Create a new subscription for a customer.
const subscription = await revstack.subscriptions.create(params);
params
CreateSubscriptionParams
required
Subscription creation parameters.
subscription
Subscription
The newly created subscription.
Example:
const subscription = await revstack.subscriptions.create({
  customerId: "usr_abc123",
  planId: "plan_pro",
});

console.log(`Subscription ${subscription.id} created`);

get()

Retrieve a subscription by ID.
const subscription = await revstack.subscriptions.get(subscriptionId);
subscriptionId
string
required
The subscription’s unique identifier.Example: "sub_abc123"
subscription
Subscription
The subscription record.
Example:
const subscription = await revstack.subscriptions.get("sub_abc123");
console.log(subscription.status); // "active"

list()

List subscriptions with optional filters.
const response = await revstack.subscriptions.list(params);
params
ListSubscriptionsParams
Filter and pagination parameters.
response
PaginatedResponse<Subscription>
A paginated list of subscriptions.
Example:
// Get all active subscriptions for a customer
const { data: subscriptions } = await revstack.subscriptions.list({
  customerId: "usr_abc123",
  status: "active",
});

cancel()

Cancel an active subscription. The subscription will remain active until the end of the current billing period.
const subscription = await revstack.subscriptions.cancel(subscriptionId);
subscriptionId
string
required
The subscription to cancel.Example: "sub_abc123"
subscription
Subscription
The updated subscription with canceled status.
Example:
const subscription = await revstack.subscriptions.cancel("sub_abc123");
console.log(subscription.status); // "canceled"

changePlan()

Change the plan of an existing subscription (upgrade or downgrade). Proration is handled automatically by the billing engine.
const subscription = await revstack.subscriptions.changePlan(
  subscriptionId,
  params
);
subscriptionId
string
required
The subscription to modify.
params
ChangePlanParams
required
The new plan parameters.
subscription
Subscription
The updated subscription.
Example:
// Upgrade a customer from Pro to Enterprise
const subscription = await revstack.subscriptions.changePlan(
  "sub_abc123",
  { newPlanId: "plan_enterprise" }
);

console.log(`Upgraded to ${subscription.planId}`);

Build docs developers (and LLMs) love