rebilly/client-php

Rebilly PHP Client

3.0.0 2023-10-05 12:37 UTC

README

Latest Version on Packagist Software License Total Downloads

The Rebilly SDK for PHP makes it easy for developers to access Rebilly REST APIs in their PHP code.

Requirements

  • PHP 8.0+.
  • 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)

Installation

Warning

This package does not follow semantic versioning, so minor version updates can cause backward compatibility breaks. Updates to the package should be tested before switching versions.

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 getcomposer.org.

Supported Versions

The previous version of the SDK can be outdated and won't provide all (or the correct) specifications to communicate with the REST APIs. Only the latest version is constantly supported.

Version Supported Documentation
2.x ⚠️ (security fixes only) See tab PHP-SDK-2.0
3.x ✅ (current) See tab PHP

Quick Examples

Create a Rebilly Client

use Rebilly\Sdk\Client;
use Rebilly\Sdk\CoreService;

// Instantiate Rebilly client.
$client = new Client([
    'base_uri' => Client::SANDBOX_HOST,
    'organizationId' => '{organizationId}',
    'apiKey' => '{secretKey}',
]);
$coreService = new CoreService(client: $client);

Create a Customer

use Rebilly\Sdk\Exception\DataValidationException;
use Rebilly\Sdk\Model\ContactObject;
use Rebilly\Sdk\Model\Customer;

$customer = Customer::from([])
    ->setWebsiteId('{websiteId}')
    ->setPrimaryAddress(
        ContactObject::from([])
            ->setFirstName('John')
            ->setLastName('Doe'),
    );

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

For more see examples directory.

Documentation

Read Rebilly REST APIs documentation for more details.

Migration from SDK v2.x to v3.x

This new major version brings several new helper classes to communicate with Rebilly REST APIs and some incompatibilities that should be tested before switching SDK versions.

  • Now, a service class can be explicitly created to make the API calls instead of using only the Client. The service is a helper class that encapsulates the API calls for a specific context. It means that CoreService is responsible for the API calls related to the core API, UsersService for the users API, and ReportsService for the reports API. CombinedService can be used to make calls to any of the contexts.

  • To simplify the migration from the previous version, the Client object can be used to make calls to any API context directly. For example, instead of instantiating a service class, one can use:

    $client->customers()->create($form);
  • The namespace changed from Rebilly\Entities to Rebilly\Sdk\Model. Now, the src is Rebilly\Sdk.

  • The classes are now generated by an automated process that is triggered every time a new version of the API definitions is released. It means more frequency on the SDK updates, keeping it synced with the REST APIs.