PHP code example of signwell / signwell-sdk-php

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

    

signwell / signwell-sdk-php example snippets




ignWell\Sdk\Client;

$signwell = Client::fromApiKey(getenv('SIGNWELL_API_KEY') ?: '');

$document = $signwell->createDocument([
    'test_mode' => true,
    'name' => 'NDA',
    'files' => [
        ['name' => 'nda.pdf', 'file_url' => 'https://example.com/nda.pdf'],
    ],
    'recipients' => [
        ['id' => '1', 'name' => 'Jane Doe', 'email' => '[email protected]'],
    ],
    'fields' => [
        [
            ['page' => 1, 'x' => 120, 'y' => 240, 'type' => 'signature', 'recipient_id' => '1'],
        ],
    ],
]);

use SignWell\Sdk\Errors;
use SignWell\Sdk\Models;
use SignWell\Sdk\Resources;

$documents = new Resources\DocumentApi();
$request = new Models\DocumentRequest(['name' => 'NDA']);

try {
    $documents->getDocument('document-id');
} catch (Errors\NotFoundError $error) {
    // Document was not found.
} catch (Errors\RateLimitError $error) {
    // Retry after backing off.
    $rateLimit = $error->getRateLimit();
} catch (Errors\ApiError $error) {
    // Generic SDK error.
}

$documents = $signwell->documents();

$pdf = $documents->getCompletedPdf('document-id');
// $pdf is an SplFileObject.

$urlResponse = $documents->getCompletedPdf('document-id', url_only: true);
// $urlResponse is a SignWell\Sdk\Models\CompletedPdfUrlResponse.

$regional = $signwell->regional();
$certificate = $regional->getNom151Certificate('document-id', object_only: true);

$account = $signwell->getMe();
$document = $signwell->createDocument([...]);
$templateDocument = $signwell->createDocumentFromTemplate([...]);
$sent = $signwell->sendDocument('draft-document-id', ['subject' => 'Please sign']);
$signwell->sendReminder('document-id');
$template = $signwell->createTemplate([...]);
$updatedTemplate = $signwell->updateTemplate('template-id', ['name' => 'Updated NDA']);
$bulkSend = $signwell->createBulkSend([...]);
$csvCheck = $signwell->validateBulkSendCsv([...]);
$csvTemplate = $signwell->getBulkSendCsvTemplate(['template-id'], base64: true);

use SignWell\Sdk\Client;

$signwell = Client::fromApiKey(getenv('SIGNWELL_API_KEY') ?: '');

$document = $signwell->createSigningDocument([
    'name' => 'NDA',
    'test_mode' => true,
    'files' => [
        ['name' => 'nda.pdf', 'file_url' => 'https://example.com/nda.pdf'],
    ],
    'recipients' => [
        ['name' => 'Jane Doe', 'email' => '[email protected]'],
    ],
    'fields' => [
        [
            ['page' => 1, 'x' => 120, 'y' => 240, 'type' => 'signature'],
        ],
    ],
]);

$signingUrl = $signwell->embeddedSigningUrl($document);
$nonce = base64_encode(random_bytes(16));
$loader = $signwell->scriptTag($nonce);
$script = $signwell->signingIframe([
    'url' => $signingUrl,
    'nonce' => $nonce,
    'events' => ['completed' => 'SignWellHandlers.completed'],
]);

use SignWell\Sdk\Webhook;
use SignWell\Sdk\Webhook\MemoryReplayStore;

$payload = json_decode(file_get_contents('php://input'), true, flags: JSON_THROW_ON_ERROR);
$event = $payload['event'];
$webhookId = getenv('SIGNWELL_WEBHOOK_ID');
if (!is_string($webhookId) || $webhookId === '') {
    throw new RuntimeException('SIGNWELL_WEBHOOK_ID must be set.');
}

Webhook::verifyEventOrThrow(
    event: $event,
    webhookId: $webhookId,
    toleranceSeconds: 300,
);

$store = new MemoryReplayStore();
Webhook::verifyEventOnceOrThrow(
    event: $event,
    webhookId: $webhookId,
    replayStore: $store,
    toleranceSeconds: 300,
);

$documents = app(SignWell\Sdk\Resources\DocumentApi::class);
$document = $documents->getDocument('document-id');

$documents = SignWell::documents();

$document = SignWell::createSigningDocument([
    'name' => 'NDA',
    'test_mode' => true,
    'files' => [['name' => 'nda.pdf', 'file_url' => 'https://example.com/nda.pdf']],
    'recipients' => [['name' => 'Jane Doe', 'email' => '[email protected]']],
    'fields' => [[['page' => 1, 'x' => 120, 'y' => 240, 'type' => 'signature']]],
]);
bash
composer 
bash
php artisan vendor:publish --tag=signwell-config
bash
SIGNWELL_API_KEY=your_key php examples/vanilla_send_request.php
SIGNWELL_API_KEY=your_key php examples/laravel_facade_send_request.php