<?php
namespace App\Services;
use Symfony\Component\DependencyInjection\Tests\Fixtures\StdClassDecorator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormError;
use GuzzleHttp\Client;
use App\Entity\User;
use App\Entity\Membership;
use App\Entity\Dic;
use App\Entity\Fic;
use App\Entity\Ba;
use App\Services\GenerateDocuments;
use App\Services\GenerateDocumentsFullweb;
use Symfony\Component\HttpFoundation\RequestStack;
// Import the Twig Environment
use Twig\Environment;
use setasign\Fpdi\Fpdi;
class Utils
{
private $container;
private $twig;
protected $fileUploader;
private $yousignApiV2;
private $yousignUrlV2;
private $yousignApi;
private $yousignUrl;
private $yousignUi;
private $yousignUiConditions;
/**
* Constructor
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container, $yousignApiV2, $yousignUrlV2, $yousignApi, $yousignUrl, $yousignUi, $yousignUiConditions, EntityManagerInterface $entityManager, \Swift_Mailer $mailer, Environment $twig, \Knp\Snappy\Pdf $knpSnappy, FileUploader $fileUploader, GenerateDocuments $generateDocuments, GenerateDocumentsFullweb $generateDocumentsFullweb)
{
$this->container = $container;
$this->mailer = $mailer;
$this->em = $entityManager;
$this->twig = $twig;
$this->knpSnappy = $knpSnappy;
$this->fileUploader = $fileUploader;
$this->yousignApiV2 = $yousignApiV2['yousignApiV2'];
$this->yousignUrlV2 = $yousignUrlV2['yousignUrlV2'];
$this->yousignApi = $yousignApi['yousignApi'];
$this->yousignUrl = $yousignUrl['yousignUrl'];
$this->yousignUi = $yousignUi['yousignUi'];
$this->yousignUiConditions = $yousignUiConditions['yousignUiConditions'];
$this->generateDocuments = $generateDocuments;
$this->generateDocumentsFullweb = $generateDocumentsFullweb;
}
public function decode($value)
{
// convert from utf8 to latin1
return mb_convert_encoding($value, 'ISO-8859-1', 'UTF-8');
}
public function getMembershipByCustomer($customer)
{
$membership = $this->em
->getRepository(Membership::class)
->findOneBy(['user' => $customer], array("id" => "DESC"));
if (!$membership) {
$customer = $this->em
->getRepository(User::class)
->findOneBy(['id' => $customer]);
$membership = new Membership;
$membership->setUser($customer);
$membership->setStatus("DRAFT");
if($customer->getDicIsFile()){
$membership->setPlatformVersion(1);
}
else{
$membership->setPlatformVersion(2);
}
$this->em->persist($membership);
$this->em->flush();
$membershipLast = $membership;
} else {
$membershipLast = $membership;
}
//Create folder customer
$urlFolderCustomer = $this->fileUploader->getTargetDirectory() . "/" . $membership->getUser()->getId();
if (!file_exists($urlFolderCustomer)) {
//Remove last file
mkdir($urlFolderCustomer);
}
if($membershipLast->getPlatformVersion() == 1){
if (!$membershipLast->getDic()) {
$dic = new Dic;
$membershipLast->setDic($dic);
$this->em->persist($dic);
$this->em->persist($membershipLast);
$this->em->flush();
}
}
else{
if (!$membershipLast->getFic()) {
$fic = new Fic;
$membershipLast->setFic($fic);
$this->em->persist($fic);
$this->em->persist($membershipLast);
$this->em->flush();
}
}
if (!$membershipLast->getBa()) {
$ba = new Ba;
$membershipLast->setBa($ba);
$this->em->persist($ba);
$this->em->persist($membershipLast);
$this->em->flush();
}
return $membershipLast;
}
public function getCustomerByNumberMembership($nb)
{
$customer = null;
$membership = $this->em
->getRepository(Membership::class)
->findOneBy(['numberMembershipFolder' => $nb], array("id" => "DESC"));
if ($membership) {
$customer = $membership->getUser();
}
return $customer;
}
public function sendEmailEndSignin($user)
{
$mailNoReply = $this->container->getParameter('mail_no_reply');
$senderName = $this->container->getParameter('sender_name');
$url = $this->container->get('router')->generate('signin_end', array('token' => $user->getTokenReset()), UrlGeneratorInterface::ABSOLUTE_URL);
$bodyEmail = $this->twig->render(
'email/addUserWithToken.html.twig',
array('user' => $user, 'confirmationToken' => $url)
);
$message = (new \Swift_Message("Fin d'inscription"))
->setSubject("Fin d'inscription")
->setFrom(array($mailNoReply => $senderName))
->setTo(array($user->getEmail() => $senderName))
->setBody($bodyEmail, 'text/html');
$this->mailer->send($message);
}
public function sendEmailEndSigninCustomer($user)
{
$mailNoReply = $this->container->getParameter('mail_no_reply');
$senderName = $this->container->getParameter('sender_name');
$url = $this->container->get('router')->generate('signin_end', array('token' => $user->getTokenReset()), UrlGeneratorInterface::ABSOLUTE_URL);
$bodyEmail = $this->twig->render(
'email/addCustomerWithToken.html.twig',
array('user' => $user, 'confirmationToken' => $url)
);
$message = (new \Swift_Message("Finalisez votre adhésion"))
->setSubject("Finalisez votre adhésion")
->setFrom(array($mailNoReply => $senderName))
->setTo(array($user->getEmail() => $senderName))
->setBody($bodyEmail, 'text/html');
$this->mailer->send($message);
}
public function generateDic($customer)
{
$dicFileName = "dic-no-sign.pdf";
$dicFullPath = $this->fileUploader->getTargetDirectory() . "/" . $customer->getId() . "/" . $dicFileName;
//If file exist
if (file_exists($dicFullPath)) {
//Remove last file
unlink($dicFullPath);
}
$this->knpSnappy->setOption('page-size', 'A4');
$this->knpSnappy->setOption('encoding', 'UTF-8');
$this->knpSnappy->setOption('zoom', '1.17');
$this->knpSnappy->setOption('margin-left', '0');
$this->knpSnappy->setOption('margin-right', '0');
$this->knpSnappy->setOption('margin-top', '5');
$this->knpSnappy->setOption('margin-bottom', '5');
$this->knpSnappy->setOption('dpi', '96');
$this->knpSnappy->generateFromHtml(
$this->twig->render(
'membership/pdf/dicView.html.twig',
array(
'dic' => $customer->getCurrentMemberships()->getDic()
)
),
$dicFullPath
);
return $dicFileName;
}
public function generateFicV2023($customer)
{
$ficFileName = "fic-no-sign.pdf";
$ficFullPath = $this->fileUploader->getTargetDirectory() . "/" . $customer->getId() . "/" . $ficFileName;
//If file exist
if (file_exists($ficFullPath)) {
//Remove last file
unlink($ficFullPath);
}
$this->knpSnappy->setOption('page-size', 'A4');
$this->knpSnappy->setOption('encoding', 'UTF-8');
$this->knpSnappy->setOption('zoom', '1.62');
$this->knpSnappy->setOption('margin-left', '0');
$this->knpSnappy->setOption('margin-right', '0');
$this->knpSnappy->setOption('margin-top', '5');
$this->knpSnappy->setOption('margin-bottom', '5');
$this->knpSnappy->setOption('dpi', '96');
$this->knpSnappy->generateFromHtml(
$this->twig->render(
'membership/pdf/ficView.html.twig',
array(
'fic' => $customer->getCurrentMemberships()->getFic()
)
),
$ficFullPath
);
return $ficFileName;
}
public function generateFic($customer)
{
$ficFileName = $this->generateDocuments->generateFic($customer);
return $ficFileName;
}
public function generateFicFullweb($customer)
{
$ficFileName = $this->generateDocumentsFullweb->generateFic($customer);
return $ficFileName;
}
public function generateBaV2023($customer)
{
$baFileName = "ba-no-sign.pdf";
$baFullPath = $this->fileUploader->getTargetDirectory() . "/" . $customer->getId() . "/" . $baFileName;
//If file exist
if (file_exists($baFullPath)) {
//Remove last file
unlink($baFullPath);
}
$this->knpSnappy->setOption('page-size', 'A4');
$this->knpSnappy->setOption('encoding', 'UTF-8');
$this->knpSnappy->setOption('zoom', '1.62');
$this->knpSnappy->setOption('margin-left', '0');
$this->knpSnappy->setOption('margin-right', '0');
$this->knpSnappy->setOption('margin-top', '5');
$this->knpSnappy->setOption('margin-bottom', '5');
$this->knpSnappy->setOption('dpi', '96');
$this->knpSnappy->generateFromHtml(
$this->twig->render(
'membership/pdf/baView.html.twig',
array(
'ba' => $customer->getCurrentMemberships()->getBa()
)
),
$baFullPath
);
return $baFileName;
}
public function generateBa($customer)
{
$baFileName = $this->generateDocuments->generateBa($customer);
return $baFileName;
}
public function generateBaFullweb($customer)
{
$baFileName = $this->generateDocumentsFullweb->generateBa($customer);
return $baFileName;
}
public function generateSepa($customer)
{
$sepaFileName = "sepa-no-sign.pdf";
$ba = $customer->getCurrentMemberships()->getBa();
$sepaFullPath = $this->fileUploader->getTargetDirectory() . "/" . $customer->getId() . "/" . $sepaFileName;
//If file exist
if (file_exists($sepaFullPath)) {
//Remove last file
unlink($sepaFullPath);
}
// initiate FPDI
$pdf = new Fpdi();
// add a page
$pdf->AddPage();
// set the source file
$numberPagesSource = $pdf->setSourceFile("default/SEPA_2024.pdf");
for ($i = 1; $i <= $numberPagesSource ; $i++) {
if($i > 1){
$pdf->AddPage();
}
// import page
$tplId = $pdf->importPage($i);
$pdf->useTemplate($tplId, 0, 0);
//Global pages
$font = "Helvetica";
$fontSizeText = 11;
$fontSizeChecked = 11;
$pdf->setFont($font, null, 10);
switch ($i) {
case '1':
//Non et adresse postale
$pdf->setFont($font, null, 11);
$pdf -> SetY(71.6);
$pdf -> SetX(18.5);
$pdf->MultiCell(103, 10, $ba->getSepaNom()." ".$ba->getSepaPrenom()."\n".$ba->getSepaAdresse().", ".$ba->getSepaCodePostal()." ".$ba->getSepaVille().", ".$ba->getSepaPays(), 0, 'L', 0);
//Iban
$pdf->setFont($font, null, 11.3);
$pdf->Text(28.6, 116.2, $this->formatString($ba->getSepaCodeIban(), "iban"));
//Bic
$pdf->setFont($font, null, 11.1);
$pdf->Text(29.8, 124.8, $this->formatString($ba->getSepaCodeBic()));
default:
// code...
break;
}
}
$pdf->Output('F', $sepaFullPath);
return $sepaFileName;
}
public function generateSepaV2023($customer)
{
$sepaFileName = "sepa-no-sign.pdf";
$sepaFullPath = $this->fileUploader->getTargetDirectory() . "/" . $customer->getId() . "/" . $sepaFileName;
//If file exist
if (file_exists($sepaFullPath)) {
//Remove last file
unlink($sepaFullPath);
}
$this->knpSnappy->setOption('page-size', 'A4');
$this->knpSnappy->setOption('encoding', 'UTF-8');
$this->knpSnappy->setOption('zoom', '1.17');
$this->knpSnappy->setOption('margin-left', '0');
$this->knpSnappy->setOption('margin-right', '0');
$this->knpSnappy->setOption('margin-top', '5');
$this->knpSnappy->setOption('margin-bottom', '5');
$this->knpSnappy->generateFromHtml(
$this->twig->render(
'membership/pdf/sepaView.html.twig',
array(
'ba' => $customer->getCurrentMemberships()->getBa()
)
),
$sepaFullPath
);
return $sepaFileName;
}
public function formatString($stringLetters, $typeFormat = "default"){
$string = "";
$forNumber = 1;
$tabString = str_split($stringLetters);
foreach ($tabString as $keyLetter => $stringLetter) {
if($keyLetter > 0){
$string .= " ";
}
$string .= $stringLetter;
switch ($typeFormat) {
case 'iban':
if($forNumber == 4 && count($tabString) != ($keyLetter + 1)){
$string .= " ";
$forNumber = 0;
}
break;
case 'ss':
if($keyLetter == 0 || $keyLetter == 2 || $keyLetter == 4 || $keyLetter == 6 || $keyLetter == 9){
$string .= " ";
}
break;
default:
// code...
break;
}
$forNumber++;
}
return $string;
}
public function getStatusMembership($customer)
{
$status = "no-status";
$membershipCurrent = $this->getMembershipByCustomer($customer);
if ($membershipCurrent->getStatus() == "DRAFT") {
$status = "Brouillon";
} else if ($membershipCurrent->getStatus() == "VALIDBYSELLER" && $membershipCurrent->getUser()->getStatus() == "SIGNINEND") {
$status = "En attente de fin d'inscription";
} else if ($membershipCurrent->getStatus() == "VALIDBYSELLER") {
$status = "En attente de validation";
} else if ($membershipCurrent->getStatus() == "VALIDBYCUSTOMER") {
$status = "En attente de signature";
} else if ($membershipCurrent->getStatus() == "SIGNBYCUSTOMER") {
$status = "En attente de paiement";
} else if ($membershipCurrent->getStatus() == "PAYBYCUSTOMER") {
$status = "Validé";
}
return $status;
}
public function getNumberMembership($customer)
{
$number = null;
$currentMemberships = $this->getMembershipByCustomer($customer);
if ($customer) {
if ($currentMemberships) {
$number = $currentMemberships->getNumberMembershipFolder();
}
}
if ($number == null) {
$number = "Aucun numéro";
}
return $number;
}
function formatSizeUnits($bytes)
{
if ($bytes >= 1073741824) {
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
} elseif ($bytes >= 1048576) {
$bytes = number_format($bytes / 1048576, 2) . ' MB';
} elseif ($bytes >= 1024) {
$bytes = number_format($bytes / 1024, 2) . ' KB';
} elseif ($bytes > 1) {
$bytes = $bytes . ' bytes';
} elseif ($bytes == 1) {
$bytes = $bytes . ' byte';
} else {
$bytes = '0 bytes';
}
return $bytes;
}
function addSign($customer, $membership, $type)
{
$client = new Client();
$uploadDicId = null;
$uploadFicId = null;
$uploadBaId = null;
$uploadSepaId = null;
$newSignerSellerId = null;
$newSignerCustomerId = null;
$newSignerCustomerResponseBody = null;
$activateSignatureResponseBody = null;
$responseErrorTab = [];
//Font default for all fields
$fontDefault = new \stdClass();
$fontDefault->size = 9;
$fontDefault->family = "Inconsolata";
$fontDefault->variants = array(
"italic" => false,
"bold" => false
);
$fontDefault->color = "#000000";
/* ----------------------------------- Add Signature ------------------------------------- */
//Create signature
$newSignature = new \stdClass();
$newSignature->delivery_mode = "none";
$newSignature->reminder_settings = null;
$newSignature->ordered_signers = true;
$newSignature->signers_allowed_to_decline = false;
$newSignature->workspace_id = "e2389f49-f598-47b1-a8d4-66d84244123a";
$newSignature->name = "Nouvelle adhésion épargne retraite";
$newSignature->custom_experience_id = $this->yousignUi;
try {
$newSignatureResponse = $client->request('POST', $this->yousignUrl .'/signature_requests',
[
'body' => json_encode($newSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
//201 for create
$newSignatureResponseStatusCode = $newSignatureResponse->getStatusCode();
$newSignatureResponseBody = json_decode($newSignatureResponse->getBody());
$newSignatureId = $newSignatureResponseBody->id;
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
/* ----------------------------------- Add Metadata ------------------------------------- */
//Create meta
$newMetaData = new \stdClass();
$newMetaData->data = array(
"membershipId" => $membership->getId()
);
try {
$newMetaDataResponse = $client->request('POST', $this->yousignUrl .'/signature_requests/'.$newSignatureId.'/metadata',
[
'body' => json_encode($newMetaData),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
//201 for create
$newMetaDataResponseStatusCode = $newMetaDataResponse->getStatusCode();
$newMetaDataResponseBody = json_decode($newMetaDataResponse->getBody());
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
/* ----------------------------------- Add Files ------------------------------------- */
//Add FIC file
if ($customer->getDicIsFile() != true) {
$ficUrl = "files/" . $customer->getId() . '/' . $membership->getFic()->getUrlPdf();
try {
$uploadFicResponse = $client->request('POST', $this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents',
[
'multipart' => [
[
'name' => 'nature',
'contents' => 'signable_document'
],
[
'name' => 'parse_anchors',
'contents' => 'false'
],
[
'name' => 'file',
'filename' => "Fiche d'information et de conseil.pdf",
'contents' => fopen($ficUrl, 'r'),
]
],
'headers' => [
'accept' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
]
]
);
$uploadFicResponseBody = json_decode($uploadFicResponse->getBody());
$uploadFicId = $uploadFicResponseBody->id;
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
}
//Add BA file
$baUrl = "files/" . $customer->getId() . '/' . $membership->getBa()->getUrlPdf();
if($customer->getDicIsFile() != true) {
$multipart =
[
[
'name' => 'nature',
'contents' => 'signable_document'
],
[
'name' => 'parse_anchors',
'contents' => 'false'
],
[
'name' => 'insert_after_id',
'contents' => $uploadFicId
],
[
'name' => 'file',
'filename' => "Demande d'adhésion.pdf",
'contents' => fopen($baUrl, 'r'),
]
];
}
else{
$multipart =
[
[
'name' => 'nature',
'contents' => 'signable_document'
],
[
'name' => 'parse_anchors',
'contents' => 'false'
],
[
'name' => 'file',
'filename' => "Demande d'adhésion.pdf",
'contents' => fopen($baUrl, 'r'),
]
];
}
try {
$uploadBaResponse = $client->request('POST', $this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents',
[
'multipart' => $multipart,
'headers' => [
'accept' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
]
]
);
$uploadBaResponseBody = json_decode($uploadBaResponse->getBody());
$uploadBaId = $uploadBaResponseBody->id;
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
//Add SEPA file
if ($membership->getBa()->getVersementProgramme() == 1 || $membership->getBa()->getMoyenDeVersement() == 3) {
$sepaUrl = "files/" . $customer->getId() . '/' . $membership->getBa()->getSepaUrlPdf();
try {
$uploadSepaResponse = $client->request('POST', $this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents',
[
'multipart' => [
[
'name' => 'nature',
'contents' => 'signable_document'
],
[
'name' => 'parse_anchors',
'contents' => 'false'
],
[
'name' => 'insert_after_id',
'contents' => $uploadBaId
],
[
'name' => 'file',
'filename' => "Mandat de prélèvement SEPA.pdf",
'contents' => fopen($sepaUrl, 'r'),
]
],
'headers' => [
'accept' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
]
]
);
$uploadSepaResponseBody = json_decode($uploadSepaResponse->getBody());
$uploadSepaId = $uploadSepaResponseBody->id;
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
}
/* ----------------------------------- Add Signers ------------------------------------- */
//Add Signer (seller)
if($membership->getPlatformVersion() == 2 && !$customer->isIsAutoSignup()){
$seller = $customer->getSeller();
//Add Signer (seller)
$phone = $seller->getPhone();
$phone = str_replace("(", "", $phone);
$phone = str_replace(")", "", $phone);
$phone = str_replace(" ", "", $phone);
if ($seller->getPhonePrefix()) {
$phone = $seller->getPhonePrefix() . $phone;
}
else{
$phone = "+33" . $phone;
}
$newSignerSellerMember = new \stdClass();
$newSignerSellerMember->locale = "fr";
$newSignerSellerMember->first_name = $seller->getFirstName();
$newSignerSellerMember->last_name = $seller->getLastName();
$newSignerSellerMember->email = $seller->getEmail();
$newSignerSellerMember->phone_number = $phone;
//$newSignerSellerRedirect = new \stdClass();
//$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end_seller', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
//$newSignerSellerRedirect->success = $urlSignEnd;
//$newSignerSellerRedirect->error = $urlSignEnd;
$newSignerSeller = new \stdClass();
$newSignerSeller->info = $newSignerSellerMember;
$newSignerSeller->signature_level = "electronic_signature";
$newSignerSeller->signature_authentication_mode = "otp_email";
//$newSignerSeller->redirect_urls = $newSignerSellerRedirect;
try {
$newSignerSellerResponse = $client->request('POST', $this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers',
[
'body' => json_encode($newSignerSeller),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
$newSignerSellerResponseBody = json_decode($newSignerSellerResponse->getBody());
$newSignerSellerId = $newSignerSellerResponseBody->id;
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
}
//Add Signer (customer)
$phone = $customer->getPhone();
$phone = str_replace("(", "", $phone);
$phone = str_replace(")", "", $phone);
$phone = str_replace(" ", "", $phone);
if ($customer->getPhonePrefix()) {
$phone = $customer->getPhonePrefix() . $phone;
}
$newSignerCustomerMember = new \stdClass();
$newSignerCustomerMember->locale = "fr";
$newSignerCustomerMember->first_name = $customer->getFirstName();
$newSignerCustomerMember->last_name = $customer->getLastName();
$newSignerCustomerMember->email = $customer->getEmail();
$newSignerCustomerMember->phone_number = $phone;
//$newSignerCustomerRedirect = new \stdClass();
//$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
//$newSignerCustomerRedirect->success = $urlSignEnd;
//$newSignerCustomerRedirect->error = $urlSignEnd;
$newSignerCustomer = new \stdClass();
$newSignerCustomer->info = $newSignerCustomerMember;
$newSignerCustomer->signature_level = "electronic_signature";
$newSignerCustomer->signature_authentication_mode = "otp_sms";
//For order
if($membership->getPlatformVersion() == 2 && !$customer->isIsAutoSignup()){
$newSignerCustomer->insert_after_id = $newSignerSellerId;
}
//$newSignerCustomer->redirect_urls = $newSignerCustomerRedirect;
try {
$newSignerCustomerResponse = $client->request('POST', $this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers',
[
'body' => json_encode($newSignerCustomer),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
$newSignerCustomerResponseBody = json_decode($newSignerCustomerResponse->getBody());
$newSignerCustomerId = $newSignerCustomerResponseBody->id;
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
/* ----------------------------------- Add Fields ------------------------------------- */
//Add fields on FIC for sgnature
//No Allianz customer
if ($customer->getDicIsFile() != true) {
//For v2 with seller
if($membership->getPlatformVersion() == 2 && !$customer->isIsAutoSignup()){
//For seller
$newFieldSellerSignature = new \stdClass();
$newFieldSellerSignature->signer_id = $newSignerSellerId;
$newFieldSellerSignature->type = "signature";
$newFieldSellerSignature->page = 7;
$newFieldSellerSignature->width = 194;
$newFieldSellerSignature->height = 88;
$newFieldSellerSignature->x = 355;
$newFieldSellerSignature->y = 558;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields',
[
'body' => json_encode($newFieldSellerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
/* --------------------------------------------------- */
//For customer
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "signature";
$newFieldCustomerSignature->page = 7;
$newFieldCustomerSignature->width = 194;
$newFieldCustomerSignature->height = 88;
$newFieldCustomerSignature->x = 62;
$newFieldCustomerSignature->y = 558;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
}
else{
//For customer
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "signature";
$newFieldCustomerSignature->page = 7;
$newFieldCustomerSignature->width = 160;
$newFieldCustomerSignature->height = 94;
$newFieldCustomerSignature->x = 78;
$newFieldCustomerSignature->y = 554;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
}
//Add fields on FIC for city (customer)
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "text";
$newFieldCustomerSignature->max_length = 44;
$newFieldCustomerSignature->question = "Veuillez indiquer la ville";
$newFieldCustomerSignature->page = 7;
$newFieldCustomerSignature->width = 286;
$newFieldCustomerSignature->height = 24;
$newFieldCustomerSignature->x = 68;
$newFieldCustomerSignature->y = 377;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
//Add fields on FIC for date (customer)
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "mention";
$newFieldCustomerSignature->mention = "%date%";
$newFieldCustomerSignature->font = $fontDefault;
$newFieldCustomerSignature->page = 7;
$newFieldCustomerSignature->width = 286;
$newFieldCustomerSignature->height = 24;
$newFieldCustomerSignature->x = 68;
$newFieldCustomerSignature->y = 401;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
}
///Add fields on BA for -> Demande attribution de (customer)
if ($membership->getBa()->getJaiDemandeAttributionDe() != null) {
/*
Print on document in new version
$font = new \stdClass();
$font->size = 9;
$font->family = "Inconsolata";
$font->variants = array(
"italic" => false,
"bold" => false
);
$font->color = "#000000";
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "text";
$newFieldCustomerSignature->max_length = 40;
$newFieldCustomerSignature->font = $font;
$newFieldCustomerSignature->question = "Veuillez indiquer votre nom et prénom";
$newFieldCustomerSignature->page = 4;
$newFieldCustomerSignature->width = 260;
$newFieldCustomerSignature->height = 24;
$newFieldCustomerSignature->x = 94;
$newFieldCustomerSignature->y = 89;
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
*/
}
//Add fields on BA for sgnature (customer)
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "signature";
$newFieldCustomerSignature->page = 7;
$newFieldCustomerSignature->width = 187;
$newFieldCustomerSignature->height = 97;
$newFieldCustomerSignature->x = 339;
$newFieldCustomerSignature->y = 423;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
//Add fields on BA for city (customer)
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "text";
$newFieldCustomerSignature->max_length = 44;
$newFieldCustomerSignature->question = "Veuillez indiquer la ville";
$newFieldCustomerSignature->page = 7;
$newFieldCustomerSignature->width = 272;
$newFieldCustomerSignature->height = 24;
$newFieldCustomerSignature->x = 50;
$newFieldCustomerSignature->y = 403;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
//Add fields on BA for date (customer)
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "mention";
$newFieldCustomerSignature->font = $fontDefault;
$newFieldCustomerSignature->mention = "%date%";
$newFieldCustomerSignature->page = 7;
$newFieldCustomerSignature->width = 272;
$newFieldCustomerSignature->height = 24;
$newFieldCustomerSignature->x = 49;
$newFieldCustomerSignature->y = 417;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
//Benef on BA (customer)
if($membership->getBa()->isTypeBeneficiaires() == true && $membership->getBa()->isTypeBeneficiairesClauseNotariee() == false){
//Signature (customer)
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "signature";
$newFieldCustomerSignature->page = 9;
$newFieldCustomerSignature->width = 156;
$newFieldCustomerSignature->height = 64;
$newFieldCustomerSignature->x = 339;
$newFieldCustomerSignature->y = 708;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
//City (customer)
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "text";
$newFieldCustomerSignature->max_length = 44;
$newFieldCustomerSignature->question = "Veuillez indiquer la ville";
$newFieldCustomerSignature->page = 9;
$newFieldCustomerSignature->width = 272;
$newFieldCustomerSignature->height = 24;
$newFieldCustomerSignature->x = 49;
$newFieldCustomerSignature->y = 669;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
//Date (customer)
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "mention";
$newFieldCustomerSignature->font = $fontDefault;
$newFieldCustomerSignature->mention = "%date%";
$newFieldCustomerSignature->page = 9;
$newFieldCustomerSignature->width = 272;
$newFieldCustomerSignature->height = 24;
$newFieldCustomerSignature->x = 49;
$newFieldCustomerSignature->y = 690;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
}
//SEPA
if ($membership->getBa()->getVersementProgramme() == 1 || $membership->getBa()->getMoyenDeVersement() == 3) {
//Signature (customer)
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "signature";
$newFieldCustomerSignature->page = 1;
$newFieldCustomerSignature->width = 137;
$newFieldCustomerSignature->height = 49;
$newFieldCustomerSignature->x = 355;
$newFieldCustomerSignature->y = 535;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
//City (customer)
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "text";
$newFieldCustomerSignature->max_length = 35;
$newFieldCustomerSignature->question = "Veuillez indiquer la ville";
$newFieldCustomerSignature->page = 1;
$newFieldCustomerSignature->width = 217;
$newFieldCustomerSignature->height = 24;
$newFieldCustomerSignature->x = 149;
$newFieldCustomerSignature->y = 498;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
//Date (customer)
$newFieldCustomerSignature = new \stdClass();
$newFieldCustomerSignature->signer_id = $newSignerCustomerId;
$newFieldCustomerSignature->type = "mention";
$newFieldCustomerSignature->font = $fontDefault;
$newFieldCustomerSignature->mention = "%date%";
$newFieldCustomerSignature->page = 1;
$newFieldCustomerSignature->width = 217;
$newFieldCustomerSignature->height = 24;
$newFieldCustomerSignature->x = 149;
$newFieldCustomerSignature->y = 519;
try {
$response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields',
[
'body' => json_encode($newFieldCustomerSignature),
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
}
/* ----------------------------------- Active signature (end step) ------------------------------------- */
//Activate signature
try {
$activateSignatureResponse = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/activate',
[
'headers' => [
'accept' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
$activateSignatureResponseBody = json_decode($activateSignatureResponse->getBody());
$activateSignatureResponseSigners = $activateSignatureResponseBody->signers;
}
catch (\Exception $e) {
$responseErrorTab[] = $e->getMessage();
}
$urlSeller = null;
$urlCustomer = null;
if(!$responseErrorTab){
if($membership->getPlatformVersion() == 2 && !$customer->isIsAutoSignup()){
$urlSeller = $activateSignatureResponseSigners[0]->signature_link;
$urlCustomer = $activateSignatureResponseSigners[1]->signature_link;
}
else{
$urlCustomer = $activateSignatureResponseSigners[0]->signature_link;
}
}
$tab = array(
"responseProcedure" => $activateSignatureResponseBody,
"yousignUi" => $this->yousignUi,
"dicFileId" => $uploadDicId,
"ficFileId" => $uploadFicId,
"baFileId" => $uploadBaId,
"sepaFileId" => $uploadSepaId,
"signerCustomer" => $newSignerCustomerResponseBody,
"signerSellerUrl" => $urlSeller,
"signerCustomerUrl" => $urlCustomer,
"signerCustomerId" => $newSignerCustomerId,
"signerSellerId" => $newSignerSellerId,
"responseErrorTab" => $responseErrorTab
);
return $tab;
}
function addSign2023($customer, $membership, $type)
{
if ($customer->getDicIsFile() != true) {
if($membership->getPlatformVersion() == 1){
//V1 DIC
//Get DIC BASE 64
$dicUrl = "files/" . $customer->getId() . '/' . $membership->getDic()->getUrlPdf();
$b64Dic = chunk_split(base64_encode(file_get_contents($dicUrl)));
$fileDic = new \stdClass();
$fileDic->name = "Document d’information et de conseil";
$fileDic->content = $b64Dic;
$fileDic->position = 1;
//Create files
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->yousignUrl . "/files",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fileDic),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $this->yousignApi,
"Content-Type: application/json"
),
));
$responseFile = curl_exec($curl);
curl_close($curl);
$responseFileDic = json_decode($responseFile);
} else{
//V2 FIC
//Get FIC BASE 64
$ficUrl = "files/" . $customer->getId() . '/' . $membership->getFic()->getUrlPdf();
$b64Fic = chunk_split(base64_encode(file_get_contents($ficUrl)));
$fileFic = new \stdClass();
$fileFic->name = "Fiche d’information et de conseil";
$fileFic->content = $b64Fic;
$fileFic->position = 1;
//Create files
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->yousignUrl . "/signature_requests//documents",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fileFic),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $this->yousignApi,
"Content-Type: application/json"
),
));
$responseFile = curl_exec($curl);
curl_close($curl);
$responseFileFic = json_decode($responseFile);
}
}
/* --------------------------------------------------------------------------- */
//Get BA BASE 64
$baUrl = "files/" . $customer->getId() . '/' . $membership->getBa()->getUrlPdf();
$b64Ba = chunk_split(base64_encode(file_get_contents($baUrl)));
$fileBa = new \stdClass();
$fileBa->name = "Demande d’adhésion";
$fileBa->content = $b64Ba;
$fileBa->position = 2;
//Create files
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->yousignUrl . "/files",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fileBa),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $this->yousignApi,
"Content-Type: application/json"
),
));
$responseFileBa = curl_exec($curl);
curl_close($curl);
$responseFileBa = json_decode($responseFileBa);
/* --------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------- */
if ($membership->getBa()->getVersementProgramme() == 1 || $membership->getBa()->getMoyenDeVersement() == 3) {
//Get BA BASE 64
$sepaUrl = "files/" . $customer->getId() . '/' . $membership->getBa()->getSepaUrlPdf();
$b64Sepa = chunk_split(base64_encode(file_get_contents($sepaUrl)));
$fileSepa = new \stdClass();
$fileSepa->name = "Mandat de prélèvement SEPA";
$fileSepa->content = $b64Sepa;
$fileSepa->position = 3;
//Create files
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->yousignUrl . "/files",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fileSepa),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $this->yousignApi,
"Content-Type: application/json"
),
));
$responseFileSepa = curl_exec($curl);
curl_close($curl);
$responseFileSepa = json_decode($responseFileSepa);
}
/* --------------------------------------------------------------------------- */
//Add procedure
$curl = curl_init();
//Set webhook
if ($type == "seller") {
$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end_seller', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
} else {
$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
}
$firstName = str_replace(",", " ", $customer->getFirstName());
$config = new \stdClass();
$webhook = new \stdClass();
$webhookEnd = new \stdClass();
$header = new \stdClass();
$webhookEnd->url = $urlSignEnd;
$webhookEnd->method = "GET";
$webhookEnd->headers = (object)array(
'X-Custom-Header' => "End sign"
);
$config->webhook = (object)array(
'member.finished' => array(
$webhookEnd
)
);
$arrayObjectFiles = array();
$dicFileId = null;
$ficFileId = null;
$baFileId = null;
$sepaFileId = null;
if ($customer->getDicIsFile() != true) {
if($membership->getPlatformVersion() == 1){
//V1 DIC
//Set file DIC
$fileObjectDic = new \stdClass();
$fileObjectDic->file = $responseFileDic->id;
$fileObjectDic->page = 1;
$fileObjectDic->position = "171,80,317,120";
$fileObjectDic->mention = "";
$fileObjectDic->mention2 = "Signé par " . $firstName . " " . $customer->getLastName();
$arrayObjectFiles[] = $fileObjectDic;
$dicFileId = $responseFileDic->id;
//Set file DIC VILLE
$fileObjectDicVille = new \stdClass();
$fileObjectDicVille->file = $responseFileDic->id;
$fileObjectDicVille->page = 1;
$fileObjectDicVille->type = "text";
$fileObjectDicVille->fontSize = 10;
$fileObjectDicVille->contentRequired = true;
$fileObjectDicVille->content = $membership->getBa()->getVille();
$fileObjectDicVille->position = "48,79,158,96";
$arrayObjectFiles[] = $fileObjectDicVille;
//Set file DIC DATE
$fileObjectDicDate = new \stdClass();
$fileObjectDicDate->file = $responseFileDic->id;
$fileObjectDicDate->page = 1;
$fileObjectDicDate->type = "text";
$fileObjectDicDate->fontSize = 10;
$fileObjectDicDate->contentRequired = true;
$fileObjectDicDate->content = date("d/m/Y");
$fileObjectDicDate->position = "49,98,159,115";
$arrayObjectFiles[] = $fileObjectDicDate;
} else{
//V2 FIC
$fileObjectFic = new \stdClass();
$fileObjectFic->file = $responseFileFic->id;
$fileObjectFic->page = 7;
$fileObjectFic->position = "69,199,247,304";
$fileObjectFic->mention = "";
$fileObjectFic->mention2 = "Signé par " . $firstName . " " . $customer->getLastName();
$arrayObjectFiles[] = $fileObjectFic;
$ficFileId = $responseFileFic->id;
//FOR SELLER
//$fileObjectFic->position = "323,182,503,246";
//Set file FIC VILLE
$fileObjectFicVille = new \stdClass();
$fileObjectFicVille->file = $responseFileFic->id;
$fileObjectFicVille->page = 7;
$fileObjectFicVille->type = "text";
$fileObjectFicVille->fontSize = 10;
$fileObjectFicVille->contentRequired = true;
$fileObjectFicVille->content = $membership->getFic()->getAdresseFiscaleVille();
$fileObjectFicVille->position = "66,449,293,464";
$arrayObjectFiles[] = $fileObjectFicVille;
//Set file FIC DATE
$fileObjectFicDate = new \stdClass();
$fileObjectFicDate->file = $responseFileFic->id;
$fileObjectFicDate->page = 7;
$fileObjectFicDate->type = "text";
$fileObjectFicDate->fontSize = 10;
$fileObjectFicDate->contentRequired = true;
$fileObjectFicDate->content = date("d/m/Y");
$fileObjectFicDate->position = "74,424,301,439";
$arrayObjectFiles[] = $fileObjectFicDate;
}
}
//Set file BA -> Demande attribution de
if ($membership->getBa()->getJaiDemandeAttributionDe() != null) {
$fileObjectBaName = new \stdClass();
$fileObjectBaName->file = $responseFileBa->id;
$fileObjectBaName->page = 4;
$fileObjectBaName->type = "text";
$fileObjectBaName->fontSize = 8;
$fileObjectBaName->contentRequired = true;
$fileObjectBaName->content = $firstName . " " . $membership->getUser()->getLastName();
$fileObjectBaName->position = "94,731,255,749";
$arrayObjectFiles[] = $fileObjectBaName;
}
//Set file BA
$fileObjectBa = new \stdClass();
$fileObjectBa->file = $responseFileBa->id;
$fileObjectBa->page = 7;
$fileObjectBa->position = "350,307,500,410";
$fileObjectBa->mention = "Lu et approuvé";
$fileObjectBa->mention2 = "Signé par " . $firstName . " " . $customer->getLastName();
$arrayObjectFiles[] = $fileObjectBa;
$baFileId = $responseFileBa->id;
$fileObjectBaLieu = new \stdClass();
$fileObjectBaLieu->file = $responseFileBa->id;
$fileObjectBaLieu->page = 7;
$fileObjectBaLieu->type = "text";
$fileObjectBaLieu->fontSize = 10;
$fileObjectBaLieu->contentRequired = true;
$fileObjectBaLieu->content = $membership->getBa()->getFiscaleVille();
$fileObjectBaLieu->position = "45,419,200,437";
$arrayObjectFiles[] = $fileObjectBaLieu;
$fileObjectBaDate = new \stdClass();
$fileObjectBaDate->file = $responseFileBa->id;
$fileObjectBaDate->page = 7;
$fileObjectBaDate->type = "text";
$fileObjectBaDate->fontSize = 10;
$fileObjectBaDate->contentRequired = true;
$fileObjectBaDate->content = date("d/m/Y");
$fileObjectBaDate->position = "47,403,202,421";
$arrayObjectFiles[] = $fileObjectBaDate;
//Benef
if($membership->getBa()->isTypeBeneficiaires() == true && $membership->getBa()->isTypeBeneficiairesClauseNotariee() == false){
$fileObjectBa = new \stdClass();
$fileObjectBa->file = $responseFileBa->id;
$fileObjectBa->page = 9;
$fileObjectBa->position = "347,68,521,131";
$fileObjectBa->mention = "Lu et approuvé";
$fileObjectBa->mention2 = "Signé par " . $firstName . " " . $customer->getLastName();
$arrayObjectFiles[] = $fileObjectBa;
$baFileId = $responseFileBa->id;
$fileObjectBaLieu = new \stdClass();
$fileObjectBaLieu->file = $responseFileBa->id;
$fileObjectBaLieu->page = 9;
$fileObjectBaLieu->type = "text";
$fileObjectBaLieu->fontSize = 10;
$fileObjectBaLieu->contentRequired = true;
$fileObjectBaLieu->content = $membership->getBa()->getFiscaleVille();
$fileObjectBaLieu->position = "50,150,201,171";
$arrayObjectFiles[] = $fileObjectBaLieu;
$fileObjectBaDate = new \stdClass();
$fileObjectBaDate->file = $responseFileBa->id;
$fileObjectBaDate->page = 9;
$fileObjectBaDate->type = "text";
$fileObjectBaDate->fontSize = 10;
$fileObjectBaDate->contentRequired = true;
$fileObjectBaDate->content = date("d/m/Y");
$fileObjectBaDate->position = "51,136,202,157";
$arrayObjectFiles[] = $fileObjectBaDate;
}
//SEPA
if ($membership->getBa()->getVersementProgramme() == 1 || $membership->getBa()->getMoyenDeVersement() == 3) {
//Set file SEPA
$fileObjectSepa = new \stdClass();
$fileObjectSepa->file = $responseFileSepa->id;
$fileObjectSepa->page = 1;
$fileObjectSepa->position = "365,227,506,309";
$fileObjectSepa->mention = "";
$fileObjectSepa->mention2 = "Signé par " . $firstName . " " . $customer->getLastName();
$arrayObjectFiles[] = $fileObjectSepa;
$sepaFileId = $responseFileSepa->id;
$fileObjectSepaDate = new \stdClass();
$fileObjectSepaDate->file = $responseFileSepa->id;
$fileObjectSepaDate->page = 1;
$fileObjectSepaDate->position = "148,303,300,322";
$fileObjectSepaDate->type = "text";
$fileObjectSepaDate->fontSize = 8;
$fileObjectSepaDate->contentRequired = true;
$fileObjectSepaDate->content = date("d/m/Y");
$arrayObjectFiles[] = $fileObjectSepaDate;
$fileObjectSepaLieu = new \stdClass();
$fileObjectSepaLieu->file = $responseFileSepa->id;
$fileObjectSepaLieu->page = 1;
$fileObjectSepaLieu->position = "147,321,299,340";
$fileObjectSepaLieu->type = "text";
$fileObjectSepaLieu->fontSize = 8;
$fileObjectSepaLieu->contentRequired = true;
$fileObjectSepaLieu->content = $membership->getBa()->getFiscaleVille();
$arrayObjectFiles[] = $fileObjectSepaLieu;
}
//Set member - customer
$member = new \stdClass();
$member->firstname = $firstName;
$member->lastname = $customer->getLastName();
$member->email = $customer->getEmail();
$phone = $customer->getPhone();
$phone = str_replace("(", "", $phone);
$phone = str_replace(")", "", $phone);
$phone = str_replace(" ", "", $phone);
if ($customer->getPhonePrefix()) {
$phone = $customer->getPhonePrefix() . $phone;
}
$member->phone = $phone;
$member->fileObjects = $arrayObjectFiles;
if($membership->getPlatformVersion() == 2 && $customer->isIsAutoSignup() != true){
//Set file FIC SELLER
$fileObjectFicSeller = new \stdClass();
$fileObjectFicSeller->file = $responseFileFic->id;
$fileObjectFicSeller->page = 7;
$fileObjectFicSeller->position = "350,198,528,303";
$fileObjectFicSeller->mention = "";
$fileObjectFicSeller->mention2 = "Signé par ".$customer->getSeller()->getFirstName()." ".$customer->getSeller()->getLastName();
//Set member - seller
$memberSeller = new \stdClass();
$memberSeller->position = 1;
$memberSeller->firstname = $customer->getSeller()->getFirstName();
$memberSeller->lastname = $customer->getSeller()->getLastName();
$memberSeller->email = $customer->getSeller()->getEmail();
$memberSeller->phone = $customer->getSeller()->getPhone();
$memberSeller->operationCustomModes = [ "email" ];
$memberSeller->fileObjects = array(
$fileObjectFicSeller,
);
$member->position = 2;
//Set procedure
$procedure = new \stdClass();
$procedure->name = "Signature adhésion";
$procedure->description = "Fin d'adhésion";
$procedure->start = true;
$procedure->ordered = false;
$procedure->members = array(
$memberSeller,
$member
);
$procedure->config = $config;
}
else{
//Set procedure
$procedure = new \stdClass();
$procedure->name = "Signature adhésion";
$procedure->description = "Fin d'adhésion";
$procedure->start = true;
$procedure->members = array(
$member,
);
$procedure->config = $config;
}
curl_setopt_array($curl, array(
CURLOPT_URL => $this->yousignUrl . "/procedures",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($procedure),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $this->yousignApi,
"Content-Type: application/json"
),
));
$responseProcedure = curl_exec($curl);
curl_close($curl);
$responseProcedure = json_decode($responseProcedure);
//var_dump($member);
//die;
$tab = array(
"responseProcedure" => $responseProcedure,
"yousignUi" => $this->yousignUi,
"dicFileId" => $dicFileId,
"ficFileId" => $ficFileId,
"baFileId" => $baFileId,
"sepaFileId" => $sepaFileId,
);
return $tab;
}
function saveFilesYouSignV3($membership, $typeUser = "customer")
{
$newSignatureId = $membership->getProcedureId();
//Wait 2 secondes Yousign create file
//sleep(2);
if ($membership->getUser()->getDicIsFile() != true) {
/* ------------------------ SAVE FIC START ------------------------ */
//GET FIC FILE
$client = new Client();
$fileResponse = $client->request('GET', $this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$membership->getFic()->getIdYouSign().'/download',
[
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
$fileBody = $fileResponse->getBody();
$name = $membership->getNumberMembershipFolder() . '_' . strtoupper($membership->getUser()->getLastName()) . '_' . strtoupper($membership->getUser()->getFirstName()) . '_' . 'FIC.pdf';
file_put_contents($this->fileUploader->getTargetDirectory() . "/" . $membership->getUser()->getId() . "/" . $name, $fileBody);
$membership->getFic()->setUrlPdfSign($name);
$this->em->persist($membership->getFic());
/* ------------------------ SAVE FIC END ------------------------ */
}
if($typeUser == "customer"){
/* ------------------------ SAVE BA START ------------------------ */
//GET BA FILE
$client = new Client();
$fileResponse = $client->request('GET', $this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$membership->getBa()->getIdYouSign().'/download',
[
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
$fileBody = $fileResponse->getBody();
$name = $membership->getNumberMembershipFolder() . '_' . strtoupper($membership->getUser()->getLastName()) . '_' . strtoupper($membership->getUser()->getFirstName()) . '_' . 'BA.pdf';
file_put_contents($this->fileUploader->getTargetDirectory() . "/" . $membership->getUser()->getId() . "/" . $name, $fileBody);
$membership->getBa()->setUrlPdfSign($name);
/* ------------------------ SAVE BA END ------------------------ */
/* ------------------------ SAVE SEPA START ------------------------ */
if ($membership->getBa()->getVersementProgramme() == 1 || $membership->getBa()->getMoyenDeVersement() == 3) {
//GET SEPA FILE
$client = new Client();
$fileResponse = $client->request('GET', $this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$membership->getBa()->getSepaIdYouSign().'/download',
[
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'Authorization' => 'Bearer ' . $this->yousignApi
],
]
);
$fileBody = $fileResponse->getBody();
$name = $membership->getNumberMembershipFolder() . '_' . strtoupper($membership->getUser()->getLastName()) . '_' . strtoupper($membership->getUser()->getFirstName()) . '_' . 'SEPA.pdf';
file_put_contents($this->fileUploader->getTargetDirectory() . "/" . $membership->getUser()->getId() . "/" . $name, $fileBody);
$membership->getBa()->setSepaUrlPdfSign($name);
}
/* ------------------------ SAVE SEPA END ------------------------ */
$this->em->persist($membership->getBa());
}
$this->em->flush();
}
function saveFilesYouSign($membership, $typeUser = "customer")
{
//Wait 2 secondes Yousign create file
sleep(2);
if ($membership->getUser()->getDicIsFile() != true) {
if($membership->getPlatformVersion() == 1){
//V1 DIC
/* ------------------------ SAVE DIC START ------------------------ */
//GET DIC FILE
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->yousignUrlV2 . $membership->getDic()->getIdYouSign() . "/download",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 30,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $this->yousignApiV2,
"Content-Type: application/json"
),
));
$responseFileDic = curl_exec($curl);
curl_close($curl);
$dicFile = json_decode($responseFileDic);
$dicFileBin = base64_decode($dicFile, true);
$name = $membership->getNumberMembershipFolder() . '_' . strtoupper($membership->getUser()->getLastName()) . '_' . strtoupper($membership->getUser()->getFirstName()) . '_' . 'DIC.pdf';
file_put_contents($this->fileUploader->getTargetDirectory() . "/" . $membership->getUser()->getId() . "/" . $name, $dicFileBin);
$membership->getDic()->setUrlPdfSign($name);
/* ------------------------ SAVE DIC END ------------------------ */
} else {
// V2 FIC
/* ------------------------ SAVE FIC START ------------------------ */
//GET FIC FILE
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->yousignUrlV2 . $membership->getFic()->getIdYouSign() . "/download",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 30,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $this->yousignApiV2,
"Content-Type: application/json"
),
));
$responseFileFic = curl_exec($curl);
curl_close($curl);
$ficFile = json_decode($responseFileFic);
$ficFileBin = base64_decode($ficFile, true);
$name = $membership->getNumberMembershipFolder() . '_' . strtoupper($membership->getUser()->getLastName()) . '_' . strtoupper($membership->getUser()->getFirstName()) . '_' . 'FIC.pdf';
file_put_contents($this->fileUploader->getTargetDirectory() . "/" . $membership->getUser()->getId() . "/" . $name, $ficFileBin);
$membership->getFic()->setUrlPdfSign($name);
/* ------------------------ SAVE FIC END ------------------------ */
}
}
if($typeUser == "customer"){
/* ------------------------ SAVE BA START ------------------------ */
//GET BA FILE
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->yousignUrlV2 . $membership->getBa()->getIdYouSign() . "/download",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 30,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $this->yousignApiV2,
"Content-Type: application/json"
),
));
$responseFileBa = curl_exec($curl);
curl_close($curl);
$baFile = json_decode($responseFileBa);
$baFileBin = base64_decode($baFile, true);
$name = $membership->getNumberMembershipFolder() . '_' . strtoupper($membership->getUser()->getLastName()) . '_' . strtoupper($membership->getUser()->getFirstName()) . '_' . 'BA.pdf';
file_put_contents($this->fileUploader->getTargetDirectory() . "/" . $membership->getUser()->getId() . "/" . $name, $baFileBin);
$membership->getBa()->setUrlPdfSign($name);
/* ------------------------ SAVE BA END ------------------------ */
/* ------------------------ SAVE SEPA START ------------------------ */
if ($membership->getBa()->getVersementProgramme() == 1 || $membership->getBa()->getMoyenDeVersement() == 3) {
//GET SEPA FILE
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->yousignUrlV2 . $membership->getBa()->getSepaIdYouSign() . "/download",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 30,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $this->yousignApiV2,
"Content-Type: application/json"
),
));
$responseFileSepa = curl_exec($curl);
curl_close($curl);
$sepaFile = json_decode($responseFileSepa);
$sepaFileBin = base64_decode($sepaFile, true);
$name = $membership->getNumberMembershipFolder() . '_' . strtoupper($membership->getUser()->getLastName()) . '_' . strtoupper($membership->getUser()->getFirstName()) . '_' . 'SEPA.pdf';
file_put_contents($this->fileUploader->getTargetDirectory() . "/" . $membership->getUser()->getId() . "/" . $name, $sepaFileBin);
$membership->getBa()->setSepaUrlPdfSign($name);
}
/* ------------------------ SAVE SEPA END ------------------------ */
$this->em->persist($membership->getBa());
}
if($membership->getPlatformVersion() == 1){
$this->em->persist($membership->getDic());
}
else{
$this->em->persist($membership->getFic());
}
$this->em->flush();
}
function startSign($procedure)
{
$memberId = $procedure->members[0]->id;
$yousignUrlV2 = $this->container->getParameter('yousign_url_v2');
header('Location: ' . $yousignUrlV2 . '/procedure/sign?members=' . $memberId . '&signatureUi=/signature_uis/' . $this->yousignUi);
exit();
}
function youSignConditions($fileURL, $document, $userCurrent = null): array
{
$responseProcedure = null;
$cpFileId = null;
//Get CP BASE 64
$b64Cp = chunk_split(base64_encode(file_get_contents($fileURL)));
$fileCp = new \stdClass();
$fileCp->name = "Conditions particulières";
$fileCp->content = $b64Cp;
$fileCp->position = 1;
//Create files
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->yousignUrl . "/files",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fileCp),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $this->yousignApi,
"Content-Type: application/json"
),
));
$responseFile = curl_exec($curl);
curl_close($curl);
$responseFileCp = json_decode($responseFile);
if($responseFileCp){
//Default (last value) : "432,131,548,184"; page 2;
if($document->getFileType()){
if($document->getFileType()->isSignedOrder()){
//Right
$position = "432,131,548,184";
}
else{
//Left
$position = "50,134,178,180";
}
} else {
// default position
$position = "432,131,548,184";
}
if($document->getFileType()){
$page = $document->getFileType()->getNumberPage();
}
else{
// default page
$page = 2;
}
//Set file CP
$fileObjectCp = new \stdClass();
$fileObjectCp->file = $responseFileCp->id;
$fileObjectCp->page = $page;
$fileObjectCp->position = $position;
$fileObjectCp->mention = "Lu et approuvé";
$fileObjectCp->reason = "Signed by John Doe (Yousign)";
$firstName = $userCurrent->getFirstName();
$lastName = $userCurrent->getLastName();
if($firstName && $lastName){
$fileObjectCp->mention2 = "Signé par " . $firstName . " " . $lastName;
}
$arrayObjectFiles[] = $fileObjectCp;
$cpFileId = $responseFileCp->id;
//Add procedure
$config = new \stdClass();
$webhook = new \stdClass();
$webhookEnd = new \stdClass();
$header = new \stdClass();
$urlSignEnd = $this->container->get('router')->generate('yousign_sign_conditions_end', array('documentID' => $document->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
$webhookEnd->url = $urlSignEnd;
$webhookEnd->method = "GET";
$webhookEnd->headers = (object)array(
'X-Custom-Header' => "End sign"
);
$config->webhook = (object)array(
'procedure.finished' => array(
$webhookEnd
)
);
//Set member - customer
$member = new \stdClass();
$member->firstname = $userCurrent->getFirstName();
$member->phone = $userCurrent->getPhone();
$member->lastname = $userCurrent->getLastName();
$member->email = $userCurrent->getEmail();
$member->fileObjects = $arrayObjectFiles;
$member->type = "signer";
//Set procedure
$procedure = new \stdClass();
$procedure->name = "Signature des conditions particulières";
$procedure->description = "Fin d'adhésion";
$procedure->start = true;
$procedure->members = array(
$member
);
$procedure->config = $config;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->yousignUrl . "/procedures",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($procedure),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $this->yousignApi,
"Content-Type: application/json"
),
));
$responseProcedure = curl_exec($curl);
curl_close($curl);
$responseProcedure = json_decode($responseProcedure);
}
return [
"responseProcedure" => $responseProcedure,
"yousignUi" => $this->yousignUiConditions,
"fileId" => $cpFileId,
];
}
function saveFilesConditionsYouSign($document)
{
//GET DIC FILE
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->yousignUrl . $document->getIdYouSign() . "/download",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer " . $this->yousignApi,
"Content-Type: application/json"
),
));
$responseFile = curl_exec($curl);
curl_close($curl);
$file = json_decode($responseFile);
$fileBin = base64_decode($file, true);
$name = $document->getNumeroAdherent() . "_" . $document->getLastName() . "_" . $document->getFirstName() . "_CONDITIONS_PARTICULIERES.pdf";
$path = $this->fileUploader->getTargetDirectory() . "/cp/" . $document->getId() . "/" . $name;
file_put_contents($path, $fileBin);
$document->setUrlPdfSign($path);
$document->setFilename($name);
$this->em->persist($document);
$this->em->flush();
}
}