Installation

Node.js Setup

Use Commet SDK in any Node.js or TypeScript project

Install

pnpm add @commet/node
npm install @commet/node
yarn add @commet/node
bun add @commet/node

Configure

.env
COMMET_API_KEY=ck_sandbox_xxx

Initialize

lib/commet.ts
import { Commet } from '@commet/node'

export const commet = new Commet({
  apiKey: process.env.COMMET_API_KEY!,
  environment: 'sandbox',
})

Use

// Create customer
const customer = await commet.customers.create({
  email: 'billing@acme.com',
  externalId: 'user_123',
})

// Create subscription and get payment link
const subscription = await commet.subscriptions.create({
  externalId: 'user_123',
  planCode: 'pro',
})

// Redirect user to pay
redirect(subscription.data.checkoutUrl)

Check Subscription

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

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

Check Features

const { data } = await commet.features.check('custom_branding', 'user_123')

if (!data.allowed) {
  redirect('/upgrade')
}

How is this guide?