src/Services/Utils.php line 60

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.             
  79.             echo 'Une erreur est survenue liée à une migration de la plateforme, veuillez contacter le support et indiquez l’erreur : "Error 11 - migration". Cette erreur sera résolue au plus vite.';
  80.             die;
  81.         } else {
  82.             $membershipLast $membership;
  83.         }
  84.         //Create folder customer
  85.         $urlFolderCustomer $this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId();
  86.         if (!file_exists($urlFolderCustomer)) {
  87.             //Remove last file
  88.             mkdir($urlFolderCustomer);        
  89.         }
  90.         if($membershipLast->getPlatformVersion() == 1){
  91.             if (!$membershipLast->getDic()) {
  92.                 $dic = new Dic;
  93.                 $membershipLast->setDic($dic);
  94.                 $this->em->persist($dic);
  95.                 $this->em->persist($membershipLast);
  96.                 $this->em->flush();
  97.             }
  98.         }
  99.         else{
  100.             if (!$membershipLast->getFic()) {
  101.                 $fic = new Fic;
  102.                 $membershipLast->setFic($fic);
  103.                 $this->em->persist($fic);
  104.                 $this->em->persist($membershipLast);
  105.                 $this->em->flush();
  106.             }
  107.         }
  108.         if (!$membershipLast->getBa()) {
  109.             $ba = new Ba;
  110.             $membershipLast->setBa($ba);
  111.             $this->em->persist($ba);
  112.             $this->em->persist($membershipLast);
  113.             $this->em->flush();
  114.         }
  115.         return $membershipLast;
  116.     }
  117.     public function createMembershipByProduct($customer$product$seller)
  118.     {
  119.         $siretFilter $this->container->getParameter('siret_filter');
  120.         $membership = new Membership;
  121.         $membership->setUser($customer);
  122.         $membership->setStatus("DRAFT");
  123.         $membership->setProduct($product);
  124.         //Set seller
  125.         if($seller == "fullweb"){
  126.             $membership->setSeller(null);
  127.         }
  128.         else{
  129.             $membership->setSeller($seller);
  130.             if($seller->getNumeroSiren() == $siretFilter){
  131.                 $membership->setDicIsFile(true);
  132.             }
  133.             if($membership->getDicIsFile()){
  134.                 $membership->setPlatformVersion(1);
  135.             }
  136.             else{
  137.                 $membership->setPlatformVersion(2);
  138.             }
  139.         }
  140.         
  141.         $this->em->persist($membership);
  142.         $this->em->flush();
  143.         //Create folder customer
  144.         $urlFolderCustomer $this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId();
  145.         if (!file_exists($urlFolderCustomer)) {
  146.             //Remove last file
  147.             mkdir($urlFolderCustomer);        
  148.         }
  149.         if($membership->getPlatformVersion() == 1){
  150.             if (!$membership->getDic()) {
  151.                 $dic = new Dic;
  152.                 $membership->setDic($dic);
  153.                 $this->em->persist($dic);
  154.                 $this->em->persist($membership);
  155.                 $this->em->flush();
  156.             }
  157.         }
  158.         else{
  159.             if (!$membership->getFic()) {
  160.                 $fic = new Fic;
  161.                 $membership->setFic($fic);
  162.                 $this->em->persist($fic);
  163.                 $this->em->persist($membership);
  164.                 $this->em->flush();
  165.             }
  166.         }
  167.         if (!$membership->getBa()) {
  168.             $ba = new Ba;
  169.             $membership->setBa($ba);
  170.             $this->em->persist($ba);
  171.             $this->em->persist($membership);
  172.             $this->em->flush();
  173.         }
  174.         return $membership;
  175.     }
  176.     public function getCustomerByNumberMembership($nb)
  177.     {
  178.         $customer null;
  179.         $membership $this->em
  180.             ->getRepository(Membership::class)
  181.             ->findOneBy(['numberMembershipFolder' => $nb], array("id" => "DESC"));
  182.         if ($membership) {
  183.             $customer $membership->getUser();
  184.         }
  185.         return $customer;
  186.     }
  187.     public function sendEmailEndSignin($user)
  188.     {
  189.         $mailNoReply $this->container->getParameter('mail_no_reply');
  190.         $senderName $this->container->getParameter('sender_name');
  191.         $tokenGenerator random_bytes(10);
  192.         $user->setTokenReset(md5($tokenGenerator));
  193.         $this->em->persist($user);
  194.         $this->em->flush();
  195.         $url $this->container->get('router')->generate('signin_end', array('token' => $user->getTokenReset()), UrlGeneratorInterface::ABSOLUTE_URL);
  196.         $bodyEmail $this->twig->render(
  197.             'email/addUserWithToken.html.twig',
  198.             array('user' => $user'confirmationToken' => $url)
  199.         );
  200.         $message = (new \Swift_Message("Fin d'inscription"))
  201.             ->setSubject("Fin d'inscription")
  202.             ->setFrom(array($mailNoReply => $senderName))
  203.             ->setTo(array($user->getEmail() => $senderName))
  204.             ->setBody($bodyEmail'text/html');
  205.         $this->mailer->send($message);
  206.     }
  207.     public function sendEmailEndSigninCustomer($user)
  208.     {
  209.         $mailNoReply $this->container->getParameter('mail_no_reply');
  210.         $senderName $this->container->getParameter('sender_name');
  211.         $tokenGenerator random_bytes(10);
  212.         $user->setTokenReset(md5($tokenGenerator));
  213.         $this->em->persist($user);
  214.         $this->em->flush();
  215.         $url $this->container->get('router')->generate('signin_end', array('token' => $user->getTokenReset()), UrlGeneratorInterface::ABSOLUTE_URL);
  216.         $bodyEmail $this->twig->render(
  217.             'email/addCustomerWithToken.html.twig',
  218.             array('user' => $user'confirmationToken' => $url)
  219.         );
  220.         $message = (new \Swift_Message("Finalisez votre adhésion"))
  221.             ->setSubject("Finalisez votre adhésion")
  222.             ->setFrom(array($mailNoReply => $senderName))
  223.             ->setTo(array($user->getEmail() => $senderName))
  224.             ->setBody($bodyEmail'text/html');
  225.         $this->mailer->send($message);
  226.     }
  227.     public function generateDic($customer)
  228.     {
  229.         $dicFileName "dic-no-sign.pdf";
  230.         $dicFullPath $this->fileUploader->getTargetDirectory() . "/" $customer->getId() . "/" $dicFileName;
  231.         //If file exist
  232.         if (file_exists($dicFullPath)) {
  233.             //Remove last file
  234.             unlink($dicFullPath);
  235.         }
  236.         $this->knpSnappy->setOption('page-size''A4');
  237.         $this->knpSnappy->setOption('encoding''UTF-8');
  238.         $this->knpSnappy->setOption('zoom''1.17');
  239.         $this->knpSnappy->setOption('margin-left''0');
  240.         $this->knpSnappy->setOption('margin-right''0');
  241.         $this->knpSnappy->setOption('margin-top''5');
  242.         $this->knpSnappy->setOption('margin-bottom''5');
  243.         $this->knpSnappy->setOption('dpi''96');
  244.         $this->knpSnappy->generateFromHtml(
  245.             $this->twig->render(
  246.                 'membership/pdf/dicView.html.twig',
  247.                 array(
  248.                     'dic' => $customer->getCurrentMemberships()->getDic()
  249.                 )
  250.             ),
  251.             $dicFullPath
  252.         );
  253.         return $dicFileName;
  254.     }
  255.     public function generateFicV2023($customer)
  256.     {
  257.         $ficFileName "fic-no-sign.pdf";
  258.         $ficFullPath $this->fileUploader->getTargetDirectory() . "/" $customer->getId() . "/" $ficFileName;
  259.         //If file exist
  260.         if (file_exists($ficFullPath)) {
  261.             //Remove last file
  262.             unlink($ficFullPath);
  263.         }
  264.         $this->knpSnappy->setOption('page-size''A4');
  265.         $this->knpSnappy->setOption('encoding''UTF-8');
  266.         $this->knpSnappy->setOption('zoom''1.62');
  267.         $this->knpSnappy->setOption('margin-left''0');
  268.         $this->knpSnappy->setOption('margin-right''0');
  269.         $this->knpSnappy->setOption('margin-top''5');
  270.         $this->knpSnappy->setOption('margin-bottom''5');
  271.         $this->knpSnappy->setOption('dpi''96');
  272.         $this->knpSnappy->generateFromHtml(
  273.             $this->twig->render(
  274.                 'membership/pdf/ficView.html.twig',
  275.                 array(
  276.                     'fic' => $customer->getCurrentMemberships()->getFic()
  277.                 )
  278.             ),
  279.             $ficFullPath
  280.         );
  281.         return $ficFileName;
  282.     }
  283.     public function generateFic($customer$fic null)
  284.     {
  285.         $ficFileName $this->generateDocuments->generateFic($customer$fic);
  286.         return $ficFileName;
  287.     }
  288.     public function generateFicFullweb($customer$fic null)
  289.     {
  290.         $ficFileName $this->generateDocumentsFullweb->generateFic($customer$fic);
  291.         return $ficFileName;
  292.     }
  293.     public function generateBaV2023($customer)
  294.     {
  295.         $baFileName "ba-no-sign.pdf";
  296.         $baFullPath $this->fileUploader->getTargetDirectory() . "/" $customer->getId() . "/" $baFileName;
  297.         //If file exist
  298.         if (file_exists($baFullPath)) {
  299.             //Remove last file
  300.             unlink($baFullPath);
  301.         }
  302.         $this->knpSnappy->setOption('page-size''A4');
  303.         $this->knpSnappy->setOption('encoding''UTF-8');
  304.         $this->knpSnappy->setOption('zoom''1.62');
  305.         $this->knpSnappy->setOption('margin-left''0');
  306.         $this->knpSnappy->setOption('margin-right''0');
  307.         $this->knpSnappy->setOption('margin-top''5');
  308.         $this->knpSnappy->setOption('margin-bottom''5');
  309.         $this->knpSnappy->setOption('dpi''96');
  310.         $this->knpSnappy->generateFromHtml(
  311.             $this->twig->render(
  312.                 'membership/pdf/baView.html.twig',
  313.                 array(
  314.                     'ba' => $customer->getCurrentMemberships()->getBa()
  315.                 )
  316.             ),
  317.             $baFullPath
  318.         );
  319.         return $baFileName;
  320.     }
  321.     public function generateBa($customer$ba null)
  322.     {
  323.         $baFileName $this->generateDocuments->generateBa($customer$ba);
  324.         return $baFileName;
  325.     }
  326.     public function generateBaFullweb($customer$ba null)
  327.     {
  328.         $baFileName $this->generateDocumentsFullweb->generateBa($customer$ba);
  329.         return $baFileName;
  330.     }
  331.     
  332.     public function generateSepa($customer$ba null)
  333.     {
  334.         $sepaFileName "sepa-no-sign.pdf";
  335.         if(!$ba){
  336.             $ba $customer->getCurrentMemberships()->getBa();
  337.         }
  338.         $membership $ba->getMembership();
  339.         $sepaFullPath $this->fileUploader->getTargetDirectory() . "/" $customer->getId() . "/" $sepaFileName;
  340.         $iban $ba->getSepaCodeIban();
  341.         $iban str_replace(" """$iban);
  342.         $bic $ba->getSepaCodeBic();
  343.         $bic str_replace(" """$bic);
  344.         $ba->setSepaCodeIban($iban);
  345.         $ba->setSepaCodeBic($bic);
  346.         //If file exist
  347.         if (file_exists($sepaFullPath)) {
  348.             //Remove last file
  349.             unlink($sepaFullPath);
  350.         }
  351.         // initiate FPDI
  352.         $pdf = new Fpdi();
  353.         // add a page
  354.         $pdf->AddPage();
  355.         // set the source file
  356.         $productType $ba->getMembership()->getProduct();
  357.         if($productType == "epargne"){
  358.             $numberPagesSource $pdf->setSourceFile("default/epargne/SEPA.pdf");
  359.         }
  360.         else{
  361.             $numberPagesSource $pdf->setSourceFile("default/SEPA_2024.pdf");
  362.         }
  363.         for ($i 1$i <= $numberPagesSource $i++) { 
  364.             if($i 1){
  365.                 $pdf->AddPage();
  366.             }
  367.             // import page
  368.             $tplId $pdf->importPage($i);
  369.             $pdf->useTemplate($tplId00);
  370.             //Global pages
  371.             $font "Helvetica";
  372.             $fontSizeText 11;
  373.             $fontSizeChecked 11;
  374.             $pdf->setFont($fontnull10);
  375.             if($productType == "epargne"){
  376.                 switch ($i) {
  377.                     case '1':
  378.                     //Garantie
  379.                     $pdf->setFont($fontnull11);
  380.                     $pdf->Text(71.3,49.8$this->decode("Épargne"));
  381.                     //Numéro distributeur
  382.                     $pdf->setFont($fontnull11);
  383.                     $pdf->Text(71.6,58.8$ba->getAdherentDistributeur());
  384.                     //versementProgramme
  385.                     if($ba->isVersementProgramme()){
  386.                         $pdf->setFont($fontnull11);
  387.                         $pdf->Text(29.5,75.7"X");
  388.                         //versementProgrammeMontant
  389.                         $pdf->setFont($fontnull11);
  390.                         $pdf->Text(50.3,81.6$ba->getMontantVersementPeriodique());
  391.                         switch ($ba->getPeriodicite()) {
  392.                             case 0:
  393.                                 $pdf->setFont($fontnull$fontSizeChecked);
  394.                                 $pdf->Text(52.8,89.8'X');
  395.                                 break;
  396.                             case 1:
  397.                                 $pdf->setFont($fontnull$fontSizeChecked);
  398.                                 $pdf->Text(52.8,93.6'X');
  399.                                 break;
  400.                             case 2:
  401.                                 $pdf->setFont($fontnull$fontSizeChecked);
  402.                                 $pdf->Text(52.8,97.6'X');
  403.                                 break;
  404.                             case 3:
  405.                                 $pdf->setFont($fontnull$fontSizeChecked);
  406.                                 $pdf->Text(52.8,101'X');
  407.                                 break;
  408.                             
  409.                             default:
  410.                                 // code...
  411.                                 break;
  412.                         }
  413.                     }
  414.                     //versementInitial
  415.                     $pdf->setFont($fontnull11);
  416.                     $pdf->Text(100.6,75.7"X");
  417.                     //versementInitialMontant
  418.                     $pdf->setFont($fontnull11);
  419.                     $pdf->Text(121.2,81.6$ba->getVersementInitial());
  420.                     //Name
  421.                     $pdf->setFont($fontnull11);
  422.                     $pdf->Text(46.9,131.3$this->decode($ba->getSepaNom())." ".$this->decode($ba->getSepaPrenom()));
  423.                     //Non et adresse postale
  424.                     $pdf->setFont($fontnull11);
  425.                     $pdf->Text(20.6,146.7$this->decode($ba->getSepaAdresse()).", ".$ba->getSepaCodePostal()." ".$this->decode($ba->getSepaVille()));
  426.                     //Pays
  427.                     $pdf->setFont($fontnull11);
  428.                     $pdf->Text(31.1,155$this->decode($ba->getSepaPays()));
  429.                     //Iban
  430.                     $pdf->setFont($fontnull11.3);
  431.                         $pdf->Text(29.3,176$this->formatString($ba->getSepaCodeIban(), "iban"));
  432.                     //Bic
  433.                     $pdf->setFont($fontnull10.8);
  434.                         $pdf->Text(31.4,184.8$this->formatString($ba->getSepaCodeBic()));
  435.                     default:
  436.                         // code...
  437.                         break;
  438.                 }
  439.             }
  440.             else{
  441.                 switch ($i) {
  442.                     case '1':
  443.                     //Non et adresse postale
  444.                     $pdf->setFont($fontnull11);
  445.                     $pdf -> SetY(71.6);
  446.                     $pdf -> SetX(18.5); 
  447.                     $pdf->MultiCell(10310$this->decode($ba->getSepaNom())." ".$this->decode($ba->getSepaPrenom())."\n".$this->decode($ba->getSepaAdresse()).", ".$ba->getSepaCodePostal()." ".$this->decode($ba->getSepaVille()).", ".$this->decode($ba->getSepaPays()), 0'L'0);
  448.                     //Iban
  449.                     $pdf->setFont($fontnull11.3);
  450.                         $pdf->Text(28.6116.2$this->formatString($ba->getSepaCodeIban(), "iban"));
  451.                     //Bic
  452.                     $pdf->setFont($fontnull10.8);
  453.                         $pdf->Text(30.2124.8$this->formatString($ba->getSepaCodeBic()));
  454.                     default:
  455.                         // code...
  456.                         break;
  457.                 }
  458.             }
  459.         }
  460.         $pdf->Output('F'$sepaFullPath);
  461.         return $sepaFileName;
  462.     }
  463.     public function generateSepaV2023($customer)
  464.     {
  465.         $sepaFileName "sepa-no-sign.pdf";
  466.         $sepaFullPath $this->fileUploader->getTargetDirectory() . "/" $customer->getId() . "/" $sepaFileName;
  467.         //If file exist
  468.         if (file_exists($sepaFullPath)) {
  469.             //Remove last file
  470.             unlink($sepaFullPath);
  471.         }
  472.         $this->knpSnappy->setOption('page-size''A4');
  473.         $this->knpSnappy->setOption('encoding''UTF-8');
  474.         $this->knpSnappy->setOption('zoom''1.17');
  475.         $this->knpSnappy->setOption('margin-left''0');
  476.         $this->knpSnappy->setOption('margin-right''0');
  477.         $this->knpSnappy->setOption('margin-top''5');
  478.         $this->knpSnappy->setOption('margin-bottom''5');
  479.         $this->knpSnappy->generateFromHtml(
  480.             $this->twig->render(
  481.                 'membership/pdf/sepaView.html.twig',
  482.                 array(
  483.                     'ba' => $customer->getCurrentMemberships()->getBa()
  484.                 )
  485.             ),
  486.             $sepaFullPath
  487.         );
  488.         return $sepaFileName;
  489.     }
  490.     public function formatString($stringLetters$typeFormat "default"){
  491.         $string "";
  492.         $forNumber 1;
  493.         $tabString str_split($stringLetters);
  494.         foreach ($tabString as $keyLetter => $stringLetter) {
  495.             if($keyLetter 0){
  496.                 $string .= " ";
  497.             }
  498.             $string .= $stringLetter;
  499.             switch ($typeFormat) {
  500.                 case 'iban':
  501.                     if($forNumber == && count($tabString) != ($keyLetter 1)){
  502.                         $string .= " ";
  503.                         $forNumber 0;
  504.                     }
  505.                     break;
  506.                 case 'ss':
  507.                     if($keyLetter == || $keyLetter == || $keyLetter == || $keyLetter == || $keyLetter == 9){
  508.                         $string .= " ";
  509.                     }
  510.                     break;
  511.                 
  512.                 default:
  513.                     // code...
  514.                     break;
  515.             }
  516.             $forNumber++;
  517.         }
  518.         return $string;
  519.     }
  520.     public function getStatusMembership($customer)
  521.     {
  522.         $status "no-status";
  523.         $membershipCurrent $this->getMembershipByCustomer($customer);
  524.         if ($membershipCurrent->getStatus() == "DRAFT") {
  525.             $status "Brouillon";
  526.         } else if ($membershipCurrent->getStatus() == "VALIDBYSELLER" && $membershipCurrent->getUser()->getStatus() == "SIGNINEND") {
  527.             $status "En attente de fin d'inscription";
  528.         } else if ($membershipCurrent->getStatus() == "VALIDBYSELLER") {
  529.             $status "En attente de validation";
  530.         } else if ($membershipCurrent->getStatus() == "VALIDBYCUSTOMER") {
  531.             $status "En attente de signature";
  532.         } else if ($membershipCurrent->getStatus() == "SIGNBYCUSTOMER") {
  533.             $status "En attente de paiement";
  534.         } else if ($membershipCurrent->getStatus() == "PAYBYCUSTOMER") {
  535.             $status "Validé";
  536.         }
  537.         return $status;
  538.     }
  539.     public function getStatusMembershipByProduct($membership)
  540.     {
  541.         $status "no-status";
  542.         $membershipCurrent $membership;
  543.         if ($membershipCurrent->getStatus() == "DRAFT") {
  544.             $status "Brouillon";
  545.         } else if ($membershipCurrent->getStatus() == "VALIDBYSELLER" && $membershipCurrent->getUser()->getStatus() == "SIGNINEND") {
  546.             $status "En attente de fin d'inscription";
  547.         } else if ($membershipCurrent->getStatus() == "VALIDBYSELLER") {
  548.             $status "En attente de validation";
  549.         } else if ($membershipCurrent->getStatus() == "VALIDBYCUSTOMER") {
  550.             $status "En attente de signature";
  551.         } else if ($membershipCurrent->getStatus() == "SIGNBYCUSTOMER") {
  552.             $status "En attente de paiement";
  553.         } else if ($membershipCurrent->getStatus() == "PAYBYCUSTOMER") {
  554.             $status "Validé";
  555.         }
  556.         return $status;
  557.     }
  558.     public function getStatusMembershipByString($string$customer)
  559.     {
  560.         $status "no-status";
  561.         if ($string == "DRAFT") {
  562.             $status "Brouillon";
  563.         } else if ($string == "VALIDBYSELLER" && $customer->getStatus() == "SIGNINEND") {
  564.             $status "En attente de fin d'inscription";
  565.         } else if ($string == "VALIDBYSELLER") {
  566.             $status "En attente de validation";
  567.         } else if ($string == "VALIDBYCUSTOMER") {
  568.             $status "En attente de signature";
  569.         } else if ($string == "SIGNBYCUSTOMER") {
  570.             $status "En attente de paiement";
  571.         } else if ($string == "PAYBYCUSTOMER") {
  572.             $status "Validé";
  573.         }
  574.         return $status;
  575.     }
  576.     public function getTypeProductByProduct($membership)
  577.     {
  578.         $typeProduct "no-product";
  579.         $membershipCurrent $membership;
  580.         if ($membershipCurrent->getProduct() == "epargne") {
  581.             $typeProduct "Épargne";
  582.         } else if ($membershipCurrent->getProduct() == "retraite") {
  583.             $typeProduct "Retraite";
  584.         }
  585.         return $typeProduct;
  586.     }
  587.     public function getNumberMembership($customer)
  588.     {
  589.         $number null;
  590.         $currentMemberships $this->getMembershipByCustomer($customer);
  591.         if ($customer) {
  592.             if ($currentMemberships) {
  593.                 $number $currentMemberships->getNumberMembershipFolder();
  594.             }
  595.         }
  596.         if ($number == null) {
  597.             $number "Aucun numéro";
  598.         }
  599.         return $number;
  600.     }
  601.     function isMinor(\DateTime $birthDate): bool {
  602.         $currentDate = new \DateTime();
  603.         // Calculate age
  604.         $age $currentDate->diff($birthDate)->y;
  605.         return $age 18;
  606.     }
  607.     function isSeventyOrOlder(\DateTime $birthDate): bool {
  608.         $currentDate = new \DateTime();
  609.         // Calculate age
  610.         $age $currentDate->diff($birthDate)->y;
  611.         return $age >= 70;
  612.     }
  613.     function getProductName($product) {
  614.         if($product == "epargne"){
  615.             return "MER Horizon +";
  616.         }
  617.         else{
  618.             return "MER Retraite mutualiste du combattant";
  619.         }
  620.     }
  621.     function formatSizeUnits($bytes)
  622.     {
  623.         if ($bytes >= 1073741824) {
  624.             $bytes number_format($bytes 10737418242) . ' GB';
  625.         } elseif ($bytes >= 1048576) {
  626.             $bytes number_format($bytes 10485762) . ' MB';
  627.         } elseif ($bytes >= 1024) {
  628.             $bytes number_format($bytes 10242) . ' KB';
  629.         } elseif ($bytes 1) {
  630.             $bytes $bytes ' bytes';
  631.         } elseif ($bytes == 1) {
  632.             $bytes $bytes ' byte';
  633.         } else {
  634.             $bytes '0 bytes';
  635.         }
  636.         return $bytes;
  637.     }
  638.     function addSign($customer$membership$type)
  639.     {
  640.         $client = new Client();
  641.         $typeProduct $membership->getProduct();
  642.         $isLegal1 $membership->getBa()->isRepLegal1Use(); 
  643.         $isLegal2 $membership->getBa()->isRepLegal2Use(); 
  644.         $uploadDicId null;
  645.         $uploadFicId null;
  646.         $uploadBaId null;
  647.         $uploadSepaId null;
  648.         $newSignerSellerId null;
  649.         $newSignerCustomerId null;
  650.         $newSignerCustomerLegal1Id null;
  651.         $newSignerCustomerLegal2Id null
  652.         $newSignerCustomerResponseBody null;
  653.         $activateSignatureResponseBody null;
  654.         $responseErrorTab = [];
  655.         //Font default for all fields
  656.         $fontDefault = new \stdClass();
  657.         $fontDefault->size 9;
  658.         $fontDefault->family "Inconsolata";
  659.         $fontDefault->variants = array(
  660.             "italic" => false,
  661.             "bold" => false
  662.         );
  663.         $fontDefault->color "#000000";
  664.         /* -----------------------------------  Add Signature   ------------------------------------- */
  665.         //Create signature
  666.         $newSignature = new \stdClass();
  667.         $newSignature->delivery_mode "none";
  668.         $newSignature->reminder_settings null;
  669.         $newSignature->ordered_signers true;
  670.         $newSignature->signers_allowed_to_decline false;
  671.         $newSignature->workspace_id $this->yousignWorkspace;
  672.         $newSignature->name "Nouvelle adhésion épargne retraite"." - ".$membership->getProduct();
  673.         $newSignature->custom_experience_id $this->yousignUi;
  674.         try {
  675.             $newSignatureResponse $client->request('POST'$this->yousignUrl .'/signature_requests'
  676.                 [
  677.                     'body' => json_encode($newSignature),
  678.                     'headers' => [
  679.                         'accept' => 'application/json',
  680.                         'content-type' => 'application/json',
  681.                         'Authorization' => 'Bearer ' $this->yousignApi
  682.                     ],
  683.                 ]
  684.             );
  685.             //201 for create
  686.             $newSignatureResponseStatusCode $newSignatureResponse->getStatusCode();
  687.             $newSignatureResponseBody json_decode($newSignatureResponse->getBody());
  688.             $newSignatureId $newSignatureResponseBody->id;
  689.         }
  690.         catch (\Exception $e) {
  691.             $responseErrorTab[] = $e->getMessage();
  692.         }
  693.         /* -----------------------------------  Add Metadata   ------------------------------------- */
  694.         //Create meta
  695.         $newMetaData = new \stdClass();
  696.         $newMetaData->data = array(
  697.             "membershipId" => $membership->getId()
  698.         );
  699.         try {
  700.             $newMetaDataResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/metadata'
  701.                 [
  702.                     'body' => json_encode($newMetaData),
  703.                     'headers' => [
  704.                         'accept' => 'application/json',
  705.                         'content-type' => 'application/json',
  706.                         'Authorization' => 'Bearer ' $this->yousignApi
  707.                     ],
  708.                 ]
  709.             );
  710.             //201 for create
  711.             $newMetaDataResponseStatusCode $newMetaDataResponse->getStatusCode();
  712.             $newMetaDataResponseBody json_decode($newMetaDataResponse->getBody());
  713.         }
  714.         catch (\Exception $e) {
  715.             $responseErrorTab[] = $e->getMessage();
  716.         }
  717.         /* -----------------------------------  Add Files   ------------------------------------- */
  718.         //Add FIC file
  719.         if ($membership->getDicIsFile() != true) {
  720.             $ficUrl "files/" $customer->getId() . '/' $membership->getFic()->getUrlPdf();
  721.             try {
  722.                 $uploadFicResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents'
  723.                     [
  724.                         'multipart' => [
  725.                             [
  726.                                 'name' => 'nature',
  727.                                 'contents' => 'signable_document'
  728.                             ],
  729.                             [
  730.                                 'name' => 'parse_anchors',
  731.                                 'contents' => 'false'
  732.                             ],
  733.                             [
  734.                                 'name' => 'file',
  735.                                 'filename' => "Fiche d'information et de conseil.pdf",
  736.                                 'contents' => fopen($ficUrl'r'),
  737.                             ]
  738.                         ],
  739.                         'headers' => [
  740.                             'accept' => 'application/json',
  741.                             'Authorization' => 'Bearer ' $this->yousignApi
  742.                         ]
  743.                     ]
  744.                 );
  745.                 $uploadFicResponseBody json_decode($uploadFicResponse->getBody());
  746.                 $uploadFicId $uploadFicResponseBody->id;
  747.             }
  748.             catch (\Exception $e) {
  749.                 $responseErrorTab[] = $e->getMessage();
  750.             }
  751.         }
  752.         //Add BA file
  753.         $baUrl "files/" $customer->getId() . '/' $membership->getBa()->getUrlPdf();
  754.         if($membership->getDicIsFile() != true) {
  755.             $multipart 
  756.             [
  757.                 [
  758.                     'name' => 'nature',
  759.                     'contents' => 'signable_document'
  760.                 ],
  761.                 [
  762.                     'name' => 'parse_anchors',
  763.                     'contents' => 'false'
  764.                 ],
  765.                 [
  766.                     'name' => 'insert_after_id',
  767.                     'contents' => $uploadFicId
  768.                 ],
  769.                 [
  770.                     'name' => 'file',
  771.                     'filename' => "Demande d'adhésion.pdf",
  772.                     'contents' => fopen($baUrl'r'),
  773.                 ]
  774.             ];
  775.         }
  776.         else{
  777.             $multipart 
  778.             [
  779.                 [
  780.                     'name' => 'nature',
  781.                     'contents' => 'signable_document'
  782.                 ],
  783.                 [
  784.                     'name' => 'parse_anchors',
  785.                     'contents' => 'false'
  786.                 ],
  787.                 [
  788.                     'name' => 'file',
  789.                     'filename' => "Demande d'adhésion.pdf",
  790.                     'contents' => fopen($baUrl'r'),
  791.                 ]
  792.             ];
  793.         }
  794.         try {
  795.             $uploadBaResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents'
  796.                 [
  797.                     'multipart' => $multipart,
  798.                     'headers' => [
  799.                         'accept' => 'application/json',
  800.                         'Authorization' => 'Bearer ' $this->yousignApi
  801.                     ]
  802.                 ]
  803.             );
  804.             $uploadBaResponseBody json_decode($uploadBaResponse->getBody());
  805.             $uploadBaId $uploadBaResponseBody->id;
  806.         }
  807.         catch (\Exception $e) {
  808.             $responseErrorTab[] = $e->getMessage();
  809.         }
  810.         //Add SEPA file
  811.         if (($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) && $membership->getBa()->getSepaOriginVersmement() != 2) {
  812.             $sepaUrl "files/" $customer->getId() . '/' $membership->getBa()->getSepaUrlPdf();
  813.             try {
  814.                 $uploadSepaResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents'
  815.                     [
  816.                         'multipart' => [
  817.                             [
  818.                                 'name' => 'nature',
  819.                                 'contents' => 'signable_document'
  820.                             ],
  821.                             [
  822.                                 'name' => 'parse_anchors',
  823.                                 'contents' => 'false'
  824.                             ],
  825.                             [
  826.                                 'name' => 'insert_after_id',
  827.                                 'contents' => $uploadBaId
  828.                             ],
  829.                             [
  830.                                 'name' => 'file',
  831.                                 'filename' => "Mandat de prélèvement SEPA.pdf",
  832.                                 'contents' => fopen($sepaUrl'r'),
  833.                             ]
  834.                         ],
  835.                         'headers' => [
  836.                             'accept' => 'application/json',
  837.                             'Authorization' => 'Bearer ' $this->yousignApi
  838.                         ]
  839.                     ]
  840.                 );
  841.                 $uploadSepaResponseBody json_decode($uploadSepaResponse->getBody());
  842.                 $uploadSepaId $uploadSepaResponseBody->id;
  843.              }
  844.             catch (\Exception $e) {
  845.                 $responseErrorTab[] = $e->getMessage();
  846.             }
  847.         }
  848.         /* -----------------------------------  Add Signers   ------------------------------------- */
  849.         //Add Signer (seller)
  850.         if($membership->getPlatformVersion() == && !$customer->isIsAutoSignup()){
  851.             $seller $membership->getSeller();
  852.             //Add Signer (seller)
  853.             $phone $seller->getPhone();
  854.             $phone str_replace("("""$phone);
  855.             $phone str_replace(")"""$phone);
  856.             $phone str_replace(" """$phone);
  857.             if ($seller->getPhonePrefix()) {
  858.                 $phone $seller->getPhonePrefix() . $phone;
  859.             }
  860.             else{
  861.                 $phone "+33" $phone;
  862.             }
  863.             $newSignerSellerMember = new \stdClass();
  864.             $newSignerSellerMember->locale "fr";
  865.             $newSignerSellerMember->first_name $seller->getFirstName();
  866.             $newSignerSellerMember->last_name $seller->getLastName();
  867.             $newSignerSellerMember->email $seller->getEmail();
  868.             $newSignerSellerMember->phone_number $phone;
  869.             //$newSignerSellerRedirect = new \stdClass();
  870.             //$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end_seller', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  871.             //$newSignerSellerRedirect->success = $urlSignEnd;
  872.             //$newSignerSellerRedirect->error = $urlSignEnd;
  873.             $newSignerSeller = new \stdClass();
  874.             $newSignerSeller->info $newSignerSellerMember;
  875.             $newSignerSeller->signature_level "electronic_signature";
  876.             $newSignerSeller->signature_authentication_mode "otp_email";
  877.             //$newSignerSeller->redirect_urls = $newSignerSellerRedirect;
  878.             try {
  879.                 $newSignerSellerResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers'
  880.                     [
  881.                         'body' => json_encode($newSignerSeller),
  882.                         'headers' => [
  883.                             'accept' => 'application/json',
  884.                             'content-type' => 'application/json',
  885.                             'Authorization' => 'Bearer ' $this->yousignApi
  886.                         ],
  887.                     ]
  888.                 );
  889.                 $newSignerSellerResponseBody json_decode($newSignerSellerResponse->getBody());
  890.                 $newSignerSellerId $newSignerSellerResponseBody->id;
  891.              }
  892.             catch (\Exception $e) {
  893.                 $responseErrorTab[] = $e->getMessage();
  894.             }
  895.         }
  896.         //Add Signer (customer)
  897.         $phone $customer->getPhone();
  898.         $phone str_replace("("""$phone);
  899.         $phone str_replace(")"""$phone);
  900.         $phone str_replace(" """$phone);
  901.         if ($customer->getPhonePrefix()) {
  902.             $phone $customer->getPhonePrefix() . $phone;
  903.         }
  904.         //FirstName
  905.         $customerFirstName $customer->getFirstName();
  906.         $customerFirstName str_replace(","" "$customerFirstName);
  907.         $newSignerCustomerMember = new \stdClass();
  908.         $newSignerCustomerMember->locale "fr";
  909.         $newSignerCustomerMember->first_name $customerFirstName;
  910.         $newSignerCustomerMember->last_name $customer->getLastName();
  911.         $newSignerCustomerMember->email $customer->getEmail();
  912.         $newSignerCustomerMember->phone_number $phone;
  913.         //$newSignerCustomerRedirect = new \stdClass();
  914.         //$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  915.         //$newSignerCustomerRedirect->success = $urlSignEnd;
  916.         //$newSignerCustomerRedirect->error = $urlSignEnd;
  917.         $newSignerCustomer = new \stdClass();
  918.         $newSignerCustomer->info $newSignerCustomerMember;
  919.         $newSignerCustomer->signature_level "electronic_signature";
  920.         if($customer->isMethodForSignEmail()){
  921.             $newSignerCustomer->signature_authentication_mode "otp_email";
  922.         }
  923.         else{
  924.             $newSignerCustomer->signature_authentication_mode "otp_sms";
  925.         }
  926.         //For order
  927.         if($membership->getPlatformVersion() == && !$customer->isIsAutoSignup()){
  928.             $newSignerCustomer->insert_after_id $newSignerSellerId;
  929.         }
  930.         try {
  931.             $newSignerCustomerResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers'
  932.                 [
  933.                     'body' => json_encode($newSignerCustomer),
  934.                     'headers' => [
  935.                         'accept' => 'application/json',
  936.                         'content-type' => 'application/json',
  937.                         'Authorization' => 'Bearer ' $this->yousignApi
  938.                     ],
  939.                 ]
  940.             );
  941.             $newSignerCustomerResponseBody json_decode($newSignerCustomerResponse->getBody());
  942.             $newSignerCustomerId $newSignerCustomerResponseBody->id;
  943.         }
  944.         catch (\Exception $e) {
  945.             $responseErrorTab[] = $e->getMessage();
  946.         }
  947.         //ForLegal1
  948.         if($isLegal1){
  949.             //Add Signer (customer)
  950.             $phone $membership->getBa()->getRepLegal1TelephonePortable();
  951.             $phone str_replace("("""$phone);
  952.             $phone str_replace(")"""$phone);
  953.             $phone str_replace(" """$phone);
  954.             if ($membership->getBa()->getRepLegal1TelephonePortablePrefix()) {
  955.                 $phone $membership->getBa()->getRepLegal1TelephonePortablePrefix() . $phone;
  956.             }
  957.             //FirstName
  958.             $customerFirstName $membership->getBa()->getRepLegal1Prenoms();
  959.             $customerFirstName str_replace(","" "$customerFirstName);
  960.             $newSignerCustomerLegal1Member = new \stdClass();
  961.             $newSignerCustomerLegal1Member->locale "fr";
  962.             $newSignerCustomerLegal1Member->first_name $customerFirstName;
  963.             $newSignerCustomerLegal1Member->last_name $membership->getBa()->getRepLegal1Nom();
  964.             $newSignerCustomerLegal1Member->email $membership->getBa()->getRepLegal1Email();
  965.             $newSignerCustomerLegal1Member->phone_number $phone;
  966.             //$newSignerCustomerRedirect = new \stdClass();
  967.             //$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  968.             //$newSignerCustomerRedirect->success = $urlSignEnd;
  969.             //$newSignerCustomerRedirect->error = $urlSignEnd;
  970.             $newSignerCustomerLegal1 = new \stdClass();
  971.             $newSignerCustomerLegal1->info $newSignerCustomerLegal1Member;
  972.             $newSignerCustomerLegal1->signature_level "electronic_signature";
  973.             $newSignerCustomerLegal1->delivery_mode "email";
  974.             if($customer->isMethodForSignEmail()){
  975.                 $newSignerCustomerLegal1->signature_authentication_mode "otp_email";
  976.             }
  977.             else{
  978.                 $newSignerCustomerLegal1->signature_authentication_mode "otp_sms";
  979.             }
  980.             //For order
  981.             if(!$customer->isIsAutoSignup()){
  982.                 $newSignerCustomerLegal1->insert_after_id $newSignerCustomerId;
  983.             }
  984.             try {
  985.                 $newSignerCustomerLegal1Response $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers'
  986.                     [
  987.                         'body' => json_encode($newSignerCustomerLegal1),
  988.                         'headers' => [
  989.                             'accept' => 'application/json',
  990.                             'content-type' => 'application/json',
  991.                             'Authorization' => 'Bearer ' $this->yousignApi
  992.                         ],
  993.                     ]
  994.                 );
  995.                 $newSignerCustomerLegal1ResponseBody json_decode($newSignerCustomerLegal1Response->getBody());
  996.                 $newSignerCustomerLegal1Id $newSignerCustomerLegal1ResponseBody->id;
  997.             }
  998.             catch (\Exception $e) {
  999.                 $responseErrorTab[] = $e->getMessage();
  1000.             }
  1001.         }
  1002.         //ForLegal2
  1003.         if($isLegal2){
  1004.             //Add Signer (customer)
  1005.             $phone $membership->getBa()->getRepLegal2TelephonePortable();
  1006.             $phone str_replace("("""$phone);
  1007.             $phone str_replace(")"""$phone);
  1008.             $phone str_replace(" """$phone);
  1009.             if ($membership->getBa()->getRepLegal2TelephonePortablePrefix()) {
  1010.                 $phone $membership->getBa()->getRepLegal2TelephonePortablePrefix() . $phone;
  1011.             }
  1012.             //FirstName
  1013.             $customerFirstName $membership->getBa()->getRepLegal2Prenoms();
  1014.             $customerFirstName str_replace(","" "$customerFirstName);
  1015.             $newSignerCustomerLegal2Member = new \stdClass();
  1016.             $newSignerCustomerLegal2Member->locale "fr";
  1017.             $newSignerCustomerLegal2Member->first_name $customerFirstName;
  1018.             $newSignerCustomerLegal2Member->last_name $membership->getBa()->getRepLegal2Nom();
  1019.             $newSignerCustomerLegal2Member->email $membership->getBa()->getRepLegal2Email();
  1020.             $newSignerCustomerLegal2Member->phone_number $phone;
  1021.             //$newSignerCustomerRedirect = new \stdClass();
  1022.             //$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  1023.             //$newSignerCustomerRedirect->success = $urlSignEnd;
  1024.             //$newSignerCustomerRedirect->error = $urlSignEnd;
  1025.             $newSignerCustomerLegal2 = new \stdClass();
  1026.             $newSignerCustomerLegal2->info $newSignerCustomerLegal2Member;
  1027.             $newSignerCustomerLegal2->signature_level "electronic_signature";
  1028.             $newSignerCustomerLegal2->delivery_mode "email";
  1029.             if($customer->isMethodForSignEmail()){
  1030.                 $newSignerCustomerLegal2->signature_authentication_mode "otp_email";
  1031.             }
  1032.             else{
  1033.                 $newSignerCustomerLegal2->signature_authentication_mode "otp_sms";
  1034.             }
  1035.             //For order
  1036.             if(!$customer->isIsAutoSignup()){
  1037.                 $newSignerCustomerLegal2->insert_after_id $newSignerCustomerLegal1Id;
  1038.             }
  1039.             try {
  1040.                 $newSignerCustomerLegal2Response $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers'
  1041.                     [
  1042.                         'body' => json_encode($newSignerCustomerLegal2),
  1043.                         'headers' => [
  1044.                             'accept' => 'application/json',
  1045.                             'content-type' => 'application/json',
  1046.                             'Authorization' => 'Bearer ' $this->yousignApi
  1047.                         ],
  1048.                     ]
  1049.                 );
  1050.                 $newSignerCustomerLegal2ResponseBody json_decode($newSignerCustomerLegal2Response->getBody());
  1051.                 $newSignerCustomerLegal2Id $newSignerCustomerLegal2ResponseBody->id;
  1052.             }
  1053.             catch (\Exception $e) {
  1054.                 $responseErrorTab[] = $e->getMessage();
  1055.             }
  1056.         }
  1057.         /* -----------------------------------  Add Fields   ------------------------------------- */
  1058.         //Add fields on FIC for sgnature
  1059.         //No Allianz customer
  1060.         if ($membership->getDicIsFile() != true) {
  1061.             if($typeProduct == "epargne"){
  1062.                 if($customer->isIsAutoSignup()){
  1063.                     //For customer
  1064.                     $newFieldCustomerSignature = new \stdClass();
  1065.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1066.                     $newFieldCustomerSignature->type "signature";
  1067.                     $newFieldCustomerSignature->page 9;
  1068.                     $newFieldCustomerSignature->width 139;
  1069.                     $newFieldCustomerSignature->height 62;
  1070.                     $newFieldCustomerSignature->35;
  1071.                     $newFieldCustomerSignature->697;
  1072.                     try {
  1073.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1074.                             [
  1075.                                 'body' => json_encode($newFieldCustomerSignature),
  1076.                                 'headers' => [
  1077.                                     'accept' => 'application/json',
  1078.                                     'content-type' => 'application/json',
  1079.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1080.                                 ],
  1081.                             ]
  1082.                         );
  1083.                     }
  1084.                     catch (\Exception $e) {
  1085.                         $responseErrorTab[] = $e->getMessage();
  1086.                     }
  1087.                     //Add fields on FIC for city (customer)
  1088.                     $newFieldCustomerSignature = new \stdClass();
  1089.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1090.                     $newFieldCustomerSignature->type "text";
  1091.                     $newFieldCustomerSignature->max_length 44;
  1092.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1093.                     $newFieldCustomerSignature->page 9;
  1094.                     $newFieldCustomerSignature->width 202;
  1095.                     $newFieldCustomerSignature->height 18;
  1096.                     $newFieldCustomerSignature->49;
  1097.                     $newFieldCustomerSignature->540;
  1098.                     try {
  1099.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1100.                             [
  1101.                                 'body' => json_encode($newFieldCustomerSignature),
  1102.                                 'headers' => [
  1103.                                     'accept' => 'application/json',
  1104.                                     'content-type' => 'application/json',
  1105.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1106.                                 ],
  1107.                             ]
  1108.                         );
  1109.                     }
  1110.                     catch (\Exception $e) {
  1111.                         $responseErrorTab[] = $e->getMessage();
  1112.                     }
  1113.                     //Add fields on FIC for date (customer)
  1114.                     $newFieldCustomerSignature = new \stdClass();
  1115.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1116.                     $newFieldCustomerSignature->type "mention";
  1117.                     $newFieldCustomerSignature->mention "%date%";
  1118.                     $newFieldCustomerSignature->font $fontDefault;
  1119.                     $newFieldCustomerSignature->page 9;
  1120.                     $newFieldCustomerSignature->width 202;
  1121.                     $newFieldCustomerSignature->height 18;
  1122.                     $newFieldCustomerSignature->50;
  1123.                     $newFieldCustomerSignature->582;
  1124.                     try {
  1125.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1126.                             [
  1127.                                 'body' => json_encode($newFieldCustomerSignature),
  1128.                                 'headers' => [
  1129.                                     'accept' => 'application/json',
  1130.                                     'content-type' => 'application/json',
  1131.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1132.                                 ],
  1133.                             ]
  1134.                         );
  1135.                     }
  1136.                     catch (\Exception $e) {
  1137.                         $responseErrorTab[] = $e->getMessage();
  1138.                     }
  1139.                 }
  1140.                 else{
  1141.                     //For seller
  1142.                     $newFieldSellerSignature = new \stdClass();
  1143.                     $newFieldSellerSignature->signer_id $newSignerSellerId;
  1144.                     $newFieldSellerSignature->type "signature";
  1145.                     $newFieldSellerSignature->page 12;
  1146.                     $newFieldSellerSignature->width 123;
  1147.                     $newFieldSellerSignature->height 66;
  1148.                     $newFieldSellerSignature->414;
  1149.                     $newFieldSellerSignature->611;
  1150.                     try {
  1151.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1152.                             [
  1153.                                 'body' => json_encode($newFieldSellerSignature),
  1154.                                 'headers' => [
  1155.                                     'accept' => 'application/json',
  1156.                                     'content-type' => 'application/json',
  1157.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1158.                                 ],
  1159.                             ]
  1160.                         );
  1161.                     }
  1162.                     catch (\Exception $e) {
  1163.                         $responseErrorTab[] = $e->getMessage();
  1164.                     }
  1165.                     //For customer
  1166.                     $newFieldCustomerSignature = new \stdClass();
  1167.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1168.                     $newFieldCustomerSignature->type "signature";
  1169.                     $newFieldCustomerSignature->page 12;
  1170.                     $newFieldCustomerSignature->width 212;
  1171.                     $newFieldCustomerSignature->height 42;
  1172.                     $newFieldCustomerSignature->36;
  1173.                     $newFieldCustomerSignature->574;
  1174.                     try {
  1175.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1176.                             [
  1177.                                 'body' => json_encode($newFieldCustomerSignature),
  1178.                                 'headers' => [
  1179.                                     'accept' => 'application/json',
  1180.                                     'content-type' => 'application/json',
  1181.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1182.                                 ],
  1183.                             ]
  1184.                         );
  1185.                     }
  1186.                     catch (\Exception $e) {
  1187.                         $responseErrorTab[] = $e->getMessage();
  1188.                     }
  1189.                     //Add fields on FIC for city (customer)
  1190.                     $newFieldCustomerSignature = new \stdClass();
  1191.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1192.                     $newFieldCustomerSignature->type "text";
  1193.                     $newFieldCustomerSignature->max_length 44;
  1194.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1195.                     $newFieldCustomerSignature->page 12;
  1196.                     $newFieldCustomerSignature->width 149;
  1197.                     $newFieldCustomerSignature->height 19;
  1198.                     $newFieldCustomerSignature->51;
  1199.                     $newFieldCustomerSignature->473;
  1200.                     try {
  1201.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1202.                             [
  1203.                                 'body' => json_encode($newFieldCustomerSignature),
  1204.                                 'headers' => [
  1205.                                     'accept' => 'application/json',
  1206.                                     'content-type' => 'application/json',
  1207.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1208.                                 ],
  1209.                             ]
  1210.                         );
  1211.                     }
  1212.                     catch (\Exception $e) {
  1213.                         $responseErrorTab[] = $e->getMessage();
  1214.                     }
  1215.                     //Add fields on FIC for date (customer)
  1216.                     $newFieldCustomerSignature = new \stdClass();
  1217.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1218.                     $newFieldCustomerSignature->type "mention";
  1219.                     $newFieldCustomerSignature->mention "%date%";
  1220.                     $newFieldCustomerSignature->font $fontDefault;
  1221.                     $newFieldCustomerSignature->page 12;
  1222.                     $newFieldCustomerSignature->width 149;
  1223.                     $newFieldCustomerSignature->height 19;
  1224.                     $newFieldCustomerSignature->51;
  1225.                     $newFieldCustomerSignature->509;
  1226.                     try {
  1227.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1228.                             [
  1229.                                 'body' => json_encode($newFieldCustomerSignature),
  1230.                                 'headers' => [
  1231.                                     'accept' => 'application/json',
  1232.                                     'content-type' => 'application/json',
  1233.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1234.                                 ],
  1235.                             ]
  1236.                         );
  1237.                     }
  1238.                     catch (\Exception $e) {
  1239.                         $responseErrorTab[] = $e->getMessage();
  1240.                     }
  1241.                     //ForLegal1
  1242.                     if($isLegal1){
  1243.                         $newFieldCustomerLegal1Signature = new \stdClass();
  1244.                         $newFieldCustomerLegal1Signature->signer_id $newSignerCustomerLegal1Id;
  1245.                         $newFieldCustomerLegal1Signature->type "signature";
  1246.                         $newFieldCustomerLegal1Signature->page 12;
  1247.                         $newFieldCustomerLegal1Signature->width 112;
  1248.                         $newFieldCustomerLegal1Signature->height 42;
  1249.                         $newFieldCustomerLegal1Signature->36;
  1250.                         $newFieldCustomerLegal1Signature->672;
  1251.                         try {
  1252.                             $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1253.                                 [
  1254.                                     'body' => json_encode($newFieldCustomerLegal1Signature),
  1255.                                     'headers' => [
  1256.                                         'accept' => 'application/json',
  1257.                                         'content-type' => 'application/json',
  1258.                                         'Authorization' => 'Bearer ' $this->yousignApi
  1259.                                     ],
  1260.                                 ]
  1261.                             );
  1262.                         }
  1263.                         catch (\Exception $e) {
  1264.                             $responseErrorTab[] = $e->getMessage();
  1265.                         }
  1266.                     }
  1267.                     //ForLegal2
  1268.                     if($isLegal2){
  1269.                         $newFieldCustomerLegal2Signature = new \stdClass();
  1270.                         $newFieldCustomerLegal2Signature->signer_id $newSignerCustomerLegal2Id;
  1271.                         $newFieldCustomerLegal2Signature->type "signature";
  1272.                         $newFieldCustomerLegal2Signature->page 12;
  1273.                         $newFieldCustomerLegal2Signature->width 112;
  1274.                         $newFieldCustomerLegal2Signature->height 42;
  1275.                         $newFieldCustomerLegal2Signature->36;
  1276.                         $newFieldCustomerLegal2Signature->743;
  1277.                         try {
  1278.                             $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1279.                                 [
  1280.                                     'body' => json_encode($newFieldCustomerLegal2Signature),
  1281.                                     'headers' => [
  1282.                                         'accept' => 'application/json',
  1283.                                         'content-type' => 'application/json',
  1284.                                         'Authorization' => 'Bearer ' $this->yousignApi
  1285.                                     ],
  1286.                                 ]
  1287.                             );
  1288.                         }
  1289.                         catch (\Exception $e) {
  1290.                             $responseErrorTab[] = $e->getMessage();
  1291.                         }
  1292.                     }
  1293.                 }
  1294.             }
  1295.             else {
  1296.                 //For v2 with seller
  1297.                 if($membership->getPlatformVersion() == && !$customer->isIsAutoSignup()){
  1298.                     //For seller
  1299.                     $newFieldSellerSignature = new \stdClass();
  1300.                     $newFieldSellerSignature->signer_id $newSignerSellerId;
  1301.                     $newFieldSellerSignature->type "signature";
  1302.                     $newFieldSellerSignature->page 9;
  1303.                     $newFieldSellerSignature->width 194;
  1304.                     $newFieldSellerSignature->height 88;
  1305.                     $newFieldSellerSignature->355;
  1306.                     $newFieldSellerSignature->558;
  1307.                     try {
  1308.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1309.                             [
  1310.                                 'body' => json_encode($newFieldSellerSignature),
  1311.                                 'headers' => [
  1312.                                     'accept' => 'application/json',
  1313.                                     'content-type' => 'application/json',
  1314.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1315.                                 ],
  1316.                             ]
  1317.                         );
  1318.                     }
  1319.                     catch (\Exception $e) {
  1320.                         $responseErrorTab[] = $e->getMessage();
  1321.                     }
  1322.                     /* --------------------------------------------------- */
  1323.                     //For customer
  1324.                     $newFieldCustomerSignature = new \stdClass();
  1325.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1326.                     $newFieldCustomerSignature->type "signature";
  1327.                     $newFieldCustomerSignature->page 9;
  1328.                     $newFieldCustomerSignature->width 194;
  1329.                     $newFieldCustomerSignature->height 88;
  1330.                     $newFieldCustomerSignature->62;
  1331.                     $newFieldCustomerSignature->558;
  1332.                     try {
  1333.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1334.                             [
  1335.                                 'body' => json_encode($newFieldCustomerSignature),
  1336.                                 'headers' => [
  1337.                                     'accept' => 'application/json',
  1338.                                     'content-type' => 'application/json',
  1339.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1340.                                 ],
  1341.                             ]
  1342.                         );
  1343.                     }
  1344.                     catch (\Exception $e) {
  1345.                         $responseErrorTab[] = $e->getMessage();
  1346.                     }
  1347.                     //Add fields on FIC for city (customer)
  1348.                     $newFieldCustomerSignature = new \stdClass();
  1349.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1350.                     $newFieldCustomerSignature->type "text";
  1351.                     $newFieldCustomerSignature->max_length 44;
  1352.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1353.                     $newFieldCustomerSignature->page 9;
  1354.                     $newFieldCustomerSignature->width 286;
  1355.                     $newFieldCustomerSignature->height 24;
  1356.                     $newFieldCustomerSignature->68;
  1357.                     $newFieldCustomerSignature->377;
  1358.                     try {
  1359.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1360.                             [
  1361.                                 'body' => json_encode($newFieldCustomerSignature),
  1362.                                 'headers' => [
  1363.                                     'accept' => 'application/json',
  1364.                                     'content-type' => 'application/json',
  1365.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1366.                                 ],
  1367.                             ]
  1368.                         );
  1369.                     }
  1370.                     catch (\Exception $e) {
  1371.                         $responseErrorTab[] = $e->getMessage();
  1372.                     }
  1373.                     //Add fields on FIC for date (customer)
  1374.                     $newFieldCustomerSignature = new \stdClass();
  1375.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1376.                     $newFieldCustomerSignature->type "mention";
  1377.                     $newFieldCustomerSignature->mention "%date%";
  1378.                     $newFieldCustomerSignature->font $fontDefault;
  1379.                     $newFieldCustomerSignature->page 9;
  1380.                     $newFieldCustomerSignature->width 286;
  1381.                     $newFieldCustomerSignature->height 24;
  1382.                     $newFieldCustomerSignature->68;
  1383.                     $newFieldCustomerSignature->405;
  1384.                     try {
  1385.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1386.                             [
  1387.                                 'body' => json_encode($newFieldCustomerSignature),
  1388.                                 'headers' => [
  1389.                                     'accept' => 'application/json',
  1390.                                     'content-type' => 'application/json',
  1391.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1392.                                 ],
  1393.                             ]
  1394.                         );
  1395.                     }
  1396.                     catch (\Exception $e) {
  1397.                         $responseErrorTab[] = $e->getMessage();
  1398.                     }
  1399.                 }
  1400.                 else{
  1401.                     //For customer
  1402.                     $newFieldCustomerSignature = new \stdClass();
  1403.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1404.                     $newFieldCustomerSignature->type "signature";
  1405.                     $newFieldCustomerSignature->page 9;
  1406.                     $newFieldCustomerSignature->width 160;
  1407.                     $newFieldCustomerSignature->height 94;
  1408.                     $newFieldCustomerSignature->78;
  1409.                     $newFieldCustomerSignature->554;
  1410.                     try {
  1411.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1412.                             [
  1413.                                 'body' => json_encode($newFieldCustomerSignature),
  1414.                                 'headers' => [
  1415.                                     'accept' => 'application/json',
  1416.                                     'content-type' => 'application/json',
  1417.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1418.                                 ],
  1419.                             ]
  1420.                         );
  1421.                     }
  1422.                     catch (\Exception $e) {
  1423.                         $responseErrorTab[] = $e->getMessage();
  1424.                     }
  1425.                     //Add fields on FIC for city (customer)
  1426.                     $newFieldCustomerSignature = new \stdClass();
  1427.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1428.                     $newFieldCustomerSignature->type "text";
  1429.                     $newFieldCustomerSignature->max_length 44;
  1430.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1431.                     $newFieldCustomerSignature->page 9;
  1432.                     $newFieldCustomerSignature->width 286;
  1433.                     $newFieldCustomerSignature->height 24;
  1434.                     $newFieldCustomerSignature->68;
  1435.                     $newFieldCustomerSignature->378;
  1436.                     try {
  1437.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1438.                             [
  1439.                                 'body' => json_encode($newFieldCustomerSignature),
  1440.                                 'headers' => [
  1441.                                     'accept' => 'application/json',
  1442.                                     'content-type' => 'application/json',
  1443.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1444.                                 ],
  1445.                             ]
  1446.                         );
  1447.                     }
  1448.                     catch (\Exception $e) {
  1449.                         $responseErrorTab[] = $e->getMessage();
  1450.                     }
  1451.                     //Add fields on FIC for date (customer)
  1452.                     $newFieldCustomerSignature = new \stdClass();
  1453.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1454.                     $newFieldCustomerSignature->type "mention";
  1455.                     $newFieldCustomerSignature->mention "%date%";
  1456.                     $newFieldCustomerSignature->font $fontDefault;
  1457.                     $newFieldCustomerSignature->page 9;
  1458.                     $newFieldCustomerSignature->width 286;
  1459.                     $newFieldCustomerSignature->height 24;
  1460.                     $newFieldCustomerSignature->68;
  1461.                     $newFieldCustomerSignature->405;
  1462.                     try {
  1463.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1464.                             [
  1465.                                 'body' => json_encode($newFieldCustomerSignature),
  1466.                                 'headers' => [
  1467.                                     'accept' => 'application/json',
  1468.                                     'content-type' => 'application/json',
  1469.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1470.                                 ],
  1471.                             ]
  1472.                         );
  1473.                     }
  1474.                     catch (\Exception $e) {
  1475.                         $responseErrorTab[] = $e->getMessage();
  1476.                     }
  1477.                 }
  1478.             }
  1479.             
  1480.         }
  1481.         if($typeProduct == "epargne"){
  1482.             if($customer->isIsAutoSignup()){
  1483.                 //Add fields on BA for sgnature (customer)
  1484.                 $newFieldCustomerSignature = new \stdClass();
  1485.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1486.                 $newFieldCustomerSignature->type "signature";
  1487.                 $newFieldCustomerSignature->page 7;
  1488.                 $newFieldCustomerSignature->width 185;
  1489.                 $newFieldCustomerSignature->height 69;
  1490.                 $newFieldCustomerSignature->266;
  1491.                 $newFieldCustomerSignature->573;
  1492.                 try {
  1493.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1494.                         [
  1495.                             'body' => json_encode($newFieldCustomerSignature),
  1496.                             'headers' => [
  1497.                                 'accept' => 'application/json',
  1498.                                 'content-type' => 'application/json',
  1499.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1500.                             ],
  1501.                         ]
  1502.                     );
  1503.                 }
  1504.                 catch (\Exception $e) {
  1505.                     $responseErrorTab[] = $e->getMessage();
  1506.                 }
  1507.                 //Add fields on BA for city (customer)
  1508.                 $newFieldCustomerSignature = new \stdClass();
  1509.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1510.                 $newFieldCustomerSignature->type "text";
  1511.                 $newFieldCustomerSignature->max_length 44;
  1512.                 $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1513.                 $newFieldCustomerSignature->page 7;
  1514.                 $newFieldCustomerSignature->width 196;
  1515.                 $newFieldCustomerSignature->height 19;
  1516.                 $newFieldCustomerSignature->51;
  1517.                 $newFieldCustomerSignature->573;
  1518.                 try {
  1519.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1520.                         [
  1521.                             'body' => json_encode($newFieldCustomerSignature),
  1522.                             'headers' => [
  1523.                                 'accept' => 'application/json',
  1524.                                 'content-type' => 'application/json',
  1525.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1526.                             ],
  1527.                         ]
  1528.                     );
  1529.                 }
  1530.                 catch (\Exception $e) {
  1531.                     $responseErrorTab[] = $e->getMessage();
  1532.                 }
  1533.                 //Add fields on BA for date (customer)
  1534.                 $newFieldCustomerSignature = new \stdClass();
  1535.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1536.                 $newFieldCustomerSignature->type "mention";
  1537.                 $newFieldCustomerSignature->font $fontDefault;
  1538.                 $newFieldCustomerSignature->mention "%date%";
  1539.                 $newFieldCustomerSignature->page 7;
  1540.                 $newFieldCustomerSignature->width 196;
  1541.                 $newFieldCustomerSignature->height 19;
  1542.                 $newFieldCustomerSignature->51;
  1543.                 $newFieldCustomerSignature->603;
  1544.                 try {
  1545.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1546.                         [
  1547.                             'body' => json_encode($newFieldCustomerSignature),
  1548.                             'headers' => [
  1549.                                 'accept' => 'application/json',
  1550.                                 'content-type' => 'application/json',
  1551.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1552.                             ],
  1553.                         ]
  1554.                     );
  1555.                 }
  1556.                 catch (\Exception $e) {
  1557.                     $responseErrorTab[] = $e->getMessage();
  1558.                 }
  1559.             }
  1560.             else{
  1561.                 //Add fields on BA for sgnature (customer)
  1562.                 $newFieldCustomerSignature = new \stdClass();
  1563.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1564.                 $newFieldCustomerSignature->type "signature";
  1565.                 $newFieldCustomerSignature->page 8;
  1566.                 $newFieldCustomerSignature->width 99;
  1567.                 $newFieldCustomerSignature->height 39;
  1568.                 $newFieldCustomerSignature->251;
  1569.                 $newFieldCustomerSignature->568;
  1570.                 try {
  1571.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1572.                         [
  1573.                             'body' => json_encode($newFieldCustomerSignature),
  1574.                             'headers' => [
  1575.                                 'accept' => 'application/json',
  1576.                                 'content-type' => 'application/json',
  1577.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1578.                             ],
  1579.                         ]
  1580.                     );
  1581.                 }
  1582.                 catch (\Exception $e) {
  1583.                     $responseErrorTab[] = $e->getMessage();
  1584.                 }
  1585.                 //Legal 1 BA
  1586.                 if($isLegal1){
  1587.                     //Add fields on BA for sgnature (customer)
  1588.                     $newFieldCustomerLegal1Signature = new \stdClass();
  1589.                     $newFieldCustomerLegal1Signature->signer_id $newSignerCustomerLegal1Id;
  1590.                     $newFieldCustomerLegal1Signature->type "signature";
  1591.                     $newFieldCustomerLegal1Signature->page 8;
  1592.                     $newFieldCustomerLegal1Signature->width 99;
  1593.                     $newFieldCustomerLegal1Signature->height 39;
  1594.                     $newFieldCustomerLegal1Signature->251;
  1595.                     $newFieldCustomerLegal1Signature->679;
  1596.                     try {
  1597.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1598.                             [
  1599.                                 'body' => json_encode($newFieldCustomerLegal1Signature),
  1600.                                 'headers' => [
  1601.                                     'accept' => 'application/json',
  1602.                                     'content-type' => 'application/json',
  1603.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1604.                                 ],
  1605.                             ]
  1606.                         );
  1607.                     }
  1608.                     catch (\Exception $e) {
  1609.                         $responseErrorTab[] = $e->getMessage();
  1610.                     }
  1611.                 }
  1612.                 //Legal 2 BA
  1613.                 if($isLegal2){
  1614.                     //Add fields on BA for sgnature (customer)
  1615.                     $newFieldCustomerLegal2Signature = new \stdClass();
  1616.                     $newFieldCustomerLegal2Signature->signer_id $newSignerCustomerLegal2Id;
  1617.                     $newFieldCustomerLegal2Signature->type "signature";
  1618.                     $newFieldCustomerLegal2Signature->page 8;
  1619.                     $newFieldCustomerLegal2Signature->width 99;
  1620.                     $newFieldCustomerLegal2Signature->height 39;
  1621.                     $newFieldCustomerLegal2Signature->251;
  1622.                     $newFieldCustomerLegal2Signature->767;
  1623.                     try {
  1624.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1625.                             [
  1626.                                 'body' => json_encode($newFieldCustomerLegal2Signature),
  1627.                                 'headers' => [
  1628.                                     'accept' => 'application/json',
  1629.                                     'content-type' => 'application/json',
  1630.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1631.                                 ],
  1632.                             ]
  1633.                         );
  1634.                     }
  1635.                     catch (\Exception $e) {
  1636.                         $responseErrorTab[] = $e->getMessage();
  1637.                     }
  1638.                 }
  1639.                 //Add fields on BA for city (customer)
  1640.                 $newFieldCustomerSignature = new \stdClass();
  1641.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1642.                 $newFieldCustomerSignature->type "text";
  1643.                 $newFieldCustomerSignature->max_length 44;
  1644.                 $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1645.                 $newFieldCustomerSignature->page 8;
  1646.                 $newFieldCustomerSignature->width 170;
  1647.                 $newFieldCustomerSignature->height 20;
  1648.                 $newFieldCustomerSignature->52;
  1649.                 $newFieldCustomerSignature->571;
  1650.                 try {
  1651.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1652.                         [
  1653.                             'body' => json_encode($newFieldCustomerSignature),
  1654.                             'headers' => [
  1655.                                 'accept' => 'application/json',
  1656.                                 'content-type' => 'application/json',
  1657.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1658.                             ],
  1659.                         ]
  1660.                     );
  1661.                 }
  1662.                 catch (\Exception $e) {
  1663.                     $responseErrorTab[] = $e->getMessage();
  1664.                 }
  1665.                 //Add fields on BA for date (customer)
  1666.                 $newFieldCustomerSignature = new \stdClass();
  1667.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1668.                 $newFieldCustomerSignature->type "mention";
  1669.                 $newFieldCustomerSignature->font $fontDefault;
  1670.                 $newFieldCustomerSignature->mention "%date%";
  1671.                 $newFieldCustomerSignature->page 8;
  1672.                 $newFieldCustomerSignature->width 170;
  1673.                 $newFieldCustomerSignature->height 20;
  1674.                 $newFieldCustomerSignature->52;
  1675.                 $newFieldCustomerSignature->599;
  1676.                 try {
  1677.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1678.                         [
  1679.                             'body' => json_encode($newFieldCustomerSignature),
  1680.                             'headers' => [
  1681.                                 'accept' => 'application/json',
  1682.                                 'content-type' => 'application/json',
  1683.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1684.                             ],
  1685.                         ]
  1686.                     );
  1687.                 }
  1688.                 catch (\Exception $e) {
  1689.                     $responseErrorTab[] = $e->getMessage();
  1690.                 }
  1691.             }
  1692.             //Benef on BA (customer)
  1693.             if(($membership->getBa()->isTypeBeneficiaires() == true && !$membership->getBa()->isTypeBeneficiairesClauseNotariee()) || $membership->getBa()->getTypeBeneficiairesBychoices() == 2){
  1694.                 if($customer->isIsAutoSignup()){
  1695.                     $benefPage 9;
  1696.                 }
  1697.                 else{
  1698.                     $benefPage 10;
  1699.                 }
  1700.                 //Signature (customer)
  1701.                 $newFieldCustomerSignature = new \stdClass();
  1702.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1703.                 $newFieldCustomerSignature->type "signature";
  1704.                 $newFieldCustomerSignature->page $benefPage;
  1705.                 $newFieldCustomerSignature->width 156;
  1706.                 $newFieldCustomerSignature->height 64;
  1707.                 $newFieldCustomerSignature->339;
  1708.                 $newFieldCustomerSignature->708;
  1709.                 try {
  1710.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1711.                         [
  1712.                             'body' => json_encode($newFieldCustomerSignature),
  1713.                             'headers' => [
  1714.                                 'accept' => 'application/json',
  1715.                                 'content-type' => 'application/json',
  1716.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1717.                             ],
  1718.                         ]
  1719.                     );
  1720.                 }
  1721.                 catch (\Exception $e) {
  1722.                     $responseErrorTab[] = $e->getMessage();
  1723.                 }
  1724.                 if($customer->isIsAutoSignup()){
  1725.                     //City (customer)
  1726.                     $newFieldCustomerSignature = new \stdClass();
  1727.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1728.                     $newFieldCustomerSignature->type "text";
  1729.                     $newFieldCustomerSignature->max_length 44;
  1730.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1731.                     $newFieldCustomerSignature->page $benefPage;
  1732.                     $newFieldCustomerSignature->width 272;
  1733.                     $newFieldCustomerSignature->height 24;
  1734.                     $newFieldCustomerSignature->49;
  1735.                     $newFieldCustomerSignature->670;
  1736.                     try {
  1737.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1738.                             [
  1739.                                 'body' => json_encode($newFieldCustomerSignature),
  1740.                                 'headers' => [
  1741.                                     'accept' => 'application/json',
  1742.                                     'content-type' => 'application/json',
  1743.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1744.                                 ],
  1745.                             ]
  1746.                         );
  1747.                     }
  1748.                     catch (\Exception $e) {
  1749.                         $responseErrorTab[] = $e->getMessage();
  1750.                     }
  1751.                     //Date (customer)
  1752.                     $newFieldCustomerSignature = new \stdClass();
  1753.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1754.                     $newFieldCustomerSignature->type "mention";
  1755.                     $newFieldCustomerSignature->font $fontDefault;
  1756.                     $newFieldCustomerSignature->mention "%date%";
  1757.                     $newFieldCustomerSignature->page $benefPage;
  1758.                     $newFieldCustomerSignature->width 272;
  1759.                     $newFieldCustomerSignature->height 24;
  1760.                     $newFieldCustomerSignature->49;
  1761.                     $newFieldCustomerSignature->702;
  1762.                     try {
  1763.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1764.                             [
  1765.                                 'body' => json_encode($newFieldCustomerSignature),
  1766.                                 'headers' => [
  1767.                                     'accept' => 'application/json',
  1768.                                     'content-type' => 'application/json',
  1769.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1770.                                 ],
  1771.                             ]
  1772.                         );
  1773.                     }
  1774.                     catch (\Exception $e) {
  1775.                         $responseErrorTab[] = $e->getMessage();
  1776.                     }
  1777.                 }
  1778.                 else{
  1779.                     //City (customer)
  1780.                     $newFieldCustomerSignature = new \stdClass();
  1781.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1782.                     $newFieldCustomerSignature->type "text";
  1783.                     $newFieldCustomerSignature->max_length 44;
  1784.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1785.                     $newFieldCustomerSignature->page $benefPage;
  1786.                     $newFieldCustomerSignature->width 272;
  1787.                     $newFieldCustomerSignature->height 24;
  1788.                     $newFieldCustomerSignature->49;
  1789.                     $newFieldCustomerSignature->669;
  1790.                     try {
  1791.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1792.                             [
  1793.                                 'body' => json_encode($newFieldCustomerSignature),
  1794.                                 'headers' => [
  1795.                                     'accept' => 'application/json',
  1796.                                     'content-type' => 'application/json',
  1797.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1798.                                 ],
  1799.                             ]
  1800.                         );
  1801.                     }
  1802.                     catch (\Exception $e) {
  1803.                         $responseErrorTab[] = $e->getMessage();
  1804.                     }
  1805.                     //Date (customer)
  1806.                     $newFieldCustomerSignature = new \stdClass();
  1807.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1808.                     $newFieldCustomerSignature->type "mention";
  1809.                     $newFieldCustomerSignature->font $fontDefault;
  1810.                     $newFieldCustomerSignature->mention "%date%";
  1811.                     $newFieldCustomerSignature->page $benefPage;
  1812.                     $newFieldCustomerSignature->width 272;
  1813.                     $newFieldCustomerSignature->height 24;
  1814.                     $newFieldCustomerSignature->49;
  1815.                     $newFieldCustomerSignature->704;
  1816.                     try {
  1817.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1818.                             [
  1819.                                 'body' => json_encode($newFieldCustomerSignature),
  1820.                                 'headers' => [
  1821.                                     'accept' => 'application/json',
  1822.                                     'content-type' => 'application/json',
  1823.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1824.                                 ],
  1825.                             ]
  1826.                         );
  1827.                     }
  1828.                     catch (\Exception $e) {
  1829.                         $responseErrorTab[] = $e->getMessage();
  1830.                     }
  1831.                 }
  1832.             }
  1833.         }
  1834.         else {
  1835.             //Add fields on BA for sgnature (customer)
  1836.             $newFieldCustomerSignature = new \stdClass();
  1837.             $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1838.             $newFieldCustomerSignature->type "signature";
  1839.             $newFieldCustomerSignature->page 7;
  1840.             $newFieldCustomerSignature->width 187;
  1841.             $newFieldCustomerSignature->height 97;
  1842.             $newFieldCustomerSignature->339;
  1843.             $newFieldCustomerSignature->423;
  1844.             try {
  1845.                 $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1846.                     [
  1847.                         'body' => json_encode($newFieldCustomerSignature),
  1848.                         'headers' => [
  1849.                             'accept' => 'application/json',
  1850.                             'content-type' => 'application/json',
  1851.                             'Authorization' => 'Bearer ' $this->yousignApi
  1852.                         ],
  1853.                     ]
  1854.                 );
  1855.             }
  1856.             catch (\Exception $e) {
  1857.                 $responseErrorTab[] = $e->getMessage();
  1858.             }
  1859.             if($customer->isIsAutoSignup()){
  1860.                 //Add fields on BA for city (customer)
  1861.                 $newFieldCustomerSignature = new \stdClass();
  1862.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1863.                 $newFieldCustomerSignature->type "text";
  1864.                 $newFieldCustomerSignature->max_length 44;
  1865.                 $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1866.                 $newFieldCustomerSignature->page 7;
  1867.                 $newFieldCustomerSignature->width 272;
  1868.                 $newFieldCustomerSignature->height 24;
  1869.                 $newFieldCustomerSignature->48;
  1870.                 $newFieldCustomerSignature->420;
  1871.                 try {
  1872.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1873.                         [
  1874.                             'body' => json_encode($newFieldCustomerSignature),
  1875.                             'headers' => [
  1876.                                 'accept' => 'application/json',
  1877.                                 'content-type' => 'application/json',
  1878.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1879.                             ],
  1880.                         ]
  1881.                     );
  1882.                 }
  1883.                 catch (\Exception $e) {
  1884.                     $responseErrorTab[] = $e->getMessage();
  1885.                 }
  1886.                 //Add fields on BA for date (customer)
  1887.                 $newFieldCustomerSignature = new \stdClass();
  1888.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1889.                 $newFieldCustomerSignature->type "mention";
  1890.                 $newFieldCustomerSignature->font $fontDefault;
  1891.                 $newFieldCustomerSignature->mention "%date%";
  1892.                 $newFieldCustomerSignature->page 7;
  1893.                 $newFieldCustomerSignature->width 272;
  1894.                 $newFieldCustomerSignature->height 24;
  1895.                 $newFieldCustomerSignature->48;
  1896.                 $newFieldCustomerSignature->450;
  1897.                 try {
  1898.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1899.                         [
  1900.                             'body' => json_encode($newFieldCustomerSignature),
  1901.                             'headers' => [
  1902.                                 'accept' => 'application/json',
  1903.                                 'content-type' => 'application/json',
  1904.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1905.                             ],
  1906.                         ]
  1907.                     );
  1908.                 }
  1909.                 catch (\Exception $e) {
  1910.                     $responseErrorTab[] = $e->getMessage();
  1911.                 }
  1912.             }
  1913.             else{
  1914.                 //Add fields on BA for city (customer)
  1915.                 $newFieldCustomerSignature = new \stdClass();
  1916.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1917.                 $newFieldCustomerSignature->type "text";
  1918.                 $newFieldCustomerSignature->max_length 44;
  1919.                 $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1920.                 $newFieldCustomerSignature->page 7;
  1921.                 $newFieldCustomerSignature->width 272;
  1922.                 $newFieldCustomerSignature->height 24;
  1923.                 $newFieldCustomerSignature->50;
  1924.                 $newFieldCustomerSignature->420;
  1925.                 try {
  1926.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1927.                         [
  1928.                             'body' => json_encode($newFieldCustomerSignature),
  1929.                             'headers' => [
  1930.                                 'accept' => 'application/json',
  1931.                                 'content-type' => 'application/json',
  1932.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1933.                             ],
  1934.                         ]
  1935.                     );
  1936.                 }
  1937.                 catch (\Exception $e) {
  1938.                     $responseErrorTab[] = $e->getMessage();
  1939.                 }
  1940.                 //Add fields on BA for date (customer)
  1941.                 $newFieldCustomerSignature = new \stdClass();
  1942.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1943.                 $newFieldCustomerSignature->type "mention";
  1944.                 $newFieldCustomerSignature->font $fontDefault;
  1945.                 $newFieldCustomerSignature->mention "%date%";
  1946.                 $newFieldCustomerSignature->page 7;
  1947.                 $newFieldCustomerSignature->width 272;
  1948.                 $newFieldCustomerSignature->height 24;
  1949.                 $newFieldCustomerSignature->49;
  1950.                 $newFieldCustomerSignature->453;
  1951.                 try {
  1952.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1953.                         [
  1954.                             'body' => json_encode($newFieldCustomerSignature),
  1955.                             'headers' => [
  1956.                                 'accept' => 'application/json',
  1957.                                 'content-type' => 'application/json',
  1958.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1959.                             ],
  1960.                         ]
  1961.                     );
  1962.                 }
  1963.                 catch (\Exception $e) {
  1964.                     $responseErrorTab[] = $e->getMessage();
  1965.                 }
  1966.             }
  1967.             //Benef on BA (customer)
  1968.             if(($membership->getBa()->isTypeBeneficiaires() == true && !$membership->getBa()->isTypeBeneficiairesClauseNotariee()) || $membership->getBa()->getTypeBeneficiairesBychoices() == 2){
  1969.                 $benefPage 9;
  1970.                 //Signature (customer)
  1971.                 $newFieldCustomerSignature = new \stdClass();
  1972.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1973.                 $newFieldCustomerSignature->type "signature";
  1974.                 $newFieldCustomerSignature->page $benefPage;
  1975.                 $newFieldCustomerSignature->width 156;
  1976.                 $newFieldCustomerSignature->height 64;
  1977.                 $newFieldCustomerSignature->339;
  1978.                 $newFieldCustomerSignature->708;
  1979.                 try {
  1980.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1981.                         [
  1982.                             'body' => json_encode($newFieldCustomerSignature),
  1983.                             'headers' => [
  1984.                                 'accept' => 'application/json',
  1985.                                 'content-type' => 'application/json',
  1986.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1987.                             ],
  1988.                         ]
  1989.                     );
  1990.                 }
  1991.                 catch (\Exception $e) {
  1992.                     $responseErrorTab[] = $e->getMessage();
  1993.                 }
  1994.                 if($customer->isIsAutoSignup()){
  1995.                     //City (customer)
  1996.                     $newFieldCustomerSignature = new \stdClass();
  1997.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1998.                     $newFieldCustomerSignature->type "text";
  1999.                     $newFieldCustomerSignature->max_length 44;
  2000.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  2001.                     $newFieldCustomerSignature->page $benefPage;
  2002.                     $newFieldCustomerSignature->width 272;
  2003.                     $newFieldCustomerSignature->height 24;
  2004.                     $newFieldCustomerSignature->49;
  2005.                     $newFieldCustomerSignature->670;
  2006.                     try {
  2007.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  2008.                             [
  2009.                                 'body' => json_encode($newFieldCustomerSignature),
  2010.                                 'headers' => [
  2011.                                     'accept' => 'application/json',
  2012.                                     'content-type' => 'application/json',
  2013.                                     'Authorization' => 'Bearer ' $this->yousignApi
  2014.                                 ],
  2015.                             ]
  2016.                         );
  2017.                     }
  2018.                     catch (\Exception $e) {
  2019.                         $responseErrorTab[] = $e->getMessage();
  2020.                     }
  2021.                     //Date (customer)
  2022.                     $newFieldCustomerSignature = new \stdClass();
  2023.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2024.                     $newFieldCustomerSignature->type "mention";
  2025.                     $newFieldCustomerSignature->font $fontDefault;
  2026.                     $newFieldCustomerSignature->mention "%date%";
  2027.                     $newFieldCustomerSignature->page $benefPage;
  2028.                     $newFieldCustomerSignature->width 272;
  2029.                     $newFieldCustomerSignature->height 24;
  2030.                     $newFieldCustomerSignature->49;
  2031.                     $newFieldCustomerSignature->702;
  2032.                     try {
  2033.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  2034.                             [
  2035.                                 'body' => json_encode($newFieldCustomerSignature),
  2036.                                 'headers' => [
  2037.                                     'accept' => 'application/json',
  2038.                                     'content-type' => 'application/json',
  2039.                                     'Authorization' => 'Bearer ' $this->yousignApi
  2040.                                 ],
  2041.                             ]
  2042.                         );
  2043.                     }
  2044.                     catch (\Exception $e) {
  2045.                         $responseErrorTab[] = $e->getMessage();
  2046.                     }
  2047.                 }
  2048.                 else{
  2049.                     //City (customer)
  2050.                     $newFieldCustomerSignature = new \stdClass();
  2051.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2052.                     $newFieldCustomerSignature->type "text";
  2053.                     $newFieldCustomerSignature->max_length 44;
  2054.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  2055.                     $newFieldCustomerSignature->page $benefPage;
  2056.                     $newFieldCustomerSignature->width 272;
  2057.                     $newFieldCustomerSignature->height 24;
  2058.                     $newFieldCustomerSignature->49;
  2059.                     $newFieldCustomerSignature->669;
  2060.                     try {
  2061.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  2062.                             [
  2063.                                 'body' => json_encode($newFieldCustomerSignature),
  2064.                                 'headers' => [
  2065.                                     'accept' => 'application/json',
  2066.                                     'content-type' => 'application/json',
  2067.                                     'Authorization' => 'Bearer ' $this->yousignApi
  2068.                                 ],
  2069.                             ]
  2070.                         );
  2071.                     }
  2072.                     catch (\Exception $e) {
  2073.                         $responseErrorTab[] = $e->getMessage();
  2074.                     }
  2075.                     //Date (customer)
  2076.                     $newFieldCustomerSignature = new \stdClass();
  2077.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2078.                     $newFieldCustomerSignature->type "mention";
  2079.                     $newFieldCustomerSignature->font $fontDefault;
  2080.                     $newFieldCustomerSignature->mention "%date%";
  2081.                     $newFieldCustomerSignature->page $benefPage;
  2082.                     $newFieldCustomerSignature->width 272;
  2083.                     $newFieldCustomerSignature->height 24;
  2084.                     $newFieldCustomerSignature->49;
  2085.                     $newFieldCustomerSignature->704;
  2086.                     try {
  2087.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  2088.                             [
  2089.                                 'body' => json_encode($newFieldCustomerSignature),
  2090.                                 'headers' => [
  2091.                                     'accept' => 'application/json',
  2092.                                     'content-type' => 'application/json',
  2093.                                     'Authorization' => 'Bearer ' $this->yousignApi
  2094.                                 ],
  2095.                             ]
  2096.                         );
  2097.                     }
  2098.                     catch (\Exception $e) {
  2099.                         $responseErrorTab[] = $e->getMessage();
  2100.                     }
  2101.                 }
  2102.             }
  2103.         }
  2104.         //SEPA
  2105.         if (($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) && $membership->getBa()->getSepaOriginVersmement() != 2) {
  2106.         
  2107.             if($membership->getBa()->getSepaOriginVersmement() == 1){
  2108.                 if($isLegal1){
  2109.                     //Signature (customer)
  2110.                     $newFieldCustomerLegal1Signature = new \stdClass();
  2111.                     $newFieldCustomerLegal1Signature->signer_id $newSignerCustomerLegal1Id;
  2112.                     $newFieldCustomerLegal1Signature->type "signature";
  2113.                     $newFieldCustomerLegal1Signature->page 1;
  2114.                     $newFieldCustomerLegal1Signature->width 99;
  2115.                     $newFieldCustomerLegal1Signature->height 39;
  2116.                     $newFieldCustomerLegal1Signature->355;
  2117.                     $newFieldCustomerLegal1Signature->757;
  2118.                     try {
  2119.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2120.                             [
  2121.                                 'body' => json_encode($newFieldCustomerLegal1Signature),
  2122.                                 'headers' => [
  2123.                                     'accept' => 'application/json',
  2124.                                     'content-type' => 'application/json',
  2125.                                     'Authorization' => 'Bearer ' $this->yousignApi
  2126.                                 ],
  2127.                             ]
  2128.                         );
  2129.                     }
  2130.                     catch (\Exception $e) {
  2131.                         $responseErrorTab[] = $e->getMessage();
  2132.                     }
  2133.                 }
  2134.                 if($isLegal2){
  2135.                     //Signature (customer)
  2136.                     $newFieldCustomerLegal2Signature = new \stdClass();
  2137.                     $newFieldCustomerLegal2Signature->signer_id $newSignerCustomerLegal2Id;
  2138.                     $newFieldCustomerLegal2Signature->type "signature";
  2139.                     $newFieldCustomerLegal2Signature->page 1;
  2140.                     $newFieldCustomerLegal2Signature->width 99;
  2141.                     $newFieldCustomerLegal2Signature->height 39;
  2142.                     $newFieldCustomerLegal2Signature->239;
  2143.                     $newFieldCustomerLegal2Signature->757;
  2144.                     try {
  2145.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2146.                             [
  2147.                                 'body' => json_encode($newFieldCustomerLegal2Signature),
  2148.                                 'headers' => [
  2149.                                     'accept' => 'application/json',
  2150.                                     'content-type' => 'application/json',
  2151.                                     'Authorization' => 'Bearer ' $this->yousignApi
  2152.                                 ],
  2153.                             ]
  2154.                         );
  2155.                     }
  2156.                     catch (\Exception $e) {
  2157.                         $responseErrorTab[] = $e->getMessage();
  2158.                     }
  2159.                 }
  2160.             }
  2161.             if($typeProduct == "epargne"){
  2162.                 //Signature (customer)
  2163.                 $newFieldCustomerSignature = new \stdClass();
  2164.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2165.                 $newFieldCustomerSignature->type "signature";
  2166.                 $newFieldCustomerSignature->page 1;
  2167.                 $newFieldCustomerSignature->width 99;
  2168.                 $newFieldCustomerSignature->height 39;
  2169.                 $newFieldCustomerSignature->472;
  2170.                 $newFieldCustomerSignature->724;
  2171.                 try {
  2172.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2173.                         [
  2174.                             'body' => json_encode($newFieldCustomerSignature),
  2175.                             'headers' => [
  2176.                                 'accept' => 'application/json',
  2177.                                 'content-type' => 'application/json',
  2178.                                 'Authorization' => 'Bearer ' $this->yousignApi
  2179.                             ],
  2180.                         ]
  2181.                     );
  2182.                 }
  2183.                 catch (\Exception $e) {
  2184.                     $responseErrorTab[] = $e->getMessage();
  2185.                 }
  2186.                 
  2187.                 //City (customer)
  2188.                 $newFieldCustomerSignature = new \stdClass();
  2189.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2190.                 $newFieldCustomerSignature->type "text";
  2191.                 $newFieldCustomerSignature->max_length 35;
  2192.                 $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  2193.                 $newFieldCustomerSignature->page 1;
  2194.                 $newFieldCustomerSignature->width 182;
  2195.                 $newFieldCustomerSignature->height 20;
  2196.                 $newFieldCustomerSignature->75;
  2197.                 $newFieldCustomerSignature->725;
  2198.                 try {
  2199.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2200.                         [
  2201.                             'body' => json_encode($newFieldCustomerSignature),
  2202.                             'headers' => [
  2203.                                 'accept' => 'application/json',
  2204.                                 'content-type' => 'application/json',
  2205.                                 'Authorization' => 'Bearer ' $this->yousignApi
  2206.                             ],
  2207.                         ]
  2208.                     );
  2209.                 }
  2210.                 catch (\Exception $e) {
  2211.                     $responseErrorTab[] = $e->getMessage();
  2212.                 }
  2213.                 //Date (customer)
  2214.                 $newFieldCustomerSignature = new \stdClass();
  2215.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2216.                 $newFieldCustomerSignature->type "mention";
  2217.                 $newFieldCustomerSignature->font $fontDefault;
  2218.                 $newFieldCustomerSignature->mention "%date%";
  2219.                 $newFieldCustomerSignature->page 1;
  2220.                 $newFieldCustomerSignature->width 182;
  2221.                 $newFieldCustomerSignature->height 20;
  2222.                 $newFieldCustomerSignature->53;
  2223.                 $newFieldCustomerSignature->756;
  2224.                 try {
  2225.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2226.                         [
  2227.                             'body' => json_encode($newFieldCustomerSignature),
  2228.                             'headers' => [
  2229.                                 'accept' => 'application/json',
  2230.                                 'content-type' => 'application/json',
  2231.                                 'Authorization' => 'Bearer ' $this->yousignApi
  2232.                             ],
  2233.                         ]
  2234.                     );
  2235.                 }
  2236.                 catch (\Exception $e) {
  2237.                     $responseErrorTab[] = $e->getMessage();
  2238.                 }
  2239.             }
  2240.             else{
  2241.                 //Signature (customer)
  2242.                 $newFieldCustomerSignature = new \stdClass();
  2243.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2244.                 $newFieldCustomerSignature->type "signature";
  2245.                 $newFieldCustomerSignature->page 1;
  2246.                 $newFieldCustomerSignature->width 137;
  2247.                 $newFieldCustomerSignature->height 49;
  2248.                 $newFieldCustomerSignature->355;
  2249.                 $newFieldCustomerSignature->535;
  2250.                 try {
  2251.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2252.                         [
  2253.                             'body' => json_encode($newFieldCustomerSignature),
  2254.                             'headers' => [
  2255.                                 'accept' => 'application/json',
  2256.                                 'content-type' => 'application/json',
  2257.                                 'Authorization' => 'Bearer ' $this->yousignApi
  2258.                             ],
  2259.                         ]
  2260.                     );
  2261.                 }
  2262.                 catch (\Exception $e) {
  2263.                     $responseErrorTab[] = $e->getMessage();
  2264.                 }
  2265.                 //City (customer)
  2266.                 $newFieldCustomerSignature = new \stdClass();
  2267.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2268.                 $newFieldCustomerSignature->type "text";
  2269.                 $newFieldCustomerSignature->max_length 35;
  2270.                 $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  2271.                 $newFieldCustomerSignature->page 1;
  2272.                 $newFieldCustomerSignature->width 217;
  2273.                 $newFieldCustomerSignature->height 24;
  2274.                 $newFieldCustomerSignature->86;
  2275.                 $newFieldCustomerSignature->503;
  2276.                 try {
  2277.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2278.                         [
  2279.                             'body' => json_encode($newFieldCustomerSignature),
  2280.                             'headers' => [
  2281.                                 'accept' => 'application/json',
  2282.                                 'content-type' => 'application/json',
  2283.                                 'Authorization' => 'Bearer ' $this->yousignApi
  2284.                             ],
  2285.                         ]
  2286.                     );
  2287.                 }
  2288.                 catch (\Exception $e) {
  2289.                     $responseErrorTab[] = $e->getMessage();
  2290.                 }
  2291.                 //Date (customer)
  2292.                 $newFieldCustomerSignature = new \stdClass();
  2293.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2294.                 $newFieldCustomerSignature->type "mention";
  2295.                 $newFieldCustomerSignature->font $fontDefault;
  2296.                 $newFieldCustomerSignature->mention "%date%";
  2297.                 $newFieldCustomerSignature->page 1;
  2298.                 $newFieldCustomerSignature->width 217;
  2299.                 $newFieldCustomerSignature->height 24;
  2300.                 $newFieldCustomerSignature->86;
  2301.                 $newFieldCustomerSignature->537;
  2302.                 try {
  2303.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2304.                         [
  2305.                             'body' => json_encode($newFieldCustomerSignature),
  2306.                             'headers' => [
  2307.                                 'accept' => 'application/json',
  2308.                                 'content-type' => 'application/json',
  2309.                                 'Authorization' => 'Bearer ' $this->yousignApi
  2310.                             ],
  2311.                         ]
  2312.                     );
  2313.                 }
  2314.                 catch (\Exception $e) {
  2315.                     $responseErrorTab[] = $e->getMessage();
  2316.                 }
  2317.             }
  2318.         }
  2319.         /* -----------------------------------  Active signature (end step)   ------------------------------------- */
  2320.         //Activate signature
  2321.         try {
  2322.             $activateSignatureResponse $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/activate'
  2323.                 [
  2324.                     'headers' => [
  2325.                         'accept' => 'application/json',
  2326.                         'Authorization' => 'Bearer ' $this->yousignApi
  2327.                     ],
  2328.                 ]
  2329.             );
  2330.             $activateSignatureResponseBody json_decode($activateSignatureResponse->getBody());
  2331.             $activateSignatureResponseSigners $activateSignatureResponseBody->signers;
  2332.         }
  2333.         catch (\Exception $e) {
  2334.             $responseErrorTab[] = $e->getMessage();
  2335.         }
  2336.         $urlSeller null;
  2337.         $urlCustomer null;
  2338.         if(!$responseErrorTab){
  2339.             if($membership->getPlatformVersion() == && !$customer->isIsAutoSignup()){
  2340.                 $urlSeller $activateSignatureResponseSigners[0]->signature_link;
  2341.                 $urlCustomer $activateSignatureResponseSigners[1]->signature_link;
  2342.             }
  2343.             else{
  2344.                 $urlCustomer $activateSignatureResponseSigners[0]->signature_link;
  2345.             }
  2346.         }
  2347.         $tab = array(
  2348.             "responseProcedure" => $activateSignatureResponseBody,
  2349.             "yousignUi" => $this->yousignUi,
  2350.             "dicFileId" => $uploadDicId,
  2351.             "ficFileId" => $uploadFicId,
  2352.             "baFileId" => $uploadBaId,
  2353.             "sepaFileId" => $uploadSepaId,
  2354.             "signerCustomer" => $newSignerCustomerResponseBody,
  2355.             "signerSellerUrl" => $urlSeller,
  2356.             "signerCustomerUrl" => $urlCustomer,
  2357.             "signerCustomerId" => $newSignerCustomerId,
  2358.             "signerCustomerLegal1Id" => $newSignerCustomerLegal1Id,
  2359.             "signerCustomerLegal2Id" => $newSignerCustomerLegal2Id,
  2360.             "signerSellerId" => $newSignerSellerId,
  2361.             "responseErrorTab" => $responseErrorTab
  2362.         );
  2363.         return $tab;
  2364.     }
  2365.     function addSign2023($customer$membership$type)
  2366.     {
  2367.         if ($membership->getDicIsFile() != true) {
  2368.             if($membership->getPlatformVersion() == 1){
  2369.                 //V1 DIC
  2370.                 //Get DIC BASE 64
  2371.                 $dicUrl "files/" $customer->getId() . '/' $membership->getDic()->getUrlPdf();
  2372.                 $b64Dic chunk_split(base64_encode(file_get_contents($dicUrl)));
  2373.                 $fileDic = new \stdClass();
  2374.                 $fileDic->name "Document d’information et de conseil";
  2375.                 $fileDic->content $b64Dic;
  2376.                 $fileDic->position 1;
  2377.                 //Create files
  2378.                 $curl curl_init();
  2379.                 curl_setopt_array($curl, array(
  2380.                     CURLOPT_URL => $this->yousignUrl "/files",
  2381.                     CURLOPT_RETURNTRANSFER => true,
  2382.                     CURLOPT_ENCODING => "",
  2383.                     CURLOPT_MAXREDIRS => 10,
  2384.                     CURLOPT_TIMEOUT => 0,
  2385.                     CURLOPT_FOLLOWLOCATION => true,
  2386.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2387.                     CURLOPT_CUSTOMREQUEST => "POST",
  2388.                     CURLOPT_POSTFIELDS => json_encode($fileDic),
  2389.                     CURLOPT_HTTPHEADER => array(
  2390.                         "Authorization: Bearer " $this->yousignApi,
  2391.                         "Content-Type: application/json"
  2392.                     ),
  2393.                 ));
  2394.                 $responseFile curl_exec($curl);
  2395.                 curl_close($curl);
  2396.                 $responseFileDic json_decode($responseFile);
  2397.             } else{
  2398.                 //V2 FIC
  2399.                 //Get FIC BASE 64
  2400.                 $ficUrl "files/" $customer->getId() . '/' $membership->getFic()->getUrlPdf();
  2401.                 $b64Fic chunk_split(base64_encode(file_get_contents($ficUrl)));
  2402.                 $fileFic = new \stdClass();
  2403.                 $fileFic->name "Fiche d’information et de conseil";
  2404.                 $fileFic->content $b64Fic;
  2405.                 $fileFic->position 1;
  2406.                 //Create files
  2407.                 $curl curl_init();
  2408.                 curl_setopt_array($curl, array(
  2409.                     CURLOPT_URL => $this->yousignUrl "/signature_requests//documents",
  2410.                     CURLOPT_RETURNTRANSFER => true,
  2411.                     CURLOPT_ENCODING => "",
  2412.                     CURLOPT_MAXREDIRS => 10,
  2413.                     CURLOPT_TIMEOUT => 0,
  2414.                     CURLOPT_FOLLOWLOCATION => true,
  2415.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2416.                     CURLOPT_CUSTOMREQUEST => "POST",
  2417.                     CURLOPT_POSTFIELDS => json_encode($fileFic),
  2418.                     CURLOPT_HTTPHEADER => array(
  2419.                         "Authorization: Bearer " $this->yousignApi,
  2420.                         "Content-Type: application/json"
  2421.                     ),
  2422.                 ));
  2423.                 $responseFile curl_exec($curl);
  2424.                 curl_close($curl);
  2425.                 $responseFileFic json_decode($responseFile);
  2426.             }
  2427.         }
  2428.         /* --------------------------------------------------------------------------- */
  2429.         //Get BA BASE 64
  2430.         $baUrl "files/" $customer->getId() . '/' $membership->getBa()->getUrlPdf();
  2431.         $b64Ba chunk_split(base64_encode(file_get_contents($baUrl)));
  2432.         $fileBa = new \stdClass();
  2433.         $fileBa->name "Demande d’adhésion";
  2434.         $fileBa->content $b64Ba;
  2435.         $fileBa->position 2;
  2436.         //Create files
  2437.         $curl curl_init();
  2438.         curl_setopt_array($curl, array(
  2439.             CURLOPT_URL => $this->yousignUrl "/files",
  2440.             CURLOPT_RETURNTRANSFER => true,
  2441.             CURLOPT_ENCODING => "",
  2442.             CURLOPT_MAXREDIRS => 10,
  2443.             CURLOPT_TIMEOUT => 0,
  2444.             CURLOPT_FOLLOWLOCATION => true,
  2445.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2446.             CURLOPT_CUSTOMREQUEST => "POST",
  2447.             CURLOPT_POSTFIELDS => json_encode($fileBa),
  2448.             CURLOPT_HTTPHEADER => array(
  2449.                 "Authorization: Bearer " $this->yousignApi,
  2450.                 "Content-Type: application/json"
  2451.             ),
  2452.         ));
  2453.         $responseFileBa curl_exec($curl);
  2454.         curl_close($curl);
  2455.         $responseFileBa json_decode($responseFileBa);
  2456.         /* --------------------------------------------------------------------------- */
  2457.         /* --------------------------------------------------------------------------- */
  2458.         if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  2459.             //Get BA BASE 64
  2460.             $sepaUrl "files/" $customer->getId() . '/' $membership->getBa()->getSepaUrlPdf();
  2461.             $b64Sepa chunk_split(base64_encode(file_get_contents($sepaUrl)));
  2462.             $fileSepa = new \stdClass();
  2463.             $fileSepa->name "Mandat de prélèvement SEPA";
  2464.             $fileSepa->content $b64Sepa;
  2465.             $fileSepa->position 3;
  2466.             //Create files
  2467.             $curl curl_init();
  2468.             curl_setopt_array($curl, array(
  2469.                 CURLOPT_URL => $this->yousignUrl "/files",
  2470.                 CURLOPT_RETURNTRANSFER => true,
  2471.                 CURLOPT_ENCODING => "",
  2472.                 CURLOPT_MAXREDIRS => 10,
  2473.                 CURLOPT_TIMEOUT => 0,
  2474.                 CURLOPT_FOLLOWLOCATION => true,
  2475.                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2476.                 CURLOPT_CUSTOMREQUEST => "POST",
  2477.                 CURLOPT_POSTFIELDS => json_encode($fileSepa),
  2478.                 CURLOPT_HTTPHEADER => array(
  2479.                     "Authorization: Bearer " $this->yousignApi,
  2480.                     "Content-Type: application/json"
  2481.                 ),
  2482.             ));
  2483.             $responseFileSepa curl_exec($curl);
  2484.             curl_close($curl);
  2485.             $responseFileSepa json_decode($responseFileSepa);
  2486.         }
  2487.         /* --------------------------------------------------------------------------- */
  2488.         //Add procedure
  2489.         $curl curl_init();
  2490.         //Set webhook
  2491.         if ($type == "seller") {
  2492.             $urlSignEnd $this->container->get('router')->generate('yousign_sign_end_seller', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  2493.         } else {
  2494.             $urlSignEnd $this->container->get('router')->generate('yousign_sign_end', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  2495.         }
  2496.         $firstName str_replace(","" "$customer->getFirstName());
  2497.         $config = new \stdClass();
  2498.         $webhook = new \stdClass();
  2499.         $webhookEnd = new \stdClass();
  2500.         $header = new \stdClass();
  2501.         $webhookEnd->url $urlSignEnd;
  2502.         $webhookEnd->method "GET";
  2503.         $webhookEnd->headers = (object)array(
  2504.             'X-Custom-Header' => "End sign"
  2505.         );
  2506.         $config->webhook = (object)array(
  2507.             'member.finished' => array(
  2508.                 $webhookEnd
  2509.             )
  2510.         );
  2511.         $arrayObjectFiles = array();
  2512.         $dicFileId null;
  2513.         $ficFileId null;
  2514.         $baFileId null;
  2515.         $sepaFileId null;
  2516.         if ($membership->getDicIsFile() != true) {
  2517.             if($membership->getPlatformVersion() == 1){
  2518.                 //V1 DIC
  2519.                 //Set file DIC
  2520.                 $fileObjectDic = new \stdClass();
  2521.                 $fileObjectDic->file $responseFileDic->id;
  2522.                 $fileObjectDic->page 1;
  2523.                 $fileObjectDic->position "171,80,317,120";
  2524.                 $fileObjectDic->mention "";
  2525.                 $fileObjectDic->mention2 "Signé par " $firstName " " $customer->getLastName();
  2526.                 $arrayObjectFiles[] = $fileObjectDic;
  2527.                 $dicFileId $responseFileDic->id;
  2528.                 //Set file DIC VILLE
  2529.                 $fileObjectDicVille = new \stdClass();
  2530.                 $fileObjectDicVille->file $responseFileDic->id;
  2531.                 $fileObjectDicVille->page 1;
  2532.                 $fileObjectDicVille->type "text";
  2533.                 $fileObjectDicVille->fontSize 10;
  2534.                 $fileObjectDicVille->contentRequired true;
  2535.                 $fileObjectDicVille->content $membership->getBa()->getVille();
  2536.                 $fileObjectDicVille->position "48,79,158,96";
  2537.                 $arrayObjectFiles[] = $fileObjectDicVille;
  2538.                 //Set file DIC DATE
  2539.                 $fileObjectDicDate = new \stdClass();
  2540.                 $fileObjectDicDate->file $responseFileDic->id;
  2541.                 $fileObjectDicDate->page 1;
  2542.                 $fileObjectDicDate->type "text";
  2543.                 $fileObjectDicDate->fontSize 10;
  2544.                 $fileObjectDicDate->contentRequired true;
  2545.                 $fileObjectDicDate->content date("d/m/Y");
  2546.                 $fileObjectDicDate->position "49,98,159,115";
  2547.                 $arrayObjectFiles[] = $fileObjectDicDate;
  2548.             } else{
  2549.                 //V2 FIC
  2550.                 $fileObjectFic = new \stdClass();
  2551.                 $fileObjectFic->file $responseFileFic->id;
  2552.                 $fileObjectFic->page 7;
  2553.                 $fileObjectFic->position "69,199,247,304";
  2554.                 $fileObjectFic->mention "";
  2555.                 $fileObjectFic->mention2 "Signé par " $firstName " " $customer->getLastName();
  2556.                 $arrayObjectFiles[] = $fileObjectFic;
  2557.                 $ficFileId $responseFileFic->id;
  2558.                 //FOR SELLER 
  2559.                 //$fileObjectFic->position = "323,182,503,246";
  2560.                 //Set file FIC VILLE
  2561.                 $fileObjectFicVille = new \stdClass();
  2562.                 $fileObjectFicVille->file $responseFileFic->id;
  2563.                 $fileObjectFicVille->page 9;
  2564.                 $fileObjectFicVille->type "text";
  2565.                 $fileObjectFicVille->fontSize 10;
  2566.                 $fileObjectFicVille->contentRequired true;
  2567.                 $fileObjectFicVille->content $membership->getFic()->getAdresseFiscaleVille();
  2568.                 $fileObjectFicVille->position "66,449,293,464";
  2569.                 $arrayObjectFiles[] = $fileObjectFicVille;
  2570.                 //Set file FIC DATE
  2571.                 $fileObjectFicDate = new \stdClass();
  2572.                 $fileObjectFicDate->file $responseFileFic->id;
  2573.                 $fileObjectFicDate->page 9;
  2574.                 $fileObjectFicDate->type "text";
  2575.                 $fileObjectFicDate->fontSize 10;
  2576.                 $fileObjectFicDate->contentRequired true;
  2577.                 $fileObjectFicDate->content date("d/m/Y");
  2578.                 $fileObjectFicDate->position "74,424,301,439";
  2579.                 $arrayObjectFiles[] = $fileObjectFicDate;
  2580.             }
  2581.         }
  2582.         //Set file BA -> Demande attribution de
  2583.         if ($membership->getBa()->getJaiDemandeAttributionDe() != null) {
  2584.             $fileObjectBaName = new \stdClass();
  2585.             $fileObjectBaName->file $responseFileBa->id;
  2586.             $fileObjectBaName->page 4;
  2587.             $fileObjectBaName->type "text";
  2588.             $fileObjectBaName->fontSize 8;
  2589.             $fileObjectBaName->contentRequired true;
  2590.             $fileObjectBaName->content $firstName " " $membership->getUser()->getLastName();
  2591.             $fileObjectBaName->position "94,731,255,749";
  2592.             $arrayObjectFiles[] = $fileObjectBaName;
  2593.         }
  2594.         //Set file BA 
  2595.         $fileObjectBa = new \stdClass();
  2596.         $fileObjectBa->file $responseFileBa->id;
  2597.         $fileObjectBa->page 7;
  2598.         $fileObjectBa->position "350,307,500,410";
  2599.         $fileObjectBa->mention "Lu et approuvé";
  2600.         $fileObjectBa->mention2 "Signé par " $firstName " " $customer->getLastName();
  2601.         $arrayObjectFiles[] = $fileObjectBa;
  2602.         $baFileId $responseFileBa->id;
  2603.         $fileObjectBaLieu = new \stdClass();
  2604.         $fileObjectBaLieu->file $responseFileBa->id;
  2605.         $fileObjectBaLieu->page 7;
  2606.         $fileObjectBaLieu->type "text";
  2607.         $fileObjectBaLieu->fontSize 10;
  2608.         $fileObjectBaLieu->contentRequired true;
  2609.         $fileObjectBaLieu->content $membership->getBa()->getFiscaleVille();
  2610.         $fileObjectBaLieu->position "45,419,200,437";
  2611.         $arrayObjectFiles[] = $fileObjectBaLieu;
  2612.         $fileObjectBaDate = new \stdClass();
  2613.         $fileObjectBaDate->file $responseFileBa->id;
  2614.         $fileObjectBaDate->page 7;
  2615.         $fileObjectBaDate->type "text";
  2616.         $fileObjectBaDate->fontSize 10;
  2617.         $fileObjectBaDate->contentRequired true;
  2618.         $fileObjectBaDate->content date("d/m/Y");
  2619.         $fileObjectBaDate->position "47,403,202,421";
  2620.         $arrayObjectFiles[] = $fileObjectBaDate;
  2621.         //Benef
  2622.         if($membership->getBa()->isTypeBeneficiaires() == true && $membership->getBa()->isTypeBeneficiairesClauseNotariee() == false){
  2623.             $fileObjectBa = new \stdClass();
  2624.             $fileObjectBa->file $responseFileBa->id;
  2625.             $fileObjectBa->page 9;
  2626.             $fileObjectBa->position "347,68,521,131";
  2627.             $fileObjectBa->mention "Lu et approuvé";
  2628.             $fileObjectBa->mention2 "Signé par " $firstName " " $customer->getLastName();
  2629.             $arrayObjectFiles[] = $fileObjectBa;
  2630.             $baFileId $responseFileBa->id;
  2631.             $fileObjectBaLieu = new \stdClass();
  2632.             $fileObjectBaLieu->file $responseFileBa->id;
  2633.             $fileObjectBaLieu->page 9;
  2634.             $fileObjectBaLieu->type "text";
  2635.             $fileObjectBaLieu->fontSize 10;
  2636.             $fileObjectBaLieu->contentRequired true;
  2637.             $fileObjectBaLieu->content $membership->getBa()->getFiscaleVille();
  2638.             $fileObjectBaLieu->position "50,150,201,171";
  2639.             $arrayObjectFiles[] = $fileObjectBaLieu;
  2640.             $fileObjectBaDate = new \stdClass();
  2641.             $fileObjectBaDate->file $responseFileBa->id;
  2642.             $fileObjectBaDate->page 9;
  2643.             $fileObjectBaDate->type "text";
  2644.             $fileObjectBaDate->fontSize 10;
  2645.             $fileObjectBaDate->contentRequired true;
  2646.             $fileObjectBaDate->content date("d/m/Y");
  2647.             $fileObjectBaDate->position "51,136,202,157";
  2648.             $arrayObjectFiles[] = $fileObjectBaDate;
  2649.         }
  2650.         //SEPA
  2651.         if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  2652.             //Set file SEPA
  2653.             $fileObjectSepa = new \stdClass();
  2654.             $fileObjectSepa->file $responseFileSepa->id;
  2655.             $fileObjectSepa->page 1;
  2656.             $fileObjectSepa->position "365,227,506,309";
  2657.             $fileObjectSepa->mention "";
  2658.             $fileObjectSepa->mention2 "Signé par " $firstName " " $customer->getLastName();
  2659.             $arrayObjectFiles[] = $fileObjectSepa;
  2660.             $sepaFileId $responseFileSepa->id;
  2661.             $fileObjectSepaDate = new \stdClass();
  2662.             $fileObjectSepaDate->file $responseFileSepa->id;
  2663.             $fileObjectSepaDate->page 1;
  2664.             $fileObjectSepaDate->position "148,303,300,322";
  2665.             $fileObjectSepaDate->type "text";
  2666.             $fileObjectSepaDate->fontSize 8;
  2667.             $fileObjectSepaDate->contentRequired true;
  2668.             $fileObjectSepaDate->content date("d/m/Y");
  2669.             $arrayObjectFiles[] = $fileObjectSepaDate;
  2670.             $fileObjectSepaLieu = new \stdClass();
  2671.             $fileObjectSepaLieu->file $responseFileSepa->id;
  2672.             $fileObjectSepaLieu->page 1;
  2673.             $fileObjectSepaLieu->position "147,321,299,340";
  2674.             $fileObjectSepaLieu->type "text";
  2675.             $fileObjectSepaLieu->fontSize 8;
  2676.             $fileObjectSepaLieu->contentRequired true;
  2677.             $fileObjectSepaLieu->content $membership->getBa()->getFiscaleVille();
  2678.             $arrayObjectFiles[] = $fileObjectSepaLieu;
  2679.         }
  2680.         //Set member - customer
  2681.         $member = new \stdClass();
  2682.         $member->firstname $firstName;
  2683.         $member->lastname $customer->getLastName();
  2684.         $member->email $customer->getEmail();
  2685.         $phone $customer->getPhone();
  2686.         $phone str_replace("("""$phone);
  2687.         $phone str_replace(")"""$phone);
  2688.         $phone str_replace(" """$phone);
  2689.         if ($customer->getPhonePrefix()) {
  2690.             $phone $customer->getPhonePrefix() . $phone;
  2691.         }
  2692.         $member->phone $phone;
  2693.         $member->fileObjects $arrayObjectFiles;
  2694.         if($membership->getPlatformVersion() == && $customer->isIsAutoSignup() != true){
  2695.             //Set file FIC SELLER
  2696.             $fileObjectFicSeller  = new \stdClass();
  2697.             $fileObjectFicSeller->file $responseFileFic->id;
  2698.             $fileObjectFicSeller->page 9;
  2699.             $fileObjectFicSeller->position "350,198,528,303";
  2700.             $fileObjectFicSeller->mention "";
  2701.             $fileObjectFicSeller->mention2 "Signé par ".$membership->getSeller()->getFirstName()." ".$membership->getSeller()->getLastName();
  2702.             //Set member - seller
  2703.             $memberSeller  = new \stdClass();
  2704.             $memberSeller->position 1;
  2705.             $memberSeller->firstname $membership->getSeller()->getFirstName();
  2706.             $memberSeller->lastname $membership->getSeller()->getLastName();
  2707.             $memberSeller->email $membership->getSeller()->getEmail();
  2708.             $memberSeller->phone $membership->getSeller()->getPhone();
  2709.             $memberSeller->operationCustomModes = [ "email" ];
  2710.             $memberSeller->fileObjects = array(
  2711.                 $fileObjectFicSeller,
  2712.             );
  2713.             $member->position 2;
  2714.             //Set procedure
  2715.             $procedure = new \stdClass();
  2716.             $procedure->name "Signature adhésion";
  2717.             $procedure->description "Fin d'adhésion";
  2718.             $procedure->start true;
  2719.             $procedure->ordered false;
  2720.             $procedure->members = array(
  2721.                 $memberSeller,
  2722.                 $member
  2723.             );
  2724.             $procedure->config $config;
  2725.         }
  2726.         else{
  2727.             //Set procedure
  2728.             $procedure = new \stdClass();
  2729.             $procedure->name "Signature adhésion";
  2730.             $procedure->description "Fin d'adhésion";
  2731.             $procedure->start true;
  2732.             $procedure->members = array(
  2733.                 $member,
  2734.             );
  2735.             $procedure->config $config;
  2736.         }
  2737.         curl_setopt_array($curl, array(
  2738.             CURLOPT_URL => $this->yousignUrl "/procedures",
  2739.             CURLOPT_RETURNTRANSFER => true,
  2740.             CURLOPT_ENCODING => "",
  2741.             CURLOPT_MAXREDIRS => 10,
  2742.             CURLOPT_TIMEOUT => 0,
  2743.             CURLOPT_FOLLOWLOCATION => true,
  2744.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2745.             CURLOPT_CUSTOMREQUEST => "POST",
  2746.             CURLOPT_POSTFIELDS => json_encode($procedure),
  2747.             CURLOPT_HTTPHEADER => array(
  2748.                 "Authorization: Bearer " $this->yousignApi,
  2749.                 "Content-Type: application/json"
  2750.             ),
  2751.         ));
  2752.         $responseProcedure curl_exec($curl);
  2753.         curl_close($curl);
  2754.         $responseProcedure json_decode($responseProcedure);
  2755.         //var_dump($member);
  2756.         //die;
  2757.         $tab = array(
  2758.             "responseProcedure" => $responseProcedure,
  2759.             "yousignUi" => $this->yousignUi,
  2760.             "dicFileId" => $dicFileId,
  2761.             "ficFileId" => $ficFileId,
  2762.             "baFileId" => $baFileId,
  2763.             "sepaFileId" => $sepaFileId,
  2764.         );
  2765.         return $tab;
  2766.     }
  2767.     function saveFilesYouSignV3($membership$typeUser "customer")
  2768.     {
  2769.         $newSignatureId $membership->getProcedureId();
  2770.         //Wait 2 secondes Yousign create file
  2771.         //sleep(2);
  2772.         if ($membership->getDicIsFile() != true) {
  2773.             /* ------------------------ SAVE FIC START ------------------------ */
  2774.             //GET FIC FILE
  2775.             $client = new Client();
  2776.             $fileResponse $client->request('GET'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$membership->getFic()->getIdYouSign().'/download'
  2777.                 [
  2778.                     'headers' => [
  2779.                         'accept' => 'application/json',
  2780.                         'content-type' => 'application/json',
  2781.                         'Authorization' => 'Bearer ' $this->yousignApi
  2782.                     ],
  2783.                 ]
  2784.             );
  2785.             $fileBody $fileResponse->getBody();
  2786.             $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'FIC.pdf';
  2787.             file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$fileBody);
  2788.             $membership->getFic()->setUrlPdfSign($name);
  2789.             $this->em->persist($membership->getFic());
  2790.             /* ------------------------ SAVE FIC END ------------------------ */
  2791.         }
  2792.         if($typeUser == "customer"){
  2793.             /* ------------------------ SAVE BA START ------------------------ */
  2794.             //GET BA FILE
  2795.             $client = new Client();
  2796.             $fileResponse $client->request('GET'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$membership->getBa()->getIdYouSign().'/download'
  2797.                 [
  2798.                     'headers' => [
  2799.                         'accept' => 'application/json',
  2800.                         'content-type' => 'application/json',
  2801.                         'Authorization' => 'Bearer ' $this->yousignApi
  2802.                     ],
  2803.                 ]
  2804.             );
  2805.             $fileBody $fileResponse->getBody();
  2806.             $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'BA.pdf';
  2807.             file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$fileBody);
  2808.             $membership->getBa()->setUrlPdfSign($name);
  2809.             /* ------------------------ SAVE BA END ------------------------ */
  2810.             /* ------------------------ SAVE SEPA START ------------------------ */
  2811.             if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  2812.                 //GET SEPA FILE
  2813.                 $client = new Client();
  2814.                 $fileResponse $client->request('GET'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$membership->getBa()->getSepaIdYouSign().'/download'
  2815.                     [
  2816.                         'headers' => [
  2817.                             'accept' => 'application/json',
  2818.                             'content-type' => 'application/json',
  2819.                             'Authorization' => 'Bearer ' $this->yousignApi
  2820.                         ],
  2821.                     ]
  2822.                 );
  2823.                 $fileBody $fileResponse->getBody();
  2824.                 $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'SEPA.pdf';
  2825.                 file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$fileBody);
  2826.                 $membership->getBa()->setSepaUrlPdfSign($name);
  2827.             }
  2828.             /* ------------------------ SAVE SEPA END ------------------------ */
  2829.             $this->em->persist($membership->getBa());
  2830.         }
  2831.         $this->em->flush();
  2832.     }
  2833.     function saveFilesYouSign($membership$typeUser "customer")
  2834.     {
  2835.         //Wait 2 secondes Yousign create file
  2836.         sleep(2);
  2837.         if ($membership->getDicIsFile() != true) {
  2838.             if($membership->getPlatformVersion() == 1){
  2839.                 //V1 DIC
  2840.                 /* ------------------------ SAVE DIC START ------------------------ */
  2841.                 //GET DIC FILE
  2842.                 $curl curl_init();
  2843.                 curl_setopt_array($curl, array(
  2844.                     CURLOPT_URL => $this->yousignUrlV2 $membership->getDic()->getIdYouSign() . "/download",
  2845.                     CURLOPT_RETURNTRANSFER => true,
  2846.                     CURLOPT_ENCODING => "",
  2847.                     CURLOPT_MAXREDIRS => 30,
  2848.                     CURLOPT_TIMEOUT => 0,
  2849.                     CURLOPT_FOLLOWLOCATION => true,
  2850.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2851.                     CURLOPT_CUSTOMREQUEST => "GET",
  2852.                     CURLOPT_HTTPHEADER => array(
  2853.                         "Authorization: Bearer " $this->yousignApiV2,
  2854.                         "Content-Type: application/json"
  2855.                     ),
  2856.                 ));
  2857.                 $responseFileDic curl_exec($curl);
  2858.                 curl_close($curl);
  2859.                 $dicFile json_decode($responseFileDic);
  2860.                 $dicFileBin base64_decode($dicFiletrue);
  2861.                 $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'DIC.pdf';
  2862.                 file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$dicFileBin);
  2863.                 $membership->getDic()->setUrlPdfSign($name);
  2864.                 /* ------------------------ SAVE DIC END ------------------------ */
  2865.             } else {
  2866.                 // V2 FIC
  2867.                 /* ------------------------ SAVE FIC START ------------------------ */
  2868.                 //GET FIC FILE
  2869.                 $curl curl_init();
  2870.                 curl_setopt_array($curl, array(
  2871.                     CURLOPT_URL => $this->yousignUrlV2 $membership->getFic()->getIdYouSign() . "/download",
  2872.                     CURLOPT_RETURNTRANSFER => true,
  2873.                     CURLOPT_ENCODING => "",
  2874.                     CURLOPT_MAXREDIRS => 30,
  2875.                     CURLOPT_TIMEOUT => 0,
  2876.                     CURLOPT_FOLLOWLOCATION => true,
  2877.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2878.                     CURLOPT_CUSTOMREQUEST => "GET",
  2879.                     CURLOPT_HTTPHEADER => array(
  2880.                         "Authorization: Bearer " $this->yousignApiV2,
  2881.                         "Content-Type: application/json"
  2882.                     ),
  2883.                 ));
  2884.                 $responseFileFic curl_exec($curl);
  2885.                 curl_close($curl);
  2886.                 $ficFile json_decode($responseFileFic);
  2887.                 $ficFileBin base64_decode($ficFiletrue);
  2888.                 $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'FIC.pdf';
  2889.                 file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$ficFileBin);
  2890.                 $membership->getFic()->setUrlPdfSign($name);
  2891.                 /* ------------------------ SAVE FIC END ------------------------ */
  2892.             }
  2893.         }
  2894.         if($typeUser == "customer"){
  2895.             /* ------------------------ SAVE BA START ------------------------ */
  2896.             //GET BA FILE
  2897.             $curl curl_init();
  2898.             curl_setopt_array($curl, array(
  2899.                 CURLOPT_URL => $this->yousignUrlV2 $membership->getBa()->getIdYouSign() . "/download",
  2900.                 CURLOPT_RETURNTRANSFER => true,
  2901.                 CURLOPT_ENCODING => "",
  2902.                 CURLOPT_MAXREDIRS => 30,
  2903.                 CURLOPT_TIMEOUT => 0,
  2904.                 CURLOPT_FOLLOWLOCATION => true,
  2905.                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2906.                 CURLOPT_CUSTOMREQUEST => "GET",
  2907.                 CURLOPT_HTTPHEADER => array(
  2908.                     "Authorization: Bearer " $this->yousignApiV2,
  2909.                     "Content-Type: application/json"
  2910.                 ),
  2911.             ));
  2912.             $responseFileBa curl_exec($curl);
  2913.             curl_close($curl);
  2914.             $baFile json_decode($responseFileBa);
  2915.             $baFileBin base64_decode($baFiletrue);
  2916.             $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'BA.pdf';
  2917.             file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$baFileBin);
  2918.             $membership->getBa()->setUrlPdfSign($name);
  2919.             /* ------------------------ SAVE BA END ------------------------ */
  2920.             /* ------------------------ SAVE SEPA START ------------------------ */
  2921.             if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  2922.                 //GET SEPA FILE
  2923.                 $curl curl_init();
  2924.                 curl_setopt_array($curl, array(
  2925.                     CURLOPT_URL => $this->yousignUrlV2 $membership->getBa()->getSepaIdYouSign() . "/download",
  2926.                     CURLOPT_RETURNTRANSFER => true,
  2927.                     CURLOPT_ENCODING => "",
  2928.                     CURLOPT_MAXREDIRS => 30,
  2929.                     CURLOPT_TIMEOUT => 0,
  2930.                     CURLOPT_FOLLOWLOCATION => true,
  2931.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2932.                     CURLOPT_CUSTOMREQUEST => "GET",
  2933.                     CURLOPT_HTTPHEADER => array(
  2934.                         "Authorization: Bearer " $this->yousignApiV2,
  2935.                         "Content-Type: application/json"
  2936.                     ),
  2937.                 ));
  2938.                 $responseFileSepa curl_exec($curl);
  2939.                 curl_close($curl);
  2940.                 $sepaFile json_decode($responseFileSepa);
  2941.                 $sepaFileBin base64_decode($sepaFiletrue);
  2942.                 $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'SEPA.pdf';
  2943.                 file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$sepaFileBin);
  2944.                 $membership->getBa()->setSepaUrlPdfSign($name);
  2945.             }
  2946.             /* ------------------------ SAVE SEPA END ------------------------ */
  2947.             $this->em->persist($membership->getBa());
  2948.         }
  2949.         if($membership->getPlatformVersion() == 1){
  2950.             $this->em->persist($membership->getDic());
  2951.         }
  2952.         else{
  2953.             $this->em->persist($membership->getFic());
  2954.         }
  2955.         $this->em->flush();
  2956.     }
  2957.     function startSign($procedure)
  2958.     {
  2959.         $memberId $procedure->members[0]->id;
  2960.         $yousignUrlV2 $this->container->getParameter('yousign_url_v2');
  2961.         header('Location: ' $yousignUrlV2 '/procedure/sign?members=' $memberId '&signatureUi=/signature_uis/' $this->yousignUi);
  2962.         exit();
  2963.     }
  2964.     function youSignConditionsV3($fileURL$document$userCurrent null): array
  2965.     {
  2966.         $client = new Client();
  2967.         $responseProcedure null;
  2968.         $responseErrorTab = [];
  2969.         $cpFileId null;
  2970.         $activateSignatureResponseBody null;
  2971.         $newSignatureId null;
  2972.         $uploadDocumentId null;
  2973.         $signerUrl null;
  2974.         //Font default for all fields
  2975.         $fontDefault = new \stdClass();
  2976.         $fontDefault->size 9;
  2977.         $fontDefault->family "Inconsolata";
  2978.         $fontDefault->variants = array(
  2979.             "italic" => false,
  2980.             "bold" => false
  2981.         );
  2982.         $fontDefault->color "#000000";
  2983.         /* -----------------------------------  Add Signature   ------------------------------------- */
  2984.         //Create signature
  2985.         $newSignature = new \stdClass();
  2986.         $newSignature->delivery_mode "none";
  2987.         $newSignature->reminder_settings null;
  2988.         $newSignature->ordered_signers true;
  2989.         $newSignature->signers_allowed_to_decline false;
  2990.         $newSignature->workspace_id $this->yousignWorkspaceConditions;
  2991.         $newSignature->name "Conditions particulières";
  2992.         $newSignature->custom_experience_id $this->yousignUiConditions;
  2993.         try {
  2994.             $newSignatureResponse $client->request('POST'$this->yousignUrl .'/signature_requests'
  2995.                 [
  2996.                     'body' => json_encode($newSignature),
  2997.                     'headers' => [
  2998.                         'accept' => 'application/json',
  2999.                         'content-type' => 'application/json',
  3000.                         'Authorization' => 'Bearer ' $this->yousignApi
  3001.                     ],
  3002.                 ]
  3003.             );
  3004.             //201 for create
  3005.             $newSignatureResponseStatusCode $newSignatureResponse->getStatusCode();
  3006.             $newSignatureResponseBody json_decode($newSignatureResponse->getBody());
  3007.             $newSignatureId $newSignatureResponseBody->id;
  3008.         }
  3009.         catch (\Exception $e) {
  3010.             $responseErrorTab[] = $e->getMessage();
  3011.         }
  3012.         /* -----------------------------------  Add Metadata   ------------------------------------- */
  3013.         //Create meta
  3014.         $newMetaData = new \stdClass();
  3015.         $newMetaData->data = array(
  3016.             "documentId" => $document->getId()
  3017.         );
  3018.         try {
  3019.             $newMetaDataResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/metadata'
  3020.                 [
  3021.                     'body' => json_encode($newMetaData),
  3022.                     'headers' => [
  3023.                         'accept' => 'application/json',
  3024.                         'content-type' => 'application/json',
  3025.                         'Authorization' => 'Bearer ' $this->yousignApi
  3026.                     ],
  3027.                 ]
  3028.             );
  3029.             //201 for create
  3030.             $newMetaDataResponseStatusCode $newMetaDataResponse->getStatusCode();
  3031.             $newMetaDataResponseBody json_decode($newMetaDataResponse->getBody());
  3032.         }
  3033.         catch (\Exception $e) {
  3034.             $responseErrorTab[] = $e->getMessage();
  3035.         }
  3036.         /* -----------------------------------  Add Files   ------------------------------------- */
  3037.         //Add Document file
  3038.         try {
  3039.             $uploadDocumentResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents'
  3040.                 [
  3041.                     'multipart' => [
  3042.                         [
  3043.                             'name' => 'nature',
  3044.                             'contents' => 'signable_document'
  3045.                         ],
  3046.                         [
  3047.                             'name' => 'parse_anchors',
  3048.                             'contents' => 'false'
  3049.                         ],
  3050.                         [
  3051.                             'name' => 'file',
  3052.                             'filename' => "Conditions particulières.pdf",
  3053.                             'contents' => fopen($fileURL'r'),
  3054.                         ]
  3055.                     ],
  3056.                     'headers' => [
  3057.                         'accept' => 'application/json',
  3058.                         'Authorization' => 'Bearer ' $this->yousignApi
  3059.                     ]
  3060.                 ]
  3061.             );
  3062.             $uploadDocumentResponseBody json_decode($uploadDocumentResponse->getBody());
  3063.             $uploadDocumentId $uploadDocumentResponseBody->id;
  3064.         }
  3065.         catch (\Exception $e) {
  3066.             $responseErrorTab[] = $e->getMessage();
  3067.         }
  3068.         //Add Member
  3069.         $phone $userCurrent->getPhone();
  3070.         $phone str_replace("("""$phone);
  3071.         $phone str_replace(")"""$phone);
  3072.         $phone str_replace(" """$phone);
  3073.         if ($userCurrent->getPhonePrefix()) {
  3074.             $phone $userCurrent->getPhonePrefix() . $phone;
  3075.         }
  3076.         else{
  3077.             $phone "+33" $phone;
  3078.         }
  3079.         $newSignerMember = new \stdClass();
  3080.         $newSignerMember->locale "fr";
  3081.         $newSignerMember->first_name $userCurrent->getFirstName();
  3082.         $newSignerMember->last_name $userCurrent->getLastName();
  3083.         $newSignerMember->email $userCurrent->getEmail();
  3084.         $newSignerMember->phone_number $phone;
  3085.         //$newSignerRedirect = new \stdClass();
  3086.         //$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end_', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  3087.         //$newSignerRedirect->success = $urlSignEnd;
  3088.         //$newSignerRedirect->error = $urlSignEnd;
  3089.         $newSigner = new \stdClass();
  3090.         $newSigner->info $newSignerMember;
  3091.         $newSigner->signature_level "electronic_signature";
  3092.         $newSigner->signature_authentication_mode "otp_sms";
  3093.         //$newSigner->redirect_urls = $newSignerRedirect;
  3094.         try {
  3095.             $newSignerResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers'
  3096.                 [
  3097.                     'body' => json_encode($newSigner),
  3098.                     'headers' => [
  3099.                         'accept' => 'application/json',
  3100.                         'content-type' => 'application/json',
  3101.                         'Authorization' => 'Bearer ' $this->yousignApi
  3102.                     ],
  3103.                 ]
  3104.             );
  3105.             $newSignerResponseBody json_decode($newSignerResponse->getBody());
  3106.             $newSignerId $newSignerResponseBody->id;
  3107.          }
  3108.         catch (\Exception $e) {
  3109.             $responseErrorTab[] = $e->getMessage();
  3110.         }
  3111.         if($document->getFileType()){
  3112.             $page $document->getFileType()->getNumberPage();
  3113.         }
  3114.         else{
  3115.             // default page
  3116.             $page 2;
  3117.         }
  3118.         /* ADD SIGNATURE PLACED */
  3119.         $newFieldSignature = new \stdClass();
  3120.         $newFieldSignature->signer_id $newSignerId;
  3121.         $newFieldSignature->type "signature";
  3122.         $newFieldSignature->page $page;
  3123.         $newFieldSignature->width 114;
  3124.         $newFieldSignature->height 61;
  3125.         $newFieldSignature->433;
  3126.         $newFieldSignature->655;
  3127.         if($document->getFileType()){
  3128.             if($document->getFileType()->isSignedOrder()){
  3129.                 //Right
  3130.                 $newFieldSignature->width 114;
  3131.                 $newFieldSignature->height 61;
  3132.                 $newFieldSignature->433;
  3133.                 $newFieldSignature->655;
  3134.             }
  3135.             else{
  3136.                 //Left
  3137.                 $newFieldSignature->width 114;
  3138.                 $newFieldSignature->height 61;
  3139.                 $newFieldSignature->43;
  3140.                 $newFieldSignature->655;
  3141.             }
  3142.         } 
  3143.         try {
  3144.             $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadDocumentId.'/fields'
  3145.                 [
  3146.                     'body' => json_encode($newFieldSignature),
  3147.                     'headers' => [
  3148.                         'accept' => 'application/json',
  3149.                         'content-type' => 'application/json',
  3150.                         'Authorization' => 'Bearer ' $this->yousignApi
  3151.                     ],
  3152.                 ]
  3153.             );
  3154.         }
  3155.         catch (\Exception $e) {
  3156.             $responseErrorTab[] = $e->getMessage();
  3157.         }
  3158.         /* -----------------------------------  Active signature (end step)   ------------------------------------- */
  3159.         //Activate signature
  3160.         try {
  3161.             $activateSignatureResponse $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/activate'
  3162.                 [
  3163.                     'headers' => [
  3164.                         'accept' => 'application/json',
  3165.                         'Authorization' => 'Bearer ' $this->yousignApi
  3166.                     ],
  3167.                 ]
  3168.             );
  3169.             $activateSignatureResponseBody json_decode($activateSignatureResponse->getBody());
  3170.             $activateSignatureResponseSigners $activateSignatureResponseBody->signers;
  3171.             $signerUrl $activateSignatureResponseSigners[0]->signature_link;
  3172.         }
  3173.         catch (\Exception $e) {
  3174.             $responseErrorTab[] = $e->getMessage();
  3175.         }
  3176.         return [
  3177.             "responseProcedure" => $activateSignatureResponseBody,
  3178.             "procedureId" => $newSignatureId,
  3179.             "yousignUi" => $this->yousignUiConditions,
  3180.             "fileId" => $uploadDocumentId,
  3181.             "signerUrl" => $signerUrl,
  3182.             "responseErrorTab" => $responseErrorTab
  3183.         ];
  3184.     }
  3185.     function youSignConditions($fileURL$document$userCurrent null): array
  3186.     {
  3187.         $responseProcedure null;
  3188.         $cpFileId null;
  3189.         //Get CP BASE 64
  3190.         $b64Cp chunk_split(base64_encode(file_get_contents($fileURL)));
  3191.         $fileCp = new \stdClass();
  3192.         $fileCp->name "Conditions particulières";
  3193.         $fileCp->content $b64Cp;
  3194.         $fileCp->position 1;
  3195.         //Create files
  3196.         $curl curl_init();
  3197.         curl_setopt_array($curl, array(
  3198.             CURLOPT_URL => $this->yousignUrlV2 "/files",
  3199.             CURLOPT_RETURNTRANSFER => true,
  3200.             CURLOPT_ENCODING => '',
  3201.             CURLOPT_MAXREDIRS => 10,
  3202.             CURLOPT_TIMEOUT => 0,
  3203.             CURLOPT_FOLLOWLOCATION => true,
  3204.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  3205.             CURLOPT_CUSTOMREQUEST => "POST",
  3206.             CURLOPT_POSTFIELDS => json_encode($fileCp),
  3207.             CURLOPT_HTTPHEADER => array(
  3208.                 "Authorization: Bearer " $this->yousignApiV2,
  3209.                 "Content-Type: application/json"
  3210.             ),
  3211.         ));
  3212.         $responseFile curl_exec($curl);
  3213.         curl_close($curl);
  3214.         $responseFileCp json_decode($responseFile);
  3215.         if($responseFileCp){
  3216.             //Default (last value) : "432,131,548,184"; page 2;
  3217.             if($document->getFileType()){
  3218.                 if($document->getFileType()->isSignedOrder()){
  3219.                     //Right
  3220.                     $position "432,131,548,184";
  3221.                 }
  3222.                 else{
  3223.                     //Left
  3224.                     $position "50,134,178,180";
  3225.                 }
  3226.             } else {
  3227.                 // default position
  3228.                 $position "432,131,548,184";
  3229.             }
  3230.             if($document->getFileType()){
  3231.                 $page $document->getFileType()->getNumberPage();
  3232.             }
  3233.             else{
  3234.                 // default page
  3235.                 $page 2;
  3236.             }
  3237.             //Set file CP
  3238.             $fileObjectCp = new \stdClass();
  3239.             $fileObjectCp->file $responseFileCp->id;
  3240.             $fileObjectCp->page $page;
  3241.             $fileObjectCp->position $position;
  3242.             $fileObjectCp->mention "Lu et approuvé";
  3243.             $fileObjectCp->reason "Signed by John Doe (Yousign)";
  3244.             $firstName $userCurrent->getFirstName();
  3245.             $lastName $userCurrent->getLastName();
  3246.             if($firstName && $lastName){
  3247.                 $fileObjectCp->mention2 "Signé par " $firstName " " $lastName;
  3248.             }
  3249.             $arrayObjectFiles[] = $fileObjectCp;
  3250.             $cpFileId $responseFileCp->id;
  3251.             //Add procedure
  3252.             $config = new \stdClass();
  3253.             $webhook = new \stdClass();
  3254.             $webhookEnd = new \stdClass();
  3255.             $header = new \stdClass();
  3256.             $urlSignEnd $this->container->get('router')->generate('yousign_sign_conditions_end', array('documentID' => $document->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  3257.             $webhookEnd->url $urlSignEnd;
  3258.             $webhookEnd->method "GET";
  3259.             $webhookEnd->headers = (object)array(
  3260.                 'X-Custom-Header' => "End sign"
  3261.             );
  3262.             $config->webhook = (object)array(
  3263.                 'procedure.finished' => array(
  3264.                     $webhookEnd
  3265.                 )
  3266.             );
  3267.             //Set member - customer
  3268.             $member = new \stdClass();
  3269.             $member->firstname $userCurrent->getFirstName();
  3270.             $member->phone $userCurrent->getPhone();
  3271.             $member->lastname $userCurrent->getLastName();
  3272.             $member->email $userCurrent->getEmail();
  3273.             $member->fileObjects $arrayObjectFiles;
  3274.             $member->type "signer";
  3275.             //Set procedure
  3276.             $procedure = new \stdClass();
  3277.             $procedure->name "Signature des conditions particulières";
  3278.             $procedure->description "Fin d'adhésion";
  3279.             $procedure->start true;
  3280.             $procedure->members = array(
  3281.                 $member
  3282.             );
  3283.             $procedure->config $config;
  3284.             $curl curl_init();
  3285.             curl_setopt_array($curl, array(
  3286.                 CURLOPT_URL => $this->yousignUrlV2 "/procedures",
  3287.                 CURLOPT_RETURNTRANSFER => true,
  3288.                 CURLOPT_ENCODING => "",
  3289.                 CURLOPT_MAXREDIRS => 10,
  3290.                 CURLOPT_TIMEOUT => 0,
  3291.                 CURLOPT_FOLLOWLOCATION => true,
  3292.                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  3293.                 CURLOPT_CUSTOMREQUEST => "POST",
  3294.                 CURLOPT_POSTFIELDS => json_encode($procedure),
  3295.                 CURLOPT_HTTPHEADER => array(
  3296.                     "Authorization: Bearer " $this->yousignApiV2,
  3297.                     "Content-Type: application/json"
  3298.                 ),
  3299.             ));
  3300.             $responseProcedure curl_exec($curl);
  3301.             curl_close($curl);
  3302.             $responseProcedure json_decode($responseProcedure);
  3303.         }
  3304.         return [
  3305.             "responseProcedure" => $responseProcedure,
  3306.             "yousignUi" => $this->yousignUiConditions,
  3307.             "fileId" => $cpFileId,
  3308.         ];
  3309.     }
  3310.     function saveFilesConditionsYouSignV3($document)
  3311.     {
  3312.         $newSignatureId $document->getProcedureId();
  3313.         //Wait 2 secondes Yousign create file
  3314.         //sleep(2);
  3315.         /* ------------------------ SAVE Document START ------------------------ */
  3316.         //GET FIC FILE
  3317.         $client = new Client();
  3318.         $fileResponse $client->request('GET'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$document->getIdYouSign().'/download'
  3319.             [
  3320.                 'headers' => [
  3321.                     'accept' => 'application/json',
  3322.                     'content-type' => 'application/json',
  3323.                     'Authorization' => 'Bearer ' $this->yousignApi
  3324.                 ],
  3325.             ]
  3326.         );
  3327.         $fileBody $fileResponse->getBody();
  3328.         $name $document->getNumeroAdherent() . "_" $document->getLastName() . "_" $document->getFirstName() . "_CONDITIONS_PARTICULIERES.pdf";
  3329.         $path $this->fileUploader->getTargetDirectory() . "/cp/" $document->getId() . "/" $name;
  3330.         file_put_contents($path$fileBody);
  3331.         /* ------------------------ SAVE Document END ------------------------ */
  3332.         $document->setUrlPdfSign($path);
  3333.         $document->setFilename($name);
  3334.     
  3335.         $this->em->persist($document);
  3336.         $this->em->flush();
  3337.     }
  3338.     function saveFilesConditionsYouSign($document)
  3339.     {
  3340.         //GET DIC FILE
  3341.         $curl curl_init();
  3342.         curl_setopt_array($curl, array(
  3343.             CURLOPT_URL => $this->yousignUrl $document->getIdYouSign() . "/download",
  3344.             CURLOPT_RETURNTRANSFER => true,
  3345.             CURLOPT_ENCODING => "",
  3346.             CURLOPT_MAXREDIRS => 10,
  3347.             CURLOPT_TIMEOUT => 0,
  3348.             CURLOPT_FOLLOWLOCATION => true,
  3349.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  3350.             CURLOPT_CUSTOMREQUEST => "GET",
  3351.             CURLOPT_HTTPHEADER => array(
  3352.                 "Authorization: Bearer " $this->yousignApi,
  3353.                 "Content-Type: application/json"
  3354.             ),
  3355.         ));
  3356.         $responseFile curl_exec($curl);
  3357.         curl_close($curl);
  3358.         $file json_decode($responseFile);
  3359.         $fileBin base64_decode($filetrue);
  3360.         $name $document->getNumeroAdherent() . "_" $document->getLastName() . "_" $document->getFirstName() . "_CONDITIONS_PARTICULIERES.pdf";
  3361.         $path $this->fileUploader->getTargetDirectory() . "/cp/" $document->getId() . "/" $name;
  3362.         file_put_contents($path$fileBin);
  3363.         $document->setUrlPdfSign($path);
  3364.         $document->setFilename($name);
  3365.     
  3366.         $this->em->persist($document);
  3367.         $this->em->flush();
  3368.     }
  3369. }