PHP code example of cyril-bochet / yousign-api-client-v3
1. Go to this page and download the library: Download cyril-bochet/yousign-api-client-v3 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/ */
cyril-bochet / yousign-api-client-v3 example snippets
use YousignApiClient\YousignApiClient;
use YousignApiClient\SignatureRequest;
$apikey = 'API_KEY';
$env = 'test';
$client = new YousignApiClient($apikey, $env);
// Nouvelle requête
$signatureRequest = new SignatureRequest(string $name, string $deliveryMode, string $timezone, bool $orderedSigners);
$signatureRequest = new SignatureRequest('Contrat', 'email', 'Europe/Paris', true);
// Optionel
$signatureRequest->setCustomExperienceId("xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx");
$client->initiateSignatureRequest($signatureRequest);
use YousignApiClient\Document;
$document = new Document(string $nature, string $path, bool $parseAnchors);
$document = new Document('signable_document', 'contrat.pdf', true);
$client->addDocument($document);
$documentId = $document->getId();
use YousignApiClient\Signer;
$signer = new Signer(string $firstName, string $lastName, string $email, ?string $phoneNumber, string $locale, ?string $signatureAuthenticationMode, ?string $signatureLevel);
$signer = new Signer("Jean", "DUPOND", '[email protected]', '+33123456789', 'fr', 'otp_sms', 'electronic_signature');
use YousignApiClient\Font;
$font = new Font(string $family, string $color, int $size = 12);
$font = new Font('Raleway', '#000000', 9);
use YousignApiClient\Fields\CheckboxField;
use YousignApiClient\Fields\MentionField;
use YousignApiClient\Fields\RadioField;
use YousignApiClient\Fields\RadioGroup;
use YousignApiClient\Fields\SignatureField;
use YousignApiClient\Fields\TextField;
// Signature
$signatureField = new SignatureField(string $documentId, int $page, int $x, int $y, int $height = 37, int $width = 85);
$signatureField = new SignatureField('xxxxxxxxxxxxxxxxxx', 1, 57, 695, 85, 198);
$signer->addField($signatureField);
// Radio
$radio1 = new RadioField(string $name, int $x, int $y, int $size);
$radio1 = new RadioField('radio_1', 154, 341, 12);
$radio2 = new RadioField('radio_2', 184, 341, 12);
$radioGroup = new RadioGroup(string $documentId, int $page, string $name, bool $optional, array $radios);
$radioGroup = new RadioGroup('xxxxxxxxxxxxxx', 1, 'radio_group_name', false, [$radio1, $radio2]);
$signer->addField($radioGroup);
// Text
$textField = new TextField(int $maxLength, string $question, bool $optional, Font $font, string $documentId, int $page, int $x, int $y, int $height = 24, int $width = 24);
$textField = new TextField(10, 'Votre prénom :', false, $font, 'xxxxxxxxxxxxxx', 1, 468, 428, 24, 54);
$signer->addField($textField);
// Checkbox
$cb = new CheckboxField($size, $name, $checked, $optional, $documentId, $page, $x, $y);
$signer->addField($cb);
// Pour les documents avec beaucoup de champs, vous pouvez faire un tableau et boucler dessus
$mentionsArray = array(
"signataire1" => array(
array(
"page" => 2,
"x" => 57,
"y" => 675,
"width" => 197,
"height" => 24,
"mention" => "Certifié exact et sincère",
),
array(
"page" => 14,
"x" => 35,
"y" => 318,
"width" => 156,
"height" => 24,
"mention" => "Bon pour acceptation",
),
),
"signataire2" => array(
array(
"page" => 14,
"x" => 206,
"y" => 318,
"width" => 156,
"height" => 24,
"mention" => "Certifié exact et sincère",
),
array(
"page" => 2,
"x" => 297,
"y" => 675,
"width" => 197,
"height" => 24,
"mention" => "Bon pour acceptation",
),
),
);
// Exemple : On boucle sur les champs mentions du signataire 2
foreach ($mentionsArray["signataire2"] as $mention) {
$mf = new MentionField($mention["mention"], $font, $documentId, $mention["page"], $mention["x"], $mention["y"], $mention["height"], $mention["width"]);
$signer2->addField($mf);
}
use YousignApiClient\Webhook\Scope;
use YousignApiClient\Webhook\Webhook;
use YousignApiClient\Webhook\WebhookEvent;
// Nouveau Webhook
$allEvents = new WebhookEvent('*');
$event = new WebhookEvent('signature_request.done');
$allScopes = new Scope('*');
$scope = new Scope('public_api');
$webhook = new Webhook(bool $sandbox, bool $autoRetry, bool $enabled, string $endpoint, string $description, array $events, array $scopes);
$webhook = new Webhook(true, true, true, 'endpoint.fr', 'test', [$allEvents], [$allScopes]);
$client->createWebhook($webhook);
// Liste des Webhooks
$webhooks = $client->listWebhooks();