src/Services/Utils.php line 64

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