PHP code example of rebilly / client-php

1. Go to this page and download the library: Download rebilly/client-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rebilly / client-php example snippets


use Rebilly\Sdk\Client;
use Rebilly\Sdk\Service;

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

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 = $service->customers()->create($form);
} catch (DataValidationException $e) {
  var_dump($e->getValidationErrors());
}

  $client->customers()->create($form);
  
bash
composer