Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Rebilly SDK for PHP

Latest Version on Packagist Software License GitHub Actions status Total Downloads Coverage Status

The Rebilly SDK for PHP makes it easy for developers to access Rebilly REST APIs in their PHP code. You can get started in minutes by installing the SDK through Composer or by downloading a single zip file from our latest release.


Using Composer is the recommended way to install the Rebilly SDK for PHP. To get started, you need run the Composer commands (assume you're in the project's root directory).

  • Install the latest stable version of the SDK:
composer require rebilly/client-php

You can find out more on how to install Composer, configure autoloading, and other best-practices for defining dependencies at


  • PHP 7.1+.
  • CURL (verify peer requires a root certificate authority -- if you have not configured php curl to use one, and your system libs aren't linked to one, you may need to do a manual configuration to use the appropriate certificate authority)
  • PHPUnit (tests only)

Quick Examples

Create a Rebilly Client

use Rebilly\Client;

// Instantiate Rebilly client.
$client = new Client([
  'apiKey' => ApiKeyProvider::env(),
  'baseUrl' => Client::SANDBOX_HOST,

Create a Customer

$form = new Customer();

try {
  $customer = $client->customers()->create($form);
} catch (DataValidationException $e) {

Mock Rebilly Client for Test purposes

If you use Guzzle jump to the 2nd example, for regular usage the example with custom handler is below.

Custom handler

use Rebilly\Http\HttpHandler;

MockHandler implements HttpHandler {

    private $responses;

    public function append($response)
        $this->responses[] = $response;

    public function __invoke(Request $request)
        return array_shift($this->responses);

$httpHandler = new MockHandler();

new RebillyClient(['httpHandler' => $httpHandler]);

// Here is mocked part

Guzzle handler

use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Psr7\Response;
use Rebilly\Client as RebillyClient;
use Rebilly\Http\GuzzleAdapter;
$mockHandler = new MockHandler();
$guzzleAdapter = new GuzzleAdapter(
    new Client(
            'handler' => $mockHandler,

new RebillyClient([
    'httpHandler' => $guzzleAdapter

// Here is mocked part
$response = new Response(204);

If RebillyClient does several sequenced requests in the code you need to cover, responses have to be appended in the same order as RebillyClient is called:

// Send several sequenced requests
$transaction = $rebillyClient->transactions()->load($id);
$refundedTransaction = $rebillyClient->transactions()->refund($id, $amount);
$transactionWithCustomer = $rebillyClient->transactions()->load($id, ['expand' => 'customer']);

Tests become:

$response = new Response(200, [], json_encode($transaction));
$responseWithCustomer = new Response(200, [], json_encode($transactionWithCustomer));

 * hint: if you receive an error message 'Cannot create resource by URI "..."' during the tests
 * most probably the created Response misses appropriate "Location" header.
 * Below is an example of mocked POST response `/transactions/{transactionId}/refund` which is not listed in `Rebilly\Entities\Schema`
 * because it can be simply mapped by "Location" header from the response.
 * The "Location" header shows Client which Schema to use to create an object out of the response content.
$responseRefund = new GuzzleResponse(201, ['Location' => 'transactions/{transactionId}'], json_encode($transaction));

// Now append them in the same order as it is called in the code


Read Rebilly REST APIs documentation for more details.


# install required files
$ composer self-update
$ composer install

# run the test