This package provides an API client for Chargebee subscription management services.
It connects to Chargebee REST APIs for the following versions:
- Chargebee API : version 2 (see official API documentation)
- Product Catalog: version 2.0 (see official API documentation)
If your Chargebee site is using Product Catalog version 1.0, you can use our product_catalog_v1 branch. It works mostly the same, but be aware that it is neither maintained nor documented.
composer require globalis/chargebee-php-sdk php-http/guzzle7-adapter
<?php
use Globalis\Chargebee\Client as ChargebeeClient;
use Http\Client\Exception\HttpException;
$chargebee = new ChargebeeClient('{site}', '{site_api_key}');
try {
// List last created subscription:
$response = $chargebee->subscription()->list([
"limit" => 1,
"sort_by[desc]" => "created_at",
"status[is]" => "active",
]);
} catch (HttpException $e) {
// Get API error details:
$response = json_decode($e->getResponse()->getBody(), true);
echo sprintf("Error: (%s) %s", $response["api_error_code"], $response["message"]);
}
The API client produces events on API responses. You can listen to those events and connect any callable on them.
The events implement Psr\EventDispatcher\StoppableEventInterface from league/event PSR-14 package.
<?php
use Globalis\Chargebee\Client as Chargebee;
use Globalis\Chargebee\Events\EventChargebeeApiResponseSuccess as EventResponseSuccess;
use Globalis\Chargebee\Events\EventChargebeeApiResponseError as EventResponseError;
Chargebee::onApiResponseSuccess(function (EventResponseSuccess $event) {
// $event contains data about the API request and response
// do something
});
Chargebee::onApiResponseError(function (EventResponseError $event) {
// $event contains data about the API request and response
// do something
});
- WordPress: globalis/chargebee-php-sdk-wp converts PSR-14 events into WordPress hooks and connects to query-monitor to debug your API requests.
This project is a fork of nathandunn/chargebee-php-sdk package. We forked it so we could implement Product Catalog 2.0 changes. We also added PSR-14 events, and fixed a few bugs.
We don't have a full documentation yet.
You will find more details on the usage of HTTPlug and the HttpClient\Builder on the original README.md and wiki.