PHP code example of esigner / sdk

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

    

esigner / sdk example snippets


use Esigner\EsignerClient;

// ['market' => 'se'] for esigner.se — see the table below
$esigner = new EsignerClient(getenv('ESIGNER_API_KEY'));

$request = $esigner->signatureRequests->createWithFiles('/path/to/contract.pdf', [
    // The sender: receives the receipt and the signed PDF
    'ownerEmail'      => '[email protected]',
    'signers'         => [
        ['name' => 'Ola Nordmann', 'email' => '[email protected]'],
        ['name' => 'Kari Nordmann', 'email' => '[email protected]'],
    ],
    // Draw from your plan's quota
    'useSubscription' => true,
    // Optional: Norwegian BankID only
    'signingEids'     => ['no_bankid'],
    // Optional: where signers land after the eID step
    'returnUrl'       => 'https://example.com/contracts/123/signed',
]);

echo $request['signers'][0]['sign_url'];

$document = $esigner->documents->upload(
    ['a.pdf', 'b.docx'],
    ['ownerEmail' => '[email protected]'],
);
$request = $esigner->signatureRequests->create([
    'documentId' => $document['id'],
    'signers'    => [/* … */],
]);

// status, signers, …
$request = $esigner->signatureRequests->retrieve($id);

if ($request['status'] === 'completed') {
    // The PDF's bytes
    $pdf = $esigner->signatureRequests->downloadSignedDocument($id);
    file_put_contents('signed.pdf', $pdf);
}

// Before anyone has signed
$esigner->signatureRequests->cancel($id, ['reason' => 'Wrong version']);

// Several files → one entry per position
$esigner->signatureRequests->listSignedDocuments($id);

// ['balance_ore' => …, 'currency' => …]
$esigner->balance->retrieve();

foreach ($esigner->balance->allTransactions() as $tx) {
    // every page, newest first
}

foreach ($esigner->events->all(['type' => 'document.completed']) as $event) {
    // the same events your webhook receives — for backfilling after downtime
}

use Esigner\SignatureVerificationException;
use Esigner\Webhook;

add_action('rest_api_init', function () {
    register_rest_route('mysite/v1', '/esigner', [
        'methods'             => 'POST',
        'permission_callback' => '__return_true',
        'callback'            => function (WP_REST_Request $req) {
            try {
                $event = Webhook::constructEvent(
                    $req->get_body(),                          // the raw body
                    $req->get_header('esigner_signature'),
                    getenv('ESIGNER_WEBHOOK_SECRET'),          // whsec_…
                );
            } catch (SignatureVerificationException $e) {
                return new WP_REST_Response(null, 400);
            }
            switch ($event['type']) {
                case 'signer.signed':
                    // $event['data']['signersSigned'] of ['signersTotal']
                    break;
                case 'document.completed':
                    // downloadSignedDocument($event['data']['orderId'])
                    break;
            }
            return new WP_REST_Response(null, 200);
        },
    ]);
});

use Esigner\EsignerException;

try {
    $esigner->signatureRequests->create([/* … */]);
} catch (EsignerException $e) {
    if ($e->errorCode === 'quota_exceeded') { /* … */ }
    // also $e->status, $e->detail and the full decoded $e->body
}

new EsignerClient($key, [
    'market'      => 'no',     // which esigner site the key belongs to
    'base_url'    => null,     // or a full API base, e.g. a staging host
    'max_retries' => 2,
    'timeout'     => 60,       // seconds per attempt
]);