Skip to content

Chargebee API PHP Client (for API version 2 and Product Catalog version 2.0)

License

Notifications You must be signed in to change notification settings

globalis-ms/chargebee-php-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chargebee-php-sdk

Packagist Latest Stable Version License

Overview

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.

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

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.

About

Chargebee API PHP Client (for API version 2 and Product Catalog version 2.0)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages