src/Services/Utils.php line 63

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$membership)
  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'membership' => $membership)
  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.             $phone str_replace("_"""$phone);
  858.             if ($seller->getPhonePrefix()) {
  859.                 $phone $seller->getPhonePrefix() . $phone;
  860.             }
  861.             else{
  862.                 $phone "+33" $phone;
  863.             }
  864.             $newSignerSellerMember = new \stdClass();
  865.             $newSignerSellerMember->locale "fr";
  866.             $newSignerSellerMember->first_name $seller->getFirstName();
  867.             $newSignerSellerMember->last_name $seller->getLastName();
  868.             $newSignerSellerMember->email $seller->getEmail();
  869.             $newSignerSellerMember->phone_number $phone;
  870.             //$newSignerSellerRedirect = new \stdClass();
  871.             //$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end_seller', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  872.             //$newSignerSellerRedirect->success = $urlSignEnd;
  873.             //$newSignerSellerRedirect->error = $urlSignEnd;
  874.             $newSignerSeller = new \stdClass();
  875.             $newSignerSeller->info $newSignerSellerMember;
  876.             $newSignerSeller->signature_level "electronic_signature";
  877.             $newSignerSeller->signature_authentication_mode "otp_email";
  878.             //$newSignerSeller->redirect_urls = $newSignerSellerRedirect;
  879.             try {
  880.                 $newSignerSellerResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers'
  881.                     [
  882.                         'body' => json_encode($newSignerSeller),
  883.                         'headers' => [
  884.                             'accept' => 'application/json',
  885.                             'content-type' => 'application/json',
  886.                             'Authorization' => 'Bearer ' $this->yousignApi
  887.                         ],
  888.                     ]
  889.                 );
  890.                 $newSignerSellerResponseBody json_decode($newSignerSellerResponse->getBody());
  891.                 $newSignerSellerId $newSignerSellerResponseBody->id;
  892.              }
  893.             catch (\Exception $e) {
  894.                 $responseErrorTab[] = $e->getMessage();
  895.             }
  896.         }
  897.         //Add Signer (customer)
  898.         $phone $customer->getPhone();
  899.         $phone str_replace("("""$phone);
  900.         $phone str_replace(")"""$phone);
  901.         $phone str_replace(" """$phone);
  902.         $phone str_replace("_"""$phone);
  903.         if ($customer->getPhonePrefix()) {
  904.             $phone $customer->getPhonePrefix() . $phone;
  905.         }
  906.         //FirstName
  907.         $customerFirstName $customer->getFirstName();
  908.         $customerFirstName str_replace(","" "$customerFirstName);
  909.         $newSignerCustomerMember = new \stdClass();
  910.         $newSignerCustomerMember->locale "fr";
  911.         $newSignerCustomerMember->first_name $customerFirstName;
  912.         $newSignerCustomerMember->last_name $customer->getLastName();
  913.         $newSignerCustomerMember->email $customer->getEmail();
  914.         $newSignerCustomerMember->phone_number $phone;
  915.         //$newSignerCustomerRedirect = new \stdClass();
  916.         //$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  917.         //$newSignerCustomerRedirect->success = $urlSignEnd;
  918.         //$newSignerCustomerRedirect->error = $urlSignEnd;
  919.         $newSignerCustomer = new \stdClass();
  920.         $newSignerCustomer->info $newSignerCustomerMember;
  921.         $newSignerCustomer->signature_level "electronic_signature";
  922.         if($customer->isMethodForSignEmail()){
  923.             $newSignerCustomer->signature_authentication_mode "otp_email";
  924.         }
  925.         else{
  926.             $newSignerCustomer->signature_authentication_mode "otp_sms";
  927.         }
  928.         //For order
  929.         if($membership->getPlatformVersion() == && !$customer->isIsAutoSignup()){
  930.             $newSignerCustomer->insert_after_id $newSignerSellerId;
  931.         }
  932.         try {
  933.             $newSignerCustomerResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers'
  934.                 [
  935.                     'body' => json_encode($newSignerCustomer),
  936.                     'headers' => [
  937.                         'accept' => 'application/json',
  938.                         'content-type' => 'application/json',
  939.                         'Authorization' => 'Bearer ' $this->yousignApi
  940.                     ],
  941.                 ]
  942.             );
  943.             $newSignerCustomerResponseBody json_decode($newSignerCustomerResponse->getBody());
  944.             $newSignerCustomerId $newSignerCustomerResponseBody->id;
  945.         }
  946.         catch (\Exception $e) {
  947.             $responseErrorTab[] = $e->getMessage();
  948.         }
  949.         //ForLegal1
  950.         if($isLegal1){
  951.             //Add Signer (customer)
  952.             $phone $membership->getBa()->getRepLegal1TelephonePortable();
  953.             $phone str_replace("("""$phone);
  954.             $phone str_replace(")"""$phone);
  955.             $phone str_replace(" """$phone);
  956.             $phone str_replace("_"""$phone);
  957.             if ($membership->getBa()->getRepLegal1TelephonePortablePrefix()) {
  958.                 $phone $membership->getBa()->getRepLegal1TelephonePortablePrefix() . $phone;
  959.             }
  960.             //FirstName
  961.             $customerFirstName $membership->getBa()->getRepLegal1Prenoms();
  962.             $customerFirstName str_replace(","" "$customerFirstName);
  963.             $newSignerCustomerLegal1Member = new \stdClass();
  964.             $newSignerCustomerLegal1Member->locale "fr";
  965.             $newSignerCustomerLegal1Member->first_name $customerFirstName;
  966.             $newSignerCustomerLegal1Member->last_name $membership->getBa()->getRepLegal1Nom();
  967.             $newSignerCustomerLegal1Member->email $membership->getBa()->getRepLegal1Email();
  968.             $newSignerCustomerLegal1Member->phone_number $phone;
  969.             //$newSignerCustomerRedirect = new \stdClass();
  970.             //$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  971.             //$newSignerCustomerRedirect->success = $urlSignEnd;
  972.             //$newSignerCustomerRedirect->error = $urlSignEnd;
  973.             $newSignerCustomerLegal1 = new \stdClass();
  974.             $newSignerCustomerLegal1->info $newSignerCustomerLegal1Member;
  975.             $newSignerCustomerLegal1->signature_level "electronic_signature";
  976.             $newSignerCustomerLegal1->delivery_mode "email";
  977.             if($customer->isMethodForSignEmail()){
  978.                 $newSignerCustomerLegal1->signature_authentication_mode "otp_email";
  979.             }
  980.             else{
  981.                 $newSignerCustomerLegal1->signature_authentication_mode "otp_sms";
  982.             }
  983.             //For order
  984.             if(!$customer->isIsAutoSignup()){
  985.                 $newSignerCustomerLegal1->insert_after_id $newSignerCustomerId;
  986.             }
  987.             try {
  988.                 $newSignerCustomerLegal1Response $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers'
  989.                     [
  990.                         'body' => json_encode($newSignerCustomerLegal1),
  991.                         'headers' => [
  992.                             'accept' => 'application/json',
  993.                             'content-type' => 'application/json',
  994.                             'Authorization' => 'Bearer ' $this->yousignApi
  995.                         ],
  996.                     ]
  997.                 );
  998.                 $newSignerCustomerLegal1ResponseBody json_decode($newSignerCustomerLegal1Response->getBody());
  999.                 $newSignerCustomerLegal1Id $newSignerCustomerLegal1ResponseBody->id;
  1000.             }
  1001.             catch (\Exception $e) {
  1002.                 $responseErrorTab[] = $e->getMessage();
  1003.             }
  1004.         }
  1005.         //ForLegal2
  1006.         if($isLegal2){
  1007.             //Add Signer (customer)
  1008.             $phone $membership->getBa()->getRepLegal2TelephonePortable();
  1009.             $phone str_replace("("""$phone);
  1010.             $phone str_replace(")"""$phone);
  1011.             $phone str_replace(" """$phone);
  1012.             $phone str_replace("_"""$phone);
  1013.             if ($membership->getBa()->getRepLegal2TelephonePortablePrefix()) {
  1014.                 $phone $membership->getBa()->getRepLegal2TelephonePortablePrefix() . $phone;
  1015.             }
  1016.             //FirstName
  1017.             $customerFirstName $membership->getBa()->getRepLegal2Prenoms();
  1018.             $customerFirstName str_replace(","" "$customerFirstName);
  1019.             $newSignerCustomerLegal2Member = new \stdClass();
  1020.             $newSignerCustomerLegal2Member->locale "fr";
  1021.             $newSignerCustomerLegal2Member->first_name $customerFirstName;
  1022.             $newSignerCustomerLegal2Member->last_name $membership->getBa()->getRepLegal2Nom();
  1023.             $newSignerCustomerLegal2Member->email $membership->getBa()->getRepLegal2Email();
  1024.             $newSignerCustomerLegal2Member->phone_number $phone;
  1025.             //$newSignerCustomerRedirect = new \stdClass();
  1026.             //$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  1027.             //$newSignerCustomerRedirect->success = $urlSignEnd;
  1028.             //$newSignerCustomerRedirect->error = $urlSignEnd;
  1029.             $newSignerCustomerLegal2 = new \stdClass();
  1030.             $newSignerCustomerLegal2->info $newSignerCustomerLegal2Member;
  1031.             $newSignerCustomerLegal2->signature_level "electronic_signature";
  1032.             $newSignerCustomerLegal2->delivery_mode "email";
  1033.             if($customer->isMethodForSignEmail()){
  1034.                 $newSignerCustomerLegal2->signature_authentication_mode "otp_email";
  1035.             }
  1036.             else{
  1037.                 $newSignerCustomerLegal2->signature_authentication_mode "otp_sms";
  1038.             }
  1039.             //For order
  1040.             if(!$customer->isIsAutoSignup()){
  1041.                 $newSignerCustomerLegal2->insert_after_id $newSignerCustomerLegal1Id;
  1042.             }
  1043.             try {
  1044.                 $newSignerCustomerLegal2Response $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers'
  1045.                     [
  1046.                         'body' => json_encode($newSignerCustomerLegal2),
  1047.                         'headers' => [
  1048.                             'accept' => 'application/json',
  1049.                             'content-type' => 'application/json',
  1050.                             'Authorization' => 'Bearer ' $this->yousignApi
  1051.                         ],
  1052.                     ]
  1053.                 );
  1054.                 $newSignerCustomerLegal2ResponseBody json_decode($newSignerCustomerLegal2Response->getBody());
  1055.                 $newSignerCustomerLegal2Id $newSignerCustomerLegal2ResponseBody->id;
  1056.             }
  1057.             catch (\Exception $e) {
  1058.                 $responseErrorTab[] = $e->getMessage();
  1059.             }
  1060.         }
  1061.         /* -----------------------------------  Add Fields   ------------------------------------- */
  1062.         //Add fields on FIC for sgnature
  1063.         //No Allianz customer
  1064.         if ($membership->getDicIsFile() != true) {
  1065.             if($typeProduct == "epargne"){
  1066.                 if($customer->isIsAutoSignup()){
  1067.                     //For customer
  1068.                     $newFieldCustomerSignature = new \stdClass();
  1069.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1070.                     $newFieldCustomerSignature->type "signature";
  1071.                     $newFieldCustomerSignature->page 9;
  1072.                     $newFieldCustomerSignature->width 139;
  1073.                     $newFieldCustomerSignature->height 62;
  1074.                     $newFieldCustomerSignature->35;
  1075.                     $newFieldCustomerSignature->697;
  1076.                     try {
  1077.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1078.                             [
  1079.                                 'body' => json_encode($newFieldCustomerSignature),
  1080.                                 'headers' => [
  1081.                                     'accept' => 'application/json',
  1082.                                     'content-type' => 'application/json',
  1083.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1084.                                 ],
  1085.                             ]
  1086.                         );
  1087.                     }
  1088.                     catch (\Exception $e) {
  1089.                         $responseErrorTab[] = $e->getMessage();
  1090.                     }
  1091.                     //Add fields on FIC for city (customer)
  1092.                     $newFieldCustomerSignature = new \stdClass();
  1093.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1094.                     $newFieldCustomerSignature->type "text";
  1095.                     $newFieldCustomerSignature->max_length 44;
  1096.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1097.                     $newFieldCustomerSignature->page 9;
  1098.                     $newFieldCustomerSignature->width 202;
  1099.                     $newFieldCustomerSignature->height 18;
  1100.                     $newFieldCustomerSignature->49;
  1101.                     $newFieldCustomerSignature->540;
  1102.                     try {
  1103.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1104.                             [
  1105.                                 'body' => json_encode($newFieldCustomerSignature),
  1106.                                 'headers' => [
  1107.                                     'accept' => 'application/json',
  1108.                                     'content-type' => 'application/json',
  1109.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1110.                                 ],
  1111.                             ]
  1112.                         );
  1113.                     }
  1114.                     catch (\Exception $e) {
  1115.                         $responseErrorTab[] = $e->getMessage();
  1116.                     }
  1117.                     //Add fields on FIC for date (customer)
  1118.                     $newFieldCustomerSignature = new \stdClass();
  1119.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1120.                     $newFieldCustomerSignature->type "mention";
  1121.                     $newFieldCustomerSignature->mention "%date%";
  1122.                     $newFieldCustomerSignature->font $fontDefault;
  1123.                     $newFieldCustomerSignature->page 9;
  1124.                     $newFieldCustomerSignature->width 202;
  1125.                     $newFieldCustomerSignature->height 18;
  1126.                     $newFieldCustomerSignature->50;
  1127.                     $newFieldCustomerSignature->582;
  1128.                     try {
  1129.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1130.                             [
  1131.                                 'body' => json_encode($newFieldCustomerSignature),
  1132.                                 'headers' => [
  1133.                                     'accept' => 'application/json',
  1134.                                     'content-type' => 'application/json',
  1135.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1136.                                 ],
  1137.                             ]
  1138.                         );
  1139.                     }
  1140.                     catch (\Exception $e) {
  1141.                         $responseErrorTab[] = $e->getMessage();
  1142.                     }
  1143.                 }
  1144.                 else{
  1145.                     //For seller
  1146.                     $newFieldSellerSignature = new \stdClass();
  1147.                     $newFieldSellerSignature->signer_id $newSignerSellerId;
  1148.                     $newFieldSellerSignature->type "signature";
  1149.                     $newFieldSellerSignature->page 12;
  1150.                     $newFieldSellerSignature->width 123;
  1151.                     $newFieldSellerSignature->height 66;
  1152.                     $newFieldSellerSignature->414;
  1153.                     $newFieldSellerSignature->611;
  1154.                     try {
  1155.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1156.                             [
  1157.                                 'body' => json_encode($newFieldSellerSignature),
  1158.                                 'headers' => [
  1159.                                     'accept' => 'application/json',
  1160.                                     'content-type' => 'application/json',
  1161.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1162.                                 ],
  1163.                             ]
  1164.                         );
  1165.                     }
  1166.                     catch (\Exception $e) {
  1167.                         $responseErrorTab[] = $e->getMessage();
  1168.                     }
  1169.                     //For customer
  1170.                     $newFieldCustomerSignature = new \stdClass();
  1171.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1172.                     $newFieldCustomerSignature->type "signature";
  1173.                     $newFieldCustomerSignature->page 12;
  1174.                     $newFieldCustomerSignature->width 212;
  1175.                     $newFieldCustomerSignature->height 42;
  1176.                     $newFieldCustomerSignature->36;
  1177.                     $newFieldCustomerSignature->574;
  1178.                     try {
  1179.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1180.                             [
  1181.                                 'body' => json_encode($newFieldCustomerSignature),
  1182.                                 'headers' => [
  1183.                                     'accept' => 'application/json',
  1184.                                     'content-type' => 'application/json',
  1185.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1186.                                 ],
  1187.                             ]
  1188.                         );
  1189.                     }
  1190.                     catch (\Exception $e) {
  1191.                         $responseErrorTab[] = $e->getMessage();
  1192.                     }
  1193.                     //Add fields on FIC for city (customer)
  1194.                     $newFieldCustomerSignature = new \stdClass();
  1195.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1196.                     $newFieldCustomerSignature->type "text";
  1197.                     $newFieldCustomerSignature->max_length 44;
  1198.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1199.                     $newFieldCustomerSignature->page 12;
  1200.                     $newFieldCustomerSignature->width 149;
  1201.                     $newFieldCustomerSignature->height 19;
  1202.                     $newFieldCustomerSignature->51;
  1203.                     $newFieldCustomerSignature->473;
  1204.                     try {
  1205.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1206.                             [
  1207.                                 'body' => json_encode($newFieldCustomerSignature),
  1208.                                 'headers' => [
  1209.                                     'accept' => 'application/json',
  1210.                                     'content-type' => 'application/json',
  1211.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1212.                                 ],
  1213.                             ]
  1214.                         );
  1215.                     }
  1216.                     catch (\Exception $e) {
  1217.                         $responseErrorTab[] = $e->getMessage();
  1218.                     }
  1219.                     //Add fields on FIC for date (customer)
  1220.                     $newFieldCustomerSignature = new \stdClass();
  1221.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1222.                     $newFieldCustomerSignature->type "mention";
  1223.                     $newFieldCustomerSignature->mention "%date%";
  1224.                     $newFieldCustomerSignature->font $fontDefault;
  1225.                     $newFieldCustomerSignature->page 12;
  1226.                     $newFieldCustomerSignature->width 149;
  1227.                     $newFieldCustomerSignature->height 19;
  1228.                     $newFieldCustomerSignature->51;
  1229.                     $newFieldCustomerSignature->509;
  1230.                     try {
  1231.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1232.                             [
  1233.                                 'body' => json_encode($newFieldCustomerSignature),
  1234.                                 'headers' => [
  1235.                                     'accept' => 'application/json',
  1236.                                     'content-type' => 'application/json',
  1237.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1238.                                 ],
  1239.                             ]
  1240.                         );
  1241.                     }
  1242.                     catch (\Exception $e) {
  1243.                         $responseErrorTab[] = $e->getMessage();
  1244.                     }
  1245.                     //ForLegal1
  1246.                     if($isLegal1){
  1247.                         $newFieldCustomerLegal1Signature = new \stdClass();
  1248.                         $newFieldCustomerLegal1Signature->signer_id $newSignerCustomerLegal1Id;
  1249.                         $newFieldCustomerLegal1Signature->type "signature";
  1250.                         $newFieldCustomerLegal1Signature->page 12;
  1251.                         $newFieldCustomerLegal1Signature->width 112;
  1252.                         $newFieldCustomerLegal1Signature->height 42;
  1253.                         $newFieldCustomerLegal1Signature->36;
  1254.                         $newFieldCustomerLegal1Signature->672;
  1255.                         try {
  1256.                             $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1257.                                 [
  1258.                                     'body' => json_encode($newFieldCustomerLegal1Signature),
  1259.                                     'headers' => [
  1260.                                         'accept' => 'application/json',
  1261.                                         'content-type' => 'application/json',
  1262.                                         'Authorization' => 'Bearer ' $this->yousignApi
  1263.                                     ],
  1264.                                 ]
  1265.                             );
  1266.                         }
  1267.                         catch (\Exception $e) {
  1268.                             $responseErrorTab[] = $e->getMessage();
  1269.                         }
  1270.                     }
  1271.                     //ForLegal2
  1272.                     if($isLegal2){
  1273.                         $newFieldCustomerLegal2Signature = new \stdClass();
  1274.                         $newFieldCustomerLegal2Signature->signer_id $newSignerCustomerLegal2Id;
  1275.                         $newFieldCustomerLegal2Signature->type "signature";
  1276.                         $newFieldCustomerLegal2Signature->page 12;
  1277.                         $newFieldCustomerLegal2Signature->width 112;
  1278.                         $newFieldCustomerLegal2Signature->height 42;
  1279.                         $newFieldCustomerLegal2Signature->36;
  1280.                         $newFieldCustomerLegal2Signature->743;
  1281.                         try {
  1282.                             $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1283.                                 [
  1284.                                     'body' => json_encode($newFieldCustomerLegal2Signature),
  1285.                                     'headers' => [
  1286.                                         'accept' => 'application/json',
  1287.                                         'content-type' => 'application/json',
  1288.                                         'Authorization' => 'Bearer ' $this->yousignApi
  1289.                                     ],
  1290.                                 ]
  1291.                             );
  1292.                         }
  1293.                         catch (\Exception $e) {
  1294.                             $responseErrorTab[] = $e->getMessage();
  1295.                         }
  1296.                     }
  1297.                 }
  1298.             }
  1299.             else {
  1300.                 //For v2 with seller
  1301.                 if($membership->getPlatformVersion() == && !$customer->isIsAutoSignup()){
  1302.                     //For seller
  1303.                     $newFieldSellerSignature = new \stdClass();
  1304.                     $newFieldSellerSignature->signer_id $newSignerSellerId;
  1305.                     $newFieldSellerSignature->type "signature";
  1306.                     $newFieldSellerSignature->page 9;
  1307.                     $newFieldSellerSignature->width 194;
  1308.                     $newFieldSellerSignature->height 88;
  1309.                     $newFieldSellerSignature->355;
  1310.                     $newFieldSellerSignature->558;
  1311.                     try {
  1312.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1313.                             [
  1314.                                 'body' => json_encode($newFieldSellerSignature),
  1315.                                 'headers' => [
  1316.                                     'accept' => 'application/json',
  1317.                                     'content-type' => 'application/json',
  1318.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1319.                                 ],
  1320.                             ]
  1321.                         );
  1322.                     }
  1323.                     catch (\Exception $e) {
  1324.                         $responseErrorTab[] = $e->getMessage();
  1325.                     }
  1326.                     /* --------------------------------------------------- */
  1327.                     //For customer
  1328.                     $newFieldCustomerSignature = new \stdClass();
  1329.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1330.                     $newFieldCustomerSignature->type "signature";
  1331.                     $newFieldCustomerSignature->page 9;
  1332.                     $newFieldCustomerSignature->width 194;
  1333.                     $newFieldCustomerSignature->height 88;
  1334.                     $newFieldCustomerSignature->62;
  1335.                     $newFieldCustomerSignature->558;
  1336.                     try {
  1337.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1338.                             [
  1339.                                 'body' => json_encode($newFieldCustomerSignature),
  1340.                                 'headers' => [
  1341.                                     'accept' => 'application/json',
  1342.                                     'content-type' => 'application/json',
  1343.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1344.                                 ],
  1345.                             ]
  1346.                         );
  1347.                     }
  1348.                     catch (\Exception $e) {
  1349.                         $responseErrorTab[] = $e->getMessage();
  1350.                     }
  1351.                     //Add fields on FIC for city (customer)
  1352.                     $newFieldCustomerSignature = new \stdClass();
  1353.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1354.                     $newFieldCustomerSignature->type "text";
  1355.                     $newFieldCustomerSignature->max_length 44;
  1356.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1357.                     $newFieldCustomerSignature->page 9;
  1358.                     $newFieldCustomerSignature->width 286;
  1359.                     $newFieldCustomerSignature->height 24;
  1360.                     $newFieldCustomerSignature->68;
  1361.                     $newFieldCustomerSignature->377;
  1362.                     try {
  1363.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1364.                             [
  1365.                                 'body' => json_encode($newFieldCustomerSignature),
  1366.                                 'headers' => [
  1367.                                     'accept' => 'application/json',
  1368.                                     'content-type' => 'application/json',
  1369.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1370.                                 ],
  1371.                             ]
  1372.                         );
  1373.                     }
  1374.                     catch (\Exception $e) {
  1375.                         $responseErrorTab[] = $e->getMessage();
  1376.                     }
  1377.                     //Add fields on FIC for date (customer)
  1378.                     $newFieldCustomerSignature = new \stdClass();
  1379.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1380.                     $newFieldCustomerSignature->type "mention";
  1381.                     $newFieldCustomerSignature->mention "%date%";
  1382.                     $newFieldCustomerSignature->font $fontDefault;
  1383.                     $newFieldCustomerSignature->page 9;
  1384.                     $newFieldCustomerSignature->width 286;
  1385.                     $newFieldCustomerSignature->height 24;
  1386.                     $newFieldCustomerSignature->68;
  1387.                     $newFieldCustomerSignature->405;
  1388.                     try {
  1389.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1390.                             [
  1391.                                 'body' => json_encode($newFieldCustomerSignature),
  1392.                                 'headers' => [
  1393.                                     'accept' => 'application/json',
  1394.                                     'content-type' => 'application/json',
  1395.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1396.                                 ],
  1397.                             ]
  1398.                         );
  1399.                     }
  1400.                     catch (\Exception $e) {
  1401.                         $responseErrorTab[] = $e->getMessage();
  1402.                     }
  1403.                 }
  1404.                 else{
  1405.                     //For customer
  1406.                     $newFieldCustomerSignature = new \stdClass();
  1407.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1408.                     $newFieldCustomerSignature->type "signature";
  1409.                     $newFieldCustomerSignature->page 9;
  1410.                     $newFieldCustomerSignature->width 160;
  1411.                     $newFieldCustomerSignature->height 94;
  1412.                     $newFieldCustomerSignature->78;
  1413.                     $newFieldCustomerSignature->554;
  1414.                     try {
  1415.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1416.                             [
  1417.                                 'body' => json_encode($newFieldCustomerSignature),
  1418.                                 'headers' => [
  1419.                                     'accept' => 'application/json',
  1420.                                     'content-type' => 'application/json',
  1421.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1422.                                 ],
  1423.                             ]
  1424.                         );
  1425.                     }
  1426.                     catch (\Exception $e) {
  1427.                         $responseErrorTab[] = $e->getMessage();
  1428.                     }
  1429.                     //Add fields on FIC for city (customer)
  1430.                     $newFieldCustomerSignature = new \stdClass();
  1431.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1432.                     $newFieldCustomerSignature->type "text";
  1433.                     $newFieldCustomerSignature->max_length 44;
  1434.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1435.                     $newFieldCustomerSignature->page 9;
  1436.                     $newFieldCustomerSignature->width 286;
  1437.                     $newFieldCustomerSignature->height 24;
  1438.                     $newFieldCustomerSignature->68;
  1439.                     $newFieldCustomerSignature->378;
  1440.                     try {
  1441.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1442.                             [
  1443.                                 'body' => json_encode($newFieldCustomerSignature),
  1444.                                 'headers' => [
  1445.                                     'accept' => 'application/json',
  1446.                                     'content-type' => 'application/json',
  1447.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1448.                                 ],
  1449.                             ]
  1450.                         );
  1451.                     }
  1452.                     catch (\Exception $e) {
  1453.                         $responseErrorTab[] = $e->getMessage();
  1454.                     }
  1455.                     //Add fields on FIC for date (customer)
  1456.                     $newFieldCustomerSignature = new \stdClass();
  1457.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1458.                     $newFieldCustomerSignature->type "mention";
  1459.                     $newFieldCustomerSignature->mention "%date%";
  1460.                     $newFieldCustomerSignature->font $fontDefault;
  1461.                     $newFieldCustomerSignature->page 9;
  1462.                     $newFieldCustomerSignature->width 286;
  1463.                     $newFieldCustomerSignature->height 24;
  1464.                     $newFieldCustomerSignature->68;
  1465.                     $newFieldCustomerSignature->405;
  1466.                     try {
  1467.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadFicId.'/fields'
  1468.                             [
  1469.                                 'body' => json_encode($newFieldCustomerSignature),
  1470.                                 'headers' => [
  1471.                                     'accept' => 'application/json',
  1472.                                     'content-type' => 'application/json',
  1473.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1474.                                 ],
  1475.                             ]
  1476.                         );
  1477.                     }
  1478.                     catch (\Exception $e) {
  1479.                         $responseErrorTab[] = $e->getMessage();
  1480.                     }
  1481.                 }
  1482.             }
  1483.             
  1484.         }
  1485.         if($typeProduct == "epargne"){
  1486.             if($customer->isIsAutoSignup()){
  1487.                 //Add fields on BA for sgnature (customer)
  1488.                 $newFieldCustomerSignature = new \stdClass();
  1489.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1490.                 $newFieldCustomerSignature->type "signature";
  1491.                 $newFieldCustomerSignature->page 7;
  1492.                 $newFieldCustomerSignature->width 185;
  1493.                 $newFieldCustomerSignature->height 69;
  1494.                 $newFieldCustomerSignature->266;
  1495.                 $newFieldCustomerSignature->573;
  1496.                 try {
  1497.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1498.                         [
  1499.                             'body' => json_encode($newFieldCustomerSignature),
  1500.                             'headers' => [
  1501.                                 'accept' => 'application/json',
  1502.                                 'content-type' => 'application/json',
  1503.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1504.                             ],
  1505.                         ]
  1506.                     );
  1507.                 }
  1508.                 catch (\Exception $e) {
  1509.                     $responseErrorTab[] = $e->getMessage();
  1510.                 }
  1511.                 //Add fields on BA for city (customer)
  1512.                 $newFieldCustomerSignature = new \stdClass();
  1513.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1514.                 $newFieldCustomerSignature->type "text";
  1515.                 $newFieldCustomerSignature->max_length 44;
  1516.                 $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1517.                 $newFieldCustomerSignature->page 7;
  1518.                 $newFieldCustomerSignature->width 196;
  1519.                 $newFieldCustomerSignature->height 19;
  1520.                 $newFieldCustomerSignature->51;
  1521.                 $newFieldCustomerSignature->573;
  1522.                 try {
  1523.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1524.                         [
  1525.                             'body' => json_encode($newFieldCustomerSignature),
  1526.                             'headers' => [
  1527.                                 'accept' => 'application/json',
  1528.                                 'content-type' => 'application/json',
  1529.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1530.                             ],
  1531.                         ]
  1532.                     );
  1533.                 }
  1534.                 catch (\Exception $e) {
  1535.                     $responseErrorTab[] = $e->getMessage();
  1536.                 }
  1537.                 //Add fields on BA for date (customer)
  1538.                 $newFieldCustomerSignature = new \stdClass();
  1539.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1540.                 $newFieldCustomerSignature->type "mention";
  1541.                 $newFieldCustomerSignature->font $fontDefault;
  1542.                 $newFieldCustomerSignature->mention "%date%";
  1543.                 $newFieldCustomerSignature->page 7;
  1544.                 $newFieldCustomerSignature->width 196;
  1545.                 $newFieldCustomerSignature->height 19;
  1546.                 $newFieldCustomerSignature->51;
  1547.                 $newFieldCustomerSignature->603;
  1548.                 try {
  1549.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1550.                         [
  1551.                             'body' => json_encode($newFieldCustomerSignature),
  1552.                             'headers' => [
  1553.                                 'accept' => 'application/json',
  1554.                                 'content-type' => 'application/json',
  1555.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1556.                             ],
  1557.                         ]
  1558.                     );
  1559.                 }
  1560.                 catch (\Exception $e) {
  1561.                     $responseErrorTab[] = $e->getMessage();
  1562.                 }
  1563.             }
  1564.             else{
  1565.                 //Add fields on BA for sgnature (customer)
  1566.                 $newFieldCustomerSignature = new \stdClass();
  1567.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1568.                 $newFieldCustomerSignature->type "signature";
  1569.                 $newFieldCustomerSignature->page 8;
  1570.                 $newFieldCustomerSignature->width 99;
  1571.                 $newFieldCustomerSignature->height 39;
  1572.                 $newFieldCustomerSignature->251;
  1573.                 $newFieldCustomerSignature->568;
  1574.                 try {
  1575.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1576.                         [
  1577.                             'body' => json_encode($newFieldCustomerSignature),
  1578.                             'headers' => [
  1579.                                 'accept' => 'application/json',
  1580.                                 'content-type' => 'application/json',
  1581.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1582.                             ],
  1583.                         ]
  1584.                     );
  1585.                 }
  1586.                 catch (\Exception $e) {
  1587.                     $responseErrorTab[] = $e->getMessage();
  1588.                 }
  1589.                 //Legal 1 BA
  1590.                 if($isLegal1){
  1591.                     //Add fields on BA for sgnature (customer)
  1592.                     $newFieldCustomerLegal1Signature = new \stdClass();
  1593.                     $newFieldCustomerLegal1Signature->signer_id $newSignerCustomerLegal1Id;
  1594.                     $newFieldCustomerLegal1Signature->type "signature";
  1595.                     $newFieldCustomerLegal1Signature->page 8;
  1596.                     $newFieldCustomerLegal1Signature->width 99;
  1597.                     $newFieldCustomerLegal1Signature->height 39;
  1598.                     $newFieldCustomerLegal1Signature->251;
  1599.                     $newFieldCustomerLegal1Signature->679;
  1600.                     try {
  1601.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1602.                             [
  1603.                                 'body' => json_encode($newFieldCustomerLegal1Signature),
  1604.                                 'headers' => [
  1605.                                     'accept' => 'application/json',
  1606.                                     'content-type' => 'application/json',
  1607.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1608.                                 ],
  1609.                             ]
  1610.                         );
  1611.                     }
  1612.                     catch (\Exception $e) {
  1613.                         $responseErrorTab[] = $e->getMessage();
  1614.                     }
  1615.                 }
  1616.                 //Legal 2 BA
  1617.                 if($isLegal2){
  1618.                     //Add fields on BA for sgnature (customer)
  1619.                     $newFieldCustomerLegal2Signature = new \stdClass();
  1620.                     $newFieldCustomerLegal2Signature->signer_id $newSignerCustomerLegal2Id;
  1621.                     $newFieldCustomerLegal2Signature->type "signature";
  1622.                     $newFieldCustomerLegal2Signature->page 8;
  1623.                     $newFieldCustomerLegal2Signature->width 99;
  1624.                     $newFieldCustomerLegal2Signature->height 39;
  1625.                     $newFieldCustomerLegal2Signature->251;
  1626.                     $newFieldCustomerLegal2Signature->767;
  1627.                     try {
  1628.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1629.                             [
  1630.                                 'body' => json_encode($newFieldCustomerLegal2Signature),
  1631.                                 'headers' => [
  1632.                                     'accept' => 'application/json',
  1633.                                     'content-type' => 'application/json',
  1634.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1635.                                 ],
  1636.                             ]
  1637.                         );
  1638.                     }
  1639.                     catch (\Exception $e) {
  1640.                         $responseErrorTab[] = $e->getMessage();
  1641.                     }
  1642.                 }
  1643.                 //Add fields on BA for city (customer)
  1644.                 $newFieldCustomerSignature = new \stdClass();
  1645.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1646.                 $newFieldCustomerSignature->type "text";
  1647.                 $newFieldCustomerSignature->max_length 44;
  1648.                 $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1649.                 $newFieldCustomerSignature->page 8;
  1650.                 $newFieldCustomerSignature->width 170;
  1651.                 $newFieldCustomerSignature->height 20;
  1652.                 $newFieldCustomerSignature->52;
  1653.                 $newFieldCustomerSignature->571;
  1654.                 try {
  1655.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1656.                         [
  1657.                             'body' => json_encode($newFieldCustomerSignature),
  1658.                             'headers' => [
  1659.                                 'accept' => 'application/json',
  1660.                                 'content-type' => 'application/json',
  1661.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1662.                             ],
  1663.                         ]
  1664.                     );
  1665.                 }
  1666.                 catch (\Exception $e) {
  1667.                     $responseErrorTab[] = $e->getMessage();
  1668.                 }
  1669.                 //Add fields on BA for date (customer)
  1670.                 $newFieldCustomerSignature = new \stdClass();
  1671.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1672.                 $newFieldCustomerSignature->type "mention";
  1673.                 $newFieldCustomerSignature->font $fontDefault;
  1674.                 $newFieldCustomerSignature->mention "%date%";
  1675.                 $newFieldCustomerSignature->page 8;
  1676.                 $newFieldCustomerSignature->width 170;
  1677.                 $newFieldCustomerSignature->height 20;
  1678.                 $newFieldCustomerSignature->52;
  1679.                 $newFieldCustomerSignature->599;
  1680.                 try {
  1681.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1682.                         [
  1683.                             'body' => json_encode($newFieldCustomerSignature),
  1684.                             'headers' => [
  1685.                                 'accept' => 'application/json',
  1686.                                 'content-type' => 'application/json',
  1687.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1688.                             ],
  1689.                         ]
  1690.                     );
  1691.                 }
  1692.                 catch (\Exception $e) {
  1693.                     $responseErrorTab[] = $e->getMessage();
  1694.                 }
  1695.             }
  1696.             //Benef on BA (customer)
  1697.             if(($membership->getBa()->isTypeBeneficiaires() == true && !$membership->getBa()->isTypeBeneficiairesClauseNotariee()) || $membership->getBa()->getTypeBeneficiairesBychoices() == 2){
  1698.                 if($customer->isIsAutoSignup()){
  1699.                     $benefPage 9;
  1700.                 }
  1701.                 else{
  1702.                     $benefPage 10;
  1703.                 }
  1704.                 //Signature (customer)
  1705.                 $newFieldCustomerSignature = new \stdClass();
  1706.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1707.                 $newFieldCustomerSignature->type "signature";
  1708.                 $newFieldCustomerSignature->page $benefPage;
  1709.                 $newFieldCustomerSignature->width 156;
  1710.                 $newFieldCustomerSignature->height 64;
  1711.                 $newFieldCustomerSignature->339;
  1712.                 $newFieldCustomerSignature->708;
  1713.                 try {
  1714.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1715.                         [
  1716.                             'body' => json_encode($newFieldCustomerSignature),
  1717.                             'headers' => [
  1718.                                 'accept' => 'application/json',
  1719.                                 'content-type' => 'application/json',
  1720.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1721.                             ],
  1722.                         ]
  1723.                     );
  1724.                 }
  1725.                 catch (\Exception $e) {
  1726.                     $responseErrorTab[] = $e->getMessage();
  1727.                 }
  1728.                 if($customer->isIsAutoSignup()){
  1729.                     //City (customer)
  1730.                     $newFieldCustomerSignature = new \stdClass();
  1731.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1732.                     $newFieldCustomerSignature->type "text";
  1733.                     $newFieldCustomerSignature->max_length 44;
  1734.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1735.                     $newFieldCustomerSignature->page $benefPage;
  1736.                     $newFieldCustomerSignature->width 272;
  1737.                     $newFieldCustomerSignature->height 24;
  1738.                     $newFieldCustomerSignature->49;
  1739.                     $newFieldCustomerSignature->670;
  1740.                     try {
  1741.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1742.                             [
  1743.                                 'body' => json_encode($newFieldCustomerSignature),
  1744.                                 'headers' => [
  1745.                                     'accept' => 'application/json',
  1746.                                     'content-type' => 'application/json',
  1747.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1748.                                 ],
  1749.                             ]
  1750.                         );
  1751.                     }
  1752.                     catch (\Exception $e) {
  1753.                         $responseErrorTab[] = $e->getMessage();
  1754.                     }
  1755.                     //Date (customer)
  1756.                     $newFieldCustomerSignature = new \stdClass();
  1757.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1758.                     $newFieldCustomerSignature->type "mention";
  1759.                     $newFieldCustomerSignature->font $fontDefault;
  1760.                     $newFieldCustomerSignature->mention "%date%";
  1761.                     $newFieldCustomerSignature->page $benefPage;
  1762.                     $newFieldCustomerSignature->width 272;
  1763.                     $newFieldCustomerSignature->height 24;
  1764.                     $newFieldCustomerSignature->49;
  1765.                     $newFieldCustomerSignature->702;
  1766.                     try {
  1767.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1768.                             [
  1769.                                 'body' => json_encode($newFieldCustomerSignature),
  1770.                                 'headers' => [
  1771.                                     'accept' => 'application/json',
  1772.                                     'content-type' => 'application/json',
  1773.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1774.                                 ],
  1775.                             ]
  1776.                         );
  1777.                     }
  1778.                     catch (\Exception $e) {
  1779.                         $responseErrorTab[] = $e->getMessage();
  1780.                     }
  1781.                 }
  1782.                 else{
  1783.                     //City (customer)
  1784.                     $newFieldCustomerSignature = new \stdClass();
  1785.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1786.                     $newFieldCustomerSignature->type "text";
  1787.                     $newFieldCustomerSignature->max_length 44;
  1788.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1789.                     $newFieldCustomerSignature->page $benefPage;
  1790.                     $newFieldCustomerSignature->width 272;
  1791.                     $newFieldCustomerSignature->height 24;
  1792.                     $newFieldCustomerSignature->49;
  1793.                     $newFieldCustomerSignature->669;
  1794.                     try {
  1795.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1796.                             [
  1797.                                 'body' => json_encode($newFieldCustomerSignature),
  1798.                                 'headers' => [
  1799.                                     'accept' => 'application/json',
  1800.                                     'content-type' => 'application/json',
  1801.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1802.                                 ],
  1803.                             ]
  1804.                         );
  1805.                     }
  1806.                     catch (\Exception $e) {
  1807.                         $responseErrorTab[] = $e->getMessage();
  1808.                     }
  1809.                     //Date (customer)
  1810.                     $newFieldCustomerSignature = new \stdClass();
  1811.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1812.                     $newFieldCustomerSignature->type "mention";
  1813.                     $newFieldCustomerSignature->font $fontDefault;
  1814.                     $newFieldCustomerSignature->mention "%date%";
  1815.                     $newFieldCustomerSignature->page $benefPage;
  1816.                     $newFieldCustomerSignature->width 272;
  1817.                     $newFieldCustomerSignature->height 24;
  1818.                     $newFieldCustomerSignature->49;
  1819.                     $newFieldCustomerSignature->704;
  1820.                     try {
  1821.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1822.                             [
  1823.                                 'body' => json_encode($newFieldCustomerSignature),
  1824.                                 'headers' => [
  1825.                                     'accept' => 'application/json',
  1826.                                     'content-type' => 'application/json',
  1827.                                     'Authorization' => 'Bearer ' $this->yousignApi
  1828.                                 ],
  1829.                             ]
  1830.                         );
  1831.                     }
  1832.                     catch (\Exception $e) {
  1833.                         $responseErrorTab[] = $e->getMessage();
  1834.                     }
  1835.                 }
  1836.             }
  1837.         }
  1838.         else {
  1839.             //Add fields on BA for sgnature (customer)
  1840.             $newFieldCustomerSignature = new \stdClass();
  1841.             $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1842.             $newFieldCustomerSignature->type "signature";
  1843.             $newFieldCustomerSignature->page 7;
  1844.             $newFieldCustomerSignature->width 187;
  1845.             $newFieldCustomerSignature->height 97;
  1846.             $newFieldCustomerSignature->339;
  1847.             $newFieldCustomerSignature->423;
  1848.             try {
  1849.                 $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1850.                     [
  1851.                         'body' => json_encode($newFieldCustomerSignature),
  1852.                         'headers' => [
  1853.                             'accept' => 'application/json',
  1854.                             'content-type' => 'application/json',
  1855.                             'Authorization' => 'Bearer ' $this->yousignApi
  1856.                         ],
  1857.                     ]
  1858.                 );
  1859.             }
  1860.             catch (\Exception $e) {
  1861.                 $responseErrorTab[] = $e->getMessage();
  1862.             }
  1863.             if($customer->isIsAutoSignup()){
  1864.                 //Add fields on BA for city (customer)
  1865.                 $newFieldCustomerSignature = new \stdClass();
  1866.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1867.                 $newFieldCustomerSignature->type "text";
  1868.                 $newFieldCustomerSignature->max_length 44;
  1869.                 $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1870.                 $newFieldCustomerSignature->page 7;
  1871.                 $newFieldCustomerSignature->width 272;
  1872.                 $newFieldCustomerSignature->height 24;
  1873.                 $newFieldCustomerSignature->48;
  1874.                 $newFieldCustomerSignature->420;
  1875.                 try {
  1876.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1877.                         [
  1878.                             'body' => json_encode($newFieldCustomerSignature),
  1879.                             'headers' => [
  1880.                                 'accept' => 'application/json',
  1881.                                 'content-type' => 'application/json',
  1882.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1883.                             ],
  1884.                         ]
  1885.                     );
  1886.                 }
  1887.                 catch (\Exception $e) {
  1888.                     $responseErrorTab[] = $e->getMessage();
  1889.                 }
  1890.                 //Add fields on BA for date (customer)
  1891.                 $newFieldCustomerSignature = new \stdClass();
  1892.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1893.                 $newFieldCustomerSignature->type "mention";
  1894.                 $newFieldCustomerSignature->font $fontDefault;
  1895.                 $newFieldCustomerSignature->mention "%date%";
  1896.                 $newFieldCustomerSignature->page 7;
  1897.                 $newFieldCustomerSignature->width 272;
  1898.                 $newFieldCustomerSignature->height 24;
  1899.                 $newFieldCustomerSignature->48;
  1900.                 $newFieldCustomerSignature->450;
  1901.                 try {
  1902.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1903.                         [
  1904.                             'body' => json_encode($newFieldCustomerSignature),
  1905.                             'headers' => [
  1906.                                 'accept' => 'application/json',
  1907.                                 'content-type' => 'application/json',
  1908.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1909.                             ],
  1910.                         ]
  1911.                     );
  1912.                 }
  1913.                 catch (\Exception $e) {
  1914.                     $responseErrorTab[] = $e->getMessage();
  1915.                 }
  1916.             }
  1917.             else{
  1918.                 //Add fields on BA for city (customer)
  1919.                 $newFieldCustomerSignature = new \stdClass();
  1920.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1921.                 $newFieldCustomerSignature->type "text";
  1922.                 $newFieldCustomerSignature->max_length 44;
  1923.                 $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  1924.                 $newFieldCustomerSignature->page 7;
  1925.                 $newFieldCustomerSignature->width 272;
  1926.                 $newFieldCustomerSignature->height 24;
  1927.                 $newFieldCustomerSignature->50;
  1928.                 $newFieldCustomerSignature->420;
  1929.                 try {
  1930.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1931.                         [
  1932.                             'body' => json_encode($newFieldCustomerSignature),
  1933.                             'headers' => [
  1934.                                 'accept' => 'application/json',
  1935.                                 'content-type' => 'application/json',
  1936.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1937.                             ],
  1938.                         ]
  1939.                     );
  1940.                 }
  1941.                 catch (\Exception $e) {
  1942.                     $responseErrorTab[] = $e->getMessage();
  1943.                 }
  1944.                 //Add fields on BA for date (customer)
  1945.                 $newFieldCustomerSignature = new \stdClass();
  1946.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1947.                 $newFieldCustomerSignature->type "mention";
  1948.                 $newFieldCustomerSignature->font $fontDefault;
  1949.                 $newFieldCustomerSignature->mention "%date%";
  1950.                 $newFieldCustomerSignature->page 7;
  1951.                 $newFieldCustomerSignature->width 272;
  1952.                 $newFieldCustomerSignature->height 24;
  1953.                 $newFieldCustomerSignature->49;
  1954.                 $newFieldCustomerSignature->453;
  1955.                 try {
  1956.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1957.                         [
  1958.                             'body' => json_encode($newFieldCustomerSignature),
  1959.                             'headers' => [
  1960.                                 'accept' => 'application/json',
  1961.                                 'content-type' => 'application/json',
  1962.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1963.                             ],
  1964.                         ]
  1965.                     );
  1966.                 }
  1967.                 catch (\Exception $e) {
  1968.                     $responseErrorTab[] = $e->getMessage();
  1969.                 }
  1970.             }
  1971.             //Benef on BA (customer)
  1972.             if(($membership->getBa()->isTypeBeneficiaires() == true && !$membership->getBa()->isTypeBeneficiairesClauseNotariee()) || $membership->getBa()->getTypeBeneficiairesBychoices() == 2){
  1973.                 $benefPage 9;
  1974.                 //Signature (customer)
  1975.                 $newFieldCustomerSignature = new \stdClass();
  1976.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  1977.                 $newFieldCustomerSignature->type "signature";
  1978.                 $newFieldCustomerSignature->page $benefPage;
  1979.                 $newFieldCustomerSignature->width 156;
  1980.                 $newFieldCustomerSignature->height 64;
  1981.                 $newFieldCustomerSignature->339;
  1982.                 $newFieldCustomerSignature->708;
  1983.                 try {
  1984.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  1985.                         [
  1986.                             'body' => json_encode($newFieldCustomerSignature),
  1987.                             'headers' => [
  1988.                                 'accept' => 'application/json',
  1989.                                 'content-type' => 'application/json',
  1990.                                 'Authorization' => 'Bearer ' $this->yousignApi
  1991.                             ],
  1992.                         ]
  1993.                     );
  1994.                 }
  1995.                 catch (\Exception $e) {
  1996.                     $responseErrorTab[] = $e->getMessage();
  1997.                 }
  1998.                 if($customer->isIsAutoSignup()){
  1999.                     //City (customer)
  2000.                     $newFieldCustomerSignature = new \stdClass();
  2001.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2002.                     $newFieldCustomerSignature->type "text";
  2003.                     $newFieldCustomerSignature->max_length 44;
  2004.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  2005.                     $newFieldCustomerSignature->page $benefPage;
  2006.                     $newFieldCustomerSignature->width 272;
  2007.                     $newFieldCustomerSignature->height 24;
  2008.                     $newFieldCustomerSignature->49;
  2009.                     $newFieldCustomerSignature->670;
  2010.                     try {
  2011.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  2012.                             [
  2013.                                 'body' => json_encode($newFieldCustomerSignature),
  2014.                                 'headers' => [
  2015.                                     'accept' => 'application/json',
  2016.                                     'content-type' => 'application/json',
  2017.                                     'Authorization' => 'Bearer ' $this->yousignApi
  2018.                                 ],
  2019.                             ]
  2020.                         );
  2021.                     }
  2022.                     catch (\Exception $e) {
  2023.                         $responseErrorTab[] = $e->getMessage();
  2024.                     }
  2025.                     //Date (customer)
  2026.                     $newFieldCustomerSignature = new \stdClass();
  2027.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2028.                     $newFieldCustomerSignature->type "mention";
  2029.                     $newFieldCustomerSignature->font $fontDefault;
  2030.                     $newFieldCustomerSignature->mention "%date%";
  2031.                     $newFieldCustomerSignature->page $benefPage;
  2032.                     $newFieldCustomerSignature->width 272;
  2033.                     $newFieldCustomerSignature->height 24;
  2034.                     $newFieldCustomerSignature->49;
  2035.                     $newFieldCustomerSignature->702;
  2036.                     try {
  2037.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  2038.                             [
  2039.                                 'body' => json_encode($newFieldCustomerSignature),
  2040.                                 'headers' => [
  2041.                                     'accept' => 'application/json',
  2042.                                     'content-type' => 'application/json',
  2043.                                     'Authorization' => 'Bearer ' $this->yousignApi
  2044.                                 ],
  2045.                             ]
  2046.                         );
  2047.                     }
  2048.                     catch (\Exception $e) {
  2049.                         $responseErrorTab[] = $e->getMessage();
  2050.                     }
  2051.                 }
  2052.                 else{
  2053.                     //City (customer)
  2054.                     $newFieldCustomerSignature = new \stdClass();
  2055.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2056.                     $newFieldCustomerSignature->type "text";
  2057.                     $newFieldCustomerSignature->max_length 44;
  2058.                     $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  2059.                     $newFieldCustomerSignature->page $benefPage;
  2060.                     $newFieldCustomerSignature->width 272;
  2061.                     $newFieldCustomerSignature->height 24;
  2062.                     $newFieldCustomerSignature->49;
  2063.                     $newFieldCustomerSignature->669;
  2064.                     try {
  2065.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  2066.                             [
  2067.                                 'body' => json_encode($newFieldCustomerSignature),
  2068.                                 'headers' => [
  2069.                                     'accept' => 'application/json',
  2070.                                     'content-type' => 'application/json',
  2071.                                     'Authorization' => 'Bearer ' $this->yousignApi
  2072.                                 ],
  2073.                             ]
  2074.                         );
  2075.                     }
  2076.                     catch (\Exception $e) {
  2077.                         $responseErrorTab[] = $e->getMessage();
  2078.                     }
  2079.                     //Date (customer)
  2080.                     $newFieldCustomerSignature = new \stdClass();
  2081.                     $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2082.                     $newFieldCustomerSignature->type "mention";
  2083.                     $newFieldCustomerSignature->font $fontDefault;
  2084.                     $newFieldCustomerSignature->mention "%date%";
  2085.                     $newFieldCustomerSignature->page $benefPage;
  2086.                     $newFieldCustomerSignature->width 272;
  2087.                     $newFieldCustomerSignature->height 24;
  2088.                     $newFieldCustomerSignature->49;
  2089.                     $newFieldCustomerSignature->704;
  2090.                     try {
  2091.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadBaId.'/fields'
  2092.                             [
  2093.                                 'body' => json_encode($newFieldCustomerSignature),
  2094.                                 'headers' => [
  2095.                                     'accept' => 'application/json',
  2096.                                     'content-type' => 'application/json',
  2097.                                     'Authorization' => 'Bearer ' $this->yousignApi
  2098.                                 ],
  2099.                             ]
  2100.                         );
  2101.                     }
  2102.                     catch (\Exception $e) {
  2103.                         $responseErrorTab[] = $e->getMessage();
  2104.                     }
  2105.                 }
  2106.             }
  2107.         }
  2108.         //SEPA
  2109.         if (($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) && $membership->getBa()->getSepaOriginVersmement() != 2) {
  2110.         
  2111.             if($membership->getBa()->getSepaOriginVersmement() == 1){
  2112.                 if($isLegal1){
  2113.                     //Signature (customer)
  2114.                     $newFieldCustomerLegal1Signature = new \stdClass();
  2115.                     $newFieldCustomerLegal1Signature->signer_id $newSignerCustomerLegal1Id;
  2116.                     $newFieldCustomerLegal1Signature->type "signature";
  2117.                     $newFieldCustomerLegal1Signature->page 1;
  2118.                     $newFieldCustomerLegal1Signature->width 99;
  2119.                     $newFieldCustomerLegal1Signature->height 39;
  2120.                     $newFieldCustomerLegal1Signature->355;
  2121.                     $newFieldCustomerLegal1Signature->757;
  2122.                     try {
  2123.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2124.                             [
  2125.                                 'body' => json_encode($newFieldCustomerLegal1Signature),
  2126.                                 'headers' => [
  2127.                                     'accept' => 'application/json',
  2128.                                     'content-type' => 'application/json',
  2129.                                     'Authorization' => 'Bearer ' $this->yousignApi
  2130.                                 ],
  2131.                             ]
  2132.                         );
  2133.                     }
  2134.                     catch (\Exception $e) {
  2135.                         $responseErrorTab[] = $e->getMessage();
  2136.                     }
  2137.                 }
  2138.                 if($isLegal2){
  2139.                     //Signature (customer)
  2140.                     $newFieldCustomerLegal2Signature = new \stdClass();
  2141.                     $newFieldCustomerLegal2Signature->signer_id $newSignerCustomerLegal2Id;
  2142.                     $newFieldCustomerLegal2Signature->type "signature";
  2143.                     $newFieldCustomerLegal2Signature->page 1;
  2144.                     $newFieldCustomerLegal2Signature->width 99;
  2145.                     $newFieldCustomerLegal2Signature->height 39;
  2146.                     $newFieldCustomerLegal2Signature->239;
  2147.                     $newFieldCustomerLegal2Signature->757;
  2148.                     try {
  2149.                         $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2150.                             [
  2151.                                 'body' => json_encode($newFieldCustomerLegal2Signature),
  2152.                                 'headers' => [
  2153.                                     'accept' => 'application/json',
  2154.                                     'content-type' => 'application/json',
  2155.                                     'Authorization' => 'Bearer ' $this->yousignApi
  2156.                                 ],
  2157.                             ]
  2158.                         );
  2159.                     }
  2160.                     catch (\Exception $e) {
  2161.                         $responseErrorTab[] = $e->getMessage();
  2162.                     }
  2163.                 }
  2164.             }
  2165.             if($typeProduct == "epargne"){
  2166.                 //Signature (customer)
  2167.                 $newFieldCustomerSignature = new \stdClass();
  2168.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2169.                 $newFieldCustomerSignature->type "signature";
  2170.                 $newFieldCustomerSignature->page 1;
  2171.                 $newFieldCustomerSignature->width 99;
  2172.                 $newFieldCustomerSignature->height 39;
  2173.                 $newFieldCustomerSignature->472;
  2174.                 $newFieldCustomerSignature->724;
  2175.                 try {
  2176.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2177.                         [
  2178.                             'body' => json_encode($newFieldCustomerSignature),
  2179.                             'headers' => [
  2180.                                 'accept' => 'application/json',
  2181.                                 'content-type' => 'application/json',
  2182.                                 'Authorization' => 'Bearer ' $this->yousignApi
  2183.                             ],
  2184.                         ]
  2185.                     );
  2186.                 }
  2187.                 catch (\Exception $e) {
  2188.                     $responseErrorTab[] = $e->getMessage();
  2189.                 }
  2190.                 
  2191.                 //City (customer)
  2192.                 $newFieldCustomerSignature = new \stdClass();
  2193.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2194.                 $newFieldCustomerSignature->type "text";
  2195.                 $newFieldCustomerSignature->max_length 35;
  2196.                 $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  2197.                 $newFieldCustomerSignature->page 1;
  2198.                 $newFieldCustomerSignature->width 182;
  2199.                 $newFieldCustomerSignature->height 20;
  2200.                 $newFieldCustomerSignature->75;
  2201.                 $newFieldCustomerSignature->725;
  2202.                 try {
  2203.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2204.                         [
  2205.                             'body' => json_encode($newFieldCustomerSignature),
  2206.                             'headers' => [
  2207.                                 'accept' => 'application/json',
  2208.                                 'content-type' => 'application/json',
  2209.                                 'Authorization' => 'Bearer ' $this->yousignApi
  2210.                             ],
  2211.                         ]
  2212.                     );
  2213.                 }
  2214.                 catch (\Exception $e) {
  2215.                     $responseErrorTab[] = $e->getMessage();
  2216.                 }
  2217.                 //Date (customer)
  2218.                 $newFieldCustomerSignature = new \stdClass();
  2219.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2220.                 $newFieldCustomerSignature->type "mention";
  2221.                 $newFieldCustomerSignature->font $fontDefault;
  2222.                 $newFieldCustomerSignature->mention "%date%";
  2223.                 $newFieldCustomerSignature->page 1;
  2224.                 $newFieldCustomerSignature->width 182;
  2225.                 $newFieldCustomerSignature->height 20;
  2226.                 $newFieldCustomerSignature->53;
  2227.                 $newFieldCustomerSignature->756;
  2228.                 try {
  2229.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2230.                         [
  2231.                             'body' => json_encode($newFieldCustomerSignature),
  2232.                             'headers' => [
  2233.                                 'accept' => 'application/json',
  2234.                                 'content-type' => 'application/json',
  2235.                                 'Authorization' => 'Bearer ' $this->yousignApi
  2236.                             ],
  2237.                         ]
  2238.                     );
  2239.                 }
  2240.                 catch (\Exception $e) {
  2241.                     $responseErrorTab[] = $e->getMessage();
  2242.                 }
  2243.             }
  2244.             else{
  2245.                 //Signature (customer)
  2246.                 $newFieldCustomerSignature = new \stdClass();
  2247.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2248.                 $newFieldCustomerSignature->type "signature";
  2249.                 $newFieldCustomerSignature->page 1;
  2250.                 $newFieldCustomerSignature->width 137;
  2251.                 $newFieldCustomerSignature->height 49;
  2252.                 $newFieldCustomerSignature->355;
  2253.                 $newFieldCustomerSignature->535;
  2254.                 try {
  2255.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2256.                         [
  2257.                             'body' => json_encode($newFieldCustomerSignature),
  2258.                             'headers' => [
  2259.                                 'accept' => 'application/json',
  2260.                                 'content-type' => 'application/json',
  2261.                                 'Authorization' => 'Bearer ' $this->yousignApi
  2262.                             ],
  2263.                         ]
  2264.                     );
  2265.                 }
  2266.                 catch (\Exception $e) {
  2267.                     $responseErrorTab[] = $e->getMessage();
  2268.                 }
  2269.                 //City (customer)
  2270.                 $newFieldCustomerSignature = new \stdClass();
  2271.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2272.                 $newFieldCustomerSignature->type "text";
  2273.                 $newFieldCustomerSignature->max_length 35;
  2274.                 $newFieldCustomerSignature->question "Veuillez indiquer la ville";
  2275.                 $newFieldCustomerSignature->page 1;
  2276.                 $newFieldCustomerSignature->width 217;
  2277.                 $newFieldCustomerSignature->height 24;
  2278.                 $newFieldCustomerSignature->86;
  2279.                 $newFieldCustomerSignature->503;
  2280.                 try {
  2281.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2282.                         [
  2283.                             'body' => json_encode($newFieldCustomerSignature),
  2284.                             'headers' => [
  2285.                                 'accept' => 'application/json',
  2286.                                 'content-type' => 'application/json',
  2287.                                 'Authorization' => 'Bearer ' $this->yousignApi
  2288.                             ],
  2289.                         ]
  2290.                     );
  2291.                 }
  2292.                 catch (\Exception $e) {
  2293.                     $responseErrorTab[] = $e->getMessage();
  2294.                 }
  2295.                 //Date (customer)
  2296.                 $newFieldCustomerSignature = new \stdClass();
  2297.                 $newFieldCustomerSignature->signer_id $newSignerCustomerId;
  2298.                 $newFieldCustomerSignature->type "mention";
  2299.                 $newFieldCustomerSignature->font $fontDefault;
  2300.                 $newFieldCustomerSignature->mention "%date%";
  2301.                 $newFieldCustomerSignature->page 1;
  2302.                 $newFieldCustomerSignature->width 217;
  2303.                 $newFieldCustomerSignature->height 24;
  2304.                 $newFieldCustomerSignature->86;
  2305.                 $newFieldCustomerSignature->537;
  2306.                 try {
  2307.                     $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadSepaId.'/fields'
  2308.                         [
  2309.                             'body' => json_encode($newFieldCustomerSignature),
  2310.                             'headers' => [
  2311.                                 'accept' => 'application/json',
  2312.                                 'content-type' => 'application/json',
  2313.                                 'Authorization' => 'Bearer ' $this->yousignApi
  2314.                             ],
  2315.                         ]
  2316.                     );
  2317.                 }
  2318.                 catch (\Exception $e) {
  2319.                     $responseErrorTab[] = $e->getMessage();
  2320.                 }
  2321.             }
  2322.         }
  2323.         /* -----------------------------------  Active signature (end step)   ------------------------------------- */
  2324.         //Activate signature
  2325.         try {
  2326.             $activateSignatureResponse $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/activate'
  2327.                 [
  2328.                     'headers' => [
  2329.                         'accept' => 'application/json',
  2330.                         'Authorization' => 'Bearer ' $this->yousignApi
  2331.                     ],
  2332.                 ]
  2333.             );
  2334.             $activateSignatureResponseBody json_decode($activateSignatureResponse->getBody());
  2335.             $activateSignatureResponseSigners $activateSignatureResponseBody->signers;
  2336.         }
  2337.         catch (\Exception $e) {
  2338.             $responseErrorTab[] = $e->getMessage();
  2339.         }
  2340.         $urlSeller null;
  2341.         $urlCustomer null;
  2342.         if(!$responseErrorTab){
  2343.             if($membership->getPlatformVersion() == && !$customer->isIsAutoSignup()){
  2344.                 $urlSeller $activateSignatureResponseSigners[0]->signature_link;
  2345.                 $urlCustomer $activateSignatureResponseSigners[1]->signature_link;
  2346.             }
  2347.             else{
  2348.                 $urlCustomer $activateSignatureResponseSigners[0]->signature_link;
  2349.             }
  2350.         }
  2351.         $tab = array(
  2352.             "responseProcedure" => $activateSignatureResponseBody,
  2353.             "yousignUi" => $this->yousignUi,
  2354.             "dicFileId" => $uploadDicId,
  2355.             "ficFileId" => $uploadFicId,
  2356.             "baFileId" => $uploadBaId,
  2357.             "sepaFileId" => $uploadSepaId,
  2358.             "signerCustomer" => $newSignerCustomerResponseBody,
  2359.             "signerSellerUrl" => $urlSeller,
  2360.             "signerCustomerUrl" => $urlCustomer,
  2361.             "signerCustomerId" => $newSignerCustomerId,
  2362.             "signerCustomerLegal1Id" => $newSignerCustomerLegal1Id,
  2363.             "signerCustomerLegal2Id" => $newSignerCustomerLegal2Id,
  2364.             "signerSellerId" => $newSignerSellerId,
  2365.             "responseErrorTab" => $responseErrorTab
  2366.         );
  2367.         return $tab;
  2368.     }
  2369.     function addSign2023($customer$membership$type)
  2370.     {
  2371.         if ($membership->getDicIsFile() != true) {
  2372.             if($membership->getPlatformVersion() == 1){
  2373.                 //V1 DIC
  2374.                 //Get DIC BASE 64
  2375.                 $dicUrl "files/" $customer->getId() . '/' $membership->getDic()->getUrlPdf();
  2376.                 $b64Dic chunk_split(base64_encode(file_get_contents($dicUrl)));
  2377.                 $fileDic = new \stdClass();
  2378.                 $fileDic->name "Document d’information et de conseil";
  2379.                 $fileDic->content $b64Dic;
  2380.                 $fileDic->position 1;
  2381.                 //Create files
  2382.                 $curl curl_init();
  2383.                 curl_setopt_array($curl, array(
  2384.                     CURLOPT_URL => $this->yousignUrl "/files",
  2385.                     CURLOPT_RETURNTRANSFER => true,
  2386.                     CURLOPT_ENCODING => "",
  2387.                     CURLOPT_MAXREDIRS => 10,
  2388.                     CURLOPT_TIMEOUT => 0,
  2389.                     CURLOPT_FOLLOWLOCATION => true,
  2390.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2391.                     CURLOPT_CUSTOMREQUEST => "POST",
  2392.                     CURLOPT_POSTFIELDS => json_encode($fileDic),
  2393.                     CURLOPT_HTTPHEADER => array(
  2394.                         "Authorization: Bearer " $this->yousignApi,
  2395.                         "Content-Type: application/json"
  2396.                     ),
  2397.                 ));
  2398.                 $responseFile curl_exec($curl);
  2399.                 curl_close($curl);
  2400.                 $responseFileDic json_decode($responseFile);
  2401.             } else{
  2402.                 //V2 FIC
  2403.                 //Get FIC BASE 64
  2404.                 $ficUrl "files/" $customer->getId() . '/' $membership->getFic()->getUrlPdf();
  2405.                 $b64Fic chunk_split(base64_encode(file_get_contents($ficUrl)));
  2406.                 $fileFic = new \stdClass();
  2407.                 $fileFic->name "Fiche d’information et de conseil";
  2408.                 $fileFic->content $b64Fic;
  2409.                 $fileFic->position 1;
  2410.                 //Create files
  2411.                 $curl curl_init();
  2412.                 curl_setopt_array($curl, array(
  2413.                     CURLOPT_URL => $this->yousignUrl "/signature_requests//documents",
  2414.                     CURLOPT_RETURNTRANSFER => true,
  2415.                     CURLOPT_ENCODING => "",
  2416.                     CURLOPT_MAXREDIRS => 10,
  2417.                     CURLOPT_TIMEOUT => 0,
  2418.                     CURLOPT_FOLLOWLOCATION => true,
  2419.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2420.                     CURLOPT_CUSTOMREQUEST => "POST",
  2421.                     CURLOPT_POSTFIELDS => json_encode($fileFic),
  2422.                     CURLOPT_HTTPHEADER => array(
  2423.                         "Authorization: Bearer " $this->yousignApi,
  2424.                         "Content-Type: application/json"
  2425.                     ),
  2426.                 ));
  2427.                 $responseFile curl_exec($curl);
  2428.                 curl_close($curl);
  2429.                 $responseFileFic json_decode($responseFile);
  2430.             }
  2431.         }
  2432.         /* --------------------------------------------------------------------------- */
  2433.         //Get BA BASE 64
  2434.         $baUrl "files/" $customer->getId() . '/' $membership->getBa()->getUrlPdf();
  2435.         $b64Ba chunk_split(base64_encode(file_get_contents($baUrl)));
  2436.         $fileBa = new \stdClass();
  2437.         $fileBa->name "Demande d’adhésion";
  2438.         $fileBa->content $b64Ba;
  2439.         $fileBa->position 2;
  2440.         //Create files
  2441.         $curl curl_init();
  2442.         curl_setopt_array($curl, array(
  2443.             CURLOPT_URL => $this->yousignUrl "/files",
  2444.             CURLOPT_RETURNTRANSFER => true,
  2445.             CURLOPT_ENCODING => "",
  2446.             CURLOPT_MAXREDIRS => 10,
  2447.             CURLOPT_TIMEOUT => 0,
  2448.             CURLOPT_FOLLOWLOCATION => true,
  2449.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2450.             CURLOPT_CUSTOMREQUEST => "POST",
  2451.             CURLOPT_POSTFIELDS => json_encode($fileBa),
  2452.             CURLOPT_HTTPHEADER => array(
  2453.                 "Authorization: Bearer " $this->yousignApi,
  2454.                 "Content-Type: application/json"
  2455.             ),
  2456.         ));
  2457.         $responseFileBa curl_exec($curl);
  2458.         curl_close($curl);
  2459.         $responseFileBa json_decode($responseFileBa);
  2460.         /* --------------------------------------------------------------------------- */
  2461.         /* --------------------------------------------------------------------------- */
  2462.         if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  2463.             //Get BA BASE 64
  2464.             $sepaUrl "files/" $customer->getId() . '/' $membership->getBa()->getSepaUrlPdf();
  2465.             $b64Sepa chunk_split(base64_encode(file_get_contents($sepaUrl)));
  2466.             $fileSepa = new \stdClass();
  2467.             $fileSepa->name "Mandat de prélèvement SEPA";
  2468.             $fileSepa->content $b64Sepa;
  2469.             $fileSepa->position 3;
  2470.             //Create files
  2471.             $curl curl_init();
  2472.             curl_setopt_array($curl, array(
  2473.                 CURLOPT_URL => $this->yousignUrl "/files",
  2474.                 CURLOPT_RETURNTRANSFER => true,
  2475.                 CURLOPT_ENCODING => "",
  2476.                 CURLOPT_MAXREDIRS => 10,
  2477.                 CURLOPT_TIMEOUT => 0,
  2478.                 CURLOPT_FOLLOWLOCATION => true,
  2479.                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2480.                 CURLOPT_CUSTOMREQUEST => "POST",
  2481.                 CURLOPT_POSTFIELDS => json_encode($fileSepa),
  2482.                 CURLOPT_HTTPHEADER => array(
  2483.                     "Authorization: Bearer " $this->yousignApi,
  2484.                     "Content-Type: application/json"
  2485.                 ),
  2486.             ));
  2487.             $responseFileSepa curl_exec($curl);
  2488.             curl_close($curl);
  2489.             $responseFileSepa json_decode($responseFileSepa);
  2490.         }
  2491.         /* --------------------------------------------------------------------------- */
  2492.         //Add procedure
  2493.         $curl curl_init();
  2494.         //Set webhook
  2495.         if ($type == "seller") {
  2496.             $urlSignEnd $this->container->get('router')->generate('yousign_sign_end_seller', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  2497.         } else {
  2498.             $urlSignEnd $this->container->get('router')->generate('yousign_sign_end', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  2499.         }
  2500.         $firstName str_replace(","" "$customer->getFirstName());
  2501.         $config = new \stdClass();
  2502.         $webhook = new \stdClass();
  2503.         $webhookEnd = new \stdClass();
  2504.         $header = new \stdClass();
  2505.         $webhookEnd->url $urlSignEnd;
  2506.         $webhookEnd->method "GET";
  2507.         $webhookEnd->headers = (object)array(
  2508.             'X-Custom-Header' => "End sign"
  2509.         );
  2510.         $config->webhook = (object)array(
  2511.             'member.finished' => array(
  2512.                 $webhookEnd
  2513.             )
  2514.         );
  2515.         $arrayObjectFiles = array();
  2516.         $dicFileId null;
  2517.         $ficFileId null;
  2518.         $baFileId null;
  2519.         $sepaFileId null;
  2520.         if ($membership->getDicIsFile() != true) {
  2521.             if($membership->getPlatformVersion() == 1){
  2522.                 //V1 DIC
  2523.                 //Set file DIC
  2524.                 $fileObjectDic = new \stdClass();
  2525.                 $fileObjectDic->file $responseFileDic->id;
  2526.                 $fileObjectDic->page 1;
  2527.                 $fileObjectDic->position "171,80,317,120";
  2528.                 $fileObjectDic->mention "";
  2529.                 $fileObjectDic->mention2 "Signé par " $firstName " " $customer->getLastName();
  2530.                 $arrayObjectFiles[] = $fileObjectDic;
  2531.                 $dicFileId $responseFileDic->id;
  2532.                 //Set file DIC VILLE
  2533.                 $fileObjectDicVille = new \stdClass();
  2534.                 $fileObjectDicVille->file $responseFileDic->id;
  2535.                 $fileObjectDicVille->page 1;
  2536.                 $fileObjectDicVille->type "text";
  2537.                 $fileObjectDicVille->fontSize 10;
  2538.                 $fileObjectDicVille->contentRequired true;
  2539.                 $fileObjectDicVille->content $membership->getBa()->getVille();
  2540.                 $fileObjectDicVille->position "48,79,158,96";
  2541.                 $arrayObjectFiles[] = $fileObjectDicVille;
  2542.                 //Set file DIC DATE
  2543.                 $fileObjectDicDate = new \stdClass();
  2544.                 $fileObjectDicDate->file $responseFileDic->id;
  2545.                 $fileObjectDicDate->page 1;
  2546.                 $fileObjectDicDate->type "text";
  2547.                 $fileObjectDicDate->fontSize 10;
  2548.                 $fileObjectDicDate->contentRequired true;
  2549.                 $fileObjectDicDate->content date("d/m/Y");
  2550.                 $fileObjectDicDate->position "49,98,159,115";
  2551.                 $arrayObjectFiles[] = $fileObjectDicDate;
  2552.             } else{
  2553.                 //V2 FIC
  2554.                 $fileObjectFic = new \stdClass();
  2555.                 $fileObjectFic->file $responseFileFic->id;
  2556.                 $fileObjectFic->page 7;
  2557.                 $fileObjectFic->position "69,199,247,304";
  2558.                 $fileObjectFic->mention "";
  2559.                 $fileObjectFic->mention2 "Signé par " $firstName " " $customer->getLastName();
  2560.                 $arrayObjectFiles[] = $fileObjectFic;
  2561.                 $ficFileId $responseFileFic->id;
  2562.                 //FOR SELLER 
  2563.                 //$fileObjectFic->position = "323,182,503,246";
  2564.                 //Set file FIC VILLE
  2565.                 $fileObjectFicVille = new \stdClass();
  2566.                 $fileObjectFicVille->file $responseFileFic->id;
  2567.                 $fileObjectFicVille->page 9;
  2568.                 $fileObjectFicVille->type "text";
  2569.                 $fileObjectFicVille->fontSize 10;
  2570.                 $fileObjectFicVille->contentRequired true;
  2571.                 $fileObjectFicVille->content $membership->getFic()->getAdresseFiscaleVille();
  2572.                 $fileObjectFicVille->position "66,449,293,464";
  2573.                 $arrayObjectFiles[] = $fileObjectFicVille;
  2574.                 //Set file FIC DATE
  2575.                 $fileObjectFicDate = new \stdClass();
  2576.                 $fileObjectFicDate->file $responseFileFic->id;
  2577.                 $fileObjectFicDate->page 9;
  2578.                 $fileObjectFicDate->type "text";
  2579.                 $fileObjectFicDate->fontSize 10;
  2580.                 $fileObjectFicDate->contentRequired true;
  2581.                 $fileObjectFicDate->content date("d/m/Y");
  2582.                 $fileObjectFicDate->position "74,424,301,439";
  2583.                 $arrayObjectFiles[] = $fileObjectFicDate;
  2584.             }
  2585.         }
  2586.         //Set file BA -> Demande attribution de
  2587.         if ($membership->getBa()->getJaiDemandeAttributionDe() != null) {
  2588.             $fileObjectBaName = new \stdClass();
  2589.             $fileObjectBaName->file $responseFileBa->id;
  2590.             $fileObjectBaName->page 4;
  2591.             $fileObjectBaName->type "text";
  2592.             $fileObjectBaName->fontSize 8;
  2593.             $fileObjectBaName->contentRequired true;
  2594.             $fileObjectBaName->content $firstName " " $membership->getUser()->getLastName();
  2595.             $fileObjectBaName->position "94,731,255,749";
  2596.             $arrayObjectFiles[] = $fileObjectBaName;
  2597.         }
  2598.         //Set file BA 
  2599.         $fileObjectBa = new \stdClass();
  2600.         $fileObjectBa->file $responseFileBa->id;
  2601.         $fileObjectBa->page 7;
  2602.         $fileObjectBa->position "350,307,500,410";
  2603.         $fileObjectBa->mention "Lu et approuvé";
  2604.         $fileObjectBa->mention2 "Signé par " $firstName " " $customer->getLastName();
  2605.         $arrayObjectFiles[] = $fileObjectBa;
  2606.         $baFileId $responseFileBa->id;
  2607.         $fileObjectBaLieu = new \stdClass();
  2608.         $fileObjectBaLieu->file $responseFileBa->id;
  2609.         $fileObjectBaLieu->page 7;
  2610.         $fileObjectBaLieu->type "text";
  2611.         $fileObjectBaLieu->fontSize 10;
  2612.         $fileObjectBaLieu->contentRequired true;
  2613.         $fileObjectBaLieu->content $membership->getBa()->getFiscaleVille();
  2614.         $fileObjectBaLieu->position "45,419,200,437";
  2615.         $arrayObjectFiles[] = $fileObjectBaLieu;
  2616.         $fileObjectBaDate = new \stdClass();
  2617.         $fileObjectBaDate->file $responseFileBa->id;
  2618.         $fileObjectBaDate->page 7;
  2619.         $fileObjectBaDate->type "text";
  2620.         $fileObjectBaDate->fontSize 10;
  2621.         $fileObjectBaDate->contentRequired true;
  2622.         $fileObjectBaDate->content date("d/m/Y");
  2623.         $fileObjectBaDate->position "47,403,202,421";
  2624.         $arrayObjectFiles[] = $fileObjectBaDate;
  2625.         //Benef
  2626.         if($membership->getBa()->isTypeBeneficiaires() == true && $membership->getBa()->isTypeBeneficiairesClauseNotariee() == false){
  2627.             $fileObjectBa = new \stdClass();
  2628.             $fileObjectBa->file $responseFileBa->id;
  2629.             $fileObjectBa->page 9;
  2630.             $fileObjectBa->position "347,68,521,131";
  2631.             $fileObjectBa->mention "Lu et approuvé";
  2632.             $fileObjectBa->mention2 "Signé par " $firstName " " $customer->getLastName();
  2633.             $arrayObjectFiles[] = $fileObjectBa;
  2634.             $baFileId $responseFileBa->id;
  2635.             $fileObjectBaLieu = new \stdClass();
  2636.             $fileObjectBaLieu->file $responseFileBa->id;
  2637.             $fileObjectBaLieu->page 9;
  2638.             $fileObjectBaLieu->type "text";
  2639.             $fileObjectBaLieu->fontSize 10;
  2640.             $fileObjectBaLieu->contentRequired true;
  2641.             $fileObjectBaLieu->content $membership->getBa()->getFiscaleVille();
  2642.             $fileObjectBaLieu->position "50,150,201,171";
  2643.             $arrayObjectFiles[] = $fileObjectBaLieu;
  2644.             $fileObjectBaDate = new \stdClass();
  2645.             $fileObjectBaDate->file $responseFileBa->id;
  2646.             $fileObjectBaDate->page 9;
  2647.             $fileObjectBaDate->type "text";
  2648.             $fileObjectBaDate->fontSize 10;
  2649.             $fileObjectBaDate->contentRequired true;
  2650.             $fileObjectBaDate->content date("d/m/Y");
  2651.             $fileObjectBaDate->position "51,136,202,157";
  2652.             $arrayObjectFiles[] = $fileObjectBaDate;
  2653.         }
  2654.         //SEPA
  2655.         if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  2656.             //Set file SEPA
  2657.             $fileObjectSepa = new \stdClass();
  2658.             $fileObjectSepa->file $responseFileSepa->id;
  2659.             $fileObjectSepa->page 1;
  2660.             $fileObjectSepa->position "365,227,506,309";
  2661.             $fileObjectSepa->mention "";
  2662.             $fileObjectSepa->mention2 "Signé par " $firstName " " $customer->getLastName();
  2663.             $arrayObjectFiles[] = $fileObjectSepa;
  2664.             $sepaFileId $responseFileSepa->id;
  2665.             $fileObjectSepaDate = new \stdClass();
  2666.             $fileObjectSepaDate->file $responseFileSepa->id;
  2667.             $fileObjectSepaDate->page 1;
  2668.             $fileObjectSepaDate->position "148,303,300,322";
  2669.             $fileObjectSepaDate->type "text";
  2670.             $fileObjectSepaDate->fontSize 8;
  2671.             $fileObjectSepaDate->contentRequired true;
  2672.             $fileObjectSepaDate->content date("d/m/Y");
  2673.             $arrayObjectFiles[] = $fileObjectSepaDate;
  2674.             $fileObjectSepaLieu = new \stdClass();
  2675.             $fileObjectSepaLieu->file $responseFileSepa->id;
  2676.             $fileObjectSepaLieu->page 1;
  2677.             $fileObjectSepaLieu->position "147,321,299,340";
  2678.             $fileObjectSepaLieu->type "text";
  2679.             $fileObjectSepaLieu->fontSize 8;
  2680.             $fileObjectSepaLieu->contentRequired true;
  2681.             $fileObjectSepaLieu->content $membership->getBa()->getFiscaleVille();
  2682.             $arrayObjectFiles[] = $fileObjectSepaLieu;
  2683.         }
  2684.         //Set member - customer
  2685.         $member = new \stdClass();
  2686.         $member->firstname $firstName;
  2687.         $member->lastname $customer->getLastName();
  2688.         $member->email $customer->getEmail();
  2689.         $phone $customer->getPhone();
  2690.         $phone str_replace("("""$phone);
  2691.         $phone str_replace(")"""$phone);
  2692.         $phone str_replace(" """$phone);
  2693.         $phone str_replace("_"""$phone);
  2694.         if ($customer->getPhonePrefix()) {
  2695.             $phone $customer->getPhonePrefix() . $phone;
  2696.         }
  2697.         $member->phone $phone;
  2698.         $member->fileObjects $arrayObjectFiles;
  2699.         if($membership->getPlatformVersion() == && $customer->isIsAutoSignup() != true){
  2700.             //Set file FIC SELLER
  2701.             $fileObjectFicSeller  = new \stdClass();
  2702.             $fileObjectFicSeller->file $responseFileFic->id;
  2703.             $fileObjectFicSeller->page 9;
  2704.             $fileObjectFicSeller->position "350,198,528,303";
  2705.             $fileObjectFicSeller->mention "";
  2706.             $fileObjectFicSeller->mention2 "Signé par ".$membership->getSeller()->getFirstName()." ".$membership->getSeller()->getLastName();
  2707.             //Set member - seller
  2708.             $memberSeller  = new \stdClass();
  2709.             $memberSeller->position 1;
  2710.             $memberSeller->firstname $membership->getSeller()->getFirstName();
  2711.             $memberSeller->lastname $membership->getSeller()->getLastName();
  2712.             $memberSeller->email $membership->getSeller()->getEmail();
  2713.             $memberSeller->phone $membership->getSeller()->getPhone();
  2714.             $memberSeller->operationCustomModes = [ "email" ];
  2715.             $memberSeller->fileObjects = array(
  2716.                 $fileObjectFicSeller,
  2717.             );
  2718.             $member->position 2;
  2719.             //Set procedure
  2720.             $procedure = new \stdClass();
  2721.             $procedure->name "Signature adhésion";
  2722.             $procedure->description "Fin d'adhésion";
  2723.             $procedure->start true;
  2724.             $procedure->ordered false;
  2725.             $procedure->members = array(
  2726.                 $memberSeller,
  2727.                 $member
  2728.             );
  2729.             $procedure->config $config;
  2730.         }
  2731.         else{
  2732.             //Set procedure
  2733.             $procedure = new \stdClass();
  2734.             $procedure->name "Signature adhésion";
  2735.             $procedure->description "Fin d'adhésion";
  2736.             $procedure->start true;
  2737.             $procedure->members = array(
  2738.                 $member,
  2739.             );
  2740.             $procedure->config $config;
  2741.         }
  2742.         curl_setopt_array($curl, array(
  2743.             CURLOPT_URL => $this->yousignUrl "/procedures",
  2744.             CURLOPT_RETURNTRANSFER => true,
  2745.             CURLOPT_ENCODING => "",
  2746.             CURLOPT_MAXREDIRS => 10,
  2747.             CURLOPT_TIMEOUT => 0,
  2748.             CURLOPT_FOLLOWLOCATION => true,
  2749.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2750.             CURLOPT_CUSTOMREQUEST => "POST",
  2751.             CURLOPT_POSTFIELDS => json_encode($procedure),
  2752.             CURLOPT_HTTPHEADER => array(
  2753.                 "Authorization: Bearer " $this->yousignApi,
  2754.                 "Content-Type: application/json"
  2755.             ),
  2756.         ));
  2757.         $responseProcedure curl_exec($curl);
  2758.         curl_close($curl);
  2759.         $responseProcedure json_decode($responseProcedure);
  2760.         //var_dump($member);
  2761.         //die;
  2762.         $tab = array(
  2763.             "responseProcedure" => $responseProcedure,
  2764.             "yousignUi" => $this->yousignUi,
  2765.             "dicFileId" => $dicFileId,
  2766.             "ficFileId" => $ficFileId,
  2767.             "baFileId" => $baFileId,
  2768.             "sepaFileId" => $sepaFileId,
  2769.         );
  2770.         return $tab;
  2771.     }
  2772.     function saveFilesYouSignV3($membership$typeUser "customer")
  2773.     {
  2774.         $newSignatureId $membership->getProcedureId();
  2775.         //Wait 2 secondes Yousign create file
  2776.         //sleep(2);
  2777.         if ($membership->getDicIsFile() != true) {
  2778.             /* ------------------------ SAVE FIC START ------------------------ */
  2779.             //GET FIC FILE
  2780.             $client = new Client();
  2781.             $fileResponse $client->request('GET'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$membership->getFic()->getIdYouSign().'/download'
  2782.                 [
  2783.                     'headers' => [
  2784.                         'accept' => 'application/json',
  2785.                         'content-type' => 'application/json',
  2786.                         'Authorization' => 'Bearer ' $this->yousignApi
  2787.                     ],
  2788.                 ]
  2789.             );
  2790.             $fileBody $fileResponse->getBody();
  2791.             $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'FIC.pdf';
  2792.             file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$fileBody);
  2793.             $membership->getFic()->setUrlPdfSign($name);
  2794.             $this->em->persist($membership->getFic());
  2795.             /* ------------------------ SAVE FIC END ------------------------ */
  2796.         }
  2797.         if($typeUser == "customer"){
  2798.             /* ------------------------ SAVE BA START ------------------------ */
  2799.             //GET BA FILE
  2800.             $client = new Client();
  2801.             $fileResponse $client->request('GET'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$membership->getBa()->getIdYouSign().'/download'
  2802.                 [
  2803.                     'headers' => [
  2804.                         'accept' => 'application/json',
  2805.                         'content-type' => 'application/json',
  2806.                         'Authorization' => 'Bearer ' $this->yousignApi
  2807.                     ],
  2808.                 ]
  2809.             );
  2810.             $fileBody $fileResponse->getBody();
  2811.             $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'BA.pdf';
  2812.             file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$fileBody);
  2813.             $membership->getBa()->setUrlPdfSign($name);
  2814.             /* ------------------------ SAVE BA END ------------------------ */
  2815.             /* ------------------------ SAVE SEPA START ------------------------ */
  2816.             if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  2817.                 //GET SEPA FILE
  2818.                 $client = new Client();
  2819.                 $fileResponse $client->request('GET'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$membership->getBa()->getSepaIdYouSign().'/download'
  2820.                     [
  2821.                         'headers' => [
  2822.                             'accept' => 'application/json',
  2823.                             'content-type' => 'application/json',
  2824.                             'Authorization' => 'Bearer ' $this->yousignApi
  2825.                         ],
  2826.                     ]
  2827.                 );
  2828.                 $fileBody $fileResponse->getBody();
  2829.                 $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'SEPA.pdf';
  2830.                 file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$fileBody);
  2831.                 $membership->getBa()->setSepaUrlPdfSign($name);
  2832.             }
  2833.             /* ------------------------ SAVE SEPA END ------------------------ */
  2834.             $this->em->persist($membership->getBa());
  2835.         }
  2836.         $this->em->flush();
  2837.     }
  2838.     function saveFilesYouSign($membership$typeUser "customer")
  2839.     {
  2840.         //Wait 2 secondes Yousign create file
  2841.         sleep(2);
  2842.         if ($membership->getDicIsFile() != true) {
  2843.             if($membership->getPlatformVersion() == 1){
  2844.                 //V1 DIC
  2845.                 /* ------------------------ SAVE DIC START ------------------------ */
  2846.                 //GET DIC FILE
  2847.                 $curl curl_init();
  2848.                 curl_setopt_array($curl, array(
  2849.                     CURLOPT_URL => $this->yousignUrlV2 $membership->getDic()->getIdYouSign() . "/download",
  2850.                     CURLOPT_RETURNTRANSFER => true,
  2851.                     CURLOPT_ENCODING => "",
  2852.                     CURLOPT_MAXREDIRS => 30,
  2853.                     CURLOPT_TIMEOUT => 0,
  2854.                     CURLOPT_FOLLOWLOCATION => true,
  2855.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2856.                     CURLOPT_CUSTOMREQUEST => "GET",
  2857.                     CURLOPT_HTTPHEADER => array(
  2858.                         "Authorization: Bearer " $this->yousignApiV2,
  2859.                         "Content-Type: application/json"
  2860.                     ),
  2861.                 ));
  2862.                 $responseFileDic curl_exec($curl);
  2863.                 curl_close($curl);
  2864.                 $dicFile json_decode($responseFileDic);
  2865.                 $dicFileBin base64_decode($dicFiletrue);
  2866.                 $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'DIC.pdf';
  2867.                 file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$dicFileBin);
  2868.                 $membership->getDic()->setUrlPdfSign($name);
  2869.                 /* ------------------------ SAVE DIC END ------------------------ */
  2870.             } else {
  2871.                 // V2 FIC
  2872.                 /* ------------------------ SAVE FIC START ------------------------ */
  2873.                 //GET FIC FILE
  2874.                 $curl curl_init();
  2875.                 curl_setopt_array($curl, array(
  2876.                     CURLOPT_URL => $this->yousignUrlV2 $membership->getFic()->getIdYouSign() . "/download",
  2877.                     CURLOPT_RETURNTRANSFER => true,
  2878.                     CURLOPT_ENCODING => "",
  2879.                     CURLOPT_MAXREDIRS => 30,
  2880.                     CURLOPT_TIMEOUT => 0,
  2881.                     CURLOPT_FOLLOWLOCATION => true,
  2882.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2883.                     CURLOPT_CUSTOMREQUEST => "GET",
  2884.                     CURLOPT_HTTPHEADER => array(
  2885.                         "Authorization: Bearer " $this->yousignApiV2,
  2886.                         "Content-Type: application/json"
  2887.                     ),
  2888.                 ));
  2889.                 $responseFileFic curl_exec($curl);
  2890.                 curl_close($curl);
  2891.                 $ficFile json_decode($responseFileFic);
  2892.                 $ficFileBin base64_decode($ficFiletrue);
  2893.                 $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'FIC.pdf';
  2894.                 file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$ficFileBin);
  2895.                 $membership->getFic()->setUrlPdfSign($name);
  2896.                 /* ------------------------ SAVE FIC END ------------------------ */
  2897.             }
  2898.         }
  2899.         if($typeUser == "customer"){
  2900.             /* ------------------------ SAVE BA START ------------------------ */
  2901.             //GET BA FILE
  2902.             $curl curl_init();
  2903.             curl_setopt_array($curl, array(
  2904.                 CURLOPT_URL => $this->yousignUrlV2 $membership->getBa()->getIdYouSign() . "/download",
  2905.                 CURLOPT_RETURNTRANSFER => true,
  2906.                 CURLOPT_ENCODING => "",
  2907.                 CURLOPT_MAXREDIRS => 30,
  2908.                 CURLOPT_TIMEOUT => 0,
  2909.                 CURLOPT_FOLLOWLOCATION => true,
  2910.                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2911.                 CURLOPT_CUSTOMREQUEST => "GET",
  2912.                 CURLOPT_HTTPHEADER => array(
  2913.                     "Authorization: Bearer " $this->yousignApiV2,
  2914.                     "Content-Type: application/json"
  2915.                 ),
  2916.             ));
  2917.             $responseFileBa curl_exec($curl);
  2918.             curl_close($curl);
  2919.             $baFile json_decode($responseFileBa);
  2920.             $baFileBin base64_decode($baFiletrue);
  2921.             $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'BA.pdf';
  2922.             file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$baFileBin);
  2923.             $membership->getBa()->setUrlPdfSign($name);
  2924.             /* ------------------------ SAVE BA END ------------------------ */
  2925.             /* ------------------------ SAVE SEPA START ------------------------ */
  2926.             if ($membership->getBa()->getVersementProgramme() == || $membership->getBa()->getMoyenDeVersement() == 3) {
  2927.                 //GET SEPA FILE
  2928.                 $curl curl_init();
  2929.                 curl_setopt_array($curl, array(
  2930.                     CURLOPT_URL => $this->yousignUrlV2 $membership->getBa()->getSepaIdYouSign() . "/download",
  2931.                     CURLOPT_RETURNTRANSFER => true,
  2932.                     CURLOPT_ENCODING => "",
  2933.                     CURLOPT_MAXREDIRS => 30,
  2934.                     CURLOPT_TIMEOUT => 0,
  2935.                     CURLOPT_FOLLOWLOCATION => true,
  2936.                     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  2937.                     CURLOPT_CUSTOMREQUEST => "GET",
  2938.                     CURLOPT_HTTPHEADER => array(
  2939.                         "Authorization: Bearer " $this->yousignApiV2,
  2940.                         "Content-Type: application/json"
  2941.                     ),
  2942.                 ));
  2943.                 $responseFileSepa curl_exec($curl);
  2944.                 curl_close($curl);
  2945.                 $sepaFile json_decode($responseFileSepa);
  2946.                 $sepaFileBin base64_decode($sepaFiletrue);
  2947.                 $name $membership->getNumberMembershipFolder() . '_' strtoupper($membership->getUser()->getLastName()) . '_' strtoupper($membership->getUser()->getFirstName()) . '_' 'SEPA.pdf';
  2948.                 file_put_contents($this->fileUploader->getTargetDirectory() . "/" $membership->getUser()->getId() . "/" $name$sepaFileBin);
  2949.                 $membership->getBa()->setSepaUrlPdfSign($name);
  2950.             }
  2951.             /* ------------------------ SAVE SEPA END ------------------------ */
  2952.             $this->em->persist($membership->getBa());
  2953.         }
  2954.         if($membership->getPlatformVersion() == 1){
  2955.             $this->em->persist($membership->getDic());
  2956.         }
  2957.         else{
  2958.             $this->em->persist($membership->getFic());
  2959.         }
  2960.         $this->em->flush();
  2961.     }
  2962.     function startSign($procedure)
  2963.     {
  2964.         $memberId $procedure->members[0]->id;
  2965.         $yousignUrlV2 $this->container->getParameter('yousign_url_v2');
  2966.         header('Location: ' $yousignUrlV2 '/procedure/sign?members=' $memberId '&signatureUi=/signature_uis/' $this->yousignUi);
  2967.         exit();
  2968.     }
  2969.     function youSignConditionsV3($fileURL$document$userCurrent null): array
  2970.     {
  2971.         $client = new Client();
  2972.         $responseProcedure null;
  2973.         $responseErrorTab = [];
  2974.         $cpFileId null;
  2975.         $activateSignatureResponseBody null;
  2976.         $newSignatureId null;
  2977.         $uploadDocumentId null;
  2978.         $signerUrl null;
  2979.         //Font default for all fields
  2980.         $fontDefault = new \stdClass();
  2981.         $fontDefault->size 9;
  2982.         $fontDefault->family "Inconsolata";
  2983.         $fontDefault->variants = array(
  2984.             "italic" => false,
  2985.             "bold" => false
  2986.         );
  2987.         $fontDefault->color "#000000";
  2988.         /* -----------------------------------  Add Signature   ------------------------------------- */
  2989.         //Create signature
  2990.         $newSignature = new \stdClass();
  2991.         $newSignature->delivery_mode "none";
  2992.         $newSignature->reminder_settings null;
  2993.         $newSignature->ordered_signers true;
  2994.         $newSignature->signers_allowed_to_decline false;
  2995.         $newSignature->workspace_id $this->yousignWorkspaceConditions;
  2996.         $newSignature->name "Conditions particulières";
  2997.         $newSignature->custom_experience_id $this->yousignUiConditions;
  2998.         try {
  2999.             $newSignatureResponse $client->request('POST'$this->yousignUrl .'/signature_requests'
  3000.                 [
  3001.                     'body' => json_encode($newSignature),
  3002.                     'headers' => [
  3003.                         'accept' => 'application/json',
  3004.                         'content-type' => 'application/json',
  3005.                         'Authorization' => 'Bearer ' $this->yousignApi
  3006.                     ],
  3007.                 ]
  3008.             );
  3009.             //201 for create
  3010.             $newSignatureResponseStatusCode $newSignatureResponse->getStatusCode();
  3011.             $newSignatureResponseBody json_decode($newSignatureResponse->getBody());
  3012.             $newSignatureId $newSignatureResponseBody->id;
  3013.         }
  3014.         catch (\Exception $e) {
  3015.             $responseErrorTab[] = $e->getMessage();
  3016.         }
  3017.         /* -----------------------------------  Add Metadata   ------------------------------------- */
  3018.         //Create meta
  3019.         $newMetaData = new \stdClass();
  3020.         $newMetaData->data = array(
  3021.             "documentId" => $document->getId()
  3022.         );
  3023.         try {
  3024.             $newMetaDataResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/metadata'
  3025.                 [
  3026.                     'body' => json_encode($newMetaData),
  3027.                     'headers' => [
  3028.                         'accept' => 'application/json',
  3029.                         'content-type' => 'application/json',
  3030.                         'Authorization' => 'Bearer ' $this->yousignApi
  3031.                     ],
  3032.                 ]
  3033.             );
  3034.             //201 for create
  3035.             $newMetaDataResponseStatusCode $newMetaDataResponse->getStatusCode();
  3036.             $newMetaDataResponseBody json_decode($newMetaDataResponse->getBody());
  3037.         }
  3038.         catch (\Exception $e) {
  3039.             $responseErrorTab[] = $e->getMessage();
  3040.         }
  3041.         /* -----------------------------------  Add Files   ------------------------------------- */
  3042.         //Add Document file
  3043.         try {
  3044.             $uploadDocumentResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents'
  3045.                 [
  3046.                     'multipart' => [
  3047.                         [
  3048.                             'name' => 'nature',
  3049.                             'contents' => 'signable_document'
  3050.                         ],
  3051.                         [
  3052.                             'name' => 'parse_anchors',
  3053.                             'contents' => 'false'
  3054.                         ],
  3055.                         [
  3056.                             'name' => 'file',
  3057.                             'filename' => "Conditions particulières.pdf",
  3058.                             'contents' => fopen($fileURL'r'),
  3059.                         ]
  3060.                     ],
  3061.                     'headers' => [
  3062.                         'accept' => 'application/json',
  3063.                         'Authorization' => 'Bearer ' $this->yousignApi
  3064.                     ]
  3065.                 ]
  3066.             );
  3067.             $uploadDocumentResponseBody json_decode($uploadDocumentResponse->getBody());
  3068.             $uploadDocumentId $uploadDocumentResponseBody->id;
  3069.         }
  3070.         catch (\Exception $e) {
  3071.             $responseErrorTab[] = $e->getMessage();
  3072.         }
  3073.         //Add Member
  3074.         $phone $userCurrent->getPhone();
  3075.         $phone str_replace("("""$phone);
  3076.         $phone str_replace(")"""$phone);
  3077.         $phone str_replace(" """$phone);
  3078.         $phone str_replace("_"""$phone);
  3079.         if ($userCurrent->getPhonePrefix()) {
  3080.             $phone $userCurrent->getPhonePrefix() . $phone;
  3081.         }
  3082.         else{
  3083.             $phone "+33" $phone;
  3084.         }
  3085.         $newSignerMember = new \stdClass();
  3086.         $newSignerMember->locale "fr";
  3087.         $newSignerMember->first_name $userCurrent->getFirstName();
  3088.         $newSignerMember->last_name $userCurrent->getLastName();
  3089.         $newSignerMember->email $userCurrent->getEmail();
  3090.         $newSignerMember->phone_number $phone;
  3091.         //$newSignerRedirect = new \stdClass();
  3092.         //$urlSignEnd = $this->container->get('router')->generate('yousign_sign_end_', array('membershipID' => $membership->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  3093.         //$newSignerRedirect->success = $urlSignEnd;
  3094.         //$newSignerRedirect->error = $urlSignEnd;
  3095.         $newSigner = new \stdClass();
  3096.         $newSigner->info $newSignerMember;
  3097.         $newSigner->signature_level "electronic_signature";
  3098.         $newSigner->signature_authentication_mode "otp_sms";
  3099.         //$newSigner->redirect_urls = $newSignerRedirect;
  3100.         try {
  3101.             $newSignerResponse $client->request('POST'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/signers'
  3102.                 [
  3103.                     'body' => json_encode($newSigner),
  3104.                     'headers' => [
  3105.                         'accept' => 'application/json',
  3106.                         'content-type' => 'application/json',
  3107.                         'Authorization' => 'Bearer ' $this->yousignApi
  3108.                     ],
  3109.                 ]
  3110.             );
  3111.             $newSignerResponseBody json_decode($newSignerResponse->getBody());
  3112.             $newSignerId $newSignerResponseBody->id;
  3113.          }
  3114.         catch (\Exception $e) {
  3115.             $responseErrorTab[] = $e->getMessage();
  3116.         }
  3117.         if($document->getFileType()){
  3118.             $page $document->getFileType()->getNumberPage();
  3119.         }
  3120.         else{
  3121.             // default page
  3122.             $page 2;
  3123.         }
  3124.         /* ADD SIGNATURE PLACED */
  3125.         $newFieldSignature = new \stdClass();
  3126.         $newFieldSignature->signer_id $newSignerId;
  3127.         $newFieldSignature->type "signature";
  3128.         $newFieldSignature->page $page;
  3129.         $newFieldSignature->width 114;
  3130.         $newFieldSignature->height 61;
  3131.         $newFieldSignature->433;
  3132.         $newFieldSignature->655;
  3133.         if($document->getFileType()){
  3134.             if($document->getFileType()->isSignedOrder()){
  3135.                 //Right
  3136.                 $newFieldSignature->width 114;
  3137.                 $newFieldSignature->height 61;
  3138.                 $newFieldSignature->433;
  3139.                 $newFieldSignature->655;
  3140.             }
  3141.             else{
  3142.                 //Left
  3143.                 $newFieldSignature->width 114;
  3144.                 $newFieldSignature->height 61;
  3145.                 $newFieldSignature->43;
  3146.                 $newFieldSignature->655;
  3147.             }
  3148.         } 
  3149.         try {
  3150.             $response $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/documents/'.$uploadDocumentId.'/fields'
  3151.                 [
  3152.                     'body' => json_encode($newFieldSignature),
  3153.                     'headers' => [
  3154.                         'accept' => 'application/json',
  3155.                         'content-type' => 'application/json',
  3156.                         'Authorization' => 'Bearer ' $this->yousignApi
  3157.                     ],
  3158.                 ]
  3159.             );
  3160.         }
  3161.         catch (\Exception $e) {
  3162.             $responseErrorTab[] = $e->getMessage();
  3163.         }
  3164.         /* -----------------------------------  Active signature (end step)   ------------------------------------- */
  3165.         //Activate signature
  3166.         try {
  3167.             $activateSignatureResponse $client->request('POST'$this->yousignUrl.'/signature_requests/'.$newSignatureId.'/activate'
  3168.                 [
  3169.                     'headers' => [
  3170.                         'accept' => 'application/json',
  3171.                         'Authorization' => 'Bearer ' $this->yousignApi
  3172.                     ],
  3173.                 ]
  3174.             );
  3175.             $activateSignatureResponseBody json_decode($activateSignatureResponse->getBody());
  3176.             $activateSignatureResponseSigners $activateSignatureResponseBody->signers;
  3177.             $signerUrl $activateSignatureResponseSigners[0]->signature_link;
  3178.         }
  3179.         catch (\Exception $e) {
  3180.             $responseErrorTab[] = $e->getMessage();
  3181.         }
  3182.         return [
  3183.             "responseProcedure" => $activateSignatureResponseBody,
  3184.             "procedureId" => $newSignatureId,
  3185.             "yousignUi" => $this->yousignUiConditions,
  3186.             "fileId" => $uploadDocumentId,
  3187.             "signerUrl" => $signerUrl,
  3188.             "responseErrorTab" => $responseErrorTab
  3189.         ];
  3190.     }
  3191.     function youSignConditions($fileURL$document$userCurrent null): array
  3192.     {
  3193.         $responseProcedure null;
  3194.         $cpFileId null;
  3195.         //Get CP BASE 64
  3196.         $b64Cp chunk_split(base64_encode(file_get_contents($fileURL)));
  3197.         $fileCp = new \stdClass();
  3198.         $fileCp->name "Conditions particulières";
  3199.         $fileCp->content $b64Cp;
  3200.         $fileCp->position 1;
  3201.         //Create files
  3202.         $curl curl_init();
  3203.         curl_setopt_array($curl, array(
  3204.             CURLOPT_URL => $this->yousignUrlV2 "/files",
  3205.             CURLOPT_RETURNTRANSFER => true,
  3206.             CURLOPT_ENCODING => '',
  3207.             CURLOPT_MAXREDIRS => 10,
  3208.             CURLOPT_TIMEOUT => 0,
  3209.             CURLOPT_FOLLOWLOCATION => true,
  3210.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  3211.             CURLOPT_CUSTOMREQUEST => "POST",
  3212.             CURLOPT_POSTFIELDS => json_encode($fileCp),
  3213.             CURLOPT_HTTPHEADER => array(
  3214.                 "Authorization: Bearer " $this->yousignApiV2,
  3215.                 "Content-Type: application/json"
  3216.             ),
  3217.         ));
  3218.         $responseFile curl_exec($curl);
  3219.         curl_close($curl);
  3220.         $responseFileCp json_decode($responseFile);
  3221.         if($responseFileCp){
  3222.             //Default (last value) : "432,131,548,184"; page 2;
  3223.             if($document->getFileType()){
  3224.                 if($document->getFileType()->isSignedOrder()){
  3225.                     //Right
  3226.                     $position "432,131,548,184";
  3227.                 }
  3228.                 else{
  3229.                     //Left
  3230.                     $position "50,134,178,180";
  3231.                 }
  3232.             } else {
  3233.                 // default position
  3234.                 $position "432,131,548,184";
  3235.             }
  3236.             if($document->getFileType()){
  3237.                 $page $document->getFileType()->getNumberPage();
  3238.             }
  3239.             else{
  3240.                 // default page
  3241.                 $page 2;
  3242.             }
  3243.             //Set file CP
  3244.             $fileObjectCp = new \stdClass();
  3245.             $fileObjectCp->file $responseFileCp->id;
  3246.             $fileObjectCp->page $page;
  3247.             $fileObjectCp->position $position;
  3248.             $fileObjectCp->mention "Lu et approuvé";
  3249.             $fileObjectCp->reason "Signed by John Doe (Yousign)";
  3250.             $firstName $userCurrent->getFirstName();
  3251.             $lastName $userCurrent->getLastName();
  3252.             if($firstName && $lastName){
  3253.                 $fileObjectCp->mention2 "Signé par " $firstName " " $lastName;
  3254.             }
  3255.             $arrayObjectFiles[] = $fileObjectCp;
  3256.             $cpFileId $responseFileCp->id;
  3257.             //Add procedure
  3258.             $config = new \stdClass();
  3259.             $webhook = new \stdClass();
  3260.             $webhookEnd = new \stdClass();
  3261.             $header = new \stdClass();
  3262.             $urlSignEnd $this->container->get('router')->generate('yousign_sign_conditions_end', array('documentID' => $document->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  3263.             $webhookEnd->url $urlSignEnd;
  3264.             $webhookEnd->method "GET";
  3265.             $webhookEnd->headers = (object)array(
  3266.                 'X-Custom-Header' => "End sign"
  3267.             );
  3268.             $config->webhook = (object)array(
  3269.                 'procedure.finished' => array(
  3270.                     $webhookEnd
  3271.                 )
  3272.             );
  3273.             //Set member - customer
  3274.             $member = new \stdClass();
  3275.             $member->firstname $userCurrent->getFirstName();
  3276.             $member->phone $userCurrent->getPhone();
  3277.             $member->lastname $userCurrent->getLastName();
  3278.             $member->email $userCurrent->getEmail();
  3279.             $member->fileObjects $arrayObjectFiles;
  3280.             $member->type "signer";
  3281.             //Set procedure
  3282.             $procedure = new \stdClass();
  3283.             $procedure->name "Signature des conditions particulières";
  3284.             $procedure->description "Fin d'adhésion";
  3285.             $procedure->start true;
  3286.             $procedure->members = array(
  3287.                 $member
  3288.             );
  3289.             $procedure->config $config;
  3290.             $curl curl_init();
  3291.             curl_setopt_array($curl, array(
  3292.                 CURLOPT_URL => $this->yousignUrlV2 "/procedures",
  3293.                 CURLOPT_RETURNTRANSFER => true,
  3294.                 CURLOPT_ENCODING => "",
  3295.                 CURLOPT_MAXREDIRS => 10,
  3296.                 CURLOPT_TIMEOUT => 0,
  3297.                 CURLOPT_FOLLOWLOCATION => true,
  3298.                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  3299.                 CURLOPT_CUSTOMREQUEST => "POST",
  3300.                 CURLOPT_POSTFIELDS => json_encode($procedure),
  3301.                 CURLOPT_HTTPHEADER => array(
  3302.                     "Authorization: Bearer " $this->yousignApiV2,
  3303.                     "Content-Type: application/json"
  3304.                 ),
  3305.             ));
  3306.             $responseProcedure curl_exec($curl);
  3307.             curl_close($curl);
  3308.             $responseProcedure json_decode($responseProcedure);
  3309.         }
  3310.         return [
  3311.             "responseProcedure" => $responseProcedure,
  3312.             "yousignUi" => $this->yousignUiConditions,
  3313.             "fileId" => $cpFileId,
  3314.         ];
  3315.     }
  3316.     function saveFilesConditionsYouSignV3($document)
  3317.     {
  3318.         $newSignatureId $document->getProcedureId();
  3319.         //Wait 2 secondes Yousign create file
  3320.         //sleep(2);
  3321.         /* ------------------------ SAVE Document START ------------------------ */
  3322.         //GET FIC FILE
  3323.         $client = new Client();
  3324.         $fileResponse $client->request('GET'$this->yousignUrl .'/signature_requests/'.$newSignatureId.'/documents/'.$document->getIdYouSign().'/download'
  3325.             [
  3326.                 'headers' => [
  3327.                     'accept' => 'application/json',
  3328.                     'content-type' => 'application/json',
  3329.                     'Authorization' => 'Bearer ' $this->yousignApi
  3330.                 ],
  3331.             ]
  3332.         );
  3333.         $fileBody $fileResponse->getBody();
  3334.         $name $document->getNumeroAdherent() . "_" $document->getLastName() . "_" $document->getFirstName() . "_CONDITIONS_PARTICULIERES.pdf";
  3335.         $path $this->fileUploader->getTargetDirectory() . "/cp/" $document->getId() . "/" $name;
  3336.         file_put_contents($path$fileBody);
  3337.         /* ------------------------ SAVE Document END ------------------------ */
  3338.         $document->setUrlPdfSign($path);
  3339.         $document->setFilename($name);
  3340.     
  3341.         $this->em->persist($document);
  3342.         $this->em->flush();
  3343.     }
  3344.     function saveFilesConditionsYouSign($document)
  3345.     {
  3346.         //GET DIC FILE
  3347.         $curl curl_init();
  3348.         curl_setopt_array($curl, array(
  3349.             CURLOPT_URL => $this->yousignUrl $document->getIdYouSign() . "/download",
  3350.             CURLOPT_RETURNTRANSFER => true,
  3351.             CURLOPT_ENCODING => "",
  3352.             CURLOPT_MAXREDIRS => 10,
  3353.             CURLOPT_TIMEOUT => 0,
  3354.             CURLOPT_FOLLOWLOCATION => true,
  3355.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  3356.             CURLOPT_CUSTOMREQUEST => "GET",
  3357.             CURLOPT_HTTPHEADER => array(
  3358.                 "Authorization: Bearer " $this->yousignApi,
  3359.                 "Content-Type: application/json"
  3360.             ),
  3361.         ));
  3362.         $responseFile curl_exec($curl);
  3363.         curl_close($curl);
  3364.         $file json_decode($responseFile);
  3365.         $fileBin base64_decode($filetrue);
  3366.         $name $document->getNumeroAdherent() . "_" $document->getLastName() . "_" $document->getFirstName() . "_CONDITIONS_PARTICULIERES.pdf";
  3367.         $path $this->fileUploader->getTargetDirectory() . "/cp/" $document->getId() . "/" $name;
  3368.         file_put_contents($path$fileBin);
  3369.         $document->setUrlPdfSign($path);
  3370.         $document->setFilename($name);
  3371.     
  3372.         $this->em->persist($document);
  3373.         $this->em->flush();
  3374.     }
  3375. }