PHP code example of jeffersongoncalves / laravel-zapsign

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

    

jeffersongoncalves / laravel-zapsign example snippets


use JeffersonGoncalves\ZapSign\Facades\ZapSign;

// Create a document from a PDF URL (or base64_pdf, url_docx, base64_docx, markdown_text)
$document = ZapSign::createDocument([
    'name' => 'Service contract',
    'url_pdf' => 'https://example.com/contract.pdf',
    'lang' => 'pt-br',
    'external_id' => 'order-42',
    'signers' => [
        ['name' => 'Client', 'email' => '[email protected]', 'auth_mode' => 'assinaturaTela', 'send_automatic_email' => true],
    ],
]);

$document['token'];
$document['signers'][0]['sign_url'];

// From a template
ZapSign::createDocumentFromTemplate([
    'template_id' => 'your-template-id',
    'signer_name' => 'Client',
    'data' => [['de' => '{{NOME COMPLETO}}', 'para' => 'Client Name']],
]);

// Async variants (large files): ZapSign answers right away and notifies via webhook
ZapSign::createDocument($data, async: true);
ZapSign::createDocumentFromTemplate($data, async: true);

// Documents
ZapSign::document($token);
ZapSign::documents(page: 1, filters: ['status' => 'signed', '

use JeffersonGoncalves\ZapSign\Exceptions\RateLimitException;
use JeffersonGoncalves\ZapSign\Exceptions\ZapSignException;

try {
    ZapSign::document('missing');
} catch (RateLimitException $e) {
    $e->retryAfter; // seconds
} catch (ZapSignException $e) {
    $e->getMessage(); // ZapSign's `detail`/`message`
    $e->getCode();    // HTTP status
    $e->errors();     // decoded error body
}

use JeffersonGoncalves\ZapSign\Models\Document;

$documents = Document::query()->forModel($contract)->with('signers')->get();

$document->isSigned();
$document->isRefused();
$document->documentable; // the model you linked
Document::query()->where('status', Document::STATUS_PENDING)->get();

use JeffersonGoncalves\ZapSign\Jobs\CreateDocument;
use JeffersonGoncalves\ZapSign\Jobs\SyncDocument;

// Send a file (local path, or a path on any filesystem disk — S3  path: 'contracts/42.pdf', // .pdf or .docx
    disk: 's3',
);

// Or with url_pdf / a template
CreateDocument::dispatch(['template_id' => '...', 'signer_name' => 'Client'], $contract, fromTemplate: true);

// Refresh a document (and its signers) from the API
SyncDocument::dispatch($token);

public function handle(): void
{
    try {
        ZapSign::createDocument([...]);
    } catch (RateLimitException $e) {
        $this->release($e->retryAfter);
    }
}

ZapSign::request('post', 'user/company/webhook/', [
    'url' => route('zapsign.webhook'),
    'type' => '', // all events
    'headers' => [['name' => 'X-ZapSign-Secret', 'value' => config('zapsign.webhook.secret')]],
]);

use Illuminate\Support\Facades\Event;
use JeffersonGoncalves\ZapSign\Events\WebhookReceived;
use JeffersonGoncalves\ZapSign\Models\Document;

Event::listen(function (WebhookReceived $event) {
    $document = Document::query()->where('token', $event->documentToken())->first();

    match ($event->type()) {
        'doc_signed' => /* $event->payload['signer_who_signed'] */ null,
        'doc_refused', 'email_bounce' => /* ... */ null,
        default => null,
    };
});
bash
php artisan zapsign:install
# or
php artisan vendor:publish --tag="zapsign-config"
php artisan vendor:publish --tag="zapsign-migrations"
php artisan migrate