@commet/node 9.0.0 → 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 +2 -0
- package/dist/index.d.mts +333 -111
- package/dist/index.d.ts +333 -111
- package/dist/index.js +162 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +162 -40
- 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,214 @@
|
|
|
1
|
+
---
|
|
2
|
+
lastModified: 2026-07-28
|
|
3
|
+
title: Integrate with Symfony
|
|
4
|
+
description: Add billing and payments to your Symfony 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
|
+
composer require commet/commet-php
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
2. ## Configure
|
|
19
|
+
```bash title=".env"
|
|
20
|
+
COMMET_API_KEY=ck_sandbox_xxx
|
|
21
|
+
COMMET_WEBHOOK_SECRET=whsec_xxx
|
|
22
|
+
```
|
|
23
|
+
```yaml title="config/services.yaml"
|
|
24
|
+
services:
|
|
25
|
+
Commet\Commet:
|
|
26
|
+
factory: ['@App\Factory\CommetFactory', 'create']
|
|
27
|
+
|
|
28
|
+
App\Factory\CommetFactory:
|
|
29
|
+
arguments:
|
|
30
|
+
$apiKey: '%env(COMMET_API_KEY)%'
|
|
31
|
+
```
|
|
32
|
+
```php title="src/Factory/CommetFactory.php"
|
|
33
|
+
<?php
|
|
34
|
+
|
|
35
|
+
namespace App\Factory;
|
|
36
|
+
|
|
37
|
+
use Commet\Commet;
|
|
38
|
+
|
|
39
|
+
class CommetFactory
|
|
40
|
+
{
|
|
41
|
+
public function __construct(
|
|
42
|
+
private string $apiKey,
|
|
43
|
+
) {}
|
|
44
|
+
|
|
45
|
+
public function create(): Commet
|
|
46
|
+
{
|
|
47
|
+
return new Commet(
|
|
48
|
+
apiKey: $this->apiKey,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
3. ## Subscribe
|
|
55
|
+
```php title="src/Controller/BillingController.php"
|
|
56
|
+
<?php
|
|
57
|
+
|
|
58
|
+
namespace App\Controller;
|
|
59
|
+
|
|
60
|
+
use Commet\Commet;
|
|
61
|
+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
62
|
+
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
63
|
+
use Symfony\Component\HttpFoundation\Request;
|
|
64
|
+
use Symfony\Component\Routing\Attribute\Route;
|
|
65
|
+
|
|
66
|
+
class BillingController extends AbstractController
|
|
67
|
+
{
|
|
68
|
+
public function __construct(
|
|
69
|
+
private Commet $commet,
|
|
70
|
+
) {}
|
|
71
|
+
|
|
72
|
+
#[Route('/billing/subscribe', methods: ['POST'])]
|
|
73
|
+
public function subscribe(Request $request): JsonResponse
|
|
74
|
+
{
|
|
75
|
+
$data = $request->toArray();
|
|
76
|
+
|
|
77
|
+
$this->commet->customers->create(
|
|
78
|
+
email: $data['email'],
|
|
79
|
+
id: $data['customer_id'],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
$subscription = $this->commet->subscriptions->create(
|
|
83
|
+
customerId: $data['customer_id'],
|
|
84
|
+
planCode: 'pro',
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return $this->json([
|
|
88
|
+
'checkout_url' => $subscription->checkoutUrl,
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
4. ## Check Access
|
|
95
|
+
```php title="src/Controller/BillingController.php"
|
|
96
|
+
#[Route('/billing/subscription/{customerId}', methods: ['GET'])]
|
|
97
|
+
public function getSubscription(string $customerId): JsonResponse
|
|
98
|
+
{
|
|
99
|
+
$subscription = $this->commet->subscriptions->getActive($customerId);
|
|
100
|
+
|
|
101
|
+
if ($subscription === null) {
|
|
102
|
+
return $this->json(['error' => 'no_active_subscription'], 404);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return $this->json([
|
|
106
|
+
'status' => $subscription->status->value,
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#[Route('/billing/features/{feature}/{customerId}', methods: ['GET'])]
|
|
111
|
+
public function checkFeature(string $feature, string $customerId): JsonResponse
|
|
112
|
+
{
|
|
113
|
+
$result = $this->commet->featureAccess->get(code: $feature, customerId: $customerId);
|
|
114
|
+
|
|
115
|
+
return $this->json([
|
|
116
|
+
'allowed' => $result->allowed,
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
5. ## Track Usage
|
|
122
|
+
```php title="src/Controller/BillingController.php"
|
|
123
|
+
#[Route('/billing/usage', methods: ['POST'])]
|
|
124
|
+
public function trackUsage(Request $request): JsonResponse
|
|
125
|
+
{
|
|
126
|
+
$data = $request->toArray();
|
|
127
|
+
|
|
128
|
+
$this->commet->usage->track(
|
|
129
|
+
customerId: $data['customer_id'],
|
|
130
|
+
featureCode: 'api_calls',
|
|
131
|
+
value: 1,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
return $this->json(['tracked' => true]);
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
Usage is aggregated and billed at end of period.
|
|
138
|
+
|
|
139
|
+
6. ## Customer Portal
|
|
140
|
+
```php title="src/Controller/BillingController.php"
|
|
141
|
+
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
142
|
+
|
|
143
|
+
#[Route('/billing/portal', methods: ['GET'])]
|
|
144
|
+
public function portal(): RedirectResponse
|
|
145
|
+
{
|
|
146
|
+
$result = $this->commet->portal->getUrl(customerId: 'user_123');
|
|
147
|
+
|
|
148
|
+
return $this->redirect($result->portalUrl);
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
7. ## Webhooks
|
|
153
|
+
```php title="src/Controller/WebhookController.php"
|
|
154
|
+
<?php
|
|
155
|
+
|
|
156
|
+
namespace App\Controller;
|
|
157
|
+
|
|
158
|
+
use Commet\Resources\WebhooksResource;
|
|
159
|
+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
160
|
+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
|
161
|
+
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
162
|
+
use Symfony\Component\HttpFoundation\Request;
|
|
163
|
+
use Symfony\Component\HttpFoundation\Response;
|
|
164
|
+
use Symfony\Component\Routing\Attribute\Route;
|
|
165
|
+
|
|
166
|
+
class WebhookController extends AbstractController
|
|
167
|
+
{
|
|
168
|
+
public function __construct(
|
|
169
|
+
#[Autowire(env: 'COMMET_WEBHOOK_SECRET')]
|
|
170
|
+
private string $webhookSecret,
|
|
171
|
+
) {}
|
|
172
|
+
|
|
173
|
+
#[Route('/webhooks/commet', methods: ['POST'])]
|
|
174
|
+
public function handle(Request $request): JsonResponse|Response
|
|
175
|
+
{
|
|
176
|
+
$webhooks = new WebhooksResource();
|
|
177
|
+
|
|
178
|
+
$payload = $webhooks->verifyAndParse(
|
|
179
|
+
rawBody: $request->getContent(),
|
|
180
|
+
signature: $request->headers->get('x-commet-signature'),
|
|
181
|
+
secret: $this->webhookSecret,
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
if ($payload === null) {
|
|
185
|
+
return new Response('Invalid signature', 401);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
match ($payload['event']) {
|
|
189
|
+
'subscription.activated' => $this->handleActivated($payload),
|
|
190
|
+
'subscription.canceled' => $this->handleCanceled($payload),
|
|
191
|
+
default => null,
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
return $this->json(['ok' => true]);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private function handleActivated(array $payload): void
|
|
198
|
+
{
|
|
199
|
+
// handle activation
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private function handleCanceled(array $payload): void
|
|
203
|
+
{
|
|
204
|
+
// handle cancellation
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Related
|
|
210
|
+
|
|
211
|
+
- [Subscriptions](/docs/manage-subscriptions)
|
|
212
|
+
- [Track Usage](/docs/track-usage)
|
|
213
|
+
- [Customer Portal](/docs/customer-portal)
|
|
214
|
+
- [SDK Reference](/docs/sdk-reference)
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
---
|
|
2
|
+
lastModified: 2026-07-28
|
|
3
|
+
title: Add-ons
|
|
4
|
+
description: Offer optional features customers can activate on their subscriptions for an additional price.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Add-ons are optional features with their own price and consumption model that customers activate on their subscriptions. They extend a subscription without modifying the base plan — think SSO, SMS channels, or premium support.
|
|
8
|
+
|
|
9
|
+
## How add-ons work
|
|
10
|
+
|
|
11
|
+
| Aspect | Description |
|
|
12
|
+
| ------------------------ | ----------------------------------------------------------- |
|
|
13
|
+
| **Pricing** | Fixed base price per billing period, prorated on activation |
|
|
14
|
+
| **Charge on activation** | Immediate charge for remaining days in current period |
|
|
15
|
+
| **Recurring billing** | Base price added to the plan's invoice each cycle |
|
|
16
|
+
| **Deactivation** | No refund — the feature stops immediately |
|
|
17
|
+
| **Feature access** | The add-on's feature appears alongside plan features |
|
|
18
|
+
|
|
19
|
+
Each add-on maps to exactly one feature. When activated, that feature becomes available through `featureAccess.get`, `usage.check`, and `featureAccess.list` — no different from a plan feature.
|
|
20
|
+
|
|
21
|
+
## Consumption models
|
|
22
|
+
|
|
23
|
+
Add-ons declare their own consumption model. Boolean add-ons are compatible with any plan. All other models require matching the plan's model.
|
|
24
|
+
|
|
25
|
+
| Model | Description | Compatible Plans | Example |
|
|
26
|
+
| ----------- | ------------------------------------------ | ---------------- | ------------------------------- |
|
|
27
|
+
| **Boolean** | Unlocks access, no usage tracking | All plans | SSO, HIPAA compliance |
|
|
28
|
+
| **Metered** | Included units + overage at period end | Metered plans | SMS: 1000 included, $0.03/extra |
|
|
29
|
+
| **Credits** | Usage consumes from the plan's credit pool | Credits plans | AI summaries: 5 credits/use |
|
|
30
|
+
| **Balance** | Usage deducts from the plan's balance pool | Balance plans | Image processing: $0.015/unit |
|
|
31
|
+
|
|
32
|
+
> **Note**
|
|
33
|
+
>
|
|
34
|
+
> Credits and balance add-ons consume from the plan's **shared pool** — there's no separate pool for the add-on. If the pool runs out, the add-on's feature is blocked too.
|
|
35
|
+
|
|
36
|
+
## Create add-ons in the dashboard
|
|
37
|
+
|
|
38
|
+
Go to **Add-ons** and click **Create Add-on**. Configure the name, base price, feature, and consumption model. For metered add-ons, set included units and overage rate. For credits, set the credit cost per unit.
|
|
39
|
+
|
|
40
|
+
The feature dropdown only shows features not already assigned to another add-on. Once created, the add-on is available to any customer whose plan is compatible.
|
|
41
|
+
|
|
42
|
+
## Availability by subscription status
|
|
43
|
+
|
|
44
|
+
Add-ons can be activated on any subscription with a payment method:
|
|
45
|
+
|
|
46
|
+
| Status | Can activate add-ons |
|
|
47
|
+
| ------------- | ------------------------------------------------- |
|
|
48
|
+
| **Active** | Yes |
|
|
49
|
+
| **Trialing** | Yes — card was captured during trial checkout |
|
|
50
|
+
| **Free plan** | Yes — first purchase prompts for a payment method |
|
|
51
|
+
|
|
52
|
+
## Manage add-ons
|
|
53
|
+
|
|
54
|
+
Add-ons are managed through the dashboard, the customer portal, or the API.
|
|
55
|
+
|
|
56
|
+
| Action | Where |
|
|
57
|
+
| ------------------------------------- | ------------------------------------------------------------ |
|
|
58
|
+
| **Create / update / archive add-ons** | Dashboard → Add-ons, or the `addons` API resource |
|
|
59
|
+
| **Activate / deactivate** | Dashboard (subscription detail), Customer Portal, or the API |
|
|
60
|
+
| **List active add-ons** | API, Dashboard, or Customer Portal |
|
|
61
|
+
|
|
62
|
+
Activate or deactivate an add-on on a subscription via the SDK. Activation charges the prorated amount for the current period; deactivation stops the feature immediately with no refund.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
await commet.subscriptions.activateAddon({
|
|
66
|
+
id: 'sub_abc123',
|
|
67
|
+
addonId: 'adn_xyz789',
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
await commet.subscriptions.deactivateAddon({
|
|
71
|
+
id: 'sub_abc123',
|
|
72
|
+
addonId: 'adn_xyz789',
|
|
73
|
+
})
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
REST equivalents: `POST /api/v1/subscriptions/{id}/addons` and `DELETE /api/v1/subscriptions/{id}/addons/{addonId}`. Add-ons themselves support full CRUD through the `addons` resource: `commet.addons.list`, `get`, `create`, `update`, and `delete`.
|
|
77
|
+
|
|
78
|
+
## Feature access
|
|
79
|
+
|
|
80
|
+
Add-on features work exactly like plan features — no special handling needed:
|
|
81
|
+
|
|
82
|
+
### TypeScript
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
// Check boolean add-on
|
|
86
|
+
const sso = await commet.featureAccess.get({
|
|
87
|
+
customerId: 'user_123',
|
|
88
|
+
code: 'sso',
|
|
89
|
+
})
|
|
90
|
+
// { allowed: true, type: 'boolean', enabled: true }
|
|
91
|
+
|
|
92
|
+
// Track metered add-on usage
|
|
93
|
+
await commet.usage.track({
|
|
94
|
+
customerId: 'user_123',
|
|
95
|
+
featureCode: 'sms_messages',
|
|
96
|
+
value: 50,
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// List all features (plan + add-ons combined)
|
|
100
|
+
const features = await commet.featureAccess.list({
|
|
101
|
+
customerId: 'user_123',
|
|
102
|
+
})
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Python
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
# Check boolean add-on
|
|
109
|
+
sso = commet.feature_access.get('sso', customer_id='user_123')
|
|
110
|
+
# sso.allowed == True, sso.type == 'boolean'
|
|
111
|
+
|
|
112
|
+
# Track metered add-on usage
|
|
113
|
+
commet.usage.track(customer_id='user_123', feature_code='sms_messages', value=50)
|
|
114
|
+
|
|
115
|
+
# List all features (plan + add-ons combined)
|
|
116
|
+
features = commet.feature_access.list(customer_id='user_123')
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Go
|
|
120
|
+
|
|
121
|
+
```go
|
|
122
|
+
// Check boolean add-on
|
|
123
|
+
sso, _ := client.FeatureAccess.Get(ctx, "sso", &commet.GetFeatureAccessParams{
|
|
124
|
+
CustomerID: "user_123",
|
|
125
|
+
})
|
|
126
|
+
// sso.Allowed == true, *sso.Type == "boolean"
|
|
127
|
+
|
|
128
|
+
// Track metered add-on usage
|
|
129
|
+
value := 50
|
|
130
|
+
client.Usage.Track(ctx, &commet.TrackUsageParams{
|
|
131
|
+
CustomerID: "user_123",
|
|
132
|
+
FeatureCode: "sms_messages",
|
|
133
|
+
Value: &value,
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
// List all features (plan + add-ons combined)
|
|
137
|
+
features, _ := client.FeatureAccess.List(ctx, &commet.ListFeatureAccessParams{
|
|
138
|
+
CustomerID: "user_123",
|
|
139
|
+
})
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Java
|
|
143
|
+
|
|
144
|
+
```java
|
|
145
|
+
// Check boolean add-on
|
|
146
|
+
var sso = commet.featureAccess()
|
|
147
|
+
.get("sso", GetFeatureAccessParams.builder("user_123").build());
|
|
148
|
+
// sso.allowed() == true
|
|
149
|
+
|
|
150
|
+
// Track metered add-on usage
|
|
151
|
+
commet.usage().track(
|
|
152
|
+
TrackUsageParams.builder("sms_messages", "user_123").value(50.0).build()
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
// List all features (plan + add-ons combined)
|
|
156
|
+
var features = commet.featureAccess()
|
|
157
|
+
.list(ListFeatureAccessParams.builder("user_123").build());
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### PHP
|
|
161
|
+
|
|
162
|
+
```php
|
|
163
|
+
// Check boolean add-on
|
|
164
|
+
$sso = $commet->featureAccess->get('sso', 'user_123');
|
|
165
|
+
// $sso->allowed === true, $sso->enabled === true
|
|
166
|
+
|
|
167
|
+
// Track metered add-on usage
|
|
168
|
+
$commet->usage->track(
|
|
169
|
+
featureCode: 'sms_messages',
|
|
170
|
+
customerId: 'user_123',
|
|
171
|
+
value: 50,
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
// List all features (plan + add-ons combined)
|
|
175
|
+
$features = $commet->featureAccess->list('user_123');
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### cURL
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# Check boolean add-on
|
|
182
|
+
curl "https://commet.co/api/v1/feature-access/sso?customerId=user_123" \
|
|
183
|
+
-H "x-api-key: $COMMET_API_KEY"
|
|
184
|
+
|
|
185
|
+
# Track metered add-on usage
|
|
186
|
+
curl -X POST https://commet.co/api/v1/usage/events \
|
|
187
|
+
-H "x-api-key: $COMMET_API_KEY" \
|
|
188
|
+
-H "Content-Type: application/json" \
|
|
189
|
+
-d '{
|
|
190
|
+
"featureCode": "sms_messages",
|
|
191
|
+
"customerId": "user_123",
|
|
192
|
+
"value": 50
|
|
193
|
+
}'
|
|
194
|
+
|
|
195
|
+
# List all features (plan + add-ons combined)
|
|
196
|
+
curl "https://commet.co/api/v1/feature-access?customerId=user_123" \
|
|
197
|
+
-H "x-api-key: $COMMET_API_KEY"
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Billing behavior
|
|
201
|
+
|
|
202
|
+
### Activation charge
|
|
203
|
+
|
|
204
|
+
When a customer activates a $50/month add-on on day 11 of a 31-day period (20 days remaining):
|
|
205
|
+
|
|
206
|
+
| | Value |
|
|
207
|
+
| ---------------- | -------------------------- |
|
|
208
|
+
| **Full price** | $50.00 |
|
|
209
|
+
| **Prorated** | $50 × (20/31) = **$32.26** |
|
|
210
|
+
| **Invoice type** | `addon_activation` |
|
|
211
|
+
|
|
212
|
+
The charge goes through the subscription's payment provider immediately with its own invoice.
|
|
213
|
+
|
|
214
|
+
### Recurring invoices
|
|
215
|
+
|
|
216
|
+
Starting from the next full billing cycle, the add-on base price appears as a separate line in the plan's invoice:
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
Plan Pro (base) $99.00
|
|
220
|
+
API Calls: 12,500 (2,500 overage × $0.01) $25.00
|
|
221
|
+
|
|
222
|
+
Add-ons
|
|
223
|
+
SMS Channel (base) $15.00
|
|
224
|
+
SMS: 1,800 (800 overage × $0.03) $24.00
|
|
225
|
+
SSO $50.00
|
|
226
|
+
|
|
227
|
+
Subtotal $213.00
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Multi-currency
|
|
231
|
+
|
|
232
|
+
Add-on prices are defined in USD. For non-USD subscriptions, the price is converted using the plan's exchange rate — the same mechanism used for plan base prices.
|
|
233
|
+
|
|
234
|
+
## Customer portal
|
|
235
|
+
|
|
236
|
+
Customers can self-service add-ons from the portal:
|
|
237
|
+
|
|
238
|
+
- **Available add-ons** — see compatible add-ons with pricing
|
|
239
|
+
- **Activate** — confirmation dialog with prorated charge preview
|
|
240
|
+
- **Active add-ons** — manage active add-ons
|
|
241
|
+
- **Deactivate** — instant, no refund
|
|
242
|
+
|
|
243
|
+
> **Note**
|
|
244
|
+
>
|
|
245
|
+
> Add-ons whose feature already exists in the customer's plan are hidden from the portal automatically.
|
|
246
|
+
|
|
247
|
+
## Learn more
|
|
248
|
+
|
|
249
|
+
- [How Does Billing Work](/docs/how-does-billing-work)
|
|
250
|
+
|
|
251
|
+
## Related
|
|
252
|
+
|
|
253
|
+
- [Consumption Models](/docs/consumption-models) — Metered, Credits, and Balance explained
|
|
254
|
+
- [Configure Features](/docs/configure-features) — Define features that add-ons can unlock
|
|
255
|
+
- [Credit Packs](/docs/credit-packs) — Another way to extend plan capabilities
|
|
256
|
+
- [Manage Subscriptions](/docs/manage-subscriptions) — Subscription lifecycle and management
|
|
257
|
+
- [Customer Portal](/docs/customer-portal) — Where customers activate add-ons
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
---
|
|
2
|
+
lastModified: 2026-08-16
|
|
3
|
+
title: Balance and Top-Ups
|
|
4
|
+
description: Configure prepaid monetary usage, adjust a subscription balance, and let customers buy more.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The Balance consumption model gives a subscription a monetary allowance. Billable usage draws down that balance using each feature's configured price.
|
|
8
|
+
|
|
9
|
+
## Configure a balance plan
|
|
10
|
+
|
|
11
|
+
In **Plans**, choose **Balance**, set the amount included at each reset, and add billable features. Use [AI Token Billing](/docs/ai-token-billing) when model token cost and margin determine the charge.
|
|
12
|
+
|
|
13
|
+
Plan balance resets monthly for monthly, quarterly, yearly, free, and one-time plans. Weekly plans reset every seven days. Purchased top-ups do not survive the next reset.
|
|
14
|
+
|
|
15
|
+
## Adjust balance without charging
|
|
16
|
+
|
|
17
|
+
Use an adjustment for a support correction, migration, or administrative grant:
|
|
18
|
+
|
|
19
|
+
**TypeScript**
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { Commet } from "@commet/node";
|
|
23
|
+
|
|
24
|
+
const commet = new Commet({ apiKey: "ck_xxx" });
|
|
25
|
+
|
|
26
|
+
const balanceAdjustment = await commet.subscriptions.adjustBalance({
|
|
27
|
+
id: "sub_xxx",
|
|
28
|
+
amount: 5000,
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Python**
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from commet import Commet
|
|
36
|
+
|
|
37
|
+
commet = Commet("ck_xxx")
|
|
38
|
+
|
|
39
|
+
balance_adjustment = commet.subscriptions.adjust_balance(
|
|
40
|
+
"sub_xxx",
|
|
41
|
+
amount=5000,
|
|
42
|
+
)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Go**
|
|
46
|
+
|
|
47
|
+
```go
|
|
48
|
+
client, err := commet.New("ck_xxx")
|
|
49
|
+
if err != nil {
|
|
50
|
+
log.Fatal(err)
|
|
51
|
+
}
|
|
52
|
+
ctx := context.Background()
|
|
53
|
+
|
|
54
|
+
balanceAdjustment, err := client.Subscriptions.AdjustBalance(ctx, "sub_xxx", &commet.AdjustBalanceParams{
|
|
55
|
+
Amount: 5000,
|
|
56
|
+
})
|
|
57
|
+
if err != nil {
|
|
58
|
+
log.Fatal(err)
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Java**
|
|
63
|
+
|
|
64
|
+
```java
|
|
65
|
+
import co.commet.Commet;
|
|
66
|
+
import co.commet.params.AdjustBalanceParams;
|
|
67
|
+
|
|
68
|
+
var commet = Commet.builder().apiKey("ck_xxx").build();
|
|
69
|
+
|
|
70
|
+
var balanceAdjustment = commet.subscriptions().adjustBalance(
|
|
71
|
+
"sub_xxx",
|
|
72
|
+
AdjustBalanceParams.builder(5000L).build()
|
|
73
|
+
);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**PHP**
|
|
77
|
+
|
|
78
|
+
```php
|
|
79
|
+
use Commet\Commet;
|
|
80
|
+
|
|
81
|
+
$commet = new Commet('ck_xxx');
|
|
82
|
+
|
|
83
|
+
$balanceAdjustment = $commet->subscriptions->adjustBalance(
|
|
84
|
+
id: 'sub_xxx',
|
|
85
|
+
amount: 5000,
|
|
86
|
+
);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
A positive amount adds balance; a negative amount removes it. Adjustments do not charge the customer's payment method, so keep the reason specific.
|
|
90
|
+
|
|
91
|
+
## Charge for a top-up
|
|
92
|
+
|
|
93
|
+
**TypeScript**
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { Commet } from "@commet/node";
|
|
97
|
+
|
|
98
|
+
const commet = new Commet({ apiKey: "ck_xxx" });
|
|
99
|
+
|
|
100
|
+
const balanceTopup = await commet.subscriptions.topupBalance({
|
|
101
|
+
id: "sub_xxx",
|
|
102
|
+
amount: 5000,
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Python**
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from commet import Commet
|
|
110
|
+
|
|
111
|
+
commet = Commet("ck_xxx")
|
|
112
|
+
|
|
113
|
+
balance_topup = commet.subscriptions.topup_balance(
|
|
114
|
+
"sub_xxx",
|
|
115
|
+
amount=5000,
|
|
116
|
+
)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Go**
|
|
120
|
+
|
|
121
|
+
```go
|
|
122
|
+
client, err := commet.New("ck_xxx")
|
|
123
|
+
if err != nil {
|
|
124
|
+
log.Fatal(err)
|
|
125
|
+
}
|
|
126
|
+
ctx := context.Background()
|
|
127
|
+
|
|
128
|
+
balanceTopup, err := client.Subscriptions.TopupBalance(ctx, "sub_xxx", &commet.TopupBalanceParams{
|
|
129
|
+
Amount: 5000,
|
|
130
|
+
})
|
|
131
|
+
if err != nil {
|
|
132
|
+
log.Fatal(err)
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Java**
|
|
137
|
+
|
|
138
|
+
```java
|
|
139
|
+
import co.commet.Commet;
|
|
140
|
+
import co.commet.params.TopupBalanceParams;
|
|
141
|
+
|
|
142
|
+
var commet = Commet.builder().apiKey("ck_xxx").build();
|
|
143
|
+
|
|
144
|
+
var balanceTopup = commet.subscriptions().topupBalance(
|
|
145
|
+
"sub_xxx",
|
|
146
|
+
TopupBalanceParams.builder(5000L).build()
|
|
147
|
+
);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**PHP**
|
|
151
|
+
|
|
152
|
+
```php
|
|
153
|
+
use Commet\Commet;
|
|
154
|
+
|
|
155
|
+
$commet = new Commet('ck_xxx');
|
|
156
|
+
|
|
157
|
+
$balanceTopup = $commet->subscriptions->topupBalance(
|
|
158
|
+
id: 'sub_xxx',
|
|
159
|
+
amount: 5000,
|
|
160
|
+
);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
A top-up charges the payment method attached to the subscription. Customers can also buy balance from the [Customer Portal](/docs/customer-portal).
|
|
164
|
+
|
|
165
|
+
## Enforce before spending
|
|
166
|
+
|
|
167
|
+
Check usage before work that should not run with insufficient balance, then track only completed work. Use a stable idempotency key so a retry does not deduct twice.
|
|
168
|
+
|
|
169
|
+
Use **Credits** instead when customers should buy product-specific units that persist across resets.
|