@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,258 @@
|
|
|
1
|
+
---
|
|
2
|
+
lastModified: 2026-07-31
|
|
3
|
+
title: Integrate with Go
|
|
4
|
+
description: Add billing and payments to your Go application using net/http.
|
|
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
|
+
go get github.com/commet-labs/commet-go/v9
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
2. ## Configure
|
|
19
|
+
```bash title=".env"
|
|
20
|
+
COMMET_API_KEY=ck_sandbox_xxx
|
|
21
|
+
COMMET_WEBHOOK_SECRET=whsec_xxx
|
|
22
|
+
```
|
|
23
|
+
```go title="billing/client.go"
|
|
24
|
+
package billing
|
|
25
|
+
|
|
26
|
+
import (
|
|
27
|
+
"log"
|
|
28
|
+
"os"
|
|
29
|
+
|
|
30
|
+
commet "github.com/commet-labs/commet-go/v9"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
var Client *commet.Client
|
|
34
|
+
|
|
35
|
+
func Init() {
|
|
36
|
+
var err error
|
|
37
|
+
Client, err = commet.New(os.Getenv("COMMET_API_KEY"))
|
|
38
|
+
if err != nil {
|
|
39
|
+
log.Fatal(err)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
There is no environment option on the client: sandbox vs live is decided by the organization the API key belongs to.
|
|
44
|
+
|
|
45
|
+
3. ## Subscribe
|
|
46
|
+
```go title="billing/handlers.go"
|
|
47
|
+
package billing
|
|
48
|
+
|
|
49
|
+
import (
|
|
50
|
+
"encoding/json"
|
|
51
|
+
"net/http"
|
|
52
|
+
|
|
53
|
+
commet "github.com/commet-labs/commet-go/v9"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
type subscribeRequest struct {
|
|
57
|
+
Email string `json:"email"`
|
|
58
|
+
CustomerID string `json:"customer_id"`
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
func Subscribe(w http.ResponseWriter, r *http.Request) {
|
|
62
|
+
var req subscribeRequest
|
|
63
|
+
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
64
|
+
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
_, err := Client.Customers.Create(r.Context(), &commet.CreateCustomerParams{
|
|
69
|
+
Email: req.Email,
|
|
70
|
+
ID: &req.CustomerID,
|
|
71
|
+
})
|
|
72
|
+
if err != nil {
|
|
73
|
+
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
planCode := "pro"
|
|
78
|
+
subscription, err := Client.Subscriptions.Create(r.Context(), &commet.CreateSubscriptionParams{
|
|
79
|
+
CustomerID: req.CustomerID,
|
|
80
|
+
PlanCode: &planCode,
|
|
81
|
+
})
|
|
82
|
+
if err != nil {
|
|
83
|
+
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
checkoutURL := ""
|
|
88
|
+
if subscription.CheckoutURL != nil {
|
|
89
|
+
checkoutURL = *subscription.CheckoutURL
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
w.Header().Set("Content-Type", "application/json")
|
|
93
|
+
json.NewEncoder(w).Encode(map[string]any{"checkout_url": checkoutURL})
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
4. ## Check Access
|
|
98
|
+
```go title="billing/handlers.go"
|
|
99
|
+
func GetSubscription(w http.ResponseWriter, r *http.Request) {
|
|
100
|
+
customerID := r.PathValue("customerID")
|
|
101
|
+
|
|
102
|
+
sub, err := Client.Subscriptions.GetActive(r.Context(), &commet.GetActiveSubscriptionParams{
|
|
103
|
+
CustomerID: customerID,
|
|
104
|
+
})
|
|
105
|
+
if err != nil {
|
|
106
|
+
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if sub == nil {
|
|
111
|
+
http.Error(w, "No active subscription", http.StatusNotFound)
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
w.Header().Set("Content-Type", "application/json")
|
|
116
|
+
json.NewEncoder(w).Encode(map[string]any{"status": sub.Status})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
func CheckFeature(w http.ResponseWriter, r *http.Request) {
|
|
120
|
+
feature := r.PathValue("feature")
|
|
121
|
+
customerID := r.PathValue("customerID")
|
|
122
|
+
|
|
123
|
+
result, err := Client.FeatureAccess.Get(r.Context(), feature, &commet.GetFeatureAccessParams{
|
|
124
|
+
CustomerID: customerID,
|
|
125
|
+
})
|
|
126
|
+
if err != nil {
|
|
127
|
+
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
w.Header().Set("Content-Type", "application/json")
|
|
132
|
+
json.NewEncoder(w).Encode(map[string]any{"allowed": result.Allowed})
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
5. ## Track Usage
|
|
137
|
+
```go title="billing/handlers.go"
|
|
138
|
+
func float64Ptr(value float64) *float64 { return &value }
|
|
139
|
+
|
|
140
|
+
type usageRequest struct {
|
|
141
|
+
CustomerID string `json:"customer_id"`
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
func TrackUsage(w http.ResponseWriter, r *http.Request) {
|
|
145
|
+
var req usageRequest
|
|
146
|
+
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
147
|
+
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
_, err := Client.Usage.Track(r.Context(), &commet.TrackUsageParams{
|
|
152
|
+
CustomerID: req.CustomerID,
|
|
153
|
+
FeatureCode: "api_calls",
|
|
154
|
+
Value: float64Ptr(1),
|
|
155
|
+
})
|
|
156
|
+
if err != nil {
|
|
157
|
+
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
w.Header().Set("Content-Type", "application/json")
|
|
162
|
+
json.NewEncoder(w).Encode(map[string]any{"tracked": true})
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
Usage is aggregated and billed at end of period.
|
|
166
|
+
|
|
167
|
+
6. ## Customer Portal
|
|
168
|
+
```go title="billing/handlers.go"
|
|
169
|
+
func Portal(w http.ResponseWriter, r *http.Request) {
|
|
170
|
+
customerID := "user_123"
|
|
171
|
+
result, err := Client.Portal.GetURL(r.Context(), &commet.RequestPortalAccessParams{
|
|
172
|
+
CustomerID: &customerID,
|
|
173
|
+
})
|
|
174
|
+
if err != nil {
|
|
175
|
+
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
http.Redirect(w, r, result.PortalURL, http.StatusTemporaryRedirect)
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
7. ## Webhooks
|
|
184
|
+
```go title="billing/webhooks.go"
|
|
185
|
+
package billing
|
|
186
|
+
|
|
187
|
+
import (
|
|
188
|
+
"io"
|
|
189
|
+
"net/http"
|
|
190
|
+
"os"
|
|
191
|
+
|
|
192
|
+
commet "github.com/commet-labs/commet-go/v9"
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
func HandleWebhook(w http.ResponseWriter, r *http.Request) {
|
|
196
|
+
rawBody, err := io.ReadAll(r.Body)
|
|
197
|
+
if err != nil {
|
|
198
|
+
http.Error(w, "Failed to read body", http.StatusBadRequest)
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
webhooks := &commet.WebhooksResource{}
|
|
203
|
+
payload, err := webhooks.VerifyAndParse(
|
|
204
|
+
string(rawBody),
|
|
205
|
+
r.Header.Get("x-commet-signature"),
|
|
206
|
+
os.Getenv("COMMET_WEBHOOK_SECRET"),
|
|
207
|
+
)
|
|
208
|
+
if err != nil {
|
|
209
|
+
http.Error(w, "Invalid signature", http.StatusUnauthorized)
|
|
210
|
+
return
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
switch payload["event"] {
|
|
214
|
+
case "subscription.activated":
|
|
215
|
+
// handle activation
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
w.Header().Set("Content-Type", "application/json")
|
|
219
|
+
w.Write([]byte(`{"ok":true}`))
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
8. ## Start Server
|
|
224
|
+
```go title="main.go"
|
|
225
|
+
package main
|
|
226
|
+
|
|
227
|
+
import (
|
|
228
|
+
|
|
229
|
+
"log"
|
|
230
|
+
"net/http"
|
|
231
|
+
|
|
232
|
+
"myapp/billing"
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
func main() {
|
|
236
|
+
billing.Init()
|
|
237
|
+
defer billing.Client.Close()
|
|
238
|
+
|
|
239
|
+
mux := http.NewServeMux()
|
|
240
|
+
|
|
241
|
+
mux.HandleFunc("POST /billing/subscribe", billing.Subscribe)
|
|
242
|
+
mux.HandleFunc("GET /billing/subscription/{customerID}", billing.GetSubscription)
|
|
243
|
+
mux.HandleFunc("GET /billing/features/{feature}/{customerID}", billing.CheckFeature)
|
|
244
|
+
mux.HandleFunc("POST /billing/usage", billing.TrackUsage)
|
|
245
|
+
mux.HandleFunc("GET /billing/portal", billing.Portal)
|
|
246
|
+
mux.HandleFunc("POST /webhooks/commet", billing.HandleWebhook)
|
|
247
|
+
|
|
248
|
+
log.Println("Listening on :3000")
|
|
249
|
+
log.Fatal(http.ListenAndServe(":3000", mux))
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Related
|
|
254
|
+
|
|
255
|
+
- [Subscriptions](/docs/manage-subscriptions)
|
|
256
|
+
- [Track Usage](/docs/track-usage)
|
|
257
|
+
- [Customer Portal](/docs/customer-portal)
|
|
258
|
+
- [SDK Reference](/docs/sdk-reference)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
lastModified: 2026-08-16
|
|
3
|
+
title: Introduction
|
|
4
|
+
description: Commet is a billing and payments platform for SaaS and AI products.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Commet is a billing and payments platform for SaaS and AI products. It handles recurring billing, taxes, compliance, and payouts so you can focus on your product.
|
|
8
|
+
|
|
9
|
+
To build your first complete flow:
|
|
10
|
+
|
|
11
|
+
1. [Create a sandbox API key](/docs/create-api-key).
|
|
12
|
+
2. [Choose the billing model](/docs/choose-a-billing-model) that matches what customers buy.
|
|
13
|
+
3. Follow the quickstart for your language, then run the matching [example application](/docs/examples).
|
|
14
|
+
4. Confirm subscription and payment outcomes with signed webhooks.
|
|
15
|
+
|
|
16
|
+
## Quickstart
|
|
17
|
+
|
|
18
|
+
- [**Next.js**](/docs/integrate-with-nextjs)
|
|
19
|
+
- [**Remix**](/docs/integrate-with-remix)
|
|
20
|
+
- [**Nuxt**](/docs/integrate-with-nuxt)
|
|
21
|
+
- [**SvelteKit**](/docs/integrate-with-sveltekit)
|
|
22
|
+
- [**Astro**](/docs/integrate-with-astro)
|
|
23
|
+
- [**Express**](/docs/integrate-with-express)
|
|
24
|
+
- [**Hono**](/docs/integrate-with-hono)
|
|
25
|
+
- [**Bun**](/docs/integrate-with-bun)
|
|
26
|
+
|
|
27
|
+
## The Plan-First Model
|
|
28
|
+
|
|
29
|
+
You define what you sell, package it into a plan, and connect it to a customer. Billing runs automatically from there.
|
|
30
|
+
|
|
31
|
+
1. **Features** — define capabilities like API calls, seats, or SSO access
|
|
32
|
+
2. **Plan** — bundle features with pricing and a consumption model
|
|
33
|
+
3. **Customer** — assign the plan and a subscription is created
|
|
34
|
+
4. **Billing** — invoices, usage tracking, and payments happen without intervention
|
|
35
|
+
|
|
36
|
+
## Consumption Models
|
|
37
|
+
|
|
38
|
+
Every plan uses one consumption model. This defines how customers consume and pay for features.
|
|
39
|
+
|
|
40
|
+
| Model | How it works | Examples |
|
|
41
|
+
| ----------- | ------------------------------------------ | -------------------------- |
|
|
42
|
+
| **Metered** | Base price + overage billed at period end | Twilio, Resend, AWS |
|
|
43
|
+
| **Credits** | Prepaid credits consumed by usage | Midjourney, Cursor, Replit |
|
|
44
|
+
| **Balance** | Prepaid dollar balance drawn down by usage | Supabase, Railway, Vercel |
|
|
45
|
+
|
|
46
|
+
Models are mutually exclusive — each plan uses exactly one. [Learn more about consumption models](/docs/consumption-models).
|
|
47
|
+
|
|
48
|
+
## Explore
|
|
49
|
+
|
|
50
|
+
- [**Customers**](/docs/manage-customers)
|
|
51
|
+
- [**Plans**](/docs/create-plans)
|
|
52
|
+
- [**Subscriptions**](/docs/manage-subscriptions)
|
|
53
|
+
- [**Usage Tracking**](/docs/track-usage)
|
|
54
|
+
- [**Invoicing**](/docs/invoices-and-billing-cycles)
|
|
55
|
+
- [**Payments**](/docs/accept-one-time-payments)
|
|
56
|
+
- [**Customer Portal**](/docs/customer-portal)
|
|
57
|
+
- [**Finance & Payouts**](/docs/finance-overview)
|
|
58
|
+
- [**SDK Reference**](/docs/sdk-reference)
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
---
|
|
2
|
+
lastModified: 2026-07-28
|
|
3
|
+
title: Handle Failed Payments
|
|
4
|
+
description: What happens when a customer's payment fails and how they can reactivate from the Customer Portal.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
When a renewal payment fails, the subscription moves to `past_due` and enters dunning. The customer keeps service during this grace window while Commet retries the charge. Customers can reactivate sooner from the Customer Portal by retrying payment or updating their card.
|
|
8
|
+
|
|
9
|
+
## What happens when a payment fails
|
|
10
|
+
|
|
11
|
+
1. The subscription status changes to `past_due`
|
|
12
|
+
2. The failed invoice is marked as `outstanding`
|
|
13
|
+
3. The customer keeps service: usage events and seat events still work (usage accrues as debt)
|
|
14
|
+
4. The customer receives an email notification
|
|
15
|
+
5. Commet retries the charge on a fixed schedule (dunning)
|
|
16
|
+
|
|
17
|
+
If a retry succeeds, the subscription returns to `active`. If all retries fail, the subscription is canceled and the invoice is marked as `uncollectible`.
|
|
18
|
+
|
|
19
|
+
## Provider error mapping
|
|
20
|
+
|
|
21
|
+
Commet translates provider responses into a common payment outcome and keeps the provider detail alongside it. For recurring failures, the [`payment.failed`](/docs/webhooks/payment-failed) webhook exposes `failureCode`, `failureMessage`, and a `recoveryUrl` when a recovery path is available. The exact `failureCode` depends on the provider, so use the normalized outcome and the recovery URL for customer handling instead of matching only one provider's raw codes.
|
|
22
|
+
|
|
23
|
+
| Payment outcome | What it means | What to do |
|
|
24
|
+
| ------------------------------------ | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
25
|
+
| `requires_action` | The provider needs an additional customer step, such as 3D Secure | Keep the customer in checkout and complete the authentication flow |
|
|
26
|
+
| `PAYMENT_FAILED` with a decline code | The provider rejected the charge | Show a retry or alternate payment method and record the provider code for support |
|
|
27
|
+
| `payment.failed` | A recurring charge failed and the invoice entered dunning | Keep service during the grace window, communicate the recovery path, and wait for a retry or recovery |
|
|
28
|
+
| `payment.retry_failed` | All scheduled dunning retries were exhausted | Revoke access according to your product policy and ask the customer to start a new subscription or contact support |
|
|
29
|
+
|
|
30
|
+
Initial checkout card declines do not emit `payment.failed`; the checkout response carries the failure state directly. Recurring failures use the dunning flow below.
|
|
31
|
+
|
|
32
|
+
## Automatic retries
|
|
33
|
+
|
|
34
|
+
Retries run on day 1, day 3, day 5, and day 7 after the original failure (4 retries). The calendar is anchored to the failure and never moves. After the last failed retry the subscription is canceled.
|
|
35
|
+
|
|
36
|
+
Manual retries — from the Customer Portal or [`reactivate`](#retry-the-charge-server-to-server) — count against the same calendar: a declined manual retry consumes the next scheduled slot. Four declined retries cancel the subscription even before day 7.
|
|
37
|
+
|
|
38
|
+
Retries use the payment connection already associated with the subscription. Changing country routing does not move the retry to another provider, and Commet does not silently switch a saved payment method to a different account.
|
|
39
|
+
|
|
40
|
+
## Dunning communications
|
|
41
|
+
|
|
42
|
+
Commet sends a payment-failure notification when a recurring charge enters dunning. For product-specific messaging, subscribe to these webhooks:
|
|
43
|
+
|
|
44
|
+
- [`payment.failed`](/docs/webhooks/payment-failed) — a recurring charge failed; use `failureCode`, `failureMessage`, and `recoveryUrl` to explain the next step.
|
|
45
|
+
- [`payment.recovered`](/docs/webhooks/payment-recovered) — the outstanding invoice was paid and the subscription returned to `active`.
|
|
46
|
+
- [`payment.retry_failed`](/docs/webhooks/payment-retry-failed) — all retries were exhausted and the subscription was canceled.
|
|
47
|
+
|
|
48
|
+
Send your own email, SMS, or in-app message when you need product-specific copy. Do not create a second retry schedule in your app; use Commet's events to close the communication loop.
|
|
49
|
+
|
|
50
|
+
## Check subscription status
|
|
51
|
+
|
|
52
|
+
### TypeScript
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const subscription = await commet.subscriptions.getActive({ customerId: 'user_123' })
|
|
56
|
+
|
|
57
|
+
if (subscription?.status === 'past_due') {
|
|
58
|
+
showRecoveryPrompt()
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Python
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
subscription = commet.subscriptions.get_active(customer_id='user_123')
|
|
66
|
+
|
|
67
|
+
if subscription is not None and subscription.status == 'past_due':
|
|
68
|
+
show_recovery_prompt()
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Go
|
|
72
|
+
|
|
73
|
+
```go
|
|
74
|
+
subscription, err := client.Subscriptions.GetActive(ctx, &commet.GetActiveSubscriptionParams{CustomerID: "user_123"})
|
|
75
|
+
if err != nil {
|
|
76
|
+
log.Fatal(err)
|
|
77
|
+
}
|
|
78
|
+
if subscription != nil && subscription.Status == "past_due" {
|
|
79
|
+
showRecoveryPrompt()
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Java
|
|
84
|
+
|
|
85
|
+
```java
|
|
86
|
+
var subscription = commet.subscriptions().getActive(GetActiveSubscriptionParams.builder("user_123").build());
|
|
87
|
+
|
|
88
|
+
if (subscription != null && subscription.status() == SubscriptionStatus.PAST_DUE) {
|
|
89
|
+
showRecoveryPrompt();
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### PHP
|
|
94
|
+
|
|
95
|
+
```php
|
|
96
|
+
$result = $commet->subscriptions->getActive('user_123');
|
|
97
|
+
|
|
98
|
+
if ($result !== null && $result->status->value === 'past_due') {
|
|
99
|
+
showRecoveryPrompt();
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### cURL
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
curl "https://commet.co/api/v1/subscriptions/active?customerId=user_123" \
|
|
107
|
+
-H "x-api-key: $COMMET_API_KEY"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Gate access based on status
|
|
111
|
+
|
|
112
|
+
Commet keeps serving `past_due` customers during the dunning window — usage and seat events still work. You decide whether to gate your own product on `past_due`. To grant access only while billing is healthy, treat `active` and `trialing` as the access states:
|
|
113
|
+
|
|
114
|
+
### TypeScript
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
const subscription = await commet.subscriptions.getActive({ customerId: 'user_123' })
|
|
118
|
+
|
|
119
|
+
const hasAccess = subscription !== null &&
|
|
120
|
+
(subscription.status === 'active' || subscription.status === 'trialing')
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Python
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
subscription = commet.subscriptions.get_active(customer_id='user_123')
|
|
127
|
+
|
|
128
|
+
has_access = subscription is not None and subscription.status in ('active', 'trialing')
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Go
|
|
132
|
+
|
|
133
|
+
```go
|
|
134
|
+
subscription, err := client.Subscriptions.GetActive(ctx, &commet.GetActiveSubscriptionParams{CustomerID: "user_123"})
|
|
135
|
+
if err != nil {
|
|
136
|
+
log.Fatal(err)
|
|
137
|
+
}
|
|
138
|
+
hasAccess := subscription != nil &&
|
|
139
|
+
(subscription.Status == "active" || subscription.Status == "trialing")
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Java
|
|
143
|
+
|
|
144
|
+
```java
|
|
145
|
+
var subscription = commet.subscriptions().getActive(GetActiveSubscriptionParams.builder("user_123").build());
|
|
146
|
+
|
|
147
|
+
boolean hasAccess = subscription != null &&
|
|
148
|
+
(subscription.status() == SubscriptionStatus.ACTIVE ||
|
|
149
|
+
subscription.status() == SubscriptionStatus.TRIALING);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### PHP
|
|
153
|
+
|
|
154
|
+
```php
|
|
155
|
+
$result = $commet->subscriptions->getActive('user_123');
|
|
156
|
+
|
|
157
|
+
$hasAccess = $result !== null &&
|
|
158
|
+
in_array($result->status->value, ['active', 'trialing'], true);
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### cURL
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
curl "https://commet.co/api/v1/subscriptions/active?customerId=user_123" \
|
|
165
|
+
-H "x-api-key: $COMMET_API_KEY"
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Recover a subscription programmatically
|
|
169
|
+
|
|
170
|
+
The SDK exposes three server-side recovery primitives. For `past_due` subscriptions they all operate on the same `outstanding` renewal invoice — none of them void it. `reactivate` also reactivates `canceled` subscriptions.
|
|
171
|
+
|
|
172
|
+
### Retry the charge server-to-server
|
|
173
|
+
|
|
174
|
+
`reactivate` charges the subscription's saved payment method. It works on both `past_due` and `canceled` subscriptions, with different effects:
|
|
175
|
+
|
|
176
|
+
- `past_due`: retries the same outstanding renewal invoice. The billing anchor stays fixed. On success the subscription returns to `active` and `payment.recovered` fires.
|
|
177
|
+
- `canceled`: generates a fresh invoice, resets the billing period anchor to now, and charges the saved card. On success the subscription returns to `active` and `subscription.reactivated` fires. Requires the plan to still be available in the subscription's currency, otherwise it returns `PLAN_UNAVAILABLE` (422).
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
const result = await commet.subscriptions.reactivate({ id: 'sub_123' })
|
|
181
|
+
|
|
182
|
+
// result.retryInitiated === true
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
On a declined charge or no saved card, the response returns a `recoveryUrl` in the error details — a hosted page where the customer adds a new card and pays. This matters for subscriptions canceled by dunning: they reached `canceled` precisely because the saved card kept failing.
|
|
186
|
+
|
|
187
|
+
### Send the customer a recovery link
|
|
188
|
+
|
|
189
|
+
`createRecoveryLink` returns a hosted, signed link so the customer pays the outstanding renewal themselves. Deliver it through your own email, SMS, or dashboard. The link stays valid until the charge is paid or the subscription is no longer `past_due`.
|
|
190
|
+
|
|
191
|
+
The [`payment.failed` webhook](/docs/webhooks/payment-failed) already carries a `recoveryUrl`: the checkout URL for a first failed charge, a signed recovery link for a failed renewal. If you consume webhooks, no separate `createRecoveryLink` call is needed.
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
const recovery = await commet.subscriptions.createRecoveryLink({ id: 'sub_123' })
|
|
195
|
+
|
|
196
|
+
// recovery.url → hosted payment page
|
|
197
|
+
// recovery.token → signed token embedded in the URL
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Update the payment method
|
|
201
|
+
|
|
202
|
+
`updatePaymentMethod` returns a hosted checkout where the customer updates the subscription's default payment method.
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
const paymentMethodUpdate = await commet.subscriptions.updatePaymentMethod({
|
|
206
|
+
id: 'sub_123',
|
|
207
|
+
successUrl: 'https://yourapp.com/billing',
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
// redirect(paymentMethodUpdate.checkoutUrl)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Self-serve recovery
|
|
214
|
+
|
|
215
|
+
Customers in `past_due` see their subscription in the [Customer Portal](/docs/customer-portal) with a **Reactivate Subscription** button. They can choose:
|
|
216
|
+
|
|
217
|
+
- **Retry with their current card** — useful when the failure was temporary (insufficient funds that are now available, a bank hold that cleared).
|
|
218
|
+
- **Update their payment method** — enter a new card through the subscription's payment provider and retry in the same step.
|
|
219
|
+
|
|
220
|
+
A successful retry settles the outstanding invoice, moves the subscription back to `active`, and emits a `payment.recovered` event. A declined retry consumes the next slot on the dunning calendar. Retry attempts are rate-limited to 3 per day per customer.
|
|
221
|
+
|
|
222
|
+
## Prompt payment update
|
|
223
|
+
|
|
224
|
+
Redirect customers to the Customer Portal to reactivate:
|
|
225
|
+
|
|
226
|
+
### TypeScript
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
const portal = await commet.portal.getUrl({ customerId: 'user_123' })
|
|
230
|
+
|
|
231
|
+
redirect(portal.portalUrl)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Python
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
portal = commet.portal.get_url(customer_id='user_123')
|
|
238
|
+
|
|
239
|
+
redirect(portal.portal_url)
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Go
|
|
243
|
+
|
|
244
|
+
```go
|
|
245
|
+
portal, err := client.Portal.GetURL(ctx, &commet.GetPortalURLParams{
|
|
246
|
+
CustomerID: "user_123",
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
// redirect(portal.PortalURL)
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Java
|
|
253
|
+
|
|
254
|
+
```java
|
|
255
|
+
var portal = commet.portal().getUrl(RequestPortalAccessParams.builder().customerId("user_123").build());
|
|
256
|
+
|
|
257
|
+
// redirect(portal.portalUrl())
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### PHP
|
|
261
|
+
|
|
262
|
+
```php
|
|
263
|
+
$portal = $commet->portal->getUrl(customerId: 'user_123');
|
|
264
|
+
|
|
265
|
+
redirect($portal->portalUrl);
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### cURL
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
curl -X POST https://commet.co/api/v1/portal/request-access \
|
|
272
|
+
-H "x-api-key: $COMMET_API_KEY" \
|
|
273
|
+
-H "Content-Type: application/json" \
|
|
274
|
+
-d '{"customerId": "user_123"}'
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Related
|
|
278
|
+
|
|
279
|
+
- [Invoices and Billing Cycles](/docs/invoices-and-billing-cycles) — Invoice types and charge timing
|
|
280
|
+
- [Manage Subscriptions](/docs/manage-subscriptions) — Create and manage customer subscriptions
|
|
281
|
+
- [Customer Portal](/docs/customer-portal) — Self-service billing portal for customers
|
|
282
|
+
- [Payment Providers](/docs/payment-providers) — How Commet routes payments through Commet, Stripe, or dLocal
|
|
283
|
+
- [Payment Orchestration](/docs/payment-orchestration) — Country routing, defaults, and provider-bound payment methods
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
lastModified: 2026-07-10
|
|
3
|
+
title: Invoices and Billing Cycles
|
|
4
|
+
description: How Commet generates invoices, what they contain, and when customers are charged.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Invoices are the financial records Commet generates automatically whenever a subscription event or billing cycle occurs.
|
|
8
|
+
|
|
9
|
+
## Invoice types
|
|
10
|
+
|
|
11
|
+
| Type | When Generated | Example |
|
|
12
|
+
| --------------------- | ------------------------------------------------------- | ------------------------------------------ |
|
|
13
|
+
| **Recurring** | Every billing cycle | $99 plan base + $12.50 overage |
|
|
14
|
+
| **Overage** | Between cycles (quarterly/yearly only) | 15k extra API calls billed monthly |
|
|
15
|
+
| **Plan change** | Customer upgrades mid-cycle | Starter to Pro, prorated $45 |
|
|
16
|
+
| **Credit purchase** | Customer buys a credit pack | 500 credits for $40 |
|
|
17
|
+
| **Balance top-up** | Customer adds funds | $50 balance top-up |
|
|
18
|
+
| **Add-on activation** | Customer activates an add-on mid-cycle | SMS add-on, prorated $32.26 |
|
|
19
|
+
| **Adjustment** | Manual correction issued | $10 refund for service issue |
|
|
20
|
+
| **One-time payment** | Standalone charge (`payments.charge` or a payment link) | $250 one-off invoice, no subscription |
|
|
21
|
+
| **Reactivation** | Canceled subscription is reactivated | Fresh invoice, billing anchor reset to now |
|
|
22
|
+
|
|
23
|
+
The **One-time payment** type backs the [payments resource](/docs/accept-one-time-payments) — charges and payment links with no subscription. Its single line uses the `one_time` line type.
|
|
24
|
+
|
|
25
|
+
## Invoice line types
|
|
26
|
+
|
|
27
|
+
Each invoice is made of typed lines. The line type tells you what the charge is for.
|
|
28
|
+
|
|
29
|
+
| Line type | What it is |
|
|
30
|
+
| --------------------- | --------------------------------------------------------------------------- |
|
|
31
|
+
| `plan_base` | The plan's recurring base price |
|
|
32
|
+
| `feature_overage` | Metered usage beyond the included allowance |
|
|
33
|
+
| `feature_seats` | Seat charges — advance for excess seats plus mid-cycle true-up |
|
|
34
|
+
| `feature_quota` | Quota charges — advance plus true-up |
|
|
35
|
+
| `discount` | Introductory offer discount |
|
|
36
|
+
| `promo_code_discount` | Promo code discount |
|
|
37
|
+
| `credit` | Credit application |
|
|
38
|
+
| `balance_overage` | Balance model overage when the balance is exhausted and usage isn't blocked |
|
|
39
|
+
| `addon_base` | An add-on's base price |
|
|
40
|
+
| `one_time` | A standalone one-time payment, with no subscription |
|
|
41
|
+
|
|
42
|
+
## When charges happen
|
|
43
|
+
|
|
44
|
+
| Component | When Charged | Example |
|
|
45
|
+
| -------------------- | ---------------------------------------------------------- | ----------------------------------------------------------- |
|
|
46
|
+
| **Plan base price** | Advance (period start) | $99 on Jan 1 |
|
|
47
|
+
| **Boolean features** | Included in plan base | SSO, Custom Branding |
|
|
48
|
+
| **Metered overage** | True-up (period end) | 2,500 extra API calls |
|
|
49
|
+
| **Included seats** | Advance (with base) | 5 editor seats |
|
|
50
|
+
| **Additional seats** | Hybrid: true-up for the past period + advance for the next | 3 extra seats prorated for the days used, then billed ahead |
|
|
51
|
+
|
|
52
|
+
## Billing intervals
|
|
53
|
+
|
|
54
|
+
| Interval | Base Invoice | Overage Invoice | Consumption Reset | Example |
|
|
55
|
+
| ------------- | ------------------------- | --------------------------------- | ----------------- | ------------------------------------ |
|
|
56
|
+
| **Weekly** | Every 7 days | Included in recurring invoice | Every 7 days | $25/week every Monday |
|
|
57
|
+
| **Monthly** | Every month | Included in recurring invoice | Every month | $99/month on the 1st |
|
|
58
|
+
| **Quarterly** | Every 3 months | Monthly | Every month | $297 base quarterly, overage monthly |
|
|
59
|
+
| **Yearly** | Every 12 months | Monthly | Every month | $899 base yearly, overage monthly |
|
|
60
|
+
| **One-time** | Single charge at checkout | At period end (if overage exists) | Never | $299 lifetime, no recurring charges |
|
|
61
|
+
|
|
62
|
+
For quarterly and yearly plans, overage is calculated and invoiced monthly even though the base charge is less frequent. For weekly plans, everything runs on a 7-day cycle. For one-time plans, the customer pays once at checkout and never receives a recurring invoice — only overage charges if applicable. See [One-Time Payments](/docs/one-time-payments) for details.
|
|
63
|
+
|
|
64
|
+
## Learn more
|
|
65
|
+
|
|
66
|
+
- [What Invoices Do Customers Receive and When](/docs/what-invoices-do-customers-receive-and-when)
|
|
67
|
+
- [How Do Monthly, Quarterly, and Yearly Billing Work](/docs/how-do-monthly-quarterly-and-yearly-billing-work)
|
|
68
|
+
|
|
69
|
+
## Related
|
|
70
|
+
|
|
71
|
+
- [Handle Failed Payments](/docs/handle-failed-payments) — Retry flow and grace periods for failed charges
|
|
72
|
+
- [Consumption Models](/docs/consumption-models) — Metered, Credits, and Balance explained
|
|
73
|
+
- [Finance Overview](/docs/finance-overview) — How money flows through Commet
|