src/Services/Utils.php line 66

Open in your IDE?
  1. <?php
  2. namespace App\Services;
  3. use Symfony\Component\DependencyInjection\Tests\Fixtures\StdClassDecorator;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\File\File;
  6. use Symfony\Component\Finder\SplFileInfo;
  7. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Symfony\Component\HttpFoundation\Session\Session;
  12. use Symfony\Component\HttpFoundation\JsonResponse;
  13. use Symfony\Component\DependencyInjection\ContainerInterface;
  14. use Symfony\Component\Translation\TranslatorInterface;
  15. use Symfony\Component\Form\FormEvent;
  16. use Symfony\Component\Form\FormEvents;
  17. use Symfony\Component\Form\FormError;
  18. use GuzzleHttp\Client;
  19. use App\Entity\User;
  20. use App\Entity\Membership;
  21. use App\Entity\Dic;
  22. use App\Entity\Fic;
  23. use App\Entity\Ba;
  24. use App\Services\GenerateDocuments;
  25. use App\Services\GenerateDocumentsFullweb;
  26. use Symfony\Component\HttpFoundation\RequestStack;
  27. // Import the Twig Environment
  28. use Twig\Environment;
  29. use setasign\Fpdi\Fpdi;
  30. class Utils
  31. {
  32.     private $container;
  33.     private $twig;
  34.     protected $fileUploader;
  35.     private $yousignApiV2;
  36.     private $yousignUrlV2;
  37.     private $yousignApi;
  38.     private $yousignUrl;
  39.     private $yousignUi;
  40.     private $yousignUiConditions;
  41.     private $yousignWorkspace;
  42.     private $yousignWorkspaceConditions;
  43.     /**
  44.      * Constructor
  45.      *
  46.      * @param ContainerInterface $container
  47.      */
  48.     public function __construct(ContainerInterface $container$yousignApiV2$yousignUrlV2$yousignApi$yousignUrl$yousignUi$yousignUiConditions$yousignWorkspace$yousignWorkspaceConditionsEntityManagerInterface $entityManager\Swift_Mailer $mailerEnvironment $twig\Knp\Snappy\Pdf $knpSnappyFileUploader $fileUploaderGenerateDocuments $generateDocumentsGenerateDocumentsFullweb $generateDocumentsFullweb)
  49.     {
  50.         $this->container $container;
  51.         $this->mailer $mailer;
  52.         $this->em $entityManager;
  53.         $this->twig $twig;
  54.         $this->knpSnappy $knpSnappy;
  55.         $this->fileUploader $fileUploader;
  56.         $this->yousignApiV2 $yousignApiV2['yousignApiV2'];
  57.         $this->yousignUrlV2 $yousignUrlV2['yousignUrlV2'];
  58.         $this->yousignApi $yousignApi['yousignApi'];
  59.         $this->yousignUrl $yousignUrl['yousignUrl'];
  60.         $this->yousignUi $yousignUi['yousignUi'];
  61.         $this->yousignUiConditions $yousignUiConditions['yousignUiConditions'];
  62.         $this->yousignWorkspace $yousignWorkspace['yousignWorkspace'];
  63.         $this->yousignWorkspaceConditions $yousignWorkspaceConditions['yousignWorkspaceConditions'];
  64.         $this->generateDocuments $generateDocuments;
  65.         $this->generateDocumentsFullweb $generateDocumentsFullweb;
  66.     }
  67.     public function decode($value)
  68.     {
  69.         // convert from utf8 to latin1
  70.         return mb_convert_encoding($value'ISO-8859-1''UTF-8');
  71.     }
  72.     public function getMembershipByCustomer($customer)
  73.     {
  74.         $membership $this->em
  75.             ->getRepository(Membership::class)
  76.             ->findOneBy(['user' => $customer], array("id" => "DESC"));
  77.         if (!$membership) {
  78.             $customer $this->em
  79.                 ->getRepository(User::class)
  80.                 ->findOneBy(['id' => $customer]);
  81.             $membership = new Membership;
  82.             $membership->setUser($customer);
  83.             $membership->setStatus("DRAFT");
  84.             if($customer->getDicIsFile()){
  85.                 $membership->setPlatformVersion(1);
  86.             }
  87.             else{
  88.                 $membership->setPlatformVersion(2);
  89.             }
  90.             
  91.             $this->em->persist($membership);
  92.             $this->em->flush();
  93.             $membershipLast $membership;
  94.         } else {
  95.             $membershipLast $membership;
  96.         }
  97.         //Create folder customer
  98.         $urlFolderCustomer $this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId();
  99.         if (!file_exists($urlFolderCustomer)) {
  100.             //Remove last file
  101.             mkdir($urlFolderCustomer);        
  102.         }
  103.         if($membershipLast->getPlatformVersion() == 1){
  104.             if (!$membershipLast->getDic()) {
  105.                 $dic = new Dic;
  106.                 $membershipLast->setDic($dic);
  107.                 $this->em->persist($dic);
  108.                 $this->em->persist($membershipLast);
  109.                 $this->em->flush();
  110.             }
  111.         }
  112.         else{
  113.             if (!$membershipLast->getFic()) {
  114.                 $fic = new Fic;
  115.                 $membershipLast->setFic($fic);
  116.                 $this->em->persist($fic);
  117.                 $this->em->persist($membershipLast);
  118.                 $this->em->flush();
  119.             }
  120.         }
  121.         if (!$membershipLast->getBa()) {
  122.             $ba = new Ba;
  123.             $membershipLast->setBa($ba);
  124.             $this->em->persist($ba);
  125.             $this->em->persist($membershipLast);
  126.             $this->em->flush();
  127.         }
  128.         return $membershipLast;
  129.     }
  130.     public function getCustomerByNumberMembership($nb)
  131.     {
  132.         $customer null;
  133.         $membership $this->em
  134.             ->getRepository(Membership::class)
  135.             ->findOneBy(['numberMembershipFolder' => $nb], array("id" => "DESC"));
  136.         if ($membership) {
  137.             $customer $membership->getUser();
  138.         }
  139.         return $customer;
  140.     }
  141.     public function sendEmailEndSignin($user)
  142.     {
  143.         $mailNoReply $this->container->getParameter('mail_no_reply');
  144.         $senderName $this->container->getParameter('sender_name');
  145.         $url $this->container->get('router')->generate('signin_end', array('token' => $user->getTokenReset()), UrlGeneratorInterface::ABSOLUTE_URL);
  146.         $bodyEmail $this->twig->render(
  147.             'email/addUserWithToken.html.twig',
  148.             array('user' => $user'confirmationToken' => $url)
  149.         );
  150.         $message = (new \Swift_Message("Fin d'inscription"))
  151.             ->setSubject("Fin d'inscription")
  152.             ->setFrom(array($mailNoReply => $senderName))
  153.             ->setTo(array($user->getEmail() => $senderName))
  154.             ->setBody($bodyEmail'text/html');
  155.         $this->mailer->send($message);
  156.     }
  157.     public function sendEmailEndSigninCustomer($user)
  158.     {
  159.         $mailNoReply $this->container->getParameter('mail_no_reply');
  160.         $senderName $this->container->getParameter('sender_name');
  161.         $url $this->container->get('router')->generate('signin_end', array('token' => $user->getTokenReset()), UrlGeneratorInterface::ABSOLUTE_URL);
  162.         $bodyEmail $this->twig->render(
  163.             'email/addCustomerWithToken.html.twig',
  164.             array('user' => $user'confirmationToken' => $url)
  165.         );
  166.         $message = (new \Swift_Message("Finalisez votre adhésion"))
  167.             ->setSubject("Finalisez votre adhésion")
  168.             ->setFrom(array($mailNoReply => $senderName))
  169.             ->setTo(array($user->getEmail() => $senderName))
  170.             ->setBody($bodyEmail'text/html');
  171.         $this->mailer->send($message);
  172.     }
  173.     public function generateDic($customer)
  174.     {
  175.         $dicFileName "dic-no-sign.pdf";
  176.         $dicFullPath $this->fileUploader->getTargetDirectory() . "/" $customer->getId() . "/" $dicFileName;
  177.         //If file exist
  178.         if (file_exists($dicFullPath)) {
  179.             //Remove last file
  180.             unlink($dicFullPath);
  181.         }
  182.         $this->knpSnappy->setOption('page-size''A4');
  183.         $this->knpSnappy->setOption('encoding''UTF-8');
  184.         $this->knpSnappy->setOption('zoom''1.17');
  185.         $this->knpSnappy->setOption('margin-left''0');
  186.         $this->knpSnappy->setOption('margin-right''0');
  187.         $this->knpSnappy->setOption('margin-top''5');
  188.         $this->knpSnappy->setOption('margin-bottom''5');
  189.         $this->knpSnappy->setOption('dpi''96');
  190.         $this->knpSnappy->generateFromHtml(
  191.             $this->twig->render(
  192.                 'membership/pdf/dicView.html.twig',
  193.                 array(
  194.                     'dic' => $customer->getCurrentMemberships()->getDic()
  195.                 )
  196.             ),
  197.             $dicFullPath
  198.         );
  199.         return $dicFileName;
  200.     }
  201.     public function generateFicV2023($customer)
  202.     {
  203.         $ficFileName "fic-no-sign.pdf";
  204.         $ficFullPath $this->fileUploader->getTargetDirectory() . "/" $customer->getId() . "/" $ficFileName;
  205.         //If file exist
  206.         if (file_exists($ficFullPath)) {
  207.             //Remove last file
  208.             unlink($ficFullPath);
  209.         }
  210.         $this->knpSnappy->setOption('page-size''A4');
  211.         $this->knpSnappy->setOption('encoding''UTF-8');
  212.         $this->knpSnappy->setOption('zoom''1.62');
  213.         $this->knpSnappy->setOption('margin-left''0');
  214.         $this->knpSnappy->setOption('margin-right''0');
  215.         $this->knpSnappy->setOption('margin-top''5');
  216.         $this->knpSnappy->setOption('margin-bottom''5');
  217.         $this->knpSnappy->setOption('dpi''96');
  218.         $this->knpSnappy->generateFromHtml(
  219.             $this->twig->render(
  220.                 'membership/pdf/ficView.html.twig',
  221.                 array(
  222.                     'fic' => $customer->getCurrentMemberships()->getFic()
  223.                 )
  224.             ),
  225.             $ficFullPath
  226.         );
  227.         return $ficFileName;
  228.     }
  229.     public function generateFic($customer)
  230.     {
  231.         $ficFileName $this->generateDocuments->generateFic($customer);
  232.         return $ficFileName;
  233.     }
  234.     public function generateFicFullweb($customer)
  235.     {
  236.         $ficFileName $this->generateDocumentsFullweb->generateFic($customer);
  237.         return $ficFileName;
  238.     }
  239.     public function generateBaV2023($customer)
  240.     {
  241.         $baFileName "ba-no-sign.pdf";
  242.         $baFullPath $this->fileUploader->getTargetDirectory() . "/" $customer->getId() . "/" $baFileName;
  243.         //If file exist
  244.         if (file_exists($baFullPath)) {
  245.             //Remove last file
  246.             unlink($baFullPath);
  247.         }
  248.         $this->knpSnappy->setOption('page-size''A4');
  249.         $this->knpSnappy->setOption('encoding''UTF-8');
  250.         $this->knpSnappy->setOption('zoom''1.62');
  251.         $this->knpSnappy->setOption('margin-left''0');
  252.         $this->knpSnappy->setOption('margin-right''0');
  253.         $this->knpSnappy->setOption('margin-top''5');
  254.         $this->knpSnappy->setOption('margin-bottom''5');
  255.         $this->knpSnappy->setOption('dpi''96');
  256.         $this->knpSnappy->generateFromHtml(
  257.             $this->twig->render(
  258.                 'membership/pdf/baView.html.twig',
  259.                 array(
  260.                     'ba' => $customer->getCurrentMemberships()->getBa()
  261.                 )
  262.             ),
  263.             $baFullPath
  264.         );
  265.         return $baFileName;
  266.     }
  267.     public function generateBa($customer)
  268.     {
  269.         $baFileName $this->generateDocuments->generateBa($customer);
  270.         return $baFileName;
  271.     }
  272.     public function generateBaFullweb($customer)
  273.     {
  274.         $baFileName $this->generateDocumentsFullweb->generateBa($customer);
  275.         return $baFileName;
  276.     }
  277.     
  278.     public function generateSepa($customer)
  279.     {
  280.         $sepaFileName "sepa-no-sign.pdf";
  281.         $ba $customer->getCurrentMemberships()->getBa();
  282.         $sepaFullPath $this->fileUploader->getTargetDirectory() . "/" $customer->getId() . "/" $sepaFileName;
  283.         //If file exist
  284.         if (file_exists($sepaFullPath)) {
  285.             //Remove last file
  286.             unlink($sepaFullPath);
  287.         }
  288.         // initiate FPDI
  289.         $pdf = new Fpdi();
  290.         // add a page
  291.         $pdf->AddPage();
  292.         // set the source file
  293.         $numberPagesSource $pdf->setSourceFile("default/SEPA_2024.pdf");
  294.         for ($i 1$i <= $numberPagesSource $i++) { 
  295.             if($i 1){
  296.                 $pdf->AddPage();
  297.             }
  298.             // import page
  299.             $tplId $pdf->importPage($i);
  300.             $pdf->useTemplate($tplId00);
  301.             //Global pages
  302.             $font "Helvetica";
  303.             $fontSizeText 11;
  304.             $fontSizeChecked 11;
  305.             $pdf->setFont($fontnull10);
  306.             switch ($i) {
  307.                 case '1':
  308.                 //Non et adresse postale
  309.                 $pdf->setFont($fontnull11);
  310.                 $pdf -> SetY(71.6);
  311.                 $pdf -> SetX(18.5); 
  312.                 $pdf->MultiCell(10310$ba->getSepaNom()." ".$ba->getSepaPrenom()."\n".$ba->getSepaAdresse().", ".$ba->getSepaCodePostal()." ".$ba->getSepaVille().", ".$ba->getSepaPays(), 0'L'0);
  313.                 //Iban
  314.                 $pdf->setFont($fontnull11.3);
  315.                     $pdf->Text(28.6116.2$this->formatString($ba->getSepaCodeIban(), "iban"));
  316.                 //Bic
  317.                 $pdf->setFont($fontnull11.1);
  318.                     $pdf->Text(29.8124.8$this->formatString($ba->getSepaCodeBic()));
  319.                 default:
  320.                     // code...
  321.                     break;
  322.             }
  323.         }
  324.         $pdf->Output('F'$sepaFullPath);
  325.         return $sepaFileName;
  326.     }
  327.     public function generateSepaV2023($customer)
  328.     {
  329.         $sepaFileName "sepa-no-sign.pdf";
  330.         $sepaFullPath $this->fileUploader->getTargetDirectory() . "/" $customer->getId() . "/" $sepaFileName;
  331.         //If file exist
  332.         if (file_exists($sepaFullPath)) {
  333.             //Remove last file
  334.             unlink($sepaFullPath);
  335.         }
  336.         $this->knpSnappy->setOption('page-size''A4');
  337.         $this->knpSnappy->setOption('encoding''UTF-8');
  338.         $this->knpSnappy->setOption('zoom''1.17');
  339.         $this->knpSnappy->setOption('margin-left''0');
  340.         $this->knpSnappy->setOption('margin-right''0');
  341.         $this->knpSnappy->setOption('margin-top''5');
  342.         $this->knpSnappy->setOption('margin-bottom''5');
  343.         $this->knpSnappy->generateFromHtml(
  344.             $this->twig->render(
  345.                 'membership/pdf/sepaView.html.twig',
  346.                 array(
  347.                     'ba' => $customer->getCurrentMemberships()->getBa()
  348.                 )
  349.             ),
  350.             $sepaFullPath
  351.         );
  352.         return $sepaFileName;
  353.     }
  354.     public function formatString($stringLetters$typeFormat "default"){
  355.         $string "";
  356.         $forNumber 1;
  357.         $tabString str_split($stringLetters);
  358.         foreach ($tabString as $keyLetter => $stringLetter) {
  359.             if($keyLetter 0){
  360.                 $string .= " ";
  361.             }
  362.             $string .= $stringLetter;
  363.             switch ($typeFormat) {
  364.                 case 'iban':
  365.                     if($forNumber == && count($tabString) != ($keyLetter 1)){
  366.                         $string .= " ";
  367.                         $forNumber 0;
  368.                     }
  369.                     break;
  370.                 case 'ss':
  371.                     if($keyLetter == || $keyLetter == || $keyLetter == || $keyLetter == || $keyLetter == 9){
  372.                         $string .= " ";
  373.                     }
  374.                     break;
  375.                 
  376.                 default:
  377.                     // code...
  378.                     break;
  379.             }
  380.             $forNumber++;
  381.         }
  382.         return $string;
  383.     }
  384.     public function getStatusMembership($customer)
  385.     {
  386.         $status "no-status";
  387.         $membershipCurrent $this->getMembershipByCustomer($customer);
  388.         if ($membershipCurrent->getStatus() == "DRAFT") {
  389.             $status "Brouillon";
  390.         } else if ($membershipCurrent->getStatus() == "VALIDBYSELLER" && $membershipCurrent->getUser()->getStatus() == "SIGNINEND") {
  391.             $status "En attente de fin d'inscription";
  392.         } else if ($membershipCurrent->getStatus() == "VALIDBYSELLER") {
  393.             $status "En attente de validation";
  394.         } else if ($membershipCurrent->getStatus() == "VALIDBYCUSTOMER") {
  395.             $status "En attente de signature";
  396.         } else if ($membershipCurrent->getStatus() == "SIGNBYCUSTOMER") {
  397.             $status "En attente de paiement";
  398.         } else if ($membershipCurrent->getStatus() == "PAYBYCUSTOMER") {
  399.             $status "Validé";
  400.         }
  401.         return $status;
  402.     }
  403.     public function getNumberMembership($customer)
  404.     {
  405.         $number null;
  406.         $currentMemberships $this->getMembershipByCustomer($customer);
  407.         if ($customer) {
  408.             if ($currentMemberships) {
  409.                 $number $currentMemberships->getNumberMembershipFolder();
  410.             }
  411.         }
  412.         if ($number == null) {
  413.             $number "Aucun numéro";
  414.         }
  415.         return $number;
  416.     }
  417.     function formatSizeUnits($bytes)
  418.     {
  419.         if ($bytes >= 1073741824) {
  420.             $bytes number_format($bytes 10737418242) . ' GB';
  421.         } elseif ($bytes >= 1048576) {
  422.             $bytes number_format($bytes 10485762) . ' MB';
  423.         } elseif ($bytes >= 1024) {
  424.             $bytes number_format($bytes 10242) . ' KB';
  425.         } elseif ($bytes 1) {
  426.             $bytes $bytes ' bytes';
  427.         } elseif ($bytes == 1) {
  428.             $bytes $bytes ' byte';
  429.         } else {
  430.             $bytes '0 bytes';
  431.         }
  432.         return $bytes;
  433.     }
  434.     function addSign($customer$membership$type)
  435.     {
  436.         $client = new Client();
  437.         $uploadDicId null;
  438.         $uploadFicId null;
  439.         $uploadBaId null;
  440.         $uploadSepaId null;
  441.         $newSignerSellerId null;
  442.         $newSignerCustomerId null;
  443.         $newSignerCustomerResponseBody null;
  444.         $activateSignatureResponseBody null;
  445.         $responseErrorTab = [];
  446.         //Font default for all fields
  447.         $fontDefault = new \stdClass();
  448.         $fontDefault->size 9;
  449.         $fontDefault->family "Inconsolata";
  450.         $fontDefault->variants = array(
  451.             "italic" => false,
  452.             "bold" => false
  453.         );
  454.         $fontDefault->color "#000000";
  455.         /* -----------------------------------  Add Signature   ------------------------------------- */
  456.         //Create signature
  457.         $newSignature = new \stdClass();
  458.         $newSignature->delivery_mode "none";
  459.         $newSignature->reminder_settings null;
  460.         $newSignature->ordered_signers true;
  461.         $newSignature->signers_allowed_to_decline false;
  462.         $newSignature->workspace_id $this->yousignWorkspace;
  463.         $newSignature->name "Nouvelle adhésion épargne retraite";
  464.         $newSignature->custom_experience_id $this->yousignUi;
  465.         try {
  466.             $newSignatureResponse $client->request('POST'$this->yousignUrl .'/signature_requests'
  467.                 [
  468.                     'body' => json_encode($newSignature),
  469.                     'headers' => [
  470.                         'accept' => 'application/json',
  471.                         'content-type' => 'application/json',
  472.                         'Authorization' => 'Bearer ' $this->yousignApi
  473.                     ],
  474.                 ]
  475.             );
  476.             //201 for create
  477.             $newSignatureResponseStatusCode $newSignatureResponse->getStatusCode();
  478.             $newSignatureResponseBody json_decode($newSignatureResponse->getBody());
  479.             $newSignatureId $newSignatureResponseBody->id;
  480.         }
  481.         catch (\Exception $e) {
  482.             $responseErrorTab[] = $e->getMessage();
  483.         }
  484.         /* -----------------------------------  Add Metadata   ------------------------------------- */
  485.         //Create meta
  486.         $newMetaData = new \stdClass();
  487.         $newMetaData->data = array(
  488.             "membershipId" => $membership->getId()
  489.         );
  490.         try {
  491.             $newMetaDataResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/metadata'
  492.                 [
  493.                     'body' => json_encode($newMetaData),
  494.                     'headers' => [
  495.                         'accept' => 'application/json',
  496.                         'content-type' => 'application/json',
  497.                         'Authorization' => 'Bearer ' $this->yousignApi
  498.                     ],
  499.                 ]
  500.             );
  501.             //201 for create
  502.             $newMetaDataResponseStatusCode $newMetaDataResponse->getStatusCode();
  503.             $newMetaDataResponseBody json_decode($newMetaDataResponse->getBody());
  504.         }
  505.         catch (\Exception $e) {
  506.             $responseErrorTab[] = $e->getMessage();
  507.         }
  508.         /* -----------------------------------  Add Files   ------------------------------------- */
  509.         //Add FIC file
  510.         if ($customer->getDicIsFile() != true) {
  511.             $ficUrl "files/" $customer->getId() . '/' $membership->getFic()->getUrlPdf();
  512.             try {
  513.                 $uploadFicResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents'
  514.                     [
  515.                         'multipart' => [
  516.                             [
  517.                                 'name' => 'nature',
  518.                                 'contents' => 'signable_document'
  519.                             ],
  520.                             [
  521.                                 'name' => 'parse_anchors',
  522.                                 'contents' => 'false'
  523.                             ],
  524.                             [
  525.                                 'name' => 'file',
  526.                                 'filename' => "Fiche d'information et de conseil.pdf",
  527.                                 'contents' => fopen($ficUrl'r'),
  528.                             ]
  529.                         ],
  530.                         'headers' => [
  531.                             'accept' => 'application/json',
  532.                             'Authorization' => 'Bearer ' $this->yousignApi
  533.                         ]
  534.                     ]
  535.                 );
  536.                 $uploadFicResponseBody json_decode($uploadFicResponse->getBody());
  537.                 $uploadFicId $uploadFicResponseBody->id;
  538.             }
  539.             catch (\Exception $e) {
  540.                 $responseErrorTab[] = $e->getMessage();
  541.             }
  542.         }
  543.         //Add BA file
  544.         $baUrl "files/" $customer->getId() . '/' $membership->getBa()->getUrlPdf();
  545.         if($customer->getDicIsFile() != true) {
  546.             $multipart 
  547.             [
  548.                 [
  549.                     'name' => 'nature',
  550.                     'contents' => 'signable_document'
  551.                 ],
  552.                 [
  553.                     'name' => 'parse_anchors',
  554.                     'contents' => 'false'
  555.                 ],
  556.                 [
  557.                     'name' => 'insert_after_id',
  558.                     'contents' => $uploadFicId
  559.                 ],
  560.                 [
  561.                     'name' => 'file',
  562.                     'filename' => "Demande d'adhésion.pdf",
  563.                     'contents' => fopen($baUrl'r'),
  564.                 ]
  565.             ];
  566.         }
  567.         else{
  568.             $multipart 
  569.             [
  570.                 [
  571.                     'name' => 'nature',
  572.                     'contents' => 'signable_document'
  573.                 ],
  574.                 [
  575.                     'name' => 'parse_anchors',
  576.                     'contents' => 'false'
  577.                 ],
  578.                 [
  579.                     'name' => 'file',
  580.                     'filename' => "Demande d'adhésion.pdf",
  581.                     'contents' => fopen($baUrl'r'),
  582.                 ]
  583.             ];
  584.         }
  585.         try {
  586.             $uploadBaResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents'
  587.                 [
  588.                     'multipart' => $multipart,
  589.                     'headers' => [
  590.                         'accept' => 'application/json',
  591.                         'Authorization' => 'Bearer ' $this->yousignApi
  592.                     ]
  593.                 ]
  594.             );
  595.             $uploadBaResponseBody json_decode($uploadBaResponse->getBody());
  596.             $uploadBaId $uploadBaResponseBody->id;
  597.         }
  598.         catch (\Exception $e) {
  599.             $responseErrorTab[] = $e->getMessage();
  600.         }
  601.         //Add SEPA file
  602.         if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  603.             $sepaUrl "files/" $customer->getId() . '/' $membership->getBa()->getSepaUrlPdf();
  604.             try {
  605.                 $uploadSepaResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents'
  606.                     [
  607.                         'multipart' => [
  608.                             [
  609.                                 'name' => 'nature',
  610.                                 'contents' => 'signable_document'
  611.                             ],
  612.                             [
  613.                                 'name' => 'parse_anchors',
  614.                                 'contents' => 'false'
  615.                             ],
  616.                             [
  617.                                 'name' => 'insert_after_id',
  618.                                 'contents' => $uploadBaId
  619.                             ],
  620.                             [
  621.                                 'name' => 'file',
  622.                                 'filename' => "Mandat de prélèvement SEPA.pdf",
  623.                                 'contents' => fopen($sepaUrl'r'),
  624.                             ]
  625.                         ],
  626.                         'headers' => [
  627.                             'accept' => 'application/json',
  628.                             'Authorization' => 'Bearer ' $this->yousignApi
  629.                         ]
  630.                     ]
  631.                 );
  632.                 $uploadSepaResponseBody json_decode($uploadSepaResponse->getBody());
  633.                 $uploadSepaId $uploadSepaResponseBody->id;
  634.              }
  635.             catch (\Exception $e) {
  636.                 $responseErrorTab[] = $e->getMessage();
  637.             }
  638.         }
  639.         /* -----------------------------------  Add Signers   ------------------------------------- */
  640.         //Add Signer (seller)
  641.         if($membership->getPlatformVersion() == && !$customer->isIsAutoSignup()){
  642.             $seller $customer->getSeller();
  643.             //Add Signer (seller)
  644.             $phone $seller->getPhone();
  645.             $phone str_replace("("""$phone);
  646.             $phone str_replace(")"""$phone);
  647.             $phone str_replace(" """$phone);
  648.             if ($seller->getPhonePrefix()) {
  649.                 $phone $seller->getPhonePrefix() . $phone;
  650.             }
  651.             else{
  652.                 $phone "+33" $phone;
  653.             }
  654.             $newSignerSellerMember = new \stdClass();
  655.             $newSignerSellerMember->locale "fr";
  656.             $newSignerSellerMember->first_name $seller->getFirstName();
  657.             $newSignerSellerMember->last_name $seller->getLastName();
  658.             $newSignerSellerMember->email $seller->getEmail();
  659.             $newSignerSellerMember->phone_number $phone;
  660.             //$newSignerSellerRedirect = new \stdClass();
  661.             //$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end_seller', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  662.             //$newSignerSellerRedirect->success = $urlSignEnd;
  663.             //$newSignerSellerRedirect->error = $urlSignEnd;
  664.             $newSignerSeller = new \stdClass();
  665.             $newSignerSeller->info $newSignerSellerMember;
  666.             $newSignerSeller->signature_level "electronic_signature";
  667.             $newSignerSeller->signature_authentication_mode "otp_email";
  668.             //$newSignerSeller->redirect_urls = $newSignerSellerRedirect;
  669.             try {
  670.                 $newSignerSellerResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers'
  671.                     [
  672.                         'body' => json_encode($newSignerSeller),
  673.                         'headers' => [
  674.                             'accept' => 'application/json',
  675.                             'content-type' => 'application/json',
  676.                             'Authorization' => 'Bearer ' $this->yousignApi
  677.                         ],
  678.                     ]
  679.                 );
  680.                 $newSignerSellerResponseBody json_decode($newSignerSellerResponse->getBody());
  681.                 $newSignerSellerId $newSignerSellerResponseBody->id;
  682.              }
  683.             catch (\Exception $e) {
  684.                 $responseErrorTab[] = $e->getMessage();
  685.             }
  686.         }
  687.         //Add Signer (customer)
  688.         $phone $customer->getPhone();
  689.         $phone str_replace("("""$phone);
  690.         $phone str_replace(")"""$phone);
  691.         $phone str_replace(" """$phone);
  692.         if ($customer->getPhonePrefix()) {
  693.             $phone $customer->getPhonePrefix() . $phone;
  694.         }
  695.         $newSignerCustomerMember = new \stdClass();
  696.         $newSignerCustomerMember->locale "fr";
  697.         $newSignerCustomerMember->first_name $customer->getFirstName();
  698.         $newSignerCustomerMember->last_name $customer->getLastName();
  699.         $newSignerCustomerMember->email $customer->getEmail();
  700.         $newSignerCustomerMember->phone_number $phone;
  701.         //$newSignerCustomerRedirect = new \stdClass();
  702.         //$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  703.         //$newSignerCustomerRedirect->success = $urlSignEnd;
  704.         //$newSignerCustomerRedirect->error = $urlSignEnd;
  705.         $newSignerCustomer = new \stdClass();
  706.         $newSignerCustomer->info $newSignerCustomerMember;
  707.         $newSignerCustomer->signature_level "electronic_signature";
  708.         $newSignerCustomer->signature_authentication_mode "otp_sms";
  709.         //For order
  710.         if($membership->getPlatformVersion() == && !$customer->isIsAutoSignup()){
  711.             $newSignerCustomer->insert_after_id $newSignerSellerId;
  712.         }
  713.         //$newSignerCustomer->redirect_urls = $newSignerCustomerRedirect;
  714.         try {
  715.             $newSignerCustomerResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers'
  716.                 [
  717.                     'body' => json_encode($newSignerCustomer),
  718.                     'headers' => [
  719.                         'accept' => 'application/json',
  720.                         'content-type' => 'application/json',
  721.                         'Authorization' => 'Bearer ' $this->yousignApi
  722.                     ],
  723.                 ]
  724.             );
  725.             $newSignerCustomerResponseBody json_decode($newSignerCustomerResponse->getBody());
  726.             $newSignerCustomerId $newSignerCustomerResponseBody->id;
  727.         }
  728.         catch (\Exception $e) {
  729.             $responseErrorTab[] = $e->getMessage();
  730.         }
  731.         /* -----------------------------------  Add Fields   ------------------------------------- */
  732.         //Add fields on FIC for sgnature
  733.         //No Allianz customer
  734.         if ($customer->getDicIsFile() != true) {
  735.             //For v2 with seller
  736.             if($membership->getPlatformVersion() == && !$customer->isIsAutoSignup()){
  737.                 //For seller
  738.                 $newFieldSellerSignature = new \stdClass();
  739.                 $newFieldSellerSignature->signer_id $newSignerSellerId;
  740.                 $newFieldSellerSignature->type "signature";
  741.                 $newFieldSellerSignature->page 7;
  742.                 $newFieldSellerSignature->width 194;
  743.                 $newFieldSellerSignature->height 88;
  744.                 $newFieldSellerSignature->355;
  745.                 $newFieldSellerSignature->558;
  746.                 try {
  747.                     $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  748.                         [
  749.                             'body' => json_encode($newFieldSellerSignature),
  750.                             'headers' => [
  751.                                 'accept' => 'application/json',
  752.                                 'content-type' => 'application/json',
  753.                                 'Authorization' => 'Bearer ' $this->yousignApi
  754.                             ],
  755.                         ]
  756.                     );
  757.                 }
  758.                 catch (\Exception $e) {
  759.                     $responseErrorTab[] = $e->getMessage();
  760.                 }
  761.                 /* --------------------------------------------------- */
  762.                 //For customer
  763.                 $newFieldCustomerSignature = new \stdClass();
  764.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  765.                 $newFieldCustomerSignature->type "signature";
  766.                 $newFieldCustomerSignature->page 7;
  767.                 $newFieldCustomerSignature->width 194;
  768.                 $newFieldCustomerSignature->height 88;
  769.                 $newFieldCustomerSignature->62;
  770.                 $newFieldCustomerSignature->558;
  771.                 try {
  772.                     $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  773.                         [
  774.                             'body' => json_encode($newFieldCustomerSignature),
  775.                             'headers' => [
  776.                                 'accept' => 'application/json',
  777.                                 'content-type' => 'application/json',
  778.                                 'Authorization' => 'Bearer ' $this->yousignApi
  779.                             ],
  780.                         ]
  781.                     );
  782.                 }
  783.                 catch (\Exception $e) {
  784.                     $responseErrorTab[] = $e->getMessage();
  785.                 }
  786.             }
  787.             else{
  788.                 //For customer
  789.                 $newFieldCustomerSignature = new \stdClass();
  790.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  791.                 $newFieldCustomerSignature->type "signature";
  792.                 $newFieldCustomerSignature->page 7;
  793.                 $newFieldCustomerSignature->width 160;
  794.                 $newFieldCustomerSignature->height 94;
  795.                 $newFieldCustomerSignature->78;
  796.                 $newFieldCustomerSignature->554;
  797.                 try {
  798.                     $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  799.                         [
  800.                             'body' => json_encode($newFieldCustomerSignature),
  801.                             'headers' => [
  802.                                 'accept' => 'application/json',
  803.                                 'content-type' => 'application/json',
  804.                                 'Authorization' => 'Bearer ' $this->yousignApi
  805.                             ],
  806.                         ]
  807.                     );
  808.                 }
  809.                 catch (\Exception $e) {
  810.                     $responseErrorTab[] = $e->getMessage();
  811.                 }
  812.             }
  813.             //Add fields on FIC for city (customer)
  814.             $newFieldCustomerSignature = new \stdClass();
  815.             $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  816.             $newFieldCustomerSignature->type "text";
  817.             $newFieldCustomerSignature->max_length 44;
  818.             $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  819.             $newFieldCustomerSignature->page 7;
  820.             $newFieldCustomerSignature->width 286;
  821.             $newFieldCustomerSignature->height 24;
  822.             $newFieldCustomerSignature->68;
  823.             $newFieldCustomerSignature->377;
  824.             try {
  825.                 $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  826.                     [
  827.                         'body' => json_encode($newFieldCustomerSignature),
  828.                         'headers' => [
  829.                             'accept' => 'application/json',
  830.                             'content-type' => 'application/json',
  831.                             'Authorization' => 'Bearer ' $this->yousignApi
  832.                         ],
  833.                     ]
  834.                 );
  835.             }
  836.             catch (\Exception $e) {
  837.                 $responseErrorTab[] = $e->getMessage();
  838.             }
  839.             //Add fields on FIC for date (customer)
  840.             $newFieldCustomerSignature = new \stdClass();
  841.             $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  842.             $newFieldCustomerSignature->type "mention";
  843.             $newFieldCustomerSignature->mention "%date%";
  844.             $newFieldCustomerSignature->font $fontDefault;
  845.             $newFieldCustomerSignature->page 7;
  846.             $newFieldCustomerSignature->width 286;
  847.             $newFieldCustomerSignature->height 24;
  848.             $newFieldCustomerSignature->68;
  849.             $newFieldCustomerSignature->401;
  850.             try {
  851.                 $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  852.                     [
  853.                         'body' => json_encode($newFieldCustomerSignature),
  854.                         'headers' => [
  855.                             'accept' => 'application/json',
  856.                             'content-type' => 'application/json',
  857.                             'Authorization' => 'Bearer ' $this->yousignApi
  858.                         ],
  859.                     ]
  860.                 );
  861.             }
  862.             catch (\Exception $e) {
  863.                 $responseErrorTab[] = $e->getMessage();
  864.             }
  865.         }
  866.         ///Add fields on BA for -> Demande attribution de (customer)
  867.         if ($membership->getBa()->getJaiDemandeAttributionDe() != null) {
  868.             /*
  869.             Print on document in new version
  870.             $font = new \stdClass();
  871.             $font->size = 9;
  872.             $font->family = "Inconsolata";
  873.             $font->variants = array(
  874.                 "italic" => false,
  875.                 "bold" => false
  876.             );
  877.             $font->color = "#000000";
  878.             $newFieldCustomerSignature = new \stdClass();
  879.             $newFieldCustomerSignature->signer_id = $newSignerCustomerId;
  880.             $newFieldCustomerSignature->type = "text";
  881.             $newFieldCustomerSignature->max_length = 40;
  882.             $newFieldCustomerSignature->font = $font;
  883.             $newFieldCustomerSignature->question = "Veuillez indiquer votre nom et prénom";
  884.             $newFieldCustomerSignature->page = 4;
  885.             $newFieldCustomerSignature->width = 260;
  886.             $newFieldCustomerSignature->height = 24;
  887.             $newFieldCustomerSignature->x = 94;
  888.             $newFieldCustomerSignature->y = 89;
  889.             $response = $client->request('POST', 'https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields', 
  890.                 [
  891.                     'body' => json_encode($newFieldCustomerSignature),
  892.                     'headers' => [
  893.                         'accept' => 'application/json',
  894.                         'content-type' => 'application/json',
  895.                         'Authorization' => 'Bearer ' . $this->yousignApi
  896.                     ],
  897.                 ]
  898.             );
  899.             */
  900.         }
  901.         //Add fields on BA for sgnature (customer)
  902.         $newFieldCustomerSignature = new \stdClass();
  903.         $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  904.         $newFieldCustomerSignature->type "signature";
  905.         $newFieldCustomerSignature->page 7;
  906.         $newFieldCustomerSignature->width 187;
  907.         $newFieldCustomerSignature->height 97;
  908.         $newFieldCustomerSignature->339;
  909.         $newFieldCustomerSignature->423;
  910.         try {
  911.             $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  912.                 [
  913.                     'body' => json_encode($newFieldCustomerSignature),
  914.                     'headers' => [
  915.                         'accept' => 'application/json',
  916.                         'content-type' => 'application/json',
  917.                         'Authorization' => 'Bearer ' $this->yousignApi
  918.                     ],
  919.                 ]
  920.             );
  921.         }
  922.         catch (\Exception $e) {
  923.             $responseErrorTab[] = $e->getMessage();
  924.         }
  925.         //Add fields on BA for city (customer)
  926.         $newFieldCustomerSignature = new \stdClass();
  927.         $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  928.         $newFieldCustomerSignature->type "text";
  929.         $newFieldCustomerSignature->max_length 44;
  930.         $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  931.         $newFieldCustomerSignature->page 7;
  932.         $newFieldCustomerSignature->width 272;
  933.         $newFieldCustomerSignature->height 24;
  934.         $newFieldCustomerSignature->50;
  935.         $newFieldCustomerSignature->403;
  936.         try {
  937.             $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  938.                 [
  939.                     'body' => json_encode($newFieldCustomerSignature),
  940.                     'headers' => [
  941.                         'accept' => 'application/json',
  942.                         'content-type' => 'application/json',
  943.                         'Authorization' => 'Bearer ' $this->yousignApi
  944.                     ],
  945.                 ]
  946.             );
  947.         }
  948.         catch (\Exception $e) {
  949.             $responseErrorTab[] = $e->getMessage();
  950.         }
  951.         //Add fields on BA for date (customer)
  952.         $newFieldCustomerSignature = new \stdClass();
  953.         $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  954.         $newFieldCustomerSignature->type "mention";
  955.         $newFieldCustomerSignature->font $fontDefault;
  956.         $newFieldCustomerSignature->mention "%date%";
  957.         $newFieldCustomerSignature->page 7;
  958.         $newFieldCustomerSignature->width 272;
  959.         $newFieldCustomerSignature->height 24;
  960.         $newFieldCustomerSignature->49;
  961.         $newFieldCustomerSignature->417;
  962.         try {
  963.             $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  964.                 [
  965.                     'body' => json_encode($newFieldCustomerSignature),
  966.                     'headers' => [
  967.                         'accept' => 'application/json',
  968.                         'content-type' => 'application/json',
  969.                         'Authorization' => 'Bearer ' $this->yousignApi
  970.                     ],
  971.                 ]
  972.             );
  973.         }
  974.         catch (\Exception $e) {
  975.             $responseErrorTab[] = $e->getMessage();
  976.         }
  977.         //Benef on BA (customer)
  978.         if($membership->getBa()->isTypeBeneficiaires() == true && $membership->getBa()->isTypeBeneficiairesClauseNotariee() == false){
  979.             //Signature (customer)
  980.             $newFieldCustomerSignature = new \stdClass();
  981.             $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  982.             $newFieldCustomerSignature->type "signature";
  983.             $newFieldCustomerSignature->page 9;
  984.             $newFieldCustomerSignature->width 156;
  985.             $newFieldCustomerSignature->height 64;
  986.             $newFieldCustomerSignature->339;
  987.             $newFieldCustomerSignature->708;
  988.             try {
  989.                 $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  990.                     [
  991.                         'body' => json_encode($newFieldCustomerSignature),
  992.                         'headers' => [
  993.                             'accept' => 'application/json',
  994.                             'content-type' => 'application/json',
  995.                             'Authorization' => 'Bearer ' $this->yousignApi
  996.                         ],
  997.                     ]
  998.                 );
  999.             }
  1000.             catch (\Exception $e) {
  1001.                 $responseErrorTab[] = $e->getMessage();
  1002.             }
  1003.             //City (customer)
  1004.             $newFieldCustomerSignature = new \stdClass();
  1005.             $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1006.             $newFieldCustomerSignature->type "text";
  1007.             $newFieldCustomerSignature->max_length 44;
  1008.             $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1009.             $newFieldCustomerSignature->page 9;
  1010.             $newFieldCustomerSignature->width 272;
  1011.             $newFieldCustomerSignature->height 24;
  1012.             $newFieldCustomerSignature->49;
  1013.             $newFieldCustomerSignature->669;
  1014.             try {
  1015.                 $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1016.                     [
  1017.                         'body' => json_encode($newFieldCustomerSignature),
  1018.                         'headers' => [
  1019.                             'accept' => 'application/json',
  1020.                             'content-type' => 'application/json',
  1021.                             'Authorization' => 'Bearer ' $this->yousignApi
  1022.                         ],
  1023.                     ]
  1024.                 );
  1025.             }
  1026.             catch (\Exception $e) {
  1027.                 $responseErrorTab[] = $e->getMessage();
  1028.             }
  1029.             //Date (customer)
  1030.             $newFieldCustomerSignature = new \stdClass();
  1031.             $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1032.             $newFieldCustomerSignature->type "mention";
  1033.             $newFieldCustomerSignature->font $fontDefault;
  1034.             $newFieldCustomerSignature->mention "%date%";
  1035.             $newFieldCustomerSignature->page 9;
  1036.             $newFieldCustomerSignature->width 272;
  1037.             $newFieldCustomerSignature->height 24;
  1038.             $newFieldCustomerSignature->49;
  1039.             $newFieldCustomerSignature->690;
  1040.             try {
  1041.                 $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1042.                     [
  1043.                         'body' => json_encode($newFieldCustomerSignature),
  1044.                         'headers' => [
  1045.                             'accept' => 'application/json',
  1046.                             'content-type' => 'application/json',
  1047.                             'Authorization' => 'Bearer ' $this->yousignApi
  1048.                         ],
  1049.                     ]
  1050.                 );
  1051.             }
  1052.             catch (\Exception $e) {
  1053.                 $responseErrorTab[] = $e->getMessage();
  1054.             }
  1055.         }
  1056.         //SEPA
  1057.         if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  1058.             //Signature (customer)
  1059.             $newFieldCustomerSignature = new \stdClass();
  1060.             $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1061.             $newFieldCustomerSignature->type "signature";
  1062.             $newFieldCustomerSignature->page 1;
  1063.             $newFieldCustomerSignature->width 137;
  1064.             $newFieldCustomerSignature->height 49;
  1065.             $newFieldCustomerSignature->355;
  1066.             $newFieldCustomerSignature->535;
  1067.             try {
  1068.                 $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  1069.                     [
  1070.                         'body' => json_encode($newFieldCustomerSignature),
  1071.                         'headers' => [
  1072.                             'accept' => 'application/json',
  1073.                             'content-type' => 'application/json',
  1074.                             'Authorization' => 'Bearer ' $this->yousignApi
  1075.                         ],
  1076.                     ]
  1077.                 );
  1078.             }
  1079.             catch (\Exception $e) {
  1080.                 $responseErrorTab[] = $e->getMessage();
  1081.             }
  1082.             //City (customer)
  1083.             $newFieldCustomerSignature = new \stdClass();
  1084.             $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1085.             $newFieldCustomerSignature->type "text";
  1086.             $newFieldCustomerSignature->max_length 35;
  1087.             $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1088.             $newFieldCustomerSignature->page 1;
  1089.             $newFieldCustomerSignature->width 217;
  1090.             $newFieldCustomerSignature->height 24;
  1091.             $newFieldCustomerSignature->149;
  1092.             $newFieldCustomerSignature->498;
  1093.             try {
  1094.                 $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  1095.                     [
  1096.                         'body' => json_encode($newFieldCustomerSignature),
  1097.                         'headers' => [
  1098.                             'accept' => 'application/json',
  1099.                             'content-type' => 'application/json',
  1100.                             'Authorization' => 'Bearer ' $this->yousignApi
  1101.                         ],
  1102.                     ]
  1103.                 );
  1104.             }
  1105.             catch (\Exception $e) {
  1106.                 $responseErrorTab[] = $e->getMessage();
  1107.             }
  1108.             //Date (customer)
  1109.             $newFieldCustomerSignature = new \stdClass();
  1110.             $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1111.             $newFieldCustomerSignature->type "mention";
  1112.             $newFieldCustomerSignature->font $fontDefault;
  1113.             $newFieldCustomerSignature->mention "%date%";
  1114.             $newFieldCustomerSignature->page 1;
  1115.             $newFieldCustomerSignature->width 217;
  1116.             $newFieldCustomerSignature->height 24;
  1117.             $newFieldCustomerSignature->149;
  1118.             $newFieldCustomerSignature->519;
  1119.             try {
  1120.                 $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  1121.                     [
  1122.                         'body' => json_encode($newFieldCustomerSignature),
  1123.                         'headers' => [
  1124.                             'accept' => 'application/json',
  1125.                             'content-type' => 'application/json',
  1126.                             'Authorization' => 'Bearer ' $this->yousignApi
  1127.                         ],
  1128.                     ]
  1129.                 );
  1130.             }
  1131.             catch (\Exception $e) {
  1132.                 $responseErrorTab[] = $e->getMessage();
  1133.             }
  1134.         }
  1135.         /* -----------------------------------  Active signature (end step)   ------------------------------------- */
  1136.         //Activate signature
  1137.         try {
  1138.             $activateSignatureResponse $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/activate'
  1139.                 [
  1140.                     'headers' => [
  1141.                         'accept' => 'application/json',
  1142.                         'Authorization' => 'Bearer ' $this->yousignApi
  1143.                     ],
  1144.                 ]
  1145.             );
  1146.             $activateSignatureResponseBody json_decode($activateSignatureResponse->getBody());
  1147.             $activateSignatureResponseSigners $activateSignatureResponseBody->signers;
  1148.         }
  1149.         catch (\Exception $e) {
  1150.             $responseErrorTab[] = $e->getMessage();
  1151.         }
  1152.         $urlSeller null;
  1153.         $urlCustomer null;
  1154.         if(!$responseErrorTab){
  1155.             if($membership->getPlatformVersion() == && !$customer->isIsAutoSignup()){
  1156.                 $urlSeller $activateSignatureResponseSigners[0]->signature_link;
  1157.                 $urlCustomer $activateSignatureResponseSigners[1]->signature_link;
  1158.             }
  1159.             else{
  1160.                 $urlCustomer $activateSignatureResponseSigners[0]->signature_link;
  1161.             }
  1162.         }
  1163.         $tab = array(
  1164.             "responseProcedure" => $activateSignatureResponseBody,
  1165.             "yousignUi" => $this->yousignUi,
  1166.             "dicFileId" => $uploadDicId,
  1167.             "ficFileId" => $uploadFicId,
  1168.             "baFileId" => $uploadBaId,
  1169.             "sepaFileId" => $uploadSepaId,
  1170.             "signerCustomer" => $newSignerCustomerResponseBody,
  1171.             "signerSellerUrl" => $urlSeller,
  1172.             "signerCustomerUrl" => $urlCustomer,
  1173.             "signerCustomerId" => $newSignerCustomerId,
  1174.             "signerSellerId" => $newSignerSellerId,
  1175.             "responseErrorTab" => $responseErrorTab
  1176.         );
  1177.         return $tab;
  1178.     }
  1179.     function addSign2023($customer$membership$type)
  1180.     {
  1181.         if ($customer->getDicIsFile() != true) {
  1182.             if($membership->getPlatformVersion() == 1){
  1183.                 //V1 DIC
  1184.                 //Get DIC BASE 64
  1185.                 $dicUrl "files/" $customer->getId() . '/' $membership->getDic()->getUrlPdf();
  1186.                 $b64Dic chunk_split(base64_encode(file_get_contents($dicUrl)));
  1187.                 $fileDic = new \stdClass();
  1188.                 $fileDic->name "Document d’information et de conseil";
  1189.                 $fileDic->content $b64Dic;
  1190.                 $fileDic->position 1;
  1191.                 //Create files
  1192.                 $curl curl_init();
  1193.                 curl_setopt_array($curl, array(
  1194.                     CURLOPT_URL => $this->yousignUrl "/files",
  1195.                     CURLOPT_RETURNTRANSFER => true,
  1196.                     CURLOPT_ENCODING => "",
  1197.                     CURLOPT_MAXREDIRS => 10,
  1198.                     CURLOPT_TIMEOUT => 0,
  1199.                     CURLOPT_FOLLOWLOCATION => true,
  1200.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1201.                     CURLOPT_CUSTOMREQUEST => "POST",
  1202.                     CURLOPT_POSTFIELDS => json_encode($fileDic),
  1203.                     CURLOPT_HTTPHEADER => array(
  1204.                         "Authorization: Bearer " $this->yousignApi,
  1205.                         "Content-Type: application/json"
  1206.                     ),
  1207.                 ));
  1208.                 $responseFile curl_exec($curl);
  1209.                 curl_close($curl);
  1210.                 $responseFileDic json_decode($responseFile);
  1211.             } else{
  1212.                 //V2 FIC
  1213.                 //Get FIC BASE 64
  1214.                 $ficUrl "files/" $customer->getId() . '/' $membership->getFic()->getUrlPdf();
  1215.                 $b64Fic chunk_split(base64_encode(file_get_contents($ficUrl)));
  1216.                 $fileFic = new \stdClass();
  1217.                 $fileFic->name "Fiche d’information et de conseil";
  1218.                 $fileFic->content $b64Fic;
  1219.                 $fileFic->position 1;
  1220.                 //Create files
  1221.                 $curl curl_init();
  1222.                 curl_setopt_array($curl, array(
  1223.                     CURLOPT_URL => $this->yousignUrl "/signature_requests//documents",
  1224.                     CURLOPT_RETURNTRANSFER => true,
  1225.                     CURLOPT_ENCODING => "",
  1226.                     CURLOPT_MAXREDIRS => 10,
  1227.                     CURLOPT_TIMEOUT => 0,
  1228.                     CURLOPT_FOLLOWLOCATION => true,
  1229.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1230.                     CURLOPT_CUSTOMREQUEST => "POST",
  1231.                     CURLOPT_POSTFIELDS => json_encode($fileFic),
  1232.                     CURLOPT_HTTPHEADER => array(
  1233.                         "Authorization: Bearer " $this->yousignApi,
  1234.                         "Content-Type: application/json"
  1235.                     ),
  1236.                 ));
  1237.                 $responseFile curl_exec($curl);
  1238.                 curl_close($curl);
  1239.                 $responseFileFic json_decode($responseFile);
  1240.             }
  1241.         }
  1242.         /* --------------------------------------------------------------------------- */
  1243.         //Get BA BASE 64
  1244.         $baUrl "files/" $customer->getId() . '/' $membership->getBa()->getUrlPdf();
  1245.         $b64Ba chunk_split(base64_encode(file_get_contents($baUrl)));
  1246.         $fileBa = new \stdClass();
  1247.         $fileBa->name "Demande d’adhésion";
  1248.         $fileBa->content $b64Ba;
  1249.         $fileBa->position 2;
  1250.         //Create files
  1251.         $curl curl_init();
  1252.         curl_setopt_array($curl, array(
  1253.             CURLOPT_URL => $this->yousignUrl "/files",
  1254.             CURLOPT_RETURNTRANSFER => true,
  1255.             CURLOPT_ENCODING => "",
  1256.             CURLOPT_MAXREDIRS => 10,
  1257.             CURLOPT_TIMEOUT => 0,
  1258.             CURLOPT_FOLLOWLOCATION => true,
  1259.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1260.             CURLOPT_CUSTOMREQUEST => "POST",
  1261.             CURLOPT_POSTFIELDS => json_encode($fileBa),
  1262.             CURLOPT_HTTPHEADER => array(
  1263.                 "Authorization: Bearer " $this->yousignApi,
  1264.                 "Content-Type: application/json"
  1265.             ),
  1266.         ));
  1267.         $responseFileBa curl_exec($curl);
  1268.         curl_close($curl);
  1269.         $responseFileBa json_decode($responseFileBa);
  1270.         /* --------------------------------------------------------------------------- */
  1271.         /* --------------------------------------------------------------------------- */
  1272.         if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  1273.             //Get BA BASE 64
  1274.             $sepaUrl "files/" $customer->getId() . '/' $membership->getBa()->getSepaUrlPdf();
  1275.             $b64Sepa chunk_split(base64_encode(file_get_contents($sepaUrl)));
  1276.             $fileSepa = new \stdClass();
  1277.             $fileSepa->name "Mandat de prélèvement SEPA";
  1278.             $fileSepa->content $b64Sepa;
  1279.             $fileSepa->position 3;
  1280.             //Create files
  1281.             $curl curl_init();
  1282.             curl_setopt_array($curl, array(
  1283.                 CURLOPT_URL => $this->yousignUrl "/files",
  1284.                 CURLOPT_RETURNTRANSFER => true,
  1285.                 CURLOPT_ENCODING => "",
  1286.                 CURLOPT_MAXREDIRS => 10,
  1287.                 CURLOPT_TIMEOUT => 0,
  1288.                 CURLOPT_FOLLOWLOCATION => true,
  1289.                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1290.                 CURLOPT_CUSTOMREQUEST => "POST",
  1291.                 CURLOPT_POSTFIELDS => json_encode($fileSepa),
  1292.                 CURLOPT_HTTPHEADER => array(
  1293.                     "Authorization: Bearer " $this->yousignApi,
  1294.                     "Content-Type: application/json"
  1295.                 ),
  1296.             ));
  1297.             $responseFileSepa curl_exec($curl);
  1298.             curl_close($curl);
  1299.             $responseFileSepa json_decode($responseFileSepa);
  1300.         }
  1301.         /* --------------------------------------------------------------------------- */
  1302.         //Add procedure
  1303.         $curl curl_init();
  1304.         //Set webhook
  1305.         if ($type == "seller") {
  1306.             $urlSignEnd $this->container->get('router')->generate('yousign_sign_end_seller', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  1307.         } else {
  1308.             $urlSignEnd $this->container->get('router')->generate('yousign_sign_end', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  1309.         }
  1310.         $firstName str_replace(","" "$customer->getFirstName());
  1311.         $config = new \stdClass();
  1312.         $webhook = new \stdClass();
  1313.         $webhookEnd = new \stdClass();
  1314.         $header = new \stdClass();
  1315.         $webhookEnd->url $urlSignEnd;
  1316.         $webhookEnd->method "GET";
  1317.         $webhookEnd->headers = (object)array(
  1318.             'X-Custom-Header' => "End sign"
  1319.         );
  1320.         $config->webhook = (object)array(
  1321.             'member.finished' => array(
  1322.                 $webhookEnd
  1323.             )
  1324.         );
  1325.         $arrayObjectFiles = array();
  1326.         $dicFileId null;
  1327.         $ficFileId null;
  1328.         $baFileId null;
  1329.         $sepaFileId null;
  1330.         if ($customer->getDicIsFile() != true) {
  1331.             if($membership->getPlatformVersion() == 1){
  1332.                 //V1 DIC
  1333.                 //Set file DIC
  1334.                 $fileObjectDic = new \stdClass();
  1335.                 $fileObjectDic->file $responseFileDic->id;
  1336.                 $fileObjectDic->page 1;
  1337.                 $fileObjectDic->position "171,80,317,120";
  1338.                 $fileObjectDic->mention "";
  1339.                 $fileObjectDic->mention2 "Signé par " $firstName " " $customer->getLastName();
  1340.                 $arrayObjectFiles[] = $fileObjectDic;
  1341.                 $dicFileId $responseFileDic->id;
  1342.                 //Set file DIC VILLE
  1343.                 $fileObjectDicVille = new \stdClass();
  1344.                 $fileObjectDicVille->file $responseFileDic->id;
  1345.                 $fileObjectDicVille->page 1;
  1346.                 $fileObjectDicVille->type "text";
  1347.                 $fileObjectDicVille->fontSize 10;
  1348.                 $fileObjectDicVille->contentRequired true;
  1349.                 $fileObjectDicVille->content $membership->getBa()->getVille();
  1350.                 $fileObjectDicVille->position "48,79,158,96";
  1351.                 $arrayObjectFiles[] = $fileObjectDicVille;
  1352.                 //Set file DIC DATE
  1353.                 $fileObjectDicDate = new \stdClass();
  1354.                 $fileObjectDicDate->file $responseFileDic->id;
  1355.                 $fileObjectDicDate->page 1;
  1356.                 $fileObjectDicDate->type "text";
  1357.                 $fileObjectDicDate->fontSize 10;
  1358.                 $fileObjectDicDate->contentRequired true;
  1359.                 $fileObjectDicDate->content date("d/m/Y");
  1360.                 $fileObjectDicDate->position "49,98,159,115";
  1361.                 $arrayObjectFiles[] = $fileObjectDicDate;
  1362.             } else{
  1363.                 //V2 FIC
  1364.                 $fileObjectFic = new \stdClass();
  1365.                 $fileObjectFic->file $responseFileFic->id;
  1366.                 $fileObjectFic->page 7;
  1367.                 $fileObjectFic->position "69,199,247,304";
  1368.                 $fileObjectFic->mention "";
  1369.                 $fileObjectFic->mention2 "Signé par " $firstName " " $customer->getLastName();
  1370.                 $arrayObjectFiles[] = $fileObjectFic;
  1371.                 $ficFileId $responseFileFic->id;
  1372.                 //FOR SELLER 
  1373.                 //$fileObjectFic->position = "323,182,503,246";
  1374.                 //Set file FIC VILLE
  1375.                 $fileObjectFicVille = new \stdClass();
  1376.                 $fileObjectFicVille->file $responseFileFic->id;
  1377.                 $fileObjectFicVille->page 7;
  1378.                 $fileObjectFicVille->type "text";
  1379.                 $fileObjectFicVille->fontSize 10;
  1380.                 $fileObjectFicVille->contentRequired true;
  1381.                 $fileObjectFicVille->content $membership->getFic()->getAdresseFiscaleVille();
  1382.                 $fileObjectFicVille->position "66,449,293,464";
  1383.                 $arrayObjectFiles[] = $fileObjectFicVille;
  1384.                 //Set file FIC DATE
  1385.                 $fileObjectFicDate = new \stdClass();
  1386.                 $fileObjectFicDate->file $responseFileFic->id;
  1387.                 $fileObjectFicDate->page 7;
  1388.                 $fileObjectFicDate->type "text";
  1389.                 $fileObjectFicDate->fontSize 10;
  1390.                 $fileObjectFicDate->contentRequired true;
  1391.                 $fileObjectFicDate->content date("d/m/Y");
  1392.                 $fileObjectFicDate->position "74,424,301,439";
  1393.                 $arrayObjectFiles[] = $fileObjectFicDate;
  1394.             }
  1395.         }
  1396.         //Set file BA -> Demande attribution de
  1397.         if ($membership->getBa()->getJaiDemandeAttributionDe() != null) {
  1398.             $fileObjectBaName = new \stdClass();
  1399.             $fileObjectBaName->file $responseFileBa->id;
  1400.             $fileObjectBaName->page 4;
  1401.             $fileObjectBaName->type "text";
  1402.             $fileObjectBaName->fontSize 8;
  1403.             $fileObjectBaName->contentRequired true;
  1404.             $fileObjectBaName->content $firstName " " $membership->getUser()->getLastName();
  1405.             $fileObjectBaName->position "94,731,255,749";
  1406.             $arrayObjectFiles[] = $fileObjectBaName;
  1407.         }
  1408.         //Set file BA 
  1409.         $fileObjectBa = new \stdClass();
  1410.         $fileObjectBa->file $responseFileBa->id;
  1411.         $fileObjectBa->page 7;
  1412.         $fileObjectBa->position "350,307,500,410";
  1413.         $fileObjectBa->mention "Lu et approuvé";
  1414.         $fileObjectBa->mention2 "Signé par " $firstName " " $customer->getLastName();
  1415.         $arrayObjectFiles[] = $fileObjectBa;
  1416.         $baFileId $responseFileBa->id;
  1417.         $fileObjectBaLieu = new \stdClass();
  1418.         $fileObjectBaLieu->file $responseFileBa->id;
  1419.         $fileObjectBaLieu->page 7;
  1420.         $fileObjectBaLieu->type "text";
  1421.         $fileObjectBaLieu->fontSize 10;
  1422.         $fileObjectBaLieu->contentRequired true;
  1423.         $fileObjectBaLieu->content $membership->getBa()->getFiscaleVille();
  1424.         $fileObjectBaLieu->position "45,419,200,437";
  1425.         $arrayObjectFiles[] = $fileObjectBaLieu;
  1426.         $fileObjectBaDate = new \stdClass();
  1427.         $fileObjectBaDate->file $responseFileBa->id;
  1428.         $fileObjectBaDate->page 7;
  1429.         $fileObjectBaDate->type "text";
  1430.         $fileObjectBaDate->fontSize 10;
  1431.         $fileObjectBaDate->contentRequired true;
  1432.         $fileObjectBaDate->content date("d/m/Y");
  1433.         $fileObjectBaDate->position "47,403,202,421";
  1434.         $arrayObjectFiles[] = $fileObjectBaDate;
  1435.         //Benef
  1436.         if($membership->getBa()->isTypeBeneficiaires() == true && $membership->getBa()->isTypeBeneficiairesClauseNotariee() == false){
  1437.             $fileObjectBa = new \stdClass();
  1438.             $fileObjectBa->file $responseFileBa->id;
  1439.             $fileObjectBa->page 9;
  1440.             $fileObjectBa->position "347,68,521,131";
  1441.             $fileObjectBa->mention "Lu et approuvé";
  1442.             $fileObjectBa->mention2 "Signé par " $firstName " " $customer->getLastName();
  1443.             $arrayObjectFiles[] = $fileObjectBa;
  1444.             $baFileId $responseFileBa->id;
  1445.             $fileObjectBaLieu = new \stdClass();
  1446.             $fileObjectBaLieu->file $responseFileBa->id;
  1447.             $fileObjectBaLieu->page 9;
  1448.             $fileObjectBaLieu->type "text";
  1449.             $fileObjectBaLieu->fontSize 10;
  1450.             $fileObjectBaLieu->contentRequired true;
  1451.             $fileObjectBaLieu->content $membership->getBa()->getFiscaleVille();
  1452.             $fileObjectBaLieu->position "50,150,201,171";
  1453.             $arrayObjectFiles[] = $fileObjectBaLieu;
  1454.             $fileObjectBaDate = new \stdClass();
  1455.             $fileObjectBaDate->file $responseFileBa->id;
  1456.             $fileObjectBaDate->page 9;
  1457.             $fileObjectBaDate->type "text";
  1458.             $fileObjectBaDate->fontSize 10;
  1459.             $fileObjectBaDate->contentRequired true;
  1460.             $fileObjectBaDate->content date("d/m/Y");
  1461.             $fileObjectBaDate->position "51,136,202,157";
  1462.             $arrayObjectFiles[] = $fileObjectBaDate;
  1463.         }
  1464.         //SEPA
  1465.         if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  1466.             //Set file SEPA
  1467.             $fileObjectSepa = new \stdClass();
  1468.             $fileObjectSepa->file $responseFileSepa->id;
  1469.             $fileObjectSepa->page 1;
  1470.             $fileObjectSepa->position "365,227,506,309";
  1471.             $fileObjectSepa->mention "";
  1472.             $fileObjectSepa->mention2 "Signé par " $firstName " " $customer->getLastName();
  1473.             $arrayObjectFiles[] = $fileObjectSepa;
  1474.             $sepaFileId $responseFileSepa->id;
  1475.             $fileObjectSepaDate = new \stdClass();
  1476.             $fileObjectSepaDate->file $responseFileSepa->id;
  1477.             $fileObjectSepaDate->page 1;
  1478.             $fileObjectSepaDate->position "148,303,300,322";
  1479.             $fileObjectSepaDate->type "text";
  1480.             $fileObjectSepaDate->fontSize 8;
  1481.             $fileObjectSepaDate->contentRequired true;
  1482.             $fileObjectSepaDate->content date("d/m/Y");
  1483.             $arrayObjectFiles[] = $fileObjectSepaDate;
  1484.             $fileObjectSepaLieu = new \stdClass();
  1485.             $fileObjectSepaLieu->file $responseFileSepa->id;
  1486.             $fileObjectSepaLieu->page 1;
  1487.             $fileObjectSepaLieu->position "147,321,299,340";
  1488.             $fileObjectSepaLieu->type "text";
  1489.             $fileObjectSepaLieu->fontSize 8;
  1490.             $fileObjectSepaLieu->contentRequired true;
  1491.             $fileObjectSepaLieu->content $membership->getBa()->getFiscaleVille();
  1492.             $arrayObjectFiles[] = $fileObjectSepaLieu;
  1493.         }
  1494.         //Set member - customer
  1495.         $member = new \stdClass();
  1496.         $member->firstname $firstName;
  1497.         $member->lastname $customer->getLastName();
  1498.         $member->email $customer->getEmail();
  1499.         $phone $customer->getPhone();
  1500.         $phone str_replace("("""$phone);
  1501.         $phone str_replace(")"""$phone);
  1502.         $phone str_replace(" """$phone);
  1503.         if ($customer->getPhonePrefix()) {
  1504.             $phone $customer->getPhonePrefix() . $phone;
  1505.         }
  1506.         $member->phone $phone;
  1507.         $member->fileObjects $arrayObjectFiles;
  1508.         if($membership->getPlatformVersion() == && $customer->isIsAutoSignup() != true){
  1509.             //Set file FIC SELLER
  1510.             $fileObjectFicSeller  = new \stdClass();
  1511.             $fileObjectFicSeller->file $responseFileFic->id;
  1512.             $fileObjectFicSeller->page 7;
  1513.             $fileObjectFicSeller->position "350,198,528,303";
  1514.             $fileObjectFicSeller->mention "";
  1515.             $fileObjectFicSeller->mention2 "Signé par ".$customer->getSeller()->getFirstName()." ".$customer->getSeller()->getLastName();
  1516.             //Set member - seller
  1517.             $memberSeller  = new \stdClass();
  1518.             $memberSeller->position 1;
  1519.             $memberSeller->firstname $customer->getSeller()->getFirstName();
  1520.             $memberSeller->lastname $customer->getSeller()->getLastName();
  1521.             $memberSeller->email $customer->getSeller()->getEmail();
  1522.             $memberSeller->phone $customer->getSeller()->getPhone();
  1523.             $memberSeller->operationCustomModes = [ "email" ];
  1524.             $memberSeller->fileObjects = array(
  1525.                 $fileObjectFicSeller,
  1526.             );
  1527.             $member->position 2;
  1528.             //Set procedure
  1529.             $procedure = new \stdClass();
  1530.             $procedure->name "Signature adhésion";
  1531.             $procedure->description "Fin d'adhésion";
  1532.             $procedure->start true;
  1533.             $procedure->ordered false;
  1534.             $procedure->members = array(
  1535.                 $memberSeller,
  1536.                 $member
  1537.             );
  1538.             $procedure->config $config;
  1539.         }
  1540.         else{
  1541.             //Set procedure
  1542.             $procedure = new \stdClass();
  1543.             $procedure->name "Signature adhésion";
  1544.             $procedure->description "Fin d'adhésion";
  1545.             $procedure->start true;
  1546.             $procedure->members = array(
  1547.                 $member,
  1548.             );
  1549.             $procedure->config $config;
  1550.         }
  1551.         curl_setopt_array($curl, array(
  1552.             CURLOPT_URL => $this->yousignUrl "/procedures",
  1553.             CURLOPT_RETURNTRANSFER => true,
  1554.             CURLOPT_ENCODING => "",
  1555.             CURLOPT_MAXREDIRS => 10,
  1556.             CURLOPT_TIMEOUT => 0,
  1557.             CURLOPT_FOLLOWLOCATION => true,
  1558.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1559.             CURLOPT_CUSTOMREQUEST => "POST",
  1560.             CURLOPT_POSTFIELDS => json_encode($procedure),
  1561.             CURLOPT_HTTPHEADER => array(
  1562.                 "Authorization: Bearer " $this->yousignApi,
  1563.                 "Content-Type: application/json"
  1564.             ),
  1565.         ));
  1566.         $responseProcedure curl_exec($curl);
  1567.         curl_close($curl);
  1568.         $responseProcedure json_decode($responseProcedure);
  1569.         //var_dump($member);
  1570.         //die;
  1571.         $tab = array(
  1572.             "responseProcedure" => $responseProcedure,
  1573.             "yousignUi" => $this->yousignUi,
  1574.             "dicFileId" => $dicFileId,
  1575.             "ficFileId" => $ficFileId,
  1576.             "baFileId" => $baFileId,
  1577.             "sepaFileId" => $sepaFileId,
  1578.         );
  1579.         return $tab;
  1580.     }
  1581.     function saveFilesYouSignV3($membership$typeUser "customer")
  1582.     {
  1583.         $newSignatureId $membership->getProcedureId();
  1584.         //Wait 2 secondes Yousign create file
  1585.         //sleep(2);
  1586.         if ($membership->getUser()->getDicIsFile() != true) {
  1587.             /* ------------------------ SAVE FIC START ------------------------ */
  1588.             //GET FIC FILE
  1589.             $client = new Client();
  1590.             $fileResponse $client->request('GET'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$membership->getFic()->getIdYouSign().'/download'
  1591.                 [
  1592.                     'headers' => [
  1593.                         'accept' => 'application/json',
  1594.                         'content-type' => 'application/json',
  1595.                         'Authorization' => 'Bearer ' $this->yousignApi
  1596.                     ],
  1597.                 ]
  1598.             );
  1599.             $fileBody $fileResponse->getBody();
  1600.             $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'FIC.pdf';
  1601.             file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$fileBody);
  1602.             $membership->getFic()->setUrlPdfSign($name);
  1603.             $this->em->persist($membership->getFic());
  1604.             /* ------------------------ SAVE FIC END ------------------------ */
  1605.         }
  1606.         if($typeUser == "customer"){
  1607.             /* ------------------------ SAVE BA START ------------------------ */
  1608.             //GET BA FILE
  1609.             $client = new Client();
  1610.             $fileResponse $client->request('GET'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$membership->getBa()->getIdYouSign().'/download'
  1611.                 [
  1612.                     'headers' => [
  1613.                         'accept' => 'application/json',
  1614.                         'content-type' => 'application/json',
  1615.                         'Authorization' => 'Bearer ' $this->yousignApi
  1616.                     ],
  1617.                 ]
  1618.             );
  1619.             $fileBody $fileResponse->getBody();
  1620.             $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'BA.pdf';
  1621.             file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$fileBody);
  1622.             $membership->getBa()->setUrlPdfSign($name);
  1623.             /* ------------------------ SAVE BA END ------------------------ */
  1624.             /* ------------------------ SAVE SEPA START ------------------------ */
  1625.             if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  1626.                 //GET SEPA FILE
  1627.                 $client = new Client();
  1628.                 $fileResponse $client->request('GET'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$membership->getBa()->getSepaIdYouSign().'/download'
  1629.                     [
  1630.                         'headers' => [
  1631.                             'accept' => 'application/json',
  1632.                             'content-type' => 'application/json',
  1633.                             'Authorization' => 'Bearer ' $this->yousignApi
  1634.                         ],
  1635.                     ]
  1636.                 );
  1637.                 $fileBody $fileResponse->getBody();
  1638.                 $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'SEPA.pdf';
  1639.                 file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$fileBody);
  1640.                 $membership->getBa()->setSepaUrlPdfSign($name);
  1641.             }
  1642.             /* ------------------------ SAVE SEPA END ------------------------ */
  1643.             $this->em->persist($membership->getBa());
  1644.         }
  1645.         $this->em->flush();
  1646.     }
  1647.     function saveFilesYouSign($membership$typeUser "customer")
  1648.     {
  1649.         //Wait 2 secondes Yousign create file
  1650.         sleep(2);
  1651.         if ($membership->getUser()->getDicIsFile() != true) {
  1652.             if($membership->getPlatformVersion() == 1){
  1653.                 //V1 DIC
  1654.                 /* ------------------------ SAVE DIC START ------------------------ */
  1655.                 //GET DIC FILE
  1656.                 $curl curl_init();
  1657.                 curl_setopt_array($curl, array(
  1658.                     CURLOPT_URL => $this->yousignUrlV2 $membership->getDic()->getIdYouSign() . "/download",
  1659.                     CURLOPT_RETURNTRANSFER => true,
  1660.                     CURLOPT_ENCODING => "",
  1661.                     CURLOPT_MAXREDIRS => 30,
  1662.                     CURLOPT_TIMEOUT => 0,
  1663.                     CURLOPT_FOLLOWLOCATION => true,
  1664.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1665.                     CURLOPT_CUSTOMREQUEST => "GET",
  1666.                     CURLOPT_HTTPHEADER => array(
  1667.                         "Authorization: Bearer " $this->yousignApiV2,
  1668.                         "Content-Type: application/json"
  1669.                     ),
  1670.                 ));
  1671.                 $responseFileDic curl_exec($curl);
  1672.                 curl_close($curl);
  1673.                 $dicFile json_decode($responseFileDic);
  1674.                 $dicFileBin base64_decode($dicFiletrue);
  1675.                 $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'DIC.pdf';
  1676.                 file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$dicFileBin);
  1677.                 $membership->getDic()->setUrlPdfSign($name);
  1678.                 /* ------------------------ SAVE DIC END ------------------------ */
  1679.             } else {
  1680.                 // V2 FIC
  1681.                 /* ------------------------ SAVE FIC START ------------------------ */
  1682.                 //GET FIC FILE
  1683.                 $curl curl_init();
  1684.                 curl_setopt_array($curl, array(
  1685.                     CURLOPT_URL => $this->yousignUrlV2 $membership->getFic()->getIdYouSign() . "/download",
  1686.                     CURLOPT_RETURNTRANSFER => true,
  1687.                     CURLOPT_ENCODING => "",
  1688.                     CURLOPT_MAXREDIRS => 30,
  1689.                     CURLOPT_TIMEOUT => 0,
  1690.                     CURLOPT_FOLLOWLOCATION => true,
  1691.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1692.                     CURLOPT_CUSTOMREQUEST => "GET",
  1693.                     CURLOPT_HTTPHEADER => array(
  1694.                         "Authorization: Bearer " $this->yousignApiV2,
  1695.                         "Content-Type: application/json"
  1696.                     ),
  1697.                 ));
  1698.                 $responseFileFic curl_exec($curl);
  1699.                 curl_close($curl);
  1700.                 $ficFile json_decode($responseFileFic);
  1701.                 $ficFileBin base64_decode($ficFiletrue);
  1702.                 $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'FIC.pdf';
  1703.                 file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$ficFileBin);
  1704.                 $membership->getFic()->setUrlPdfSign($name);
  1705.                 /* ------------------------ SAVE FIC END ------------------------ */
  1706.             }
  1707.         }
  1708.         if($typeUser == "customer"){
  1709.             /* ------------------------ SAVE BA START ------------------------ */
  1710.             //GET BA FILE
  1711.             $curl curl_init();
  1712.             curl_setopt_array($curl, array(
  1713.                 CURLOPT_URL => $this->yousignUrlV2 $membership->getBa()->getIdYouSign() . "/download",
  1714.                 CURLOPT_RETURNTRANSFER => true,
  1715.                 CURLOPT_ENCODING => "",
  1716.                 CURLOPT_MAXREDIRS => 30,
  1717.                 CURLOPT_TIMEOUT => 0,
  1718.                 CURLOPT_FOLLOWLOCATION => true,
  1719.                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1720.                 CURLOPT_CUSTOMREQUEST => "GET",
  1721.                 CURLOPT_HTTPHEADER => array(
  1722.                     "Authorization: Bearer " $this->yousignApiV2,
  1723.                     "Content-Type: application/json"
  1724.                 ),
  1725.             ));
  1726.             $responseFileBa curl_exec($curl);
  1727.             curl_close($curl);
  1728.             $baFile json_decode($responseFileBa);
  1729.             $baFileBin base64_decode($baFiletrue);
  1730.             $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'BA.pdf';
  1731.             file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$baFileBin);
  1732.             $membership->getBa()->setUrlPdfSign($name);
  1733.             /* ------------------------ SAVE BA END ------------------------ */
  1734.             /* ------------------------ SAVE SEPA START ------------------------ */
  1735.             if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  1736.                 //GET SEPA FILE
  1737.                 $curl curl_init();
  1738.                 curl_setopt_array($curl, array(
  1739.                     CURLOPT_URL => $this->yousignUrlV2 $membership->getBa()->getSepaIdYouSign() . "/download",
  1740.                     CURLOPT_RETURNTRANSFER => true,
  1741.                     CURLOPT_ENCODING => "",
  1742.                     CURLOPT_MAXREDIRS => 30,
  1743.                     CURLOPT_TIMEOUT => 0,
  1744.                     CURLOPT_FOLLOWLOCATION => true,
  1745.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1746.                     CURLOPT_CUSTOMREQUEST => "GET",
  1747.                     CURLOPT_HTTPHEADER => array(
  1748.                         "Authorization: Bearer " $this->yousignApiV2,
  1749.                         "Content-Type: application/json"
  1750.                     ),
  1751.                 ));
  1752.                 $responseFileSepa curl_exec($curl);
  1753.                 curl_close($curl);
  1754.                 $sepaFile json_decode($responseFileSepa);
  1755.                 $sepaFileBin base64_decode($sepaFiletrue);
  1756.                 $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'SEPA.pdf';
  1757.                 file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$sepaFileBin);
  1758.                 $membership->getBa()->setSepaUrlPdfSign($name);
  1759.             }
  1760.             /* ------------------------ SAVE SEPA END ------------------------ */
  1761.             $this->em->persist($membership->getBa());
  1762.         }
  1763.         if($membership->getPlatformVersion() == 1){
  1764.             $this->em->persist($membership->getDic());
  1765.         }
  1766.         else{
  1767.             $this->em->persist($membership->getFic());
  1768.         }
  1769.         $this->em->flush();
  1770.     }
  1771.     function startSign($procedure)
  1772.     {
  1773.         $memberId $procedure->members[0]->id;
  1774.         $yousignUrlV2 $this->container->getParameter('yousign_url_v2');
  1775.         header('Location: ' $yousignUrlV2 '/procedure/sign?members=' $memberId '&signatureUi=/signature_uis/' $this->yousignUi);
  1776.         exit();
  1777.     }
  1778.     function youSignConditionsV3($fileURL$document$userCurrent null): array
  1779.     {
  1780.         $client = new Client();
  1781.         $responseProcedure null;
  1782.         $responseErrorTab = [];
  1783.         $cpFileId null;
  1784.         $activateSignatureResponseBody null;
  1785.         $newSignatureId null;
  1786.         $uploadDocumentId null;
  1787.         $signerUrl null;
  1788.         //Font default for all fields
  1789.         $fontDefault = new \stdClass();
  1790.         $fontDefault->size 9;
  1791.         $fontDefault->family "Inconsolata";
  1792.         $fontDefault->variants = array(
  1793.             "italic" => false,
  1794.             "bold" => false
  1795.         );
  1796.         $fontDefault->color "#000000";
  1797.         /* -----------------------------------  Add Signature   ------------------------------------- */
  1798.         //Create signature
  1799.         $newSignature = new \stdClass();
  1800.         $newSignature->delivery_mode "none";
  1801.         $newSignature->reminder_settings null;
  1802.         $newSignature->ordered_signers true;
  1803.         $newSignature->signers_allowed_to_decline false;
  1804.         $newSignature->workspace_id $this->yousignWorkspaceConditions;
  1805.         $newSignature->name "Conditions particulières";
  1806.         $newSignature->custom_experience_id $this->yousignUiConditions;
  1807.         try {
  1808.             $newSignatureResponse $client->request('POST'$this->yousignUrl .'/signature_requests'
  1809.                 [
  1810.                     'body' => json_encode($newSignature),
  1811.                     'headers' => [
  1812.                         'accept' => 'application/json',
  1813.                         'content-type' => 'application/json',
  1814.                         'Authorization' => 'Bearer ' $this->yousignApi
  1815.                     ],
  1816.                 ]
  1817.             );
  1818.             //201 for create
  1819.             $newSignatureResponseStatusCode $newSignatureResponse->getStatusCode();
  1820.             $newSignatureResponseBody json_decode($newSignatureResponse->getBody());
  1821.             $newSignatureId $newSignatureResponseBody->id;
  1822.         }
  1823.         catch (\Exception $e) {
  1824.             $responseErrorTab[] = $e->getMessage();
  1825.         }
  1826.         /* -----------------------------------  Add Metadata   ------------------------------------- */
  1827.         //Create meta
  1828.         $newMetaData = new \stdClass();
  1829.         $newMetaData->data = array(
  1830.             "documentId" => $document->getId()
  1831.         );
  1832.         try {
  1833.             $newMetaDataResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/metadata'
  1834.                 [
  1835.                     'body' => json_encode($newMetaData),
  1836.                     'headers' => [
  1837.                         'accept' => 'application/json',
  1838.                         'content-type' => 'application/json',
  1839.                         'Authorization' => 'Bearer ' $this->yousignApi
  1840.                     ],
  1841.                 ]
  1842.             );
  1843.             //201 for create
  1844.             $newMetaDataResponseStatusCode $newMetaDataResponse->getStatusCode();
  1845.             $newMetaDataResponseBody json_decode($newMetaDataResponse->getBody());
  1846.         }
  1847.         catch (\Exception $e) {
  1848.             $responseErrorTab[] = $e->getMessage();
  1849.         }
  1850.         /* -----------------------------------  Add Files   ------------------------------------- */
  1851.         //Add Document file
  1852.         try {
  1853.             $uploadDocumentResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents'
  1854.                 [
  1855.                     'multipart' => [
  1856.                         [
  1857.                             'name' => 'nature',
  1858.                             'contents' => 'signable_document'
  1859.                         ],
  1860.                         [
  1861.                             'name' => 'parse_anchors',
  1862.                             'contents' => 'false'
  1863.                         ],
  1864.                         [
  1865.                             'name' => 'file',
  1866.                             'filename' => "Conditions particulières.pdf",
  1867.                             'contents' => fopen($fileURL'r'),
  1868.                         ]
  1869.                     ],
  1870.                     'headers' => [
  1871.                         'accept' => 'application/json',
  1872.                         'Authorization' => 'Bearer ' $this->yousignApi
  1873.                     ]
  1874.                 ]
  1875.             );
  1876.             $uploadDocumentResponseBody json_decode($uploadDocumentResponse->getBody());
  1877.             $uploadDocumentId $uploadDocumentResponseBody->id;
  1878.         }
  1879.         catch (\Exception $e) {
  1880.             $responseErrorTab[] = $e->getMessage();
  1881.         }
  1882.         //Add Member
  1883.         $phone $userCurrent->getPhone();
  1884.         $phone str_replace("("""$phone);
  1885.         $phone str_replace(")"""$phone);
  1886.         $phone str_replace(" """$phone);
  1887.         if ($userCurrent->getPhonePrefix()) {
  1888.             $phone $userCurrent->getPhonePrefix() . $phone;
  1889.         }
  1890.         else{
  1891.             $phone "+33" $phone;
  1892.         }
  1893.         $newSignerMember = new \stdClass();
  1894.         $newSignerMember->locale "fr";
  1895.         $newSignerMember->first_name $userCurrent->getFirstName();
  1896.         $newSignerMember->last_name $userCurrent->getLastName();
  1897.         $newSignerMember->email $userCurrent->getEmail();
  1898.         $newSignerMember->phone_number $phone;
  1899.         //$newSignerRedirect = new \stdClass();
  1900.         //$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end_', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  1901.         //$newSignerRedirect->success = $urlSignEnd;
  1902.         //$newSignerRedirect->error = $urlSignEnd;
  1903.         $newSigner = new \stdClass();
  1904.         $newSigner->info $newSignerMember;
  1905.         $newSigner->signature_level "electronic_signature";
  1906.         $newSigner->signature_authentication_mode "otp_sms";
  1907.         //$newSigner->redirect_urls = $newSignerRedirect;
  1908.         try {
  1909.             $newSignerResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers'
  1910.                 [
  1911.                     'body' => json_encode($newSigner),
  1912.                     'headers' => [
  1913.                         'accept' => 'application/json',
  1914.                         'content-type' => 'application/json',
  1915.                         'Authorization' => 'Bearer ' $this->yousignApi
  1916.                     ],
  1917.                 ]
  1918.             );
  1919.             $newSignerResponseBody json_decode($newSignerResponse->getBody());
  1920.             $newSignerId $newSignerResponseBody->id;
  1921.          }
  1922.         catch (\Exception $e) {
  1923.             $responseErrorTab[] = $e->getMessage();
  1924.         }
  1925.         if($document->getFileType()){
  1926.             $page $document->getFileType()->getNumberPage();
  1927.         }
  1928.         else{
  1929.             // default page
  1930.             $page 2;
  1931.         }
  1932.         /* ADD SIGNATURE PLACED */
  1933.         $newFieldSignature = new \stdClass();
  1934.         $newFieldSignature->signer_id $newSignerId;
  1935.         $newFieldSignature->type "signature";
  1936.         $newFieldSignature->page $page;
  1937.         $newFieldSignature->width 114;
  1938.         $newFieldSignature->height 61;
  1939.         $newFieldSignature->433;
  1940.         $newFieldSignature->655;
  1941.         if($document->getFileType()){
  1942.             if($document->getFileType()->isSignedOrder()){
  1943.                 //Right
  1944.                 $newFieldSignature->width 114;
  1945.                 $newFieldSignature->height 61;
  1946.                 $newFieldSignature->433;
  1947.                 $newFieldSignature->655;
  1948.             }
  1949.             else{
  1950.                 //Left
  1951.                 $newFieldSignature->width 114;
  1952.                 $newFieldSignature->height 61;
  1953.                 $newFieldSignature->43;
  1954.                 $newFieldSignature->655;
  1955.             }
  1956.         } 
  1957.         try {
  1958.             $response $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/documents/'.$uploadDocumentId.'/fields'
  1959.                 [
  1960.                     'body' => json_encode($newFieldSignature),
  1961.                     'headers' => [
  1962.                         'accept' => 'application/json',
  1963.                         'content-type' => 'application/json',
  1964.                         'Authorization' => 'Bearer ' $this->yousignApi
  1965.                     ],
  1966.                 ]
  1967.             );
  1968.         }
  1969.         catch (\Exception $e) {
  1970.             $responseErrorTab[] = $e->getMessage();
  1971.         }
  1972.         /* -----------------------------------  Active signature (end step)   ------------------------------------- */
  1973.         //Activate signature
  1974.         try {
  1975.             $activateSignatureResponse $client->request('POST''https://api-sandbox.yousign.app/v3/signature_requests/'.$newSignatureId.'/activate'
  1976.                 [
  1977.                     'headers' => [
  1978.                         'accept' => 'application/json',
  1979.                         'Authorization' => 'Bearer ' $this->yousignApi
  1980.                     ],
  1981.                 ]
  1982.             );
  1983.             $activateSignatureResponseBody json_decode($activateSignatureResponse->getBody());
  1984.             $activateSignatureResponseSigners $activateSignatureResponseBody->signers;
  1985.             $signerUrl $activateSignatureResponseSigners[0]->signature_link;
  1986.         }
  1987.         catch (\Exception $e) {
  1988.             $responseErrorTab[] = $e->getMessage();
  1989.         }
  1990.         return [
  1991.             "responseProcedure" => $activateSignatureResponseBody,
  1992.             "procedureId" => $newSignatureId,
  1993.             "yousignUi" => $this->yousignUiConditions,
  1994.             "fileId" => $uploadDocumentId,
  1995.             "signerUrl" => $signerUrl,
  1996.             "responseErrorTab" => $responseErrorTab
  1997.         ];
  1998.     }
  1999.     function youSignConditions($fileURL$document$userCurrent null): array
  2000.     {
  2001.         $responseProcedure null;
  2002.         $cpFileId null;
  2003.         //Get CP BASE 64
  2004.         $b64Cp chunk_split(base64_encode(file_get_contents($fileURL)));
  2005.         $fileCp = new \stdClass();
  2006.         $fileCp->name "Conditions particulières";
  2007.         $fileCp->content $b64Cp;
  2008.         $fileCp->position 1;
  2009.         //Create files
  2010.         $curl curl_init();
  2011.         curl_setopt_array($curl, array(
  2012.             CURLOPT_URL => $this->yousignUrlV2 "/files",
  2013.             CURLOPT_RETURNTRANSFER => true,
  2014.             CURLOPT_ENCODING => '',
  2015.             CURLOPT_MAXREDIRS => 10,
  2016.             CURLOPT_TIMEOUT => 0,
  2017.             CURLOPT_FOLLOWLOCATION => true,
  2018.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2019.             CURLOPT_CUSTOMREQUEST => "POST",
  2020.             CURLOPT_POSTFIELDS => json_encode($fileCp),
  2021.             CURLOPT_HTTPHEADER => array(
  2022.                 "Authorization: Bearer " $this->yousignApiV2,
  2023.                 "Content-Type: application/json"
  2024.             ),
  2025.         ));
  2026.         $responseFile curl_exec($curl);
  2027.         curl_close($curl);
  2028.         $responseFileCp json_decode($responseFile);
  2029.         if($responseFileCp){
  2030.             //Default (last value) : "432,131,548,184"; page 2;
  2031.             if($document->getFileType()){
  2032.                 if($document->getFileType()->isSignedOrder()){
  2033.                     //Right
  2034.                     $position "432,131,548,184";
  2035.                 }
  2036.                 else{
  2037.                     //Left
  2038.                     $position "50,134,178,180";
  2039.                 }
  2040.             } else {
  2041.                 // default position
  2042.                 $position "432,131,548,184";
  2043.             }
  2044.             if($document->getFileType()){
  2045.                 $page $document->getFileType()->getNumberPage();
  2046.             }
  2047.             else{
  2048.                 // default page
  2049.                 $page 2;
  2050.             }
  2051.             //Set file CP
  2052.             $fileObjectCp = new \stdClass();
  2053.             $fileObjectCp->file $responseFileCp->id;
  2054.             $fileObjectCp->page $page;
  2055.             $fileObjectCp->position $position;
  2056.             $fileObjectCp->mention "Lu et approuvé";
  2057.             $fileObjectCp->reason "Signed by John Doe (Yousign)";
  2058.             $firstName $userCurrent->getFirstName();
  2059.             $lastName $userCurrent->getLastName();
  2060.             if($firstName && $lastName){
  2061.                 $fileObjectCp->mention2 "Signé par " $firstName " " $lastName;
  2062.             }
  2063.             $arrayObjectFiles[] = $fileObjectCp;
  2064.             $cpFileId $responseFileCp->id;
  2065.             //Add procedure
  2066.             $config = new \stdClass();
  2067.             $webhook = new \stdClass();
  2068.             $webhookEnd = new \stdClass();
  2069.             $header = new \stdClass();
  2070.             $urlSignEnd $this->container->get('router')->generate('yousign_sign_conditions_end', array('documentID' => $document->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  2071.             $webhookEnd->url $urlSignEnd;
  2072.             $webhookEnd->method "GET";
  2073.             $webhookEnd->headers = (object)array(
  2074.                 'X-Custom-Header' => "End sign"
  2075.             );
  2076.             $config->webhook = (object)array(
  2077.                 'procedure.finished' => array(
  2078.                     $webhookEnd
  2079.                 )
  2080.             );
  2081.             //Set member - customer
  2082.             $member = new \stdClass();
  2083.             $member->firstname $userCurrent->getFirstName();
  2084.             $member->phone $userCurrent->getPhone();
  2085.             $member->lastname $userCurrent->getLastName();
  2086.             $member->email $userCurrent->getEmail();
  2087.             $member->fileObjects $arrayObjectFiles;
  2088.             $member->type "signer";
  2089.             //Set procedure
  2090.             $procedure = new \stdClass();
  2091.             $procedure->name "Signature des conditions particulières";
  2092.             $procedure->description "Fin d'adhésion";
  2093.             $procedure->start true;
  2094.             $procedure->members = array(
  2095.                 $member
  2096.             );
  2097.             $procedure->config $config;
  2098.             $curl curl_init();
  2099.             curl_setopt_array($curl, array(
  2100.                 CURLOPT_URL => $this->yousignUrlV2 "/procedures",
  2101.                 CURLOPT_RETURNTRANSFER => true,
  2102.                 CURLOPT_ENCODING => "",
  2103.                 CURLOPT_MAXREDIRS => 10,
  2104.                 CURLOPT_TIMEOUT => 0,
  2105.                 CURLOPT_FOLLOWLOCATION => true,
  2106.                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2107.                 CURLOPT_CUSTOMREQUEST => "POST",
  2108.                 CURLOPT_POSTFIELDS => json_encode($procedure),
  2109.                 CURLOPT_HTTPHEADER => array(
  2110.                     "Authorization: Bearer " $this->yousignApiV2,
  2111.                     "Content-Type: application/json"
  2112.                 ),
  2113.             ));
  2114.             $responseProcedure curl_exec($curl);
  2115.             curl_close($curl);
  2116.             $responseProcedure json_decode($responseProcedure);
  2117.         }
  2118.         return [
  2119.             "responseProcedure" => $responseProcedure,
  2120.             "yousignUi" => $this->yousignUiConditions,
  2121.             "fileId" => $cpFileId,
  2122.         ];
  2123.     }
  2124.     function saveFilesConditionsYouSignV3($document)
  2125.     {
  2126.         $newSignatureId $document->getProcedureId();
  2127.         //Wait 2 secondes Yousign create file
  2128.         //sleep(2);
  2129.         /* ------------------------ SAVE Document START ------------------------ */
  2130.         //GET FIC FILE
  2131.         $client = new Client();
  2132.         $fileResponse $client->request('GET'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$document->getIdYouSign().'/download'
  2133.             [
  2134.                 'headers' => [
  2135.                     'accept' => 'application/json',
  2136.                     'content-type' => 'application/json',
  2137.                     'Authorization' => 'Bearer ' $this->yousignApi
  2138.                 ],
  2139.             ]
  2140.         );
  2141.         $fileBody $fileResponse->getBody();
  2142.         $name $document->getNumeroAdherent() . "_" $document->getLastName() . "_" $document->getFirstName() . "_CONDITIONS_PARTICULIERES.pdf";
  2143.         $path $this->fileUploader->getTargetDirectory() . "/cp/" $document->getId() . "/" $name;
  2144.         file_put_contents($path$fileBody);
  2145.         /* ------------------------ SAVE Document END ------------------------ */
  2146.         $document->setUrlPdfSign($path);
  2147.         $document->setFilename($name);
  2148.     
  2149.         $this->em->persist($document);
  2150.         $this->em->flush();
  2151.     }
  2152.     function saveFilesConditionsYouSign($document)
  2153.     {
  2154.         //GET DIC FILE
  2155.         $curl curl_init();
  2156.         curl_setopt_array($curl, array(
  2157.             CURLOPT_URL => $this->yousignUrl $document->getIdYouSign() . "/download",
  2158.             CURLOPT_RETURNTRANSFER => true,
  2159.             CURLOPT_ENCODING => "",
  2160.             CURLOPT_MAXREDIRS => 10,
  2161.             CURLOPT_TIMEOUT => 0,
  2162.             CURLOPT_FOLLOWLOCATION => true,
  2163.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2164.             CURLOPT_CUSTOMREQUEST => "GET",
  2165.             CURLOPT_HTTPHEADER => array(
  2166.                 "Authorization: Bearer " $this->yousignApi,
  2167.                 "Content-Type: application/json"
  2168.             ),
  2169.         ));
  2170.         $responseFile curl_exec($curl);
  2171.         curl_close($curl);
  2172.         $file json_decode($responseFile);
  2173.         $fileBin base64_decode($filetrue);
  2174.         $name $document->getNumeroAdherent() . "_" $document->getLastName() . "_" $document->getFirstName() . "_CONDITIONS_PARTICULIERES.pdf";
  2175.         $path $this->fileUploader->getTargetDirectory() . "/cp/" $document->getId() . "/" $name;
  2176.         file_put_contents($path$fileBin);
  2177.         $document->setUrlPdfSign($path);
  2178.         $document->setFilename($name);
  2179.     
  2180.         $this->em->persist($document);
  2181.         $this->em->flush();
  2182.     }
  2183. }