PHP code example of signdocs-brasil / signdocs-brasil-php

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

    

signdocs-brasil / signdocs-brasil-php example snippets


use SignDocsBrasil\Api\SignDocsBrasilClient;
use SignDocsBrasil\Api\Config;
use SignDocsBrasil\Api\Models\CreateTransactionRequest;
use SignDocsBrasil\Api\Models\Policy;
use SignDocsBrasil\Api\Models\Signer;

$client = new SignDocsBrasilClient(new Config(
    clientId: 'seu_client_id',
    clientSecret: 'seu_client_secret',
));

$tx = $client->transactions->create(new CreateTransactionRequest(
    purpose: 'DOCUMENT_SIGNATURE',
    policy: new Policy(profile: 'CLICK_ONLY'),
    signer: new Signer(
        name: 'João Silva',
        email: '[email protected]',
        userExternalId: 'user-001',
    ),
    document: ['content' => $pdfBase64, 'filename' => 'contrato.pdf'],
));

echo $tx->transactionId . ' ' . $tx->status;

$client = new SignDocsBrasilClient(new Config(
    clientId: 'seu_client_id',
    privateKey: file_get_contents('./private-key.pem'),
    kid: 'seu-key-id',
));

use SignDocsBrasil\Api\Models\CreateEnvelopeRequest;
use SignDocsBrasil\Api\Models\AddEnvelopeSessionRequest;

$envelope = $client->envelopes->create(new CreateEnvelopeRequest(
    signingMode: 'PARALLEL',
    totalSigners: 2,
    documentContent: $pdfBase64,
    documentFilename: 'contrato.pdf',
));

$session1 = $client->envelopes->addSession($envelope->envelopeId, new AddEnvelopeSessionRequest(
    signerName: 'João Silva',
    signerEmail: '[email protected]',
    policyProfile: 'CLICK_ONLY',
));

$session2 = $client->envelopes->addSession($envelope->envelopeId, new AddEnvelopeSessionRequest(
    signerName: 'Maria Santos',
    signerEmail: '[email protected]',
    policyProfile: 'CLICK_ONLY',
    signerIndex: 2,
));

echo $session1->url . ' ' . $session2->url;

use SignDocsBrasil\Api\Models\CreateSigningSessionRequest;

$session = $client->signingSessions->create(new CreateSigningSessionRequest(
    purpose: 'DOCUMENT_SIGNATURE',
    policy: new Policy(profile: 'CLICK_ONLY'),
    signer: new Signer(
        name: 'João Silva',
        userExternalId: 'user-001',
        phone: '+5511999998888',
        cpf: '12345678901',
    ),
    document: ['content' => $pdfBase64, 'filename' => 'contrato.pdf'],
    deliverVia: ['whatsapp'],
));

var_dump($session->whatsappInviteSent); // true quando a Meta aceitou a mensagem

use GuzzleHttp\Client as GuzzleClient;

$guzzle = new GuzzleClient(['proxy' => 'http://proxy:8080']);

$client = new SignDocsBrasilClient(new Config(
    clientId: 'seu_client_id',
    clientSecret: 'seu_client_secret',
    guzzle: $guzzle,
));

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('signdocs');
$logger->pushHandler(new StreamHandler('php://stdout'));

$client = new SignDocsBrasilClient(new Config(
    clientId: 'seu_client_id',
    clientSecret: 'seu_client_secret',
    logger: $logger,
));

$tx = $client->transactions->get('tx_123', timeout: 5);