Installation
Node.js Setup
Use Commet SDK in any Node.js or TypeScript project
Install
pnpm add @commet/nodenpm install @commet/nodeyarn add @commet/nodebun add @commet/nodeConfigure
COMMET_API_KEY=ck_sandbox_xxxInitialize
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')
}Related
How is this guide?