This package provides an API client for Chargebee subscription management services.
It connects to Chargebee REST APIs for the following versions:
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
});
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.