PHP code example of ricardo-machobear / killbill-client

1. Go to this page and download the library: Download ricardo-machobear/killbill-client 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/ */

    

ricardo-machobear / killbill-client example snippets





Killbill\Client\KillbillClient;
use Killbill\Client\Swagger\Model\Account;
use Killbill\Client\Swagger\Model\Tenant;

// Setup Killbill client
$client = new KillbillClient(null, 'http://localhost:8080', 'ADMIN_LOGIN', 'ADMIN_PASSWORD');

// Set these values for your particular tenant
$tenant = new Tenant();
$tenant->setApiKey('bob');
$tenant->setApiSecret('lazar');
$tenant = $this->client->getTenantApi()->createTenant($tenant, 'pierre', 'PHP_TEST', 'no comment');

// Point the client to work with this tenant
$client->setApiKey('bob');
$client->setApiSecret('lazar');

// Unique id for this account
$externalAccountId = uniqid();

$accountData = new Account();
$accountData->setName('Killbill php test');
$accountData->setExternalKey($externalAccountId);
$accountData->setEmail('test-' . $externalAccountId . '@kill-bill.org');
$accountData->setCurrency('USD');
$accountData->setPaymentMethodId(null);
$accountData->setAddress1('12 rue des ecoles');
$accountData->setAddress2('Poitier');
$accountData->setCompany('Renault');
$accountData->setState('Poitou');
$accountData->setCountry('France');
$accountData->setPhone('81 53 26 56');
$accountData->setFirstNameLength(4);
$accountData->setTimeZone('UTC');

$account = $client->getAccountApi()->createAccount($accountData, 'pierre', 'PHP_TEST', 'no comment');


// In case you need to make custom requests to Killbill plugins using guzzle:
use Killbill\Client\AddAuthHeadersMiddleware;

$guzzle = $client->getGuzzleClient();
// base_host is already configured
$response = $guzzle->request('POST', '/plugins/killbill-stripe/checkout', [
    'form_params' => [
        'kbAccountId' => $account->getAccountId(),
        'successUrl' => $successUrl,
        'cancelUrl' => $cancelUrl,
    ],
    //BASIC_AUTH adds admin/password credenditals;
    //TENANT_KEY adds key/secret header
    AddAuthHeadersMiddleware::OPTION => AddAuthHeadersMiddleware::BASIC_AUTH | AddAuthHeadersMiddleware::TENANT_KEY,
]);