@commet/node 8.0.1 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/index.d.mts +514 -206
- package/dist/index.d.ts +514 -206
- package/dist/index.js +202 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +202 -88
- package/dist/index.mjs.map +1 -1
- package/docs/README.md +20 -0
- package/docs/ai-onboarding/ai-onboarding.md +90 -0
- package/docs/ai-onboarding/billing-best-practices-skill.md +29 -0
- package/docs/ai-onboarding/commet-skill.md +58 -0
- package/docs/ai-onboarding/mcp-server.md +207 -0
- package/docs/ai-onboarding/meta.json +17 -0
- package/docs/ai-onboarding/pricing-models-skill.md +29 -0
- package/docs/ai-onboarding/subscription-patterns-skill.md +29 -0
- package/docs/api-reference/addons.md +127 -0
- package/docs/api-reference/api-keys.md +57 -0
- package/docs/api-reference/credit-packs.md +80 -0
- package/docs/api-reference/customers.md +274 -0
- package/docs/api-reference/feature-access.md +36 -0
- package/docs/api-reference/features.md +94 -0
- package/docs/api-reference/generated-webhooks.md +120 -0
- package/docs/api-reference/index.md +31 -0
- package/docs/api-reference/invoices.md +123 -0
- package/docs/api-reference/markets.md +92 -0
- package/docs/api-reference/meta.json +7 -0
- package/docs/api-reference/offers.md +104 -0
- package/docs/api-reference/payments.md +106 -0
- package/docs/api-reference/payouts.md +66 -0
- package/docs/api-reference/plan-groups.md +157 -0
- package/docs/api-reference/plans.md +358 -0
- package/docs/api-reference/portal.md +30 -0
- package/docs/api-reference/promo-codes.md +86 -0
- package/docs/api-reference/provisioning.md +19 -0
- package/docs/api-reference/quota.md +120 -0
- package/docs/api-reference/seats.md +123 -0
- package/docs/api-reference/subscriptions.md +387 -0
- package/docs/api-reference/test-clock.md +59 -0
- package/docs/api-reference/transactions.md +78 -0
- package/docs/api-reference/usage.md +83 -0
- package/docs/documentation/api-versioning.md +100 -0
- package/docs/documentation/better-auth.md +361 -0
- package/docs/documentation/choose-a-billing-model.md +38 -0
- package/docs/documentation/cli.md +1024 -0
- package/docs/documentation/create-api-key.md +47 -0
- package/docs/documentation/customers/customer-credits.md +48 -0
- package/docs/documentation/customers/customer-portal.md +107 -0
- package/docs/documentation/customers/manage-customers.md +346 -0
- package/docs/documentation/customers/meta.json +5 -0
- package/docs/documentation/error-handling.md +239 -0
- package/docs/documentation/examples.md +37 -0
- package/docs/documentation/finance/acceptable-use.md +145 -0
- package/docs/documentation/finance/finance-overview.md +32 -0
- package/docs/documentation/finance/local-currency-taxes.md +40 -0
- package/docs/documentation/finance/merchant-of-record.md +48 -0
- package/docs/documentation/finance/meta.json +13 -0
- package/docs/documentation/finance/payouts-verification.md +186 -0
- package/docs/documentation/finance/payouts.md +41 -0
- package/docs/documentation/finance/supported-countries.md +28 -0
- package/docs/documentation/go/integrate-with-encore.md +229 -0
- package/docs/documentation/go/integrate-with-go.md +258 -0
- package/docs/documentation/go/meta.json +5 -0
- package/docs/documentation/introduction.md +58 -0
- package/docs/documentation/invoicing/handle-failed-payments.md +283 -0
- package/docs/documentation/invoicing/invoices-and-billing-cycles.md +73 -0
- package/docs/documentation/invoicing/manage-invoices.md +340 -0
- package/docs/documentation/invoicing/meta.json +9 -0
- package/docs/documentation/java/integrate-with-java.md +117 -0
- package/docs/documentation/java/meta.json +5 -0
- package/docs/documentation/meta.json +36 -0
- package/docs/documentation/nodejs/integrate-with-astro.md +129 -0
- package/docs/documentation/nodejs/integrate-with-bun.md +113 -0
- package/docs/documentation/nodejs/integrate-with-express.md +127 -0
- package/docs/documentation/nodejs/integrate-with-hono.md +141 -0
- package/docs/documentation/nodejs/integrate-with-nextjs.md +118 -0
- package/docs/documentation/nodejs/integrate-with-nuxt.md +125 -0
- package/docs/documentation/nodejs/integrate-with-remix.md +136 -0
- package/docs/documentation/nodejs/integrate-with-sveltekit.md +127 -0
- package/docs/documentation/nodejs/meta.json +14 -0
- package/docs/documentation/payments/accept-one-time-payments.md +314 -0
- package/docs/documentation/payments/meta.json +10 -0
- package/docs/documentation/payments/payment-orchestration.md +43 -0
- package/docs/documentation/payments/payment-providers.md +59 -0
- package/docs/documentation/payments/transactions-refunds-and-retries.md +199 -0
- package/docs/documentation/php/integrate-with-laravel.md +222 -0
- package/docs/documentation/php/integrate-with-php.md +103 -0
- package/docs/documentation/php/integrate-with-symfony.md +214 -0
- package/docs/documentation/php/meta.json +9 -0
- package/docs/documentation/plans/add-ons.md +257 -0
- package/docs/documentation/plans/balance-and-top-ups.md +169 -0
- package/docs/documentation/plans/configure-features.md +335 -0
- package/docs/documentation/plans/consumption-models.md +93 -0
- package/docs/documentation/plans/create-plans.md +162 -0
- package/docs/documentation/plans/credit-packs.md +89 -0
- package/docs/documentation/plans/meta.json +14 -0
- package/docs/documentation/plans/one-time-payments.md +142 -0
- package/docs/documentation/plans/plan-groups.md +31 -0
- package/docs/documentation/platform/custom-domains.md +27 -0
- package/docs/documentation/platform/dashboard-metrics-and-events.md +25 -0
- package/docs/documentation/platform/members-and-permissions.md +21 -0
- package/docs/documentation/platform/meta.json +10 -0
- package/docs/documentation/platform/organization-settings.md +29 -0
- package/docs/documentation/python/integrate-with-django.md +161 -0
- package/docs/documentation/python/integrate-with-fastapi.md +164 -0
- package/docs/documentation/python/integrate-with-flask.md +153 -0
- package/docs/documentation/python/integrate-with-python.md +90 -0
- package/docs/documentation/python/meta.json +10 -0
- package/docs/documentation/sales/card-promotions.md +41 -0
- package/docs/documentation/sales/introductory-offers.md +64 -0
- package/docs/documentation/sales/meta.json +13 -0
- package/docs/documentation/sales/offers.md +65 -0
- package/docs/documentation/sales/promo-codes.md +65 -0
- package/docs/documentation/sales/promotional-offers.md +58 -0
- package/docs/documentation/sales/regional-prices.md +100 -0
- package/docs/documentation/sales/trial-periods.md +88 -0
- package/docs/documentation/sdk-reference.md +68 -0
- package/docs/documentation/subscriptions/manage-subscriptions.md +505 -0
- package/docs/documentation/subscriptions/meta.json +9 -0
- package/docs/documentation/subscriptions/plan-grants.md +132 -0
- package/docs/documentation/subscriptions/upgrade-and-downgrade-plans.md +35 -0
- package/docs/documentation/testing-sandbox.md +251 -0
- package/docs/documentation/usage/ai-token-billing.md +294 -0
- package/docs/documentation/usage/meta.json +10 -0
- package/docs/documentation/usage/quota-management.md +341 -0
- package/docs/documentation/usage/seat-management.md +377 -0
- package/docs/documentation/usage/track-usage.md +282 -0
- package/docs/errors/addon_already_active.md +22 -0
- package/docs/errors/addon_has_activations.md +22 -0
- package/docs/errors/addon_not_active.md +22 -0
- package/docs/errors/addon_not_found.md +22 -0
- package/docs/errors/already_has_active_subscription.md +22 -0
- package/docs/errors/already_scheduled.md +22 -0
- package/docs/errors/api_key_not_found.md +22 -0
- package/docs/errors/card_promotions_not_available.md +22 -0
- package/docs/errors/charge_failed.md +22 -0
- package/docs/errors/charge_in_progress.md +22 -0
- package/docs/errors/claim_not_pending.md +22 -0
- package/docs/errors/credit_pack_not_found.md +22 -0
- package/docs/errors/customer_not_found.md +22 -0
- package/docs/errors/duplicate.md +22 -0
- package/docs/errors/endpoint_deprecated.md +22 -0
- package/docs/errors/endpoint_not_available.md +22 -0
- package/docs/errors/feature_already_exists.md +22 -0
- package/docs/errors/feature_disabled.md +22 -0
- package/docs/errors/feature_in_use.md +22 -0
- package/docs/errors/feature_not_found.md +22 -0
- package/docs/errors/feature_not_in_plan.md +22 -0
- package/docs/errors/forbidden.md +22 -0
- package/docs/errors/free_plan_change_not_supported.md +22 -0
- package/docs/errors/idempotency_in_progress.md +22 -0
- package/docs/errors/idempotency_key_mismatch.md +22 -0
- package/docs/errors/idempotency_unavailable.md +22 -0
- package/docs/errors/included_limit_reached.md +22 -0
- package/docs/errors/index.md +89 -0
- package/docs/errors/insufficient_balance.md +22 -0
- package/docs/errors/insufficient_credits.md +22 -0
- package/docs/errors/insufficient_seats.md +22 -0
- package/docs/errors/internal_error.md +22 -0
- package/docs/errors/invalid_json.md +22 -0
- package/docs/errors/invalid_subscription_status.md +22 -0
- package/docs/errors/invoice_not_found.md +22 -0
- package/docs/errors/market_group_in_use.md +22 -0
- package/docs/errors/market_group_not_found.md +22 -0
- package/docs/errors/market_in_use.md +22 -0
- package/docs/errors/market_not_found.md +22 -0
- package/docs/errors/missing_regional_price.md +22 -0
- package/docs/errors/model_not_found.md +22 -0
- package/docs/errors/no_active_subscription.md +22 -0
- package/docs/errors/no_change_requested.md +22 -0
- package/docs/errors/no_outstanding_invoice.md +22 -0
- package/docs/errors/no_payment_method.md +22 -0
- package/docs/errors/no_prices_configured.md +22 -0
- package/docs/errors/not_found.md +22 -0
- package/docs/errors/not_scheduled_for_cancellation.md +22 -0
- package/docs/errors/offer_not_applicable.md +22 -0
- package/docs/errors/offer_not_found.md +22 -0
- package/docs/errors/one_time_subscription_not_cancelable.md +22 -0
- package/docs/errors/organization_already_claimed.md +22 -0
- package/docs/errors/payment_failed.md +22 -0
- package/docs/errors/payment_method_not_found.md +22 -0
- package/docs/errors/payment_not_cancelable.md +22 -0
- package/docs/errors/payment_not_found.md +22 -0
- package/docs/errors/payouts_not_available_in_sandbox.md +22 -0
- package/docs/errors/plan_change_scheduled.md +22 -0
- package/docs/errors/plan_group_not_found.md +22 -0
- package/docs/errors/plan_not_found.md +22 -0
- package/docs/errors/plan_unavailable.md +22 -0
- package/docs/errors/plans_not_in_same_group.md +22 -0
- package/docs/errors/price_in_use.md +22 -0
- package/docs/errors/price_not_found.md +22 -0
- package/docs/errors/pricing_mode_mismatch.md +22 -0
- package/docs/errors/promo_code_expired.md +22 -0
- package/docs/errors/promo_code_not_found.md +22 -0
- package/docs/errors/provider_unsupported.md +22 -0
- package/docs/errors/rate_limited.md +22 -0
- package/docs/errors/sandbox_only.md +22 -0
- package/docs/errors/seat_limit_exceeded.md +22 -0
- package/docs/errors/subscription_activation_failed.md +22 -0
- package/docs/errors/subscription_already_canceled.md +22 -0
- package/docs/errors/subscription_cancel_failed.md +22 -0
- package/docs/errors/subscription_creation_failed.md +22 -0
- package/docs/errors/subscription_has_open_dispute.md +22 -0
- package/docs/errors/subscription_not_active.md +22 -0
- package/docs/errors/subscription_not_found.md +22 -0
- package/docs/errors/subscription_required.md +22 -0
- package/docs/errors/subscription_uncancel_failed.md +22 -0
- package/docs/errors/transaction_not_found.md +22 -0
- package/docs/errors/unauthorized.md +22 -0
- package/docs/errors/validation_error.md +22 -0
- package/docs/errors/webhook_not_found.md +22 -0
- package/docs/errors.md +34 -0
- package/docs/getting-started.md +35 -0
- package/docs/knowledge-base/how-do-balance-and-top-ups-work.md +22 -0
- package/docs/knowledge-base/how-do-credits-credit-packs-and-customer-credits-differ.md +20 -0
- package/docs/knowledge-base/how-do-discounts-work.md +65 -0
- package/docs/knowledge-base/how-do-free-plans-work-without-payment.md +88 -0
- package/docs/knowledge-base/how-do-monthly-quarterly-and-yearly-billing-work.md +77 -0
- package/docs/knowledge-base/how-do-offers-promo-codes-and-card-promotions-work-together.md +20 -0
- package/docs/knowledge-base/how-do-trial-periods-work.md +54 -0
- package/docs/knowledge-base/how-does-billing-work.md +73 -0
- package/docs/knowledge-base/how-does-payment-routing-work.md +17 -0
- package/docs/knowledge-base/how-does-quota-based-billing-work.md +106 -0
- package/docs/knowledge-base/how-does-seat-based-billing-work.md +88 -0
- package/docs/knowledge-base/how-is-proration-calculated-when-changing-plans.md +89 -0
- package/docs/knowledge-base/meta.json +29 -0
- package/docs/knowledge-base/what-happens-when-a-customer-changes-plans.md +110 -0
- package/docs/knowledge-base/what-happens-when-a-payment-fails.md +40 -0
- package/docs/knowledge-base/what-happens-when-you-change-your-prices.md +74 -0
- package/docs/knowledge-base/what-happens-when-you-refund-or-retry-a-transaction.md +21 -0
- package/docs/knowledge-base/what-invoices-do-customers-receive-and-when.md +101 -0
- package/docs/manifest.json +1677 -0
- package/docs/meta.json +11 -0
- package/docs/platform-documentation.md +175 -0
- package/docs/schemas.md +995 -0
- package/docs/webhooks/addon-activated.md +44 -0
- package/docs/webhooks/addon-deactivated.md +40 -0
- package/docs/webhooks/balance-depleted.md +37 -0
- package/docs/webhooks/balance-low.md +39 -0
- package/docs/webhooks/balance-topped-up.md +41 -0
- package/docs/webhooks/checkout-ready.md +43 -0
- package/docs/webhooks/credits-depleted.md +35 -0
- package/docs/webhooks/credits-expired.md +35 -0
- package/docs/webhooks/credits-granted.md +37 -0
- package/docs/webhooks/credits-low.md +39 -0
- package/docs/webhooks/credits-purchased.md +41 -0
- package/docs/webhooks/customer-created.md +49 -0
- package/docs/webhooks/customer-state-changed.md +134 -0
- package/docs/webhooks/customer-updated.md +49 -0
- package/docs/webhooks/introduction.md +499 -0
- package/docs/webhooks/invoice-created.md +45 -0
- package/docs/webhooks/invoice-overdue.md +53 -0
- package/docs/webhooks/invoice-upcoming.md +43 -0
- package/docs/webhooks/invoice-voided.md +53 -0
- package/docs/webhooks/meta.json +78 -0
- package/docs/webhooks/payment-dispute-resolved.md +52 -0
- package/docs/webhooks/payment-disputed.md +49 -0
- package/docs/webhooks/payment-failed.md +37 -0
- package/docs/webhooks/payment-link-canceled.md +41 -0
- package/docs/webhooks/payment-link-completed.md +47 -0
- package/docs/webhooks/payment-link-created.md +41 -0
- package/docs/webhooks/payment-link-failed.md +45 -0
- package/docs/webhooks/payment-method-attached.md +40 -0
- package/docs/webhooks/payment-method-updated.md +38 -0
- package/docs/webhooks/payment-received.md +45 -0
- package/docs/webhooks/payment-recovered.md +39 -0
- package/docs/webhooks/payment-refunded.md +47 -0
- package/docs/webhooks/payment-retry-failed.md +39 -0
- package/docs/webhooks/payout-available.md +33 -0
- package/docs/webhooks/payout-created.md +48 -0
- package/docs/webhooks/payout-failed.md +52 -0
- package/docs/webhooks/payout-paid.md +48 -0
- package/docs/webhooks/quota-exceeded.md +44 -0
- package/docs/webhooks/quota-threshold-reached.md +41 -0
- package/docs/webhooks/seats-limit-reached.md +39 -0
- package/docs/webhooks/seats-updated.md +39 -0
- package/docs/webhooks/subscription-activated.md +43 -0
- package/docs/webhooks/subscription-canceled.md +57 -0
- package/docs/webhooks/subscription-cancellation-revoked.md +37 -0
- package/docs/webhooks/subscription-cancellation-scheduled.md +45 -0
- package/docs/webhooks/subscription-created.md +35 -0
- package/docs/webhooks/subscription-past-due.md +43 -0
- package/docs/webhooks/subscription-plan-change-revoked.md +50 -0
- package/docs/webhooks/subscription-plan-change-scheduled.md +55 -0
- package/docs/webhooks/subscription-plan-changed.md +43 -0
- package/docs/webhooks/subscription-reactivated.md +53 -0
- package/docs/webhooks/subscription-updated.md +39 -0
- package/docs/webhooks/trial-checkout-ready.md +39 -0
- package/docs/webhooks/trial-converted.md +39 -0
- package/docs/webhooks/trial-expired.md +39 -0
- package/docs/webhooks/trial-started.md +46 -0
- package/docs/webhooks/trial-will-end.md +41 -0
- package/docs/webhooks/usage-recorded.md +41 -0
- package/docs/webhooks.md +782 -0
- package/package.json +2 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
lastModified: 2026-07-28
|
|
3
|
+
title: Integrate with Bun
|
|
4
|
+
description: Add billing and payments to your Bun application.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Install the Commet Skill so your coding agent can integrate the current SDK and verify its work against the live API contract.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx skills add commet-labs/skills --skill commet
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
1. ## Install
|
|
14
|
+
```bash
|
|
15
|
+
bun add @commet/node
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
2. ## Configure
|
|
19
|
+
```bash title=".env"
|
|
20
|
+
COMMET_API_KEY=ck_sandbox_xxx
|
|
21
|
+
```
|
|
22
|
+
```typescript title="src/commet.ts"
|
|
23
|
+
import { Commet } from '@commet/node'
|
|
24
|
+
|
|
25
|
+
export const commet = new Commet({
|
|
26
|
+
apiKey: Bun.env.COMMET_API_KEY!,
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
3. ## Subscribe
|
|
31
|
+
```typescript title="src/index.ts"
|
|
32
|
+
import { commet } from './commet'
|
|
33
|
+
|
|
34
|
+
Bun.serve({
|
|
35
|
+
port: 3000,
|
|
36
|
+
async fetch(req) {
|
|
37
|
+
const url = new URL(req.url)
|
|
38
|
+
|
|
39
|
+
if (url.pathname === '/subscribe' && req.method === 'POST') {
|
|
40
|
+
const { customerId, email } = await req.json()
|
|
41
|
+
|
|
42
|
+
await commet.customers.create({ email, id: customerId })
|
|
43
|
+
|
|
44
|
+
const subscription = await commet.subscriptions.create({
|
|
45
|
+
customerId,
|
|
46
|
+
planCode: 'pro',
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return Response.json({ checkoutUrl: subscription.checkoutUrl ?? null })
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return new Response('Not Found', { status: 404 })
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
4. ## Check Access
|
|
58
|
+
Add these routes to the `fetch` handler.
|
|
59
|
+
```typescript title="src/index.ts"
|
|
60
|
+
if (url.pathname.startsWith('/subscription/') && req.method === 'GET') {
|
|
61
|
+
const customerId = url.pathname.split('/')[2]
|
|
62
|
+
|
|
63
|
+
const subscription = await commet.subscriptions.getActive({ customerId })
|
|
64
|
+
|
|
65
|
+
if (!subscription) {
|
|
66
|
+
return Response.json({ error: 'no_active_subscription' }, { status: 404 })
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return Response.json({ status: subscription.status })
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (url.pathname.startsWith('/features/') && req.method === 'GET') {
|
|
73
|
+
const [, , feature, customerId] = url.pathname.split('/')
|
|
74
|
+
|
|
75
|
+
const access = await commet.featureAccess.get({ code: feature, customerId })
|
|
76
|
+
|
|
77
|
+
return Response.json({ allowed: access.allowed })
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
5. ## Track Usage
|
|
82
|
+
```typescript title="src/index.ts"
|
|
83
|
+
if (url.pathname === '/usage' && req.method === 'POST') {
|
|
84
|
+
const { customerId } = await req.json()
|
|
85
|
+
|
|
86
|
+
await commet.usage.track({
|
|
87
|
+
customerId,
|
|
88
|
+
featureCode: 'api_calls',
|
|
89
|
+
value: 1,
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
return Response.json({ tracked: true })
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
Usage is aggregated and billed at end of period.
|
|
96
|
+
|
|
97
|
+
6. ## Customer Portal
|
|
98
|
+
```typescript title="src/index.ts"
|
|
99
|
+
if (url.pathname === '/portal' && req.method === 'GET') {
|
|
100
|
+
const customerId = url.searchParams.get('customerId')!
|
|
101
|
+
|
|
102
|
+
const portal = await commet.portal.getUrl({ customerId })
|
|
103
|
+
|
|
104
|
+
return Response.redirect(portal.portalUrl)
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Related
|
|
109
|
+
|
|
110
|
+
- [Subscriptions](/docs/manage-subscriptions)
|
|
111
|
+
- [Track Usage](/docs/track-usage)
|
|
112
|
+
- [Customer Portal](/docs/customer-portal)
|
|
113
|
+
- [SDK Reference](/docs/sdk-reference)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
---
|
|
2
|
+
lastModified: 2026-07-28
|
|
3
|
+
title: Integrate with Express
|
|
4
|
+
description: Add billing and payments to your Express application.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Install the Commet Skill so your coding agent can integrate the current SDK and verify its work against the live API contract.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx skills add commet-labs/skills --skill commet
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
1. ## Install
|
|
14
|
+
### pnpm
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @commet/node express
|
|
17
|
+
```
|
|
18
|
+
### npm
|
|
19
|
+
```bash
|
|
20
|
+
npm install @commet/node express
|
|
21
|
+
```
|
|
22
|
+
### yarn
|
|
23
|
+
```bash
|
|
24
|
+
yarn add @commet/node express
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
2. ## Configure
|
|
28
|
+
```bash title=".env"
|
|
29
|
+
COMMET_API_KEY=ck_sandbox_xxx
|
|
30
|
+
```
|
|
31
|
+
```typescript title="src/commet.ts"
|
|
32
|
+
import { Commet } from '@commet/node'
|
|
33
|
+
|
|
34
|
+
export const commet = new Commet({
|
|
35
|
+
apiKey: process.env.COMMET_API_KEY!,
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
3. ## Subscribe
|
|
40
|
+
```typescript title="src/routes/billing.ts"
|
|
41
|
+
import { Router } from 'express'
|
|
42
|
+
import { commet } from '../commet'
|
|
43
|
+
|
|
44
|
+
const router = Router()
|
|
45
|
+
|
|
46
|
+
router.post('/subscribe', async (req, res) => {
|
|
47
|
+
const { customerId, email } = req.body
|
|
48
|
+
|
|
49
|
+
await commet.customers.create({ email, id: customerId })
|
|
50
|
+
|
|
51
|
+
const subscription = await commet.subscriptions.create({
|
|
52
|
+
customerId,
|
|
53
|
+
planCode: 'pro',
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
res.json({ checkoutUrl: subscription.checkoutUrl ?? null })
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
export default router
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
4. ## Check Access
|
|
63
|
+
```typescript title="src/routes/billing.ts"
|
|
64
|
+
router.get('/subscription/:customerId', async (req, res) => {
|
|
65
|
+
const subscription = await commet.subscriptions.getActive({ customerId: req.params.customerId })
|
|
66
|
+
|
|
67
|
+
if (!subscription) {
|
|
68
|
+
return res.status(404).json({ error: 'no_active_subscription' })
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
res.json({ status: subscription.status })
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
router.get('/features/:feature/:customerId', async (req, res) => {
|
|
75
|
+
const access = await commet.featureAccess.get({
|
|
76
|
+
code: req.params.feature,
|
|
77
|
+
customerId: req.params.customerId,
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
res.json({ allowed: access.allowed })
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
5. ## Track Usage
|
|
85
|
+
```typescript title="src/routes/billing.ts"
|
|
86
|
+
router.post('/usage', async (req, res) => {
|
|
87
|
+
await commet.usage.track({
|
|
88
|
+
customerId: req.body.customerId,
|
|
89
|
+
featureCode: 'api_calls',
|
|
90
|
+
value: 1,
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
res.json({ tracked: true })
|
|
94
|
+
})
|
|
95
|
+
```
|
|
96
|
+
Usage is aggregated and billed at end of period.
|
|
97
|
+
|
|
98
|
+
6. ## Customer Portal
|
|
99
|
+
```typescript title="src/routes/billing.ts"
|
|
100
|
+
router.get('/portal', async (req, res) => {
|
|
101
|
+
const portal = await commet.portal.getUrl({
|
|
102
|
+
customerId: req.user.customerId,
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
res.redirect(portal.portalUrl)
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
7. ## Start Server
|
|
110
|
+
```typescript title="src/index.ts"
|
|
111
|
+
import express from 'express'
|
|
112
|
+
import billingRoutes from './routes/billing'
|
|
113
|
+
|
|
114
|
+
const app = express()
|
|
115
|
+
|
|
116
|
+
app.use(express.json())
|
|
117
|
+
app.use('/billing', billingRoutes)
|
|
118
|
+
|
|
119
|
+
app.listen(3000)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Related
|
|
123
|
+
|
|
124
|
+
- [Subscriptions](/docs/manage-subscriptions)
|
|
125
|
+
- [Track Usage](/docs/track-usage)
|
|
126
|
+
- [Customer Portal](/docs/customer-portal)
|
|
127
|
+
- [SDK Reference](/docs/sdk-reference)
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
---
|
|
2
|
+
lastModified: 2026-07-28
|
|
3
|
+
title: Integrate with Hono
|
|
4
|
+
description: Add billing and payments to your Hono application.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Install the Commet Skill so your coding agent can integrate the current SDK and verify its work against the live API contract.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx skills add commet-labs/skills --skill commet
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
1. ## Install
|
|
14
|
+
### pnpm
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @commet/node hono
|
|
17
|
+
```
|
|
18
|
+
### npm
|
|
19
|
+
```bash
|
|
20
|
+
npm install @commet/node hono
|
|
21
|
+
```
|
|
22
|
+
### bun
|
|
23
|
+
```bash
|
|
24
|
+
bun add @commet/node hono
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
2. ## Configure
|
|
28
|
+
```bash title=".env"
|
|
29
|
+
COMMET_API_KEY=ck_sandbox_xxx
|
|
30
|
+
```
|
|
31
|
+
```typescript title="src/commet.ts"
|
|
32
|
+
import { Commet } from '@commet/node'
|
|
33
|
+
|
|
34
|
+
export const commet = new Commet({
|
|
35
|
+
apiKey: process.env.COMMET_API_KEY!,
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
3. ## Subscribe
|
|
40
|
+
```typescript title="src/routes/billing.ts"
|
|
41
|
+
import { Hono } from 'hono'
|
|
42
|
+
import { commet } from '../commet'
|
|
43
|
+
|
|
44
|
+
const billing = new Hono()
|
|
45
|
+
|
|
46
|
+
billing.post('/subscribe', async (c) => {
|
|
47
|
+
const { customerId, email } = await c.req.json()
|
|
48
|
+
|
|
49
|
+
await commet.customers.create({ email, id: customerId })
|
|
50
|
+
|
|
51
|
+
const subscription = await commet.subscriptions.create({
|
|
52
|
+
customerId,
|
|
53
|
+
planCode: 'pro',
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
return c.json({ checkoutUrl: subscription.checkoutUrl ?? null })
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
export default billing
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
4. ## Check Access
|
|
63
|
+
```typescript title="src/routes/billing.ts"
|
|
64
|
+
billing.get('/subscription/:customerId', async (c) => {
|
|
65
|
+
const subscription = await commet.subscriptions.getActive({ customerId: c.req.param('customerId') })
|
|
66
|
+
|
|
67
|
+
if (!subscription) {
|
|
68
|
+
return c.json({ error: 'no_active_subscription' }, 404)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return c.json({ status: subscription.status })
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
billing.get('/features/:feature/:customerId', async (c) => {
|
|
75
|
+
const access = await commet.featureAccess.get({
|
|
76
|
+
code: c.req.param('feature'),
|
|
77
|
+
customerId: c.req.param('customerId'),
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
return c.json({ allowed: access.allowed })
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
5. ## Track Usage
|
|
85
|
+
```typescript title="src/routes/billing.ts"
|
|
86
|
+
billing.post('/usage', async (c) => {
|
|
87
|
+
const { customerId } = await c.req.json()
|
|
88
|
+
|
|
89
|
+
await commet.usage.track({
|
|
90
|
+
customerId,
|
|
91
|
+
featureCode: 'api_calls',
|
|
92
|
+
value: 1,
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
return c.json({ tracked: true })
|
|
96
|
+
})
|
|
97
|
+
```
|
|
98
|
+
Usage is aggregated and billed at end of period.
|
|
99
|
+
|
|
100
|
+
6. ## Customer Portal
|
|
101
|
+
```typescript title="src/routes/billing.ts"
|
|
102
|
+
billing.get('/portal', async (c) => {
|
|
103
|
+
const customerId = c.get('customerId')
|
|
104
|
+
|
|
105
|
+
const portal = await commet.portal.getUrl({ customerId })
|
|
106
|
+
|
|
107
|
+
return c.redirect(portal.portalUrl)
|
|
108
|
+
})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
7. ## Start Server
|
|
112
|
+
### Node.js
|
|
113
|
+
```typescript title="src/index.ts"
|
|
114
|
+
import { serve } from '@hono/node-server'
|
|
115
|
+
import { Hono } from 'hono'
|
|
116
|
+
import billing from './routes/billing'
|
|
117
|
+
|
|
118
|
+
const app = new Hono()
|
|
119
|
+
|
|
120
|
+
app.route('/billing', billing)
|
|
121
|
+
|
|
122
|
+
serve({ fetch: app.fetch, port: 3000 })
|
|
123
|
+
```
|
|
124
|
+
### Bun
|
|
125
|
+
```typescript title="src/index.ts"
|
|
126
|
+
import { Hono } from 'hono'
|
|
127
|
+
import billing from './routes/billing'
|
|
128
|
+
|
|
129
|
+
const app = new Hono()
|
|
130
|
+
|
|
131
|
+
app.route('/billing', billing)
|
|
132
|
+
|
|
133
|
+
export default app
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Related
|
|
137
|
+
|
|
138
|
+
- [Subscriptions](/docs/manage-subscriptions)
|
|
139
|
+
- [Track Usage](/docs/track-usage)
|
|
140
|
+
- [Customer Portal](/docs/customer-portal)
|
|
141
|
+
- [SDK Reference](/docs/sdk-reference)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
lastModified: 2026-07-28
|
|
3
|
+
title: Integrate with Next.js
|
|
4
|
+
description: Add billing and payments to your Next.js application.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Install the Commet Skill so your coding agent can integrate the current SDK and verify its work against the live API contract.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx skills add commet-labs/skills --skill commet
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
1. ## Install
|
|
14
|
+
### pnpm
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @commet/node @commet/next
|
|
17
|
+
```
|
|
18
|
+
### npm
|
|
19
|
+
```bash
|
|
20
|
+
npm install @commet/node @commet/next
|
|
21
|
+
```
|
|
22
|
+
### yarn
|
|
23
|
+
```bash
|
|
24
|
+
yarn add @commet/node @commet/next
|
|
25
|
+
```
|
|
26
|
+
### bun
|
|
27
|
+
```bash
|
|
28
|
+
bun add @commet/node @commet/next
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
2. ## Configure
|
|
32
|
+
```bash title=".env.local"
|
|
33
|
+
COMMET_API_KEY=ck_sandbox_xxx
|
|
34
|
+
```
|
|
35
|
+
```typescript title="lib/commet.ts"
|
|
36
|
+
import { Commet } from '@commet/node'
|
|
37
|
+
|
|
38
|
+
export const commet = new Commet({
|
|
39
|
+
apiKey: process.env.COMMET_API_KEY!,
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
3. ## Create Customer and Subscribe
|
|
44
|
+
`customers.create` is idempotent — if a customer with the same `id` already exists, it returns the existing record.
|
|
45
|
+
```typescript title="app/actions/billing.ts"
|
|
46
|
+
'use server'
|
|
47
|
+
|
|
48
|
+
import { redirect } from 'next/navigation'
|
|
49
|
+
import { commet } from '@/lib/commet'
|
|
50
|
+
|
|
51
|
+
export async function subscribe(customerId: string) {
|
|
52
|
+
await commet.customers.create({
|
|
53
|
+
email: 'user@example.com',
|
|
54
|
+
id: customerId,
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const subscription = await commet.subscriptions.create({
|
|
58
|
+
customerId,
|
|
59
|
+
planCode: 'pro',
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const checkoutUrl = subscription.checkoutUrl
|
|
63
|
+
if (checkoutUrl) {
|
|
64
|
+
redirect(checkoutUrl)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
The customer is redirected to checkout to complete payment. When `checkoutUrl` is `null` no payment is needed and the subscription is already active.
|
|
69
|
+
|
|
70
|
+
4. ## Check Access
|
|
71
|
+
```typescript title="app/actions/billing.ts"
|
|
72
|
+
export async function getSubscription(customerId: string) {
|
|
73
|
+
const subscription = await commet.subscriptions.getActive({ customerId })
|
|
74
|
+
|
|
75
|
+
return subscription
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
```typescript title="app/actions/features.ts"
|
|
79
|
+
export async function canUseFeature(customerId: string, feature: string) {
|
|
80
|
+
const access = await commet.featureAccess.get({ code: feature, customerId })
|
|
81
|
+
|
|
82
|
+
return access.allowed
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
5. ## Track Usage
|
|
87
|
+
```typescript title="app/actions/usage.ts"
|
|
88
|
+
export async function trackApiCall(customerId: string) {
|
|
89
|
+
await commet.usage.track({
|
|
90
|
+
customerId,
|
|
91
|
+
featureCode: 'api_calls',
|
|
92
|
+
value: 1,
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
Usage is aggregated and billed at end of period.
|
|
97
|
+
|
|
98
|
+
6. ## Customer Portal
|
|
99
|
+
```typescript title="app/api/commet/portal/route.ts"
|
|
100
|
+
import { CustomerPortal } from '@commet/next'
|
|
101
|
+
|
|
102
|
+
export const GET = CustomerPortal({
|
|
103
|
+
apiKey: process.env.COMMET_API_KEY!,
|
|
104
|
+
getCustomerId: async (req) => {
|
|
105
|
+
return 'user_123'
|
|
106
|
+
},
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
```tsx
|
|
110
|
+
<a href="/api/commet/portal">Manage Billing</a>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Related
|
|
114
|
+
|
|
115
|
+
- [Subscriptions](/docs/manage-subscriptions)
|
|
116
|
+
- [Track Usage](/docs/track-usage)
|
|
117
|
+
- [Customer Portal](/docs/customer-portal)
|
|
118
|
+
- [SDK Reference](/docs/sdk-reference)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
---
|
|
2
|
+
lastModified: 2026-07-28
|
|
3
|
+
title: Integrate with Nuxt
|
|
4
|
+
description: Add billing and payments to your Nuxt application.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Install the Commet Skill so your coding agent can integrate the current SDK and verify its work against the live API contract.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx skills add commet-labs/skills --skill commet
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
1. ## Install
|
|
14
|
+
### pnpm
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @commet/node
|
|
17
|
+
```
|
|
18
|
+
### npm
|
|
19
|
+
```bash
|
|
20
|
+
npm install @commet/node
|
|
21
|
+
```
|
|
22
|
+
### yarn
|
|
23
|
+
```bash
|
|
24
|
+
yarn add @commet/node
|
|
25
|
+
```
|
|
26
|
+
### bun
|
|
27
|
+
```bash
|
|
28
|
+
bun add @commet/node
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
2. ## Configure
|
|
32
|
+
```bash title=".env"
|
|
33
|
+
COMMET_API_KEY=ck_sandbox_xxx
|
|
34
|
+
```
|
|
35
|
+
```typescript title="nuxt.config.ts"
|
|
36
|
+
export default defineNuxtConfig({
|
|
37
|
+
runtimeConfig: {
|
|
38
|
+
commetApiKey: process.env.COMMET_API_KEY,
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
Nuxt auto-imports from `server/utils/`, so the client is available in all server routes.
|
|
43
|
+
```typescript title="server/utils/commet.ts"
|
|
44
|
+
import { Commet } from '@commet/node'
|
|
45
|
+
|
|
46
|
+
const config = useRuntimeConfig()
|
|
47
|
+
|
|
48
|
+
export const commet = new Commet({
|
|
49
|
+
apiKey: config.commetApiKey,
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
3. ## Subscribe
|
|
54
|
+
`customers.create` is idempotent — if a customer with the same `id` already exists, it returns the existing record.
|
|
55
|
+
```typescript title="server/api/billing/subscribe.post.ts"
|
|
56
|
+
export default defineEventHandler(async (event) => {
|
|
57
|
+
const { customerId, email } = await readBody(event)
|
|
58
|
+
|
|
59
|
+
await commet.customers.create({ email, id: customerId })
|
|
60
|
+
|
|
61
|
+
const subscription = await commet.subscriptions.create({
|
|
62
|
+
customerId,
|
|
63
|
+
planCode: 'pro',
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
return { checkoutUrl: subscription.checkoutUrl ?? null }
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
4. ## Check Access
|
|
71
|
+
```typescript title="server/api/billing/access/[customerId].get.ts"
|
|
72
|
+
export default defineEventHandler(async (event) => {
|
|
73
|
+
const customerId = getRouterParam(event, 'customerId')!
|
|
74
|
+
|
|
75
|
+
const subscription = await commet.subscriptions.getActive({ customerId })
|
|
76
|
+
|
|
77
|
+
if (!subscription) {
|
|
78
|
+
throw createError({ statusCode: 404, statusMessage: 'No active subscription' })
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const feature = await commet.featureAccess.get({
|
|
82
|
+
code: 'api_calls',
|
|
83
|
+
customerId,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
status: subscription.status,
|
|
88
|
+
allowed: feature.allowed,
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
5. ## Track Usage
|
|
94
|
+
```typescript title="server/api/billing/usage.post.ts"
|
|
95
|
+
export default defineEventHandler(async (event) => {
|
|
96
|
+
const { customerId } = await readBody(event)
|
|
97
|
+
|
|
98
|
+
await commet.usage.track({
|
|
99
|
+
customerId,
|
|
100
|
+
featureCode: 'api_calls',
|
|
101
|
+
value: 1,
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
return { tracked: true }
|
|
105
|
+
})
|
|
106
|
+
```
|
|
107
|
+
Usage is aggregated and billed at end of period.
|
|
108
|
+
|
|
109
|
+
6. ## Customer Portal
|
|
110
|
+
```typescript title="server/api/billing/portal.get.ts"
|
|
111
|
+
export default defineEventHandler(async (event) => {
|
|
112
|
+
const customerId = 'user_123'
|
|
113
|
+
|
|
114
|
+
const portal = await commet.portal.getUrl({ customerId })
|
|
115
|
+
|
|
116
|
+
return sendRedirect(event, portal.portalUrl)
|
|
117
|
+
})
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Related
|
|
121
|
+
|
|
122
|
+
- [Subscriptions](/docs/manage-subscriptions)
|
|
123
|
+
- [Track Usage](/docs/track-usage)
|
|
124
|
+
- [Customer Portal](/docs/customer-portal)
|
|
125
|
+
- [SDK Reference](/docs/sdk-reference)
|