PHP code example of keboola / billing-api-php-client
1. Go to this page and download the library: Download keboola/billing-api-php-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/ */
keboola / billing-api-php-client example snippets
use Keboola\BillingApi\ClientFactory;
$factory = new ClientFactory();
// Project client (authenticated with a Storage API token).
$client = $factory->createClient('https://billing.keboola.com/', $storageApiToken);
$credits = $client->getRemainingCredits();
var_dump($credits);
// Manage client (authenticated with a Manage API token).
$manageClient = $factory->createManageClient('https://billing.keboola.com/', $manageApiToken);
// Manage client without a token: authenticates with the projected Kubernetes
// service-account token (X-Kubernetes-Authorization), read from the standard
// mount path at request time. Use this when running inside the cluster.
$manageClient = $factory->createManageClient('https://billing.keboola.com/');
use Keboola\ApiClientBase\Auth\ManageApiTokenAuthenticator;
use Keboola\BillingApi\InternalClient;
use Keboola\BillingApi\ManageClient;
$manageClient = new ManageClient(
new InternalClient('https://billing.keboola.com/', new ManageApiTokenAuthenticator($manageApiToken)),
);
use Keboola\BillingApi\Exception\BillingException;
try {
$credits = $client->getRemainingCredits();
} catch (BillingException $e) {
$e->getStatusCode(); // ?int — HTTP status, or null for transport/connection failures
$e->getResponseBody(); // ?string — raw response body when available
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.