Subscriptions

Manage subscriptions with the plan-first model

Each customer can only have one active subscription at a time.

Create

Returns a checkoutUrl - redirect user there to complete payment.

const subscription = await commet.subscriptions.create({
  externalId: 'user_123',
  planCode: 'pro',
})

redirect(subscription.data.checkoutUrl)

Get

Returns full subscription details including feature usage summary.

const sub = await commet.subscriptions.get({ externalId: 'user_123' })

if (sub.data?.status === 'active') {
  // User has paid
}

Change Plan

Proration is automatic - credits unused time and charges for new plan.

await commet.subscriptions.changePlan('sub_xxx', { planCode: 'enterprise' })

Cancel

Cancels at end of current period by default.

await commet.subscriptions.cancel('sub_xxx')

How is this guide?