PHP code example of zelovance / php-sdk

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

    

zelovance / php-sdk example snippets




elovance\Sdk\ZelovanceClient;

$zelovance = new ZelovanceClient(
    apiKey: $_ENV['ZELOVANCE_API_KEY'],
    baseUrl: $_ENV['ZELOVANCE_BASE_URL'] ?? 'https://dev.zelovance.com',
);

$firstPage = $zelovance->contacts()->list();

foreach ($firstPage as $contact) {
    echo $contact['uuid'] . PHP_EOL;
    echo ($contact['company_name'] ?? $contact['last_name'] ?? '-') . PHP_EOL;
}

printf(
    "Page %d sur %d, total : %s\n",
    $firstPage->currentPage(),
    $firstPage->lastPage(),
    $firstPage->total() ?? 'inconnu',
);

foreach ($zelovance->contacts()->all() as $contact) {
    echo $contact['uuid'] . PHP_EOL;
}

$contact = $zelovance->contacts()->find(
    'b6b6b6b6-1111-4a1a-9d3e-0f1c2b3a4d5e'
);

use Zelovance\Sdk\Invoices\InvoiceBuilder;

$draft = InvoiceBuilder::forContactUuid(
    idempotencyKey: 'commande-98213',
    contactUuid: 'b6b6b6b6-1111-4a1a-9d3e-0f1c2b3a4d5e',
)
    ->date('2026-08-03')
    ->dueDate('2026-09-02')
    ->operationType('services')
    ->addSection('Conception et préparation')
    ->addItem(
        name: 'Étude et conception',
        quantity: 2,
        unitPrice: 500,
        vatRate: 20,
        unit: 'jour',
    )
    ->addSection('Développement')
    ->addItem(
        name: 'Développement du module',
        quantity: 5,
        unitPrice: 500,
        vatRate: 20,
        unit: 'jour',
    )
    ->addNote(
        'Informations complémentaires',
        'Les travaux suivent le planning validé.',
    );

$invoice = $zelovance->invoices()->create($draft);

echo $invoice['uuid'];

$product = $zelovance->products()->create([
    'name' => 'Accompagnement au développement',
    'code' => 'ACCOMP-DEV',
    'type' => 'service',
    'description' => 'Prestation facturée à la journée.',
    'unit_price' => 750,
    'unit' => 'jour',
    'vat_rate' => 20,
]);

$productUuid = $product['uuid'];

$draft = InvoiceBuilder::forContactUuid(
    idempotencyKey: 'commande-98215',
    contactUuid: 'b6b6b6b6-1111-4a1a-9d3e-0f1c2b3a4d5e',
)
    ->date('2026-08-03')
    ->dueDate('2026-09-02')
    ->addItem(
        name: 'Accompagnement au développement',
        quantity: 1,
        unitPrice: 750,
        vatRate: 20,
        unit: 'jour',
        productUuid: $productUuid,
    );

$invoice = $zelovance->invoices()->create($draft);

$firstPage = $zelovance->products()->list(['page' => 1]);

foreach ($zelovance->products()->all() as $catalogProduct) {
    echo $catalogProduct['uuid'] . PHP_EOL;
}

$product = $zelovance->products()->find($productUuid);

$product = $zelovance->products()->update($productUuid, [
    'name' => 'Accompagnement au développement — forfait',
    'unit_price' => 800,
]);

$invoice = $zelovance->invoices()->create([
    'idempotency_key' => 'commande-98214',
    'contact_external_id' => 'crm-42',
    'type' => 'standard',
    'date' => '2026-08-03',
    'due_date' => '2026-09-02',
    'lines' => [
        [
            'line_type' => 'section',
            'name' => 'Développement',
        ],
        [
            'line_type' => 'item',
            'name' => 'Développement du module',
            'quantity' => 5,
            'unit' => 'jour',
            'unit_price' => 500,
            'vat_rate' => 20,
        ],
    ],
]);

$invoices = $zelovance->invoices()->list(['page' => 1]);

$invoice = $zelovance->invoices()->find(
    '6f2e4b0a-2222-4a1a-9d3e-0f1c2b3a4d5e'
);

use Zelovance\Sdk\Exceptions\AuthenticationException;
use Zelovance\Sdk\Exceptions\IdempotencyConflictException;
use Zelovance\Sdk\Exceptions\RateLimitException;
use Zelovance\Sdk\Exceptions\ValidationException;

try {
    $invoice = $zelovance->invoices()->create($draft);
} catch (ValidationException $exception) {
    foreach ($exception->errors() as $field => $messages) {
        echo $field . ': ' . implode(', ', $messages) . PHP_EOL;
    }
} catch (AuthenticationException $exception) {
    // Clé absente, invalide, révoquée ou expirée.
} catch (IdempotencyConflictException $exception) {
    // La même clé a été utilisée avec un contenu différent.
    // Créez une nouvelle clé avant de renvoyer la facture modifiée.
} catch (RateLimitException $exception) {
    $retryAfter = $exception->retryAfter();
}

use Zelovance\Sdk\Webhooks\SignatureVerifier;

$rawBody = file_get_contents('php://input') ?: '';
$received = $_SERVER['HTTP_X_ZELOVANCE_SIGNATURE'] ?? '';

if (! SignatureVerifier::verify(
    rawBody: $rawBody,
    receivedSignature: $received,
    secret: $_ENV['ZELOVANCE_WEBHOOK_SECRET'],
)) {
    http_response_code(401);
    exit('Signature invalide');
}
bash
mkdir -p packages
unzip zelovance-php-sdk-0.2.0-beta.2.zip -d packages/zelovance-php-sdk
bash
composer config repositories.zelovance path ./packages/zelovance-php-sdk
composer 
bash
composer config repositories.zelovance.options.symlink false
composer update zelovance/php-sdk
bash
php tests/smoke.php