• Precios
  • Blog
Iniciar sesiónAgendá una demo
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 Nuxt

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

Instala la Commet Skill para que tu agente integre el SDK actual y valide su trabajo contra el contrato vivo de la API.

npx skills add commet-labs/skills --skill commet

Instalar

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

Configurar

.env
COMMET_API_KEY=ck_sandbox_xxx
nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    commetApiKey: process.env.COMMET_API_KEY,
  },
})

Nuxt importa automáticamente desde server/utils/, por lo que el cliente está disponible en todas las rutas del servidor.

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

const config = useRuntimeConfig()

export const commet = new Commet({
  apiKey: config.commetApiKey,
})

Suscribir

customers.create es idempotente — si ya existe un cliente con el mismo id, retorna el registro existente.

server/api/billing/subscribe.post.ts
export default defineEventHandler(async (event) => {
  const { customerId, email } = await readBody(event)

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

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

  return { checkoutUrl: subscription.checkoutUrl ?? null }
})

Verificar Acceso

server/api/billing/access/[customerId].get.ts
export default defineEventHandler(async (event) => {
  const customerId = getRouterParam(event, 'customerId')!

  const subscription = await commet.subscriptions.getActive({ customerId })

  if (!subscription) {
    throw createError({ statusCode: 404, statusMessage: 'No active subscription' })
  }

  const feature = await commet.featureAccess.get({
    code: 'api_calls',
    customerId,
  })

  return {
    status: subscription.status,
    allowed: feature.allowed,
  }
})

Trackear Uso

server/api/billing/usage.post.ts
export default defineEventHandler(async (event) => {
  const { customerId } = await readBody(event)

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

  return { tracked: true }
})

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

Portal del Cliente

server/api/billing/portal.get.ts
export default defineEventHandler(async (event) => {
  const customerId = 'user_123'

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

  return sendRedirect(event, portal.portalUrl)
})

Relacionado

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

¿Cómo está esta guía?

Integrar con Remix

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

Integrar con SvelteKit

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

On this page

Instalar
Configurar
Suscribir
Verificar Acceso
Trackear Uso
Portal del Cliente
Relacionado