chargebee / chargebee-php
ChargeBee API client implementation for PHP
Installs: 6 612 920
Dependents: 12
Suggesters: 2
Security: 0
Stars: 74
Watchers: 38
Forks: 67
Open Issues: 9
Requires
- php: >=8.1.0
- guzzlehttp/guzzle: >=7
- psr/http-client: ^1.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- dev-master
- v4.6.0
- v4.5.0
- v4.4.1
- v4.4.0
- v4.3.0
- v4.3.0-beta.1
- v4.2.0
- v4.1.1
- v4.1.0
- v4.0.0
- v4.0.0-beta.3
- v4.0.0-beta.2
- v4.0.0-beta.1
- v3.x-dev
- v3.44.0
- v3.43.0
- v3.42.0
- v3.41.0
- v3.40.0
- v3.39.1
- v3.39.0
- v3.38.0
- v3.37.1
- v3.37.0
- v3.36.0
- v3.35.1
- v3.35.0
- v3.34.1
- v3.34.0
- v3.33.0
- v3.32.0
- v3.31.0
- v3.30.0
- v3.29.0
- v3.28.0
- v3.27.1
- v3.27.0
- v3.26.1
- v3.26.0
- v3.25.1
- v3.25.0
- v3.24.1
- v3.24.0
- v3.23.0
- v3.22.0
- v3.21.0
- v3.20.0
- v3.19.0
- v3.18.0
- v3.17.0
- v3.16.0
- v3.15.0
- v3.14.0
- v3.13.0
- v3.12.0
- v3.11.0
- v3.10.0
- v3.9.0
- v3.8.0
- v3.7.0
- v3.6.0
- v3.5.2
- v3.5.1
- v3.5.0
- v3.4.0
- v3.3.0
- v3.2.1
- v3.2.0
- v3.2.0-rc.1
- v3.1.0
- v3.0.0
- v2.x-dev
- v2.8.3
- v2.8.2
- v2.8.1
- v2.7.9
- v2.7.8
- v2.7.7
- v2.7.6
- v2.7.5
- v2.7.4
- v2.7.3
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.9
- v2.6.8
- v2.6.7
- v2.6.6
- v2.6.5
- v2.6.4
- v2.6.3
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.9
- v2.5.8
- v2.5.7
- v2.5.6
- v2.5.5
- v2.5.4
- v2.5.3
- v2.5.2
- v2.5.1
- v2.5.0
- v2.4.9
- v2.4.8
- v2.4.7
- v2.4.6
- v2.4.5
- v2.4.4
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.9
- v2.3.8
- v2.3.7
- v2.3.6
- v2.3.5
- v2.3.4
- v2.3.3
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.9
- v2.2.8
- v2.2.7
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.9
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.7.5
- v1.7.4
- v1.7.3
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.9
- v1.6.8
- v1.6.7
- v1.6.6
- v1.6.5
- v1.6.4
- v1.6.3
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.9
- v1.5.8
- v1.5.7
- v1.5.6
- v1.5.5
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.9
- v1.4.8
- v1.4.7
- v1.4.6
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.9
- v1.3.8
- v1.3.7
- v1.3.6
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- dev-experimental
- dev-release/v4.2.0
- dev-release/v4.1.1
- dev-release/v4.1.0
- dev-cb-alish-patch-1
- dev-next
- dev-chargebee-php56-support
- dev-chargebee-v1
This package is not auto-updated.
Last update: 2025-06-23 08:59:00 UTC
README
This is the official PHP library for integrating with Chargebee.
- 📘 For a complete reference of available APIs, check out our API Documentation.
- 🧪 To explore and test API capabilities interactively, head over to our API Explorer.
Note: Chargebee now supports two API versions - V1 and V2, of which V2 is the latest release and all future developments will happen in V2. This library is for API version V2. If you’re looking for V1, head to chargebee-v1 branch.
Requirements
PHP 8.1 or later
Installation
Composer
Chargebee
is available on Packagist and can be installed using Composer
composer require chargebee/chargebee-php
To use the bindings,
require_once('vendor/autoload.php');
Usage
To create a new subscription:
use Chargebee\ChargebeeClient; $chargebee = new ChargebeeClient(options: [ "site" => "{your_site}", "apiKey" => "{your_apiKey}", ]); $result = $chargebee->subscription()->createWithItems("customer_id", [ "subscription_items" => [ [ "item_price_id" => "Montly-Item", "quantity" => "3", ] ] ]); $subscription = $result->subscription; $customer = $result->customer;
Create an idempotent request
Idempotency keys are passed along with request headers to allow a safe retry of POST requests.
use Chargebee\ChargebeeClient; $chargebee = new ChargebeeClient(options: [ "site" => "{your_site}", "apiKey" => "{your_apiKey}", ]); $responseCustomer = $chargebee->customer()->create([ "first_name" => "John", "last_name" => "Doe", "email" => "john@test.com", "card" => [ "first_name" => "Joe", "last_name" => "Doe", "number" => "4012888888881881", "expiry_month" => "10", "expiry_year" => "29", "cvv" => "231" ] ], [ "chargebee-idempotency-key" => "<<UUID>>" // Replace <<UUID>> with a unique string ] ); $responseHeaders = $responseCustomer->getResponseHeaders(); // Retrieves response headers print_r($responseHeaders); $idempotencyReplayedValue = $responseCustomer->isIdempotencyReplayed(); // Retrieves Idempotency replayed header value print_r($idempotencyReplayedValue);
isIdempotencyReplayed()
method can be accessed to differentiate between original and replayed requests.
Retry Handling
Chargebee's SDK includes built-in retry logic to handle temporary network issues and server-side errors. This feature is disabled by default but can be enabled when needed.
Key features include:
- Automatic retries for specific HTTP status codes: Retries are automatically triggered for status codes
500
,502
,503
, and504
. - Exponential backoff: Retry delays increase exponentially to prevent overwhelming the server.
- Rate limit management: If a
429 Too Many Requests
response is received with aRetry-After
header, the SDK waits for the specified duration before retrying.Note: Exponential backoff and max retries do not apply in this case.
- Customizable retry behavior: Retry logic can be configured using the
retryConfig
parameter in the environment configuration.
Example: Customizing Retry Logic
You can enable and configure the retry logic by passing a retryConfig
object when initializing the Chargebee environment:
use Chargebee\ChargebeeClient; // Retry Configurations $retryConfig = new RetryConfig(); $retryConfig->setEnabled(true); // Enable retry mechanism $retryConfig->setMaxRetries(5); // Maximum number of retries $retryConfig->setDelayMs(1000); // Delay in milliseconds before retrying $retryConfig->setRetryOn([500, 502, 503, 504]); // Retry on these HTTP status codes $chargebee = new ChargebeeClient(options: [ "site" => "{your_site}", "apiKey" => "{your_apiKey}", "retryConfig" => $retryConfig, ]); // ... your Chargebee API operations below ...
Example: Rate Limit retry logic
You can enable and configure the retry logic for rate-limit by passing a retryConfig
object when initializing the Chargebee environment:
use Chargebee\ChargebeeClient; // Retry Configurations $retryConfig = new RetryConfig(); $retryConfig->setEnabled(true); // Enable retry mechanism $retryConfig->setMaxRetries(5); // Maximum number of retries $retryConfig->setDelayMs(1000); // Delay in milliseconds before retrying $retryConfig->setRetryOn([429]); // Retry on 429 HTTP status codes $chargebee = new ChargebeeClient(options: [ "site" => "{your_site}", "apiKey" => "{your_apiKey}", "retryConfig" => $retryConfig, ]); // ... your Chargebee API operations below ...
License
See the LICENSE file.