PHP code example of elvesora / allocora-php

1. Go to this page and download the library: Download elvesora/allocora-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/ */

    

elvesora / allocora-php example snippets




lvesora\Allocora\Client;

$apiKey = getenv('ALLOCORA_API_KEY');

if (!is_string($apiKey) || $apiKey === '') {
    throw new RuntimeException('ALLOCORA_API_KEY is 

$allocora = new Client(
    apiKey: $apiKey,
    baseUrl: 'https://staging.example.com/api/v1',
);

$allocora->payees()->list();
$allocora->payees()->show($payeeId);
$allocora->payees()->create($payee);
$allocora->payees()->batchCreate($payees);
$allocora->payees()->upsert($payeeWithExternalId);
$allocora->payees()->batchUpsert($payeesWithExternalIds);
$allocora->payees()->update($payeeId, $changes);
$allocora->payees()->batchUpdate($recordsWithIds);

$allocora->products()->list();
$allocora->products()->show($productId);
$allocora->products()->create($product);
$allocora->products()->batchCreate($products);
$allocora->products()->upsert($productWithExternalId);
$allocora->products()->batchUpsert($productsWithExternalIds);
$allocora->products()->update($productId, $changes);
$allocora->products()->batchUpdate($recordsWithIds);
$allocora->products()->archive($productId);
$allocora->products()->batchArchive($recordsWithIds);

$response = $allocora->revenues()->create([
    'revenue_source_id' => $revenueSourceId,
    'external_id' => 'invoice-1042',
    'occurred_at' => '2026-08-11T10:30:00Z',
    'amount' => '150.000',
    'currency' => 'USD',
    'type' => 'sale',
]);

$allocora->revenues()->batchCreate($revenues);
$allocora->revenues()->show($revenueId);

$page = $allocora->revenues()->list([
    'page' => 2,
    'per_page' => 50,
    'currency' => 'USD',
    'date_from' => '2026-08-01',
    'date_to' => '2026-08-31',
]);

$records = $page->data();
$pagination = $page->meta();

$allocora->rules()->list();
$allocora->rules()->show($ruleId);
$allocora->rules()->create($rule);
$allocora->rules()->batchCreate($rules);
$allocora->rules()->upsert($ruleWithExternalId);
$allocora->rules()->batchUpsert($rulesWithExternalIds);
$allocora->rules()->update($ruleId, $changes);
$allocora->rules()->batchUpdate($recordsWithIds);
$allocora->rules()->toggleStatus($ruleId);
$allocora->rules()->versions($ruleId);

$response = $allocora->payees()->batchCreate($records);

foreach ((array) $response->data() as $result) {
    if ($result['success'] === false) {
        // Handle this record using index, status, error, and optional errors.
    }
}

$summary = $response->meta(); // processed, succeeded, failed, limit

$response->status();             // HTTP status
$response->body();               // complete decoded JSON object
$response->headers();            // array<string, list<string>>
$response->header('X-Request-Id');
$response->headerLine('Retry-After');
$response->data();               // body['data'] or null
$response->meta();               // body['meta'] or null

use Elvesora\Allocora\Exception\AuthenticationException;
use Elvesora\Allocora\Exception\ApiException;
use Elvesora\Allocora\Exception\AuthorizationException;
use Elvesora\Allocora\Exception\NotFoundException;
use Elvesora\Allocora\Exception\RateLimitException;
use Elvesora\Allocora\Exception\ServerException;
use Elvesora\Allocora\Exception\TransportException;
use Elvesora\Allocora\Exception\ValidationException;

try {
    $response = $allocora->products()->show($productId);
} catch (ValidationException $exception) {
    $status = $exception->statusCode();
} catch (RateLimitException $exception) {
    $waitSeconds = $exception->retryAfter();
} catch (TransportException|ServerException $exception) {
    $retryable = $exception->retryable();
} catch (ApiException $exception) {
    $status = $exception->statusCode();
    $retryable = $exception->retryable();
}
bash
composer