globalis / chargebee-php-sdk
Chargebee API PHP Client (for API version 2 and Product Catalog version 2.0)
Requires
- php: ^7.4 || ^8.0 || ^8.1
- globalis/wp-cubi-helpers: ^1.0
- http-interop/http-factory-guzzle: ^1.0
- league/event: ^3.0
- php-http/client-common: ^2.1
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.7
- php-http/message: ^1.7
- php-http/message-factory: ^1.0
- php-http/multipart-stream-builder: ^1.0
- psr/http-client: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.4.1
- guzzlehttp/psr7: ^2.1.0
- php-http/guzzle7-adapter: ^1.0.0
- php-http/mock-client: ^1.3
- phpunit/phpunit: ^9.5.13
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2024-11-18 16:31:15 UTC
README
Overview
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.
Installation
composer require globalis/chargebee-php-sdk php-http/guzzle7-adapter
Basic usage
<?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"]); }
Events
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 });
Integrations
- WordPress: globalis/chargebee-php-sdk-wp converts PSR-14 events into WordPress hooks and connects to query-monitor to debug your API requests.
History
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.
Documentation
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.