PHP code example of mekari / esign-api-php

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

    

mekari / esign-api-php example snippets


composer 


$clientId = 'your-client-id';
$clientSecret = 'your-client-secret';
$production = true; // or false if you're not using the production environment

$client = new EsignApiPhp\EsignApiClient($clientId, $clientSecret, $production);


$auth = $client->auth();

$code: The authorization code.


$auth = $client->auth();
$code = 'your-authorization-code';

try {
    $data = $auth->getUserAuthToken($code);
    echo 'Access Token: ' . $data['access_token'];
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$refreshToken: The refresh token.


$auth = $client->auth();
$refreshToken = 'your-refresh-token';

try {
    $data = $auth->getRefreshToken($refreshToken);
    echo 'New Access Token: ' . $data['access_token'];
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}


$globalSign = $client->globalSign();
$doc = 'your-document';
$filename = 'your-filename';
$signers = ['signer1', 'signer2'];
$signing_order = true //optional, default false;
$callback_url = 'your-callback-url';
$token = 'your-token';

try {
    $data = $globalSign->requestGlobalSign($doc, $filename, $signers, $signing_order, $callback_url, $token);
    echo 'Document ID: ' . $data['id'];
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}


$globalSign = $client->psreSign();
$doc = 'your-document';
$filename = 'your-filename';
$signers = ['signer1', 'signer2'];
$signing_order = true //optional, default false;
$callback_url = 'your-callback-url';
$token = 'your-token';

try {
    $data = $globalSign->requestGlobalSign($doc, $filename, $signers, $signing_order, $callback_url, $token);
    echo 'Document ID: ' . $data['id'];
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}


$psreSign = $client->psreSign();
$documentId = 'your-document-id';
$token = 'your-token';

try {
    $data = $psreSign->generateSigningUrl($documentId, $token);
    echo 'Document ID: ' . $data['id'];
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$stamping = $client->stamping();
$doc = 'your-document';
$filename = 'your-filename';
$annotation = 'your-annotation';
$callback_url = 'your-callback-url';
$token = 'your-token';

try {
    $data = $stamping->stamp($doc, $filename, $annotation, $callback_url, $token);
    echo 'Document ID: ' . $data['id'];
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$document = $client->document();
$page = 1;
$limit = 10;
$token = 'your-token';
$category = 'your-category';
$signing_status = 'your-signing-status';
$stamping_status = 'your-stamping-status';

try {
    $data = $document->getDocumentList($page, $limit, $token, $category, $signing_status, $stamping_status);
    echo 'Documents: ' . print_r($data, true);
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$document = $client->document();
$documentId = 'your-document-id';
$token = 'your-token';

try {
    $data = $document->getDocumentDetail($documentId, $token);
    echo 'Document Details: ' . print_r($data, true);
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$document = $client->document();
$documentId = 'your-document-id';
$token = 'your-token';

try {
    $data = $document->downloadDocument($documentId, $token);
    file_put_contents($documentId . '.pdf', $data);
    echo 'Document downloaded successfully.';
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$document = $client->document();
$documentId = 'your-document-id';
$token = 'your-token';

try {
    $data = $document->resendDocument($documentId, $token);
    echo 'Document resent successfully.';
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$document = $client->document();
$documentId = 'your-document-id';
$token = 'your-token';
$reason = 'your-reason';

try {
    $data = $document->voidDocument($documentId, $token, $reason);
    echo 'Document voided successfully.';
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$document = $client->document();
$documentId = 'your-document-id';
$token = 'your-token';

try {
    $data = $document->deleteDocument($documentId, $token);
    echo 'Document deleted successfully.';
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$autoSign = $client->autoSign();
$docMakerEmails = ['[email protected]', '[email protected]'];
$signerEmails = ['[email protected]', '[email protected]'];
$token = 'your-token';

try {
    $data = $autoSign->createAutoSign($docMakerEmails, $signerEmails, $token);
    echo 'AutoSign created successfully.';
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$autoSign = $client->autoSign();
$id = 'your-autosign-id';
$docMakerEmail = '[email protected]';
$signerEmail = '[email protected]';
$token = 'your-token';

try {
    $data = $autoSign->updateAutoSign($id, $docMakerEmail, $signerEmail, $token);
    echo 'AutoSign updated successfully.';
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$autoSign = $client->autoSign();
$id = 'your-autosign-id';
$token = 'your-token';

try {
    $result = $autoSign->deleteAutoSign($id, $token);
    if ($result) {
        echo 'AutoSign deleted successfully.';
    }
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$autoSign = $client->autoSign();
$id = 'your-autosign-id';
$token = 'your-token';

try {
    $data = $autoSign->detailAutoSign($id, $token);
    echo 'AutoSign Details: ' . print_r($data, true);
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$autoSign = $client->autoSign();
$docMakerEmail = '[email protected]';
$signerEmail = '[email protected]';
$page = 1;
$limit = 10;
$token = 'your-token';

try {
    $data = $autoSign->listAutoSign($docMakerEmail, $signerEmail, $page, $limit, $token);
    echo 'AutoSign List: ' . print_r($data, true);
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}