PHP code example of nidrax69 / yousign-api-laravel
1. Go to this page and download the library: Download nidrax69/yousign-api-laravel 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/ */
nidrax69 / yousign-api-laravel example snippets
use Nidrax69\YousignApiLaravel\YousignApiLaravel;
class DocumentController extends Controller
{
public function sign(Request $request) {
$client = new YousignApiLaravel();
// see all possibilities at https://dev.yousign.com/
$client->setProcedureKeyValue('name', 'Yousign');
$client->setProcedureKeyValue('description', 'Description procedure');
// to set default expiration date to the signature
$client->setProcedureKeyValue('expiresAt', '2022-04-24');
// add webhooks
// you can add different headers
$webhookUrl = env('API_URL') . 'yousign/';
$client->addWebhook('member.finished', $webhookUrl . 'signature', 'GET', array(
"X-Custom-Header" => $type . '-signature',
));
$client->addWebhook('procedure.refused', $webhookUrl . 'refused', 'GET', array(
"X-Custom-Header" => $type . '-signature',
));
// procedure created but not ready for signature
$procedure = $client->createProcedure();
// Allows you to define the content of SMS. {{code}} will be used to define the security code managed by Yousign.
// up to 150 characters
$client->addSmsContent('DIGITAL SIGNATURE - {{code}} is your security code to sign your documents.');
// add files to procedure
$file = $client->addFile($namefile, $document->url, $procedure['id']);
// add member to sign the documents
$member = $client->addMember($user->firstname, $user->lastname, $user->email, $user->phone, $procedure['id']);
// to determine the last page of your file
$lastPageNumber = $this->getNumPagesInPDF($document->url);
$reason = "Signed by " . $user->firstname . " " . $user->lastname . " (Yousign)";
// to determine position see https://placeit.yousign.fr/
$fileObject = $client->addFileObject($file['id'], $member['id'], $position, $reason, $lastPageNumber);
// start the signature process
$client->launchProcedure($procedure['id']);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.