src/Services/Utils.php line 61

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