Commet
  • Pricing
Log InTry out
Introducción

Inicio rápido

Integrar con Next.jsIntegrar con RemixIntegrar con NuxtIntegrar con SvelteKitIntegrar con AstroIntegrar con ExpressIntegrar con HonoIntegrar con Bun

Aprender

Recursos

Referencia del SDKVersionado de APIManejo de erroresTestingCLI

Plugins

Better Auth
DocumentaciónRecursosConstruir con AIAPI ReferenceWebhooks

Integrar con Hono

Agrega cobros y pagos a tu aplicación de Hono.

Usa este prompt prearmado para integrar Commet más rápido con asistentes de IA.

Instalar

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

Configurar

.env
COMMET_API_KEY=ck_sandbox_xxx
src/commet.ts
import { Commet } from '@commet/node'

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

Suscribir

src/routes/billing.ts
import { Hono } from 'hono'
import { commet } from '../commet'

const billing = new Hono()

billing.post('/subscribe', async (c) => {
  const { customerId, email } = await c.req.json()

  await commet.customers.create({ email, id: customerId })

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

  return c.json({ checkoutUrl: subscription.data.checkoutUrl })
})

export default billing

Verificar Acceso

src/routes/billing.ts
billing.get('/subscription/:customerId', async (c) => {
  const { data } = await commet.subscriptions.get(c.req.param('customerId'))

  return c.json({ status: data.status })
})

billing.get('/features/:feature/:customerId', async (c) => {
  const { data } = await commet.features.check({
    code: c.req.param('feature'),
    customerId: c.req.param('customerId'),
  })

  return c.json({ allowed: data.allowed })
})

Trackear Uso

src/routes/billing.ts
billing.post('/usage', async (c) => {
  const { customerId } = await c.req.json()

  await commet.usage.track({
    customerId,
    feature: 'api_calls',
    value: 1,
  })

  return c.json({ tracked: true })
})

El uso se agrega y se cobra al final del período.

Portal del Cliente

src/routes/billing.ts
billing.get('/portal', async (c) => {
  const customerId = c.get('customerId')

  const { data } = await commet.portal.getUrl({ customerId })

  return c.redirect(data.portalUrl)
})

Iniciar el Servidor

src/index.ts
import { serve } from '@hono/node-server'
import { Hono } from 'hono'
import billing from './routes/billing'

const app = new Hono()

app.route('/billing', billing)

serve({ fetch: app.fetch, port: 3000 })
src/index.ts
import { Hono } from 'hono'
import billing from './routes/billing'

const app = new Hono()

app.route('/billing', billing)

export default app

Relacionado

  • Suscripciones
  • Trackear Uso
  • Portal del Cliente
  • Referencia del SDK

¿Cómo está esta guía?

Integrar con Express

Agrega cobros y pagos a tu aplicación de Express.

Integrar con Bun

Agrega cobros y pagos a tu aplicación de Bun.

En esta página

Instalar
Configurar
Suscribir
Verificar Acceso
Trackear Uso
Portal del Cliente
Iniciar el Servidor
Relacionado