commet / commet-php
Commet PHP SDK - Billing and usage tracking for SaaS applications
v9.4.0
2026-09-29 18:55 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^10.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v9.4.0
- v9.3.0
- v9.2.0
- v9.0.0
- v8.0.1
- v8.0.0
- v7.10.0
- v7.9.0
- v7.7.0
- v7.6.0
- v7.5.0
- v7.4.0
- v7.2.0
- v7.1.0
- v7.0.0
- v6.0.0
- v5.5.0
- v5.4.0
- v5.3.0
- v5.2.0
- v5.0.0
- v4.6.0
- v4.5.0
- v4.3.0
- v4.2.0
- v4.1.0
- v4.0.0
- v3.1.0
- v3.0.0
- v2.0.0
- v1.10.0
- v1.9.0
- v0.3.0
- v0.2.0
- v0.1.0
- dev-feat/issue-2171
- dev-feat/issue-2538
- dev-feat/issue-2530
- dev-codex/restricted-api-keys
- dev-feat/issue-1945
- dev-feature/bil-1567
- dev-feat/sdk-codegen
- dev-fix/sdk-parity-php
- dev-feature/bil-1348-quota
- dev-fix/stale-tests
- dev-feature/bil-1509
This package is auto-updated.
Last update: 2026-09-29 18:56:12 UTC
README
Billing and usage tracking for SaaS applications.
Installation
composer require commet/commet-php
Quick start
use Commet\Commet; $commet = new Commet(apiKey: 'ck_xxx'); // Create a customer $customer = $commet->customers->create(email: 'user@example.com'); // Create a subscription $commet->subscriptions->create(customerId: $customer->id, planCode: 'pro'); // Track usage $commet->usage->track( featureCode: 'api_calls', customerId: $customer->id, value: 1, ); // Track AI token usage $commet->usage->track( featureCode: 'ai_generation', customerId: $customer->id, model: 'claude-sonnet-4-20250514', inputTokens: 1000, outputTokens: 500, );
Offers and pricing Markets
SDK v9 exposes independent Offers, top-level Markets, and selectable priceId variants:
use Commet\Models\CreateOfferParamsPhasesItemVariant2; $market = $commet->markets->create( name: 'Argentina', countryCodes: ['AR'], ); $offer = $commet->offers->create( name: 'First three months at 25% off', phases: [ new CreateOfferParamsPhasesItemVariant2( type: 'percentage', durationCycles: 3, percentage: 2500, ), ], );
Promo Codes reference compatible Offers. Omitting priceId during subscription creation keeps normal default-price resolution.
Quota
Track consumption against a fixed allowance:
$commet->quota->add(featureCode: 'tasks', count: 3, customerId: 'user_123'); $commet->quota->set(featureCode: 'tasks', count: 10, customerId: 'user_123'); $commet->quota->remove(featureCode: 'tasks', count: 1, customerId: 'user_123'); $allowance = $commet->quota->get(featureCode: 'tasks', customerId: 'user_123'); $allowances = $commet->quota->getAll(customerId: 'user_123');
Webhook verification
use Commet\Resources\WebhooksResource; $webhooks = new WebhooksResource(); $payload = $webhooks->verifyAndParse( rawBody: $requestBody, signature: $_SERVER['HTTP_X_COMMET_SIGNATURE'] ?? null, secret: 'whsec_xxx', ); if ($payload === null) { throw new \RuntimeException('Invalid webhook signature'); } if ($payload['event'] === 'subscription.activated') { // handle activation }
License
MIT