PHP code example of imzala / imzala-php

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

    

imzala / imzala-php example snippets




use Imzala\ImzalaClient;

$imzala = new ImzalaClient(getenv('IMZALA_API_KEY'));

// Aktif şablonlarını listele
$templateList = $imzala->templates()->list();

// Bir şablondan yeni sözleşme (demand) oluştur
$demand = $imzala->demands()->create([
    'template_id' => $templateList->getTemplates()[0]->getId(),
    'party_mapping' => [
        [
            'template_party_id' => $templateList->getTemplates()[0]->getParties()[0]->getId(),
            'first_name' => 'Ahmet',
            'last_name' => 'Yılmaz',
            'email' => '[email protected]',
        ],
    ],
]);

print_r($demand->getSigningUrls()); // her taraf için imzalama linki



use Imzala\ImzalaClient;

$imzala = new ImzalaClient(
    apiKey: getenv('IMZALA_API_KEY'),
    maxRetries: 2, // varsayılan 2, 0 = kapalı
    retryBaseDelayMs: 300, // varsayılan 300ms (backoff: 300ms, 600ms, ...)
);



foreach ($imzala->templates()->listAll(limit: 50) as $template) {
    echo $template->getId() . ' ' . $template->getName() . "\n";
}



use Imzala\ImzalaClient;

$rawBody = file_get_contents('php://input'); // ham body, json_decode ETMEDEN önce

$valid = ImzalaClient::verifyWebhook(
    getenv('IMZALA_WEBHOOK_SECRET'),
    $rawBody,
    $_SERVER['HTTP_X_IMZALA_SIGNATURE_256'] ?? null,
);

if (!$valid) {
    http_response_code(401);
    exit;
}

$event = json_decode($rawBody, true);
// ... $event['type']'a göre işle
http_response_code(200);



use Imzala\ImzalaException;
use Imzala\ImzalaAuthException;
use Imzala\ImzalaRateLimitException;
use Imzala\ImzalaValidationException;

try {
    $imzala->demands()->get($demandId);
} catch (ImzalaRateLimitException $e) {
    echo "Rate limit: {$e->getRetryAfter()} sn sonra tekrar dene";
} catch (ImzalaAuthException $e) {
    echo 'API anahtarı geçersiz veya yetkisiz';
} catch (ImzalaValidationException $e) {
    echo 'İstek doğrulanamadı: ' . $e->getBody();
} catch (ImzalaException $e) {
    echo 'İmzala API hatası: ' . $e->getStatusCode() . ' ' . $e->getMessage();
}
bash
composer