src/Controller/SouscriptionController.php line 2602

  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use DateTimeImmutable;
  9. use Date;
  10. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  11. use App\Entity\InfoSouscription;
  12. use App\Entity\PoliceAbonnement;
  13. use App\Entity\Client;
  14. use App\Entity\Assurance;
  15. use App\Entity\Puissance;
  16. use App\Entity\Energie;
  17. use App\Entity\Duree;
  18. use App\Entity\DureeVoyage;
  19. use App\Entity\Marque;
  20. use App\Entity\TypeClient;
  21. use App\Entity\TypeOperation;
  22. use App\Entity\AssuranceVoyage;
  23. use App\Entity\AssuranceHabitation;
  24. use App\Entity\Classe;
  25. use App\Entity\ZoneVoyage;
  26. use App\Entity\Ville;
  27. use App\Entity\Tarif;
  28. use App\Entity\TarifVoyage;
  29. use App\Entity\TarifHabitation;
  30. use App\Entity\Formule;
  31. use App\Entity\Livraison;
  32. use App\Entity\Log;
  33. use App\Entity\Paiement;
  34. use App\Entity\StatutPaiement;
  35. use App\Entity\Zone;
  36. use App\Repository\VilleRepository;
  37. use App\Repository\AssuranceRepository;
  38. use App\Repository\PuissanceRepository;
  39. use App\Repository\TarifRepository;
  40. use App\Service\FileUploader;
  41. use Symfony\Component\HttpFoundation\RedirectResponse
  42. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  43. use Symfony\Component\Validator\Validator\ValidatorInterface;
  44. class SouscriptionController extends AbstractController
  45. {
  46.     #[Route('/souscription/assurances/automobile'name'app_souscription_auto')]
  47.     public function indexAuto(
  48.         EntityManagerInterface $entityManager,
  49.         Request $request,
  50.         SessionInterface $session,
  51.         UserPasswordHasherInterface $userPasswordHasher,
  52.         AssuranceRepository $AssuranceRepository,
  53.          FileUploader $uploader
  54.     ): Response {
  55.         $today date("Y-m-d");
  56.         $energies $entityManager
  57.             ->getRepository(Energie::class)
  58.             ->findBy(['statut' => '1']);
  59.         $marques $entityManager
  60.             ->getRepository(Marque::class)
  61.             ->findBy(['statut' => '1']);
  62.         $energiesData $energies;
  63.         $durees $entityManager
  64.             ->getRepository(Duree::class)
  65.             ->findBy(['statut' => '1']);
  66.         $dureesData $durees;
  67.         if ($request->request->count() > 0) {
  68.             $nom trim($request->request->get("nom"));
  69.             $session->set('nom'$nom);
  70.             $prenom trim($request->request->get("prenom"));
  71.             $session->set('prenom'$prenom);
  72.             $telephone trim($request->request->get("phone"));
  73.             $session->set('telephone'$telephone);
  74.             $usage trim($request->request->get("usage"));
  75.             $session->set('usage'$usage);
  76.             $marque trim($request->request->get("marque"));
  77.             $session->set('marque'$marque);
  78.             $modele trim($request->request->get("modele"));
  79.             $session->set('modele'$modele);
  80.             $plaque trim($request->request->get("plaque"));
  81.             $session->set('plaque'$plaque);
  82.             $puissance trim($request->request->get("puissance"));
  83.             $session->set('puissance'$puissance);
  84.             $energie trim($request->request->get("energie"));
  85.             $session->set('energie'$energie);
  86.             $place trim($request->request->get("place"));
  87.             $session->set('place'$place);
  88.             $duree trim($request->request->get("duree"));
  89.             $session->set('duree'$duree);
  90.             $date_effet trim($request->request->get("date_effet"));
  91.             $session->set('date_effet'$date_effet);
  92.             // $livraison = $request->request->get("livraison");
  93.             // $session->set('livraison', $livraison);
  94.             // $address = $request->request->get("address");
  95.             // $session->set('address', $address);
  96.             $option $request->request->get("option");
  97.             $session->set('option'$option);
  98.             $avance_recours $request->request->get("avance_recours");
  99.             $session->set('avance_recours'$avance_recours);
  100.             $carteGrise $request->files->get("carteGrise");
  101.              if ($carteGrise) {
  102.              }else {
  103.                 # code...
  104.                 $this->addFlash('noTarif''Veuillez rensignez la carte grise.');
  105.                 $iduser null;
  106.                 $idclient null;
  107.                 $action "Souscription Automobile";
  108.                 $msg_send "Controls champs obligatoires";
  109.                 $msg_get "Veuillez rensignez la carte grise";
  110.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  111.                 $entityManager->persist($log);
  112.                 $entityManager->flush();
  113.                 return $this->redirectToRoute('app_souscription_auto');
  114.              }
  115.             $mat "Document";
  116.             $array = array("png""PNG","jpg","JPG","jpeg","JPEG");
  117.       
  118.             $zone 1;
  119.             $classe 1;
  120.             if ($usage == 1) {
  121.                 $code 101;
  122.             } else if ($usage == 2) {
  123.                 $code 105;
  124.             }
  125.             $session->set('code'$code);
  126.             $ch curl_init();
  127.             curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/clientCaren");
  128.             curl_setopt($chCURLOPT_POST1);
  129.             curl_setopt($chCURLOPT_POSTFIELDS'{
  130.             "nom" : "' $nom '",
  131.             "prenom" : "' $prenom '",
  132.             "telephone" : "' $telephone '"
  133.             }');
  134.             $headers = array(
  135.                 "Content-Type: application/json",
  136.                 "Accept: application/json",
  137.             );
  138.             curl_setopt($chCURLOPT_HTTPHEADER$headers);
  139.             //for debug only!
  140.             curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  141.             curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  142.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  143.             $server_output curl_exec($ch);
  144.             curl_close($ch);
  145.             $clientCaren json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  146.             $ener "";
  147.             if ($energie == 1) {
  148.                 $ener "E";
  149.             } else {
  150.                 $ener "D";
  151.             }
  152.             $interval_puissance $entityManager->getRepository(Puissance::class)->findPuissance((int)$puissance$ener$code);
  153.             $energie $entityManager->getRepository(Energie::class)->find($energie);
  154.             $zone $entityManager->getRepository(Zone::class)->find($zone);
  155.             $classe $entityManager->getRepository(Classe::class)->find($classe);
  156.             $duree $entityManager->getRepository(Duree::class)->find($duree);
  157.            // dd($interval_puissance);
  158.             // dd($energie, $zone, $classe, $duree, $interval_puissance->getId(), $code);
  159.             if($energie == null || $zone == null || $classe == null || $duree == null || $carteGrise == null){
  160.                 $this->addFlash('noTarif''Veuillez rensignez tous les champs obligatoires.');
  161.                 $iduser null;
  162.                 $idclient null;
  163.                 $action "Souscription Automobile";
  164.                 $msg_send "Controls champs obligatoires";
  165.                 $msg_get "Veuillez rensignez tous les champs obligatoires";
  166.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  167.                 $entityManager->persist($log);
  168.                 $entityManager->flush();
  169.                 return $this->redirectToRoute('app_souscription_auto');
  170.             }
  171.             if ($interval_puissance != null) {
  172.                 $tarif $entityManager->getRepository(Tarif::class)->findOneBy(
  173.                     [
  174.                         'energie' => $energie->getId(),
  175.                         'zone' =>  $zone->getId(),
  176.                         'classe' =>  $classe->getId(),
  177.                         'duree' =>  $duree->getId(),
  178.                         'puissance' => $interval_puissance->getId(),
  179.                         'code' => $code,
  180.                         'statut' => 1
  181.                     ]
  182.                 );
  183.             } else {
  184.                 $this->addFlash('noTarif''Aucune tarification trouvée, veuillez rééssayer.');
  185.                 $iduser null;
  186.                 $idclient null;
  187.                 $action "Souscription Automobile";
  188.                 $msg_send "Recuperation tarifs";
  189.                 $msg_get "Aucune tarification trouvée, veuillez rééssayer.";
  190.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  191.                 $entityManager->persist($log);
  192.                 $entityManager->flush();
  193.                 return $this->redirectToRoute('app_souscription_auto');
  194.             }
  195.             if ($tarif != null) {
  196.                 // $result = $tarif['result'];
  197.                 // $montant = $result['montant'];
  198.                 // dd($result,$montant);
  199.                 $clientAssur $entityManager->getRepository(Client::class)->findOneBy(['telephone' => $telephone'idTypeClient' => 2]);
  200.                
  201.              
  202.                 if($clientAssur == null ){
  203.                     $this->addFlash('noTarif''Veuillez reprendre l operation SVP');
  204.                     $iduser null;
  205.                     $idclient null;
  206.                     $action "Souscription Automobile";
  207.                     $msg_send "Controls sur le client";
  208.                     $msg_get "Veuillez reprendre l operation SVP";
  209.                     $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  210.                     $entityManager->persist($log);
  211.                     $entityManager->flush();
  212.                     return $this->redirectToRoute('app_souscription_auto');
  213.                 }
  214.                 $lastId =$AssuranceRepository->last_assur($code);
  215.                 if ($lastId == null
  216.                 {
  217.                     $numero'00001';
  218.                     $num_police $code.$numero;
  219.                 }else
  220.                 {
  221.                     $num_police $lastId->getPoliceAbonnement()->getNumeroPolice() + 1;
  222.                 }
  223.                 // $num_police = random_int(1000, 99999);
  224.                 // dd($num_police);
  225.                 $police = new PoliceAbonnement();
  226.                 $police->setIdClient($clientAssur)
  227.                     ->setNumeroPolice($num_police)
  228.                     ->setNumeroPoliceZamoha($num_police)
  229.                     ->setCreatedAt(new \DateTimeImmutable('now'))
  230.                     ->setStatut(1);
  231.                 // dd($police);
  232.                 $entityManager->persist($police);
  233.   
  234.                 // $tarifAssur = $entityManager->getRepository(Tarif::class)->findOneBy(['id' => $result['id_tarif']]);
  235.                 $tarifAssur $tarif;
  236.                 $type_operation $entityManager->getRepository(TypeOperation::class)->find(1);
  237.                 $reference =   random_int(10000999999);
  238.                 $retour =   "Le retour de l'API CAREN";
  239.                 $GARA__SC 1;
  240.                 $montant_total 0;
  241.                 $dateEffet "";
  242.                 $dateEcheance "";
  243.                 if ($option == && $avance_recours == 1) {
  244.                     $montant_total =  $tarifAssur->getTtcAvrIc2();
  245.                 } else if ($option == && $avance_recours == 2) {
  246.                     $montant_total =  $tarifAssur->getTtcIc2();
  247.                 } else if ($option == && $avance_recours == 1) {
  248.                     $montant_total =  $tarifAssur->getTtcAvr();
  249.                 } else {
  250.                     $montant_total =  $tarifAssur->getTtcBasic();
  251.                 }
  252.                 if ($date_effet $today) {
  253.                     $this->addFlash('noTarif''La date effet ne peut etre inférieur à la date du jour, veuillez rééssayer saisir une date valide.');
  254.                     $iduser null;
  255.                     $idclient null;
  256.                     $action "Souscription Automobile";
  257.                     $msg_send "Controls sur les Date tarifs";
  258.                     $msg_get "La date effet ne peut etre inférieur à la date du jour, veuillez rééssayer saisir une date valide.";
  259.                     $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  260.                     $entityManager->persist($log);
  261.                     $entityManager->flush();
  262.                     return $this->redirectToRoute('app_souscription_auto');
  263.                 } else {
  264.                     $nbrJour = (int)$duree->getLibelle() * 30;
  265.                                         // Exemple : durée en mois
  266.                     $nbMois = (int)$duree->getLibelle(); // ex: 6 pour 6 mois
  267.                     // Création de la date d'effet
  268.                     if ($date_effet == $today) {
  269.                         $dateEffet = new \DateTimeImmutable(); // maintenant
  270.                     } else {
  271.                         $dateEffet \DateTimeImmutable::createFromFormat('Y-m-d'$date_effet)->setTime(000);
  272.                     }
  273.                     // Calcul de la date d’échéance
  274.                     // $dateEcheance = $dateEffet->add(new \DateInterval("P{$nbMois}M"))->setTime(23, 59, 59);
  275.                     $dateEcheance = (clone $dateEffet)->add(new \DateInterval("P{$nbMois}M"))->sub(new \DateInterval("P1D"))->setTime(235959);
  276.                     // dd($nbrJour);
  277.                     // $dateEchean = date('Y-m-d', strtotime($date_effet . '' . (int)$nbrJour . ' day'));
  278.                     // $dateEcheance = (\DateTimeImmutable::createFromFormat('Y-m-d H:s:i', $dateEchean . '23:59:59'));
  279.                     // if ($date_effet == $today) {
  280.                     //     $day = date('Y-m-d H:s:i');
  281.                     //     $dateEffet = (\DateTimeImmutable::createFromFormat('Y-m-d H:s:i', $day));
  282.                     // } else {
  283.                     //     $dateEffet = (\DateTimeImmutable::createFromFormat('Y-m-d H:s:i', $date_effet . '00:01:00'));
  284.                     // }
  285.                 }
  286.               
  287.                 $souscription = new Assurance();
  288.                 $souscription->setPoliceAbonnement($police)
  289.                     ->setIdClient($clientAssur)
  290.                     ->setNomBeneficiaire($nom)
  291.                     ->setPrenomBeneficiaire($prenom)
  292.                     ->setTelephoneBeneficiaire($telephone)
  293.                     ->setCanal("WEB")
  294.                     ->setTarif($tarifAssur)
  295.                     ->setTypeOperation($type_operation)
  296.                     ->setReference($reference)
  297.                     ->setMontantAssurance($montant_total)
  298.                     ->setMontantTotal($montant_total)
  299.                     ->setRetourApi($retour)
  300.                     ->setNUMEENCA("000000000000")
  301.                     ->setNUMEIMMA($plaque)
  302.                     ->setMARQVEHI($marque)
  303.                     ->setDATEFFE($dateEffet)
  304.                     ->setDATEECHE($dateEcheance)
  305.                     ->setNOMBPLAC($place)
  306.                     ->setGARASC($GARA__SC)
  307.                     ->setNUMECHAS($plaque)
  308.                     ->setModele($modele)
  309.                     ->setCYLIVEHI($puissance)
  310.                     ->setSecuriteConducteur($option)
  311.                     ->setAvanceRecour($avance_recours)
  312.                     ->setCreatedAt(new \DateTimeImmutable('now'))
  313.                     ->setStatut(0);
  314.                 // dd($souscription, $dateEffet, $dateEcheance);
  315.                 $entityManager->persist($souscription);
  316.                 $paiement =  new Paiement();
  317.                 $statutPaiement $entityManager->getRepository(StatutPaiement::class)->find(1);
  318.                 $paiement->setMontant($souscription->getMontantTotal())
  319.                     ->setStatut(0)
  320.                     ->setStatutPaiement($statutPaiement)
  321.                     ->setCreatedAt(new \DateTimeImmutable('now'));
  322.                     $entityManager->persist($souscription);
  323.                 $filename2 $carteGrise->getClientOriginalName();
  324.                 $filename2 explode('.' $filename2);
  325.                 $filename2 $mat.'carteGrise_'.$reference.'.'.$filename2[1];
  326.                 $extension=substr(strrchr($filename2,'.'),1);
  327.                 $lienDocument2 "";
  328.                 if ($carteGrise->getSize() > (1024 1024)) {
  329.                      $this->addFlash('noTarif'"Le fichier ne doit pas dépasser 5 Mo");
  330.                     return $this->redirectToRoute('app_souscription_auto', [], Response::HTTP_SEE_OTHER);
  331.                 }
  332.                 if(in_array($extension$arraytrue))
  333.                 {
  334.                ini_set('upload_max_filesize''10M');
  335.                 ini_set('post_max_size''10M');
  336.                 $uploaderImag=$uploader->upload("../public/images/carteGrises"$carteGrise$filename2);
  337.                 if ($uploaderImag==400) {
  338.                     # code...
  339.                     $this->addFlash('noTarif'"Veuillez recharger une image qui ne doit pas dépasser 5 Mo et en jpg ou png");
  340.                    return $this->redirectToRoute('app_souscription_auto', [], Response::HTTP_SEE_OTHER);
  341.                 }
  342.                 
  343.                 $protocol 'https'
  344.                 $HTTP_HOST $_SERVER['HTTP_HOST'];
  345.                 $lienDocument2 $protocol'://'.$HTTP_HOST.'/'.'images/carteGrises/'.$filename2;
  346.                 }else{ 
  347.             
  348.                 $this->addFlash('noTarif'"Ce format de fichier pour l'image n'est pas accepté par le système!!");
  349.                 return $this->redirectToRoute('app_souscription_auto', [], Response::HTTP_SEE_OTHER);
  350.         
  351.                 }
  352.                 $souscription->setCarte($lienDocument2);
  353.                 $entityManager->persist($paiement);
  354.                 $souscription->setPaiement($paiement);
  355.                 $entityManager->persist($souscription);
  356.             
  357.                 $iduser null;
  358.                 $idclient null;
  359.                 $action "Souscription Automobile";
  360.                 $msg_send "Demande souscription";
  361.                 $msg_get "Demande souscription éffectuée avec succés.";
  362.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  363.                 $entityManager->persist($log);
  364.                 $entityManager->flush();
  365.                 $session->clear();
  366.                 return $this->redirectToRoute('app_payement_souscriptionAuto',['id'=>$souscription->getId()]);
  367.                 // return $this->render('souscription/payement/payementAuto.html.twig', [
  368.                 //     'souscription' => $souscription,
  369.                 //     'montant' => $montant_total,
  370.                 //     'montantLivraison' => 0,
  371.                 //     'montantTotal' => $montant_total
  372.                 // ]);
  373.                 // }
  374.             } else {
  375.                 $this->addFlash('noTarif''Aucune tarification trouvée, veuillez rééssayer.');
  376.                 $iduser null;
  377.                 $idclient null;
  378.                 $action "Souscription Automobile";
  379.                 $msg_send "Recuperation tarifs";
  380.                 $msg_get "Aucune tarification trouvée, veuillez rééssayer.";
  381.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  382.                 $entityManager->persist($log);
  383.                 $entityManager->flush();
  384.                 return $this->redirectToRoute('app_souscription_auto');
  385.             }
  386.             // }
  387.         }
  388.         return $this->render('souscription/indexAuto.html.twig', [
  389.             'energies' => $energiesData,
  390.             'durees' => $dureesData,
  391.             'marques' => $marques,
  392.             'messageErr' => '',
  393.             'messageError' => ''
  394.         ]);
  395.     }
  396.     // #[Route('/souscriptionAuto/autoPayement/{id}', name: 'app_payement_souscriptionAuto', methods: ['POST', 'GET'])]
  397.     #[Route('/souscription/auto/payement/{id}'name'app_payement_souscriptionAuto'methods: ['POST''GET'])]
  398.     public function payementAuto(EntityManagerInterface $entityManagerSessionInterface $sessionRequest $requestAssurance $assurance): Response
  399.     {
  400.        // if ($request->request->count() > 0 && $request->request->get("souscription") == "souscription") {
  401.         if($request->request->count() >)
  402.         {
  403.             $payement $request->request->get("payement");
  404.             $telephone2 $request->request->get("phone2");
  405.             $paymentOptions $request->request->get('paymentOptions');
  406.             $operateur $request->request->get('operateur');
  407.             $phonePayment trim($request->request->get('phonePayment'));
  408.             $ipay_number trim($request->request->get('ipay_number'));
  409.             if($operateur == 2){
  410.               //  $phonePayment = "40410000000";
  411.                 $phonePayment str_replace(" """$ipay_number);
  412.                 
  413.              }else{
  414.                  $phonePayment str_replace(" """$phonePayment);
  415.              }
  416.             $indicatif "227";
  417.             $typeOperation 1;
  418.             
  419.             $idAssurance $assurance->getId();
  420.             if($assurance->getPaiement()!=null && $assurance->getPaiement()->getMoyenPaiement()!=null && $assurance->getPaiement()->getExternalId()!=null ) {
  421.                     $paiement $assurance->getPaiement();
  422.                     $idAssurance $assurance->getId();
  423.                     $external_id $paiement->getExternalId();
  424.         
  425.                     $typeOperation 1;
  426.         
  427.                     $ch curl_init();
  428.         
  429.                     curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/confirm/merchant/payment");
  430.                     curl_setopt($chCURLOPT_POSTFIELDS'{
  431.                         "external_id" : ' . (int)$external_id ',
  432.                         "typeOperation" : ' . (int)$typeOperation ',
  433.                         "operateur" : ' . (int)$operateur ',
  434.                         "idAssurance" : ' . (int)$idAssurance '
  435.                     }');
  436.                     $headers = array(
  437.                         "Content-Type: application/json",
  438.                         "Accept: application/json",
  439.         
  440.                     );
  441.                 
  442.         
  443.                     curl_setopt($chCURLOPT_HTTPHEADER$headers);
  444.                     //for debug only!
  445.                     curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  446.                     curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  447.                     curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  448.         
  449.                     $server_output curl_exec($ch);
  450.         
  451.                     curl_close($ch);
  452.         
  453.                     $confirmPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  454.                     if ($confirmPaiement==null) {
  455.                       # code...
  456.                       $statut null;
  457.                     }else{
  458.                       $statut $confirmPaiement['status'];
  459.                     }
  460.                   }else{
  461.                       $statut=null;
  462.                   }
  463.         
  464.                   if ($statut == 200) { 
  465.                     $session->set('number'0);
  466.         
  467.                     $this->addFlash('success''Félicitations, votre souscription est réussie avec succès.');
  468.                     $iduser null;
  469.                     $idclient $assurance->getIdClient();
  470.                     $action "Souscription Automobile";
  471.                     $msg_send "paiement souscription";
  472.                     $msg_get "Félicitations, votre souscription est réussie avec succès";
  473.                     $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  474.                     $entityManager->persist($log);
  475.         
  476.                     $entityManager->flush();
  477.                     return $this->redirectToRoute('app_home');
  478.                   } else {
  479.         
  480.                     $ch curl_init();
  481.         
  482.                     curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/get/merchant/payment");
  483.                     curl_setopt($chCURLOPT_POSTFIELDS'{
  484.                         "msisdn" : "' $phonePayment '",
  485.                         "idAssurance" : ' . (int)$idAssurance ',
  486.                         "indicatif" : ' $indicatif ',
  487.                         "typeOperation" : ' . (int)$typeOperation ',
  488.                         "operateur" : ' . (int)$operateur '
  489.                     }');
  490.                     $headers = array(
  491.                         "Content-Type: application/json",
  492.                         "Accept: application/json",
  493.         
  494.                     );
  495.         
  496.                     curl_setopt($chCURLOPT_HTTPHEADER$headers);
  497.                     //for debug only!
  498.                     curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  499.                     curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  500.                     curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  501.         
  502.                     $server_output curl_exec($ch);
  503.         
  504.                     curl_close($ch);
  505.         
  506.                   $initiationPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  507.         
  508.                 //    dd($initiationPaiement);
  509.         
  510.         
  511.                    if($initiationPaiement !=null){
  512.         
  513.                     $statut $initiationPaiement['status'];
  514.                             if($operateur == 2){
  515.                                     if ($initiationPaiement['result']['status'] == "initiated") {
  516.                                         return new RedirectResponse($initiationPaiement['result']['page_url']);
  517.                         
  518.                                        // $session->set('number', 4);
  519.                 
  520.                                         //return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  521.                 
  522.                                     } else {
  523.                                         $this->addFlash('ErreurSous'$initiationPaiement['message']);
  524.                 
  525.                                         $session->set('number'0);
  526.                                     }
  527.                                     
  528.                             }else{
  529.                                 if ($statut == 200) {
  530.                 
  531.                                     $session->set('number'4);
  532.             
  533.                                     return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  534.             
  535.                                 } else {
  536.                                     $this->addFlash('ErreurSous'$initiationPaiement['message']);
  537.             
  538.                                     $session->set('number'0);
  539.                                 }
  540.                             }
  541.                         }else{
  542.         
  543.                             $this->addFlash('ErreurSous'"Veuillez réessayer...");
  544.         
  545.         
  546.                             $session->set('number'0);
  547.         
  548.                         }
  549.         
  550.                         return $this->redirectToRoute('app_payement_souscriptionAuto',['id'=>$idAssurance]);
  551.         
  552.                     }
  553.        }
  554.        
  555.         return $this->render('souscription/payement/payementAuto.html.twig', [
  556.             'souscription' => $assurance,
  557.         ]);
  558.      
  559.     }
  560.     #[Route('/assurance/paiement/ipay/{id}'name'details_souscriptionAutoClientError')]
  561.     public function details_souscriptionAutoClientIpay(EntityManagerInterface $entityManager$idSessionInterface $sessionRequest $requestAssurance $assurance): Response
  562.     {
  563.         $this->addFlash('ErreurSous''Paiement non aboutie, Veuillez réessayer...');
  564.         $iduser null;
  565.         $idclient $assurance->getIdClient();
  566.         $action "Souscription Automobile";
  567.         $msg_send "paiement souscription";
  568.         $msg_get "";
  569.         $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  570.         $entityManager->persist($log);
  571.         $entityManager->flush();
  572.         $idAssurance $assurance->getId();
  573.         return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  574.         // return $this->render('souscription/payement/payementAuto.html.twig', [
  575.         //     'souscription' => $assurance,
  576.         // ]);
  577.      
  578.     }
  579.     #[Route('/assurance/paiement/voyage/ipay/{id}'name'details_souscriptionVoyageClientError')]
  580.     public function details_souscriptionVoyageClientIpay(EntityManagerInterface $entityManager$idSessionInterface $sessionRequest $requestAssuranceVoyage $assurance): Response
  581.     {
  582.         $this->addFlash('ErreurSous''Paiement non aboutie, Veuillez réessayer...');
  583.         $iduser null;
  584.         $idclient $assurance->getIdClient();
  585.         $action "Souscription voyage";
  586.         $msg_send "paiement souscription";
  587.         $msg_get "";
  588.         $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  589.         $entityManager->persist($log);
  590.         $entityManager->flush();
  591.         $idAssurance $assurance->getId();
  592.         return $this->redirectToRoute('details_souscriptionVoyageClient',['id'=>$idAssurance]);
  593.      
  594.     }
  595.     #[Route('/assurance/paiement/habitation/ipay/{id}'name'details_souscriptionHabitationClientError')]
  596.     public function details_souscriptionHabitationClientIpay(EntityManagerInterface $entityManager$idSessionInterface $sessionRequest $requestAssuranceHabitation $assurance): Response
  597.     {
  598.         $this->addFlash('ErreurSous''Paiement non aboutie, Veuillez réessayer...');
  599.         $iduser null;
  600.         $idclient $assurance->getIdClient();
  601.         $action "Souscription Habitation";
  602.         $msg_send "paiement souscription";
  603.         $msg_get "";
  604.         $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  605.         $entityManager->persist($log);
  606.         $entityManager->flush();
  607.         $idAssurance $assurance->getId();
  608.         return $this->redirectToRoute('details_souscriptionHabitationClient',['id'=>$idAssurance]);
  609.      
  610.     }
  611.     #[Route('/details/souscription/auto/client/{id}'name'details_souscriptionAutoClient')]
  612.     public function details_souscriptionAutoClient(EntityManagerInterface $entityManager$idSessionInterface $sessionRequest $requestAssurance $assurance): Response
  613.     {
  614.     
  615.             $idAssurance $assurance->getId();
  616.     
  617.              if($assurance != null && $assurance->getPaiement()!=null && ($assurance->getPaiement()->getStatutPaiement()->getId() == or $assurance->getPaiement()->getStatutPaiement()->getId() == )) {
  618.                 
  619.                 $session->set('number'0);
  620.                 return $this->redirectToRoute('app_payement_souscriptionAuto',['id'=>$idAssurance]);
  621.                 // return $this->render('souscription/payement/confirmPayementAuto.html.twig', [
  622.                 //     'souscription' => $assurance,
  623.                 // ]);
  624.     
  625.                // return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  626.     
  627.              }else {
  628.     
  629.                if ($session->get('number') == 4  ) {
  630.                    $sess $session->get('number') - 1;
  631.                   $session->set('number'$sess);
  632.                   return $this->render('souscription/payement/confirmPayementAuto.html.twig', [
  633.                     'souscription' => $assurance,
  634.                 ]);
  635.                  // return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  636.     
  637.                }elseif ($session->get('number') !=) {
  638.                 if ($assurance->getPaiement()!=null) {
  639.     
  640.     
  641.                  $paiement $assurance->getPaiement();
  642.                  $idAssurance $assurance->getId();
  643.                  $external_id $paiement->getExternalId();
  644.                  $operateur $paiement->getMoyenPaiement()->getId();
  645.                  $typeOperation 1;
  646.      
  647.      
  648.                  $ch curl_init();
  649.      
  650.                  curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/confirm/merchant/payment");
  651.                  curl_setopt($chCURLOPT_POSTFIELDS'{
  652.                      "external_id" : ' . (int)$external_id ',
  653.                      "typeOperation" : ' . (int)$typeOperation ',
  654.                      "operateur" : ' . (int)$operateur ',
  655.                      "idAssurance" : ' . (int)$idAssurance '
  656.                  }');
  657.                  $headers = array(
  658.                      "Content-Type: application/json",
  659.                      "Accept: application/json",
  660.      
  661.                  );
  662.              
  663.      
  664.                  curl_setopt($chCURLOPT_HTTPHEADER$headers);
  665.                  //for debug only!
  666.                  curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  667.                  curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  668.                  curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  669.      
  670.                  $server_output curl_exec($ch);
  671.      
  672.                  curl_close($ch);
  673.                  $confirmPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  674.                  if ($confirmPaiement) {
  675.     
  676.                     $statut $confirmPaiement['status'];
  677.                     if($operateur == 2){
  678.                         if ($statut == 200) {
  679.     
  680.                             $session->set('number'0);
  681.          
  682.          
  683.                             $this->addFlash('success''Félicitations, votre souscription est réussie avec succès.');
  684.                             $iduser null;
  685.                             $idclient $assurance->getIdClient();
  686.                             $action "Souscription Automobile";
  687.                             $msg_send "paiement souscription";
  688.                             $msg_get "Félicitations, votre souscription est réussie avec succès";
  689.                             $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  690.                             $entityManager->persist($log);
  691.                 
  692.                             $entityManager->flush();
  693.                             return $this->redirectToRoute('app_home');
  694.                              //return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  695.          
  696.          
  697.                           } else {
  698.                             if($confirmPaiement['result']['status'] == "initiated") {
  699.                                  return new RedirectResponse($initiationPaiement['result']['page_url']);
  700.                             }else if($confirmPaiement['result']['status'] == "failed"){
  701.                               $session->set('number'0);
  702.                               $this->addFlash('ErreurSous'"Le paiement de votre souscription n'a pas aboutie, veuillez réessayer est réussie avec succès.");
  703.                                return $this->redirectToRoute('app_payement_souscriptionAuto',['id'=>$idAssurance]);
  704.      
  705.                                 
  706.                             }else if($confirmPaiement['result']['status'] == "cancelled"){
  707.                                 $session->set('number'0);
  708.    
  709.                                $this->addFlash('ErreurSous'"Le paiement de votre souscription n'a pas aboutie, veuillez réessayer est réussie avec succès.");
  710.                                return $this->redirectToRoute('app_payement_souscriptionAuto',['id'=>$idAssurance]);
  711.                                 
  712.                             }
  713.                              
  714.      
  715.          
  716.                           }
  717.                     }else{
  718.                         if ($statut == 200) {
  719.     
  720.                             $session->set('number'0);
  721.          
  722.          
  723.                             $this->addFlash('success''Félicitations, votre souscription est réussie avec succès.');
  724.                             $iduser null;
  725.                             $idclient $assurance->getIdClient();
  726.                             $action "Souscription Automobile";
  727.                             $msg_send "paiement souscription";
  728.                             $msg_get "Félicitations, votre souscription est réussie avec succès";
  729.                             $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  730.                             $entityManager->persist($log);
  731.                 
  732.                             $entityManager->flush();
  733.                             return $this->redirectToRoute('app_home');
  734.                              //return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  735.          
  736.          
  737.                           } else {
  738.          
  739.                               $sess $session->get('number') - 1;
  740.                               $session->set('number'$sess);
  741.      
  742.                            return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  743.      
  744.          
  745.                           }
  746.                     }
  747.     
  748.                  }else{
  749.     
  750.                    $sess $session->get('number') - 1;
  751.                    $session->set('number'$sess);
  752.     
  753.                   return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  754.     
  755.     
  756.                 //    return $this->render('souscription/payement/payementAuto.html.twig', [
  757.                 //     'souscription' => $assurance,
  758.                 // ]);
  759.                    ///return $this->redirectToRoute('detailscommande_clientpaye',['commande'=>$commandes->getCode()]);
  760.     
  761.                  }
  762.     
  763.                 }else{
  764.     
  765.                    // $sess = $session->get('number') - 1;
  766.                    $session->set('number'0);
  767.                   return $this->redirectToRoute('app_payement_souscriptionAuto',['id'=>$idAssurance]);
  768.                   // return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  769.      
  770.                    
  771.                 }
  772.                } else {
  773.                  # code...
  774.                  // $sess = $session->get('number') - 1;
  775.                  $session->set('number'0);
  776.     
  777.                  $this->addFlash('ErreurSous''Veuillez réessayer...');
  778.                  $iduser null;
  779.                  $idclient $assurance->getIdClient();
  780.                  $action "Souscription Automobile";
  781.                  $msg_send "paiement souscription";
  782.                  $msg_get "";
  783.                  $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  784.                  $entityManager->persist($log);
  785.      
  786.                  $entityManager->flush();
  787.                 return $this->redirectToRoute('app_payement_souscriptionAuto',['id'=>$idAssurance]);
  788.                 //  return $this->render('souscription/payement/confirmPayementAuto.html.twig', [
  789.                 //     'souscription' => $assurance,
  790.                 // ]);
  791.                 //return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  792.     
  793.                }
  794.     
  795.                
  796.              }
  797.     
  798.      
  799.     }
  800.     #[Route('/details/souscription/voyage/client/{id}'name'details_souscriptionVoyageClient')]
  801.     public function details_souscriptionVoyageClient(EntityManagerInterface $entityManager$idSessionInterface $sessionRequest $requestAssuranceVoyage $assurance): Response
  802.     {
  803.              $idAssurance $assurance->getId();
  804.             
  805.              if($assurance != null && $assurance->getIdPaiement()!=null && ($assurance->getIdPaiement()->getStatutPaiement()->getId() == or $assurance->getIdPaiement()->getStatutPaiement()->getId() == )) {
  806.                 
  807.                 $session->set('number'0);
  808.                 return $this->redirectToRoute('app_payement_souscriptionVoyage',['id'=>$idAssurance]);
  809.              }else {
  810.              //   $idAssurance = $assurance->getId();
  811.                // dd($session->get('number'));
  812.     
  813.                if ($session->get('number') == 4  ) {
  814.                    $sess $session->get('number') - 1;
  815.                   $session->set('number'$sess);
  816.                   return $this->render('souscription/payement/confirmPayementVoyage.html.twig', [
  817.                     'assuranceVoyage' => $assurance,
  818.                 ]);
  819.                  // return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  820.     
  821.                }elseif ($session->get('number') !=) {
  822.                 if ($assurance->getIdPaiement()!=null) {
  823.     
  824.     
  825.                  $paiement $assurance->getIdPaiement();
  826.                  $idAssurance $assurance->getId();
  827.                  $external_id $paiement->getExternalId();
  828.                  $operateur $paiement->getMoyenPaiement()->getId();
  829.                  $typeOperation 2;
  830.      
  831.      
  832.                  $ch curl_init();
  833.      
  834.                  curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/confirm/merchant/payment");
  835.                  curl_setopt($chCURLOPT_POSTFIELDS'{
  836.                      "external_id" : ' . (int)$external_id ',
  837.                      "typeOperation" : ' . (int)$typeOperation ',
  838.                      "operateur" : ' . (int)$operateur ',
  839.                      "idAssurance" : ' . (int)$idAssurance '
  840.                  }');
  841.                  $headers = array(
  842.                      "Content-Type: application/json",
  843.                      "Accept: application/json",
  844.      
  845.                  );
  846.              
  847.      
  848.                  curl_setopt($chCURLOPT_HTTPHEADER$headers);
  849.                  //for debug only!
  850.                  curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  851.                  curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  852.                  curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  853.      
  854.                  $server_output curl_exec($ch);
  855.      
  856.                  curl_close($ch);
  857.                  $confirmPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  858.                  if ($confirmPaiement) {
  859.     
  860.                     $statut $confirmPaiement['status'];
  861.                     if($operateur == 2){
  862.                         if ($statut == 200) {
  863.     
  864.                             $session->set('number'0);
  865.          
  866.          
  867.                             $this->addFlash('success''Félicitations, votre souscription est réussie avec succès.');
  868.                             $iduser null;
  869.                             $idclient $assurance->getIdClient();
  870.                             $action "Souscription Voyage";
  871.                             $msg_send "paiement souscription";
  872.                             $msg_get "Félicitations, votre souscription est réussie avec succès";
  873.                             $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  874.                             $entityManager->persist($log);
  875.                 
  876.                             $entityManager->flush();
  877.                             return $this->redirectToRoute('app_home');
  878.                              //return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  879.          
  880.          
  881.                           } else {
  882.                             if($confirmPaiement['result']['status'] == "initiated") {
  883.                                  return new RedirectResponse($initiationPaiement['result']['page_url']);
  884.                             }else if($confirmPaiement['result']['status'] == "failed"){
  885.                               $session->set('number'0);
  886.                               $this->addFlash('ErreurSous'"Le paiement de votre souscription n'a pas aboutie, veuillez réessayer est réussie avec succès.");
  887.                                return $this->redirectToRoute('app_payement_souscriptionVoyage',['id'=>$idAssurance]);
  888.      
  889.                                 
  890.                             }else if($confirmPaiement['result']['status'] == "cancelled"){
  891.                                 $session->set('number'0);
  892.    
  893.                                $this->addFlash('ErreurSous'"Le paiement de votre souscription n'a pas aboutie, veuillez réessayer est réussie avec succès.");
  894.                                return $this->redirectToRoute('app_payement_souscriptionVoyage',['id'=>$idAssurance]);
  895.                                 
  896.                             }
  897.                              
  898.                           }
  899.                     }else{
  900.                         if ($statut == 200) {
  901.     
  902.                             $session->set('number'0);
  903.          
  904.          
  905.                             $this->addFlash('success''Félicitations, votre souscription est réussie avec succès.');
  906.                             $iduser null;
  907.                             $idclient $assurance->getIdClient();
  908.                             $action "Souscription Voyage";
  909.                             $msg_send "paiement souscription";
  910.                             $msg_get "Félicitations, votre souscription est réussie avec succès";
  911.                             $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  912.                             $entityManager->persist($log);
  913.                 
  914.                             $entityManager->flush();
  915.                             return $this->redirectToRoute('app_home');
  916.                              //return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  917.          
  918.          
  919.                           } else {
  920.          
  921.                               $sess $session->get('number') - 1;
  922.                               $session->set('number'$sess);
  923.      
  924.                            return $this->redirectToRoute('details_souscriptionVoyageClient',['id'=>$idAssurance]);
  925.      
  926.          
  927.                           }
  928.                     }
  929.     
  930.                  }else{
  931.     
  932.                    $sess $session->get('number') - 1;
  933.                    $session->set('number'$sess);
  934.     
  935.                   return $this->redirectToRoute('details_souscriptionVoyageClient',['id'=>$idAssurance]);
  936.     
  937.     
  938.                 //    return $this->render('souscription/payement/payementAuto.html.twig', [
  939.                 //     'souscription' => $assurance,
  940.                 // ]);
  941.                    ///return $this->redirectToRoute('detailscommande_clientpaye',['commande'=>$commandes->getCode()]);
  942.     
  943.                  }
  944.     
  945.                 }else{
  946.     
  947.                    // $sess = $session->get('number') - 1;
  948.                    $session->set('number'0);
  949.                   return $this->redirectToRoute('app_payement_souscriptionVoyage',['id'=>$idAssurance]);
  950.                   // return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  951.      
  952.                    
  953.                 }
  954.                } else {
  955.                  # code...
  956.                  // $sess = $session->get('number') - 1;
  957.                  $session->set('number'0);
  958.     
  959.                  $this->addFlash('ErreurSous''Veuillez réessayer...');
  960.                  $iduser null;
  961.                  $idclient $assurance->getIdClient();
  962.                  $action "Souscription voyage";
  963.                  $msg_send "paiement souscription";
  964.                  $msg_get "";
  965.                  $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  966.                  $entityManager->persist($log);
  967.      
  968.                  $entityManager->flush();
  969.                 return $this->redirectToRoute('app_payement_souscriptionVoyage',['id'=>$idAssurance]);
  970.                 //  return $this->render('souscription/payement/confirmPayementAuto.html.twig', [
  971.                 //     'souscription' => $assurance,
  972.                 // ]);
  973.                 //return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  974.     
  975.                }
  976.     
  977.                
  978.              }
  979.     
  980.      
  981.     }
  982.     #[Route('/details/souscription/habitation/client/{id}'name'details_souscriptionHabitationClient')]
  983.     public function details_souscriptionHabitationClient(EntityManagerInterface $entityManager$idSessionInterface $sessionRequest $requestAssuranceHabitation $assurance): Response
  984.     {
  985.              $idAssurance $assurance->getId();
  986.             
  987.              if($assurance != null && $assurance->getIdPaiement()!=null && ($assurance->getIdPaiement()->getStatutPaiement()->getId() == or $assurance->getIdPaiement()->getStatutPaiement()->getId() == )) {
  988.                 
  989.                 $session->set('number'0);
  990.                 return $this->redirectToRoute('app_payement_souscriptionHabitation',['id'=>$idAssurance]);
  991.              }else {
  992.              //   $idAssurance = $assurance->getId();
  993.                // dd($session->get('number'));
  994.     
  995.                if ($session->get('number') == 4  ) {
  996.                    $sess $session->get('number') - 1;
  997.                   $session->set('number'$sess);
  998.                   return $this->render('souscription/payement/confirmPayementHabitation.html.twig', [
  999.                     'assuranceHabitation' => $assurance,
  1000.                 ]);
  1001.                  // return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  1002.     
  1003.                }elseif ($session->get('number') !=) {
  1004.                 if ($assurance->getIdPaiement()!=null) {
  1005.     
  1006.     
  1007.                  $paiement $assurance->getIdPaiement();
  1008.                  $idAssurance $assurance->getId();
  1009.                  $external_id $paiement->getExternalId();
  1010.                  $operateur $paiement->getMoyenPaiement()->getId();
  1011.                  $typeOperation 3;
  1012.      
  1013.      
  1014.                  $ch curl_init();
  1015.      
  1016.                  curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/confirm/merchant/payment");
  1017.                  curl_setopt($chCURLOPT_POSTFIELDS'{
  1018.                      "external_id" : ' . (int)$external_id ',
  1019.                      "typeOperation" : ' . (int)$typeOperation ',
  1020.                      "operateur" : ' . (int)$operateur ',
  1021.                      "idAssurance" : ' . (int)$idAssurance '
  1022.                  }');
  1023.                  $headers = array(
  1024.                      "Content-Type: application/json",
  1025.                      "Accept: application/json",
  1026.      
  1027.                  );
  1028.              
  1029.      
  1030.                  curl_setopt($chCURLOPT_HTTPHEADER$headers);
  1031.                  //for debug only!
  1032.                  curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  1033.                  curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  1034.                  curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1035.      
  1036.                  $server_output curl_exec($ch);
  1037.      
  1038.                  curl_close($ch);
  1039.                  $confirmPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  1040.                  if ($confirmPaiement) {
  1041.     
  1042.                     $statut $confirmPaiement['status'];
  1043.                     if($operateur == 2){
  1044.                         if ($statut == 200) {
  1045.     
  1046.                             $session->set('number'0);
  1047.          
  1048.          
  1049.                             $this->addFlash('success''Félicitations, votre souscription est réussie avec succès.');
  1050.                             $iduser null;
  1051.                             $idclient $assurance->getIdClient();
  1052.                             $action "Souscription Voyage";
  1053.                             $msg_send "paiement souscription";
  1054.                             $msg_get "Félicitations, votre souscription est réussie avec succès";
  1055.                             $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  1056.                             $entityManager->persist($log);
  1057.                 
  1058.                             $entityManager->flush();
  1059.                             return $this->redirectToRoute('app_home');
  1060.                              //return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  1061.          
  1062.          
  1063.                           } else {
  1064.                             if($confirmPaiement['result']['status'] == "initiated") {
  1065.                                  return new RedirectResponse($initiationPaiement['result']['page_url']);
  1066.                             }else if($confirmPaiement['result']['status'] == "failed"){
  1067.                               $session->set('number'0);
  1068.                               $this->addFlash('ErreurSous'"Le paiement de votre souscription n'a pas aboutie, veuillez réessayer est réussie avec succès.");
  1069.                                return $this->redirectToRoute('app_payement_souscriptionHabitation',['id'=>$idAssurance]);
  1070.      
  1071.                                 
  1072.                             }else if($confirmPaiement['result']['status'] == "cancelled"){
  1073.                                 $session->set('number'0);
  1074.    
  1075.                                $this->addFlash('ErreurSous'"Le paiement de votre souscription n'a pas aboutie, veuillez réessayer est réussie avec succès.");
  1076.                                return $this->redirectToRoute('app_payement_souscriptionHabitation',['id'=>$idAssurance]);
  1077.                                 
  1078.                             }
  1079.                              
  1080.                           }
  1081.                     }else{
  1082.                         if ($statut == 200) {
  1083.     
  1084.                             $session->set('number'0);
  1085.          
  1086.          
  1087.                             $this->addFlash('success''Félicitations, votre souscription est réussie avec succès.');
  1088.                             $iduser null;
  1089.                             $idclient $assurance->getIdClient();
  1090.                             $action "Souscription Habitation";
  1091.                             $msg_send "paiement souscription";
  1092.                             $msg_get "Félicitations, votre souscription est réussie avec succès";
  1093.                             $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  1094.                             $entityManager->persist($log);
  1095.                 
  1096.                             $entityManager->flush();
  1097.                             return $this->redirectToRoute('app_home');
  1098.                              //return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  1099.          
  1100.          
  1101.                           } else {
  1102.          
  1103.                               $sess $session->get('number') - 1;
  1104.                               $session->set('number'$sess);
  1105.      
  1106.                            return $this->redirectToRoute('details_souscriptionHabitationClient',['id'=>$idAssurance]);
  1107.      
  1108.          
  1109.                           }
  1110.                     }
  1111.     
  1112.                  }else{
  1113.     
  1114.                    $sess $session->get('number') - 1;
  1115.                    $session->set('number'$sess);
  1116.     
  1117.                   return $this->redirectToRoute('details_souscriptionHabitationClient',['id'=>$idAssurance]);
  1118.     
  1119.     
  1120.                 //    return $this->render('souscription/payement/payementAuto.html.twig', [
  1121.                 //     'souscription' => $assurance,
  1122.                 // ]);
  1123.                    ///return $this->redirectToRoute('detailscommande_clientpaye',['commande'=>$commandes->getCode()]);
  1124.     
  1125.                  }
  1126.     
  1127.                 }else{
  1128.     
  1129.                    // $sess = $session->get('number') - 1;
  1130.                    $session->set('number'0);
  1131.                   return $this->redirectToRoute('app_payement_souscriptionHabitation',['id'=>$idAssurance]);
  1132.                   // return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  1133.      
  1134.                    
  1135.                 }
  1136.                } else {
  1137.                  # code...
  1138.                  // $sess = $session->get('number') - 1;
  1139.                  $session->set('number'0);
  1140.     
  1141.                  $this->addFlash('ErreurSous''Veuillez réessayer...');
  1142.                  $iduser null;
  1143.                  $idclient $assurance->getIdClient();
  1144.                  $action "Souscription voyage";
  1145.                  $msg_send "paiement souscription";
  1146.                  $msg_get "";
  1147.                  $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  1148.                  $entityManager->persist($log);
  1149.      
  1150.                  $entityManager->flush();
  1151.                 return $this->redirectToRoute('app_payement_souscriptionHabitation',['id'=>$idAssurance]);
  1152.                 //  return $this->render('souscription/payement/confirmPayementAuto.html.twig', [
  1153.                 //     'souscription' => $assurance,
  1154.                 // ]);
  1155.                 //return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  1156.     
  1157.                }
  1158.     
  1159.                
  1160.              }
  1161.     
  1162.      
  1163.     }
  1164.     #[Route('/details/souscriptionAuto/{id}'name'details_souscriptionAuto')]
  1165.     public function details_souscriptionAuto(EntityManagerInterface $entityManager$idSessionInterface $sessionRequest $requestAssurance $assurance): Response
  1166.     {
  1167.         if ($session->get('number') == 0) {
  1168.             //$session->clear();
  1169.             $this->addFlash('ErreurSous''Le paiement de votre souscription n a pas aboutie. veuillez réessayer...');
  1170.             $iduser null;
  1171.             $idclient $assurance->getIdClient();
  1172.             $action "Souscription Automobile";
  1173.             $msg_send "paiement souscription";
  1174.             $msg_get "Erreur, le paiement de votre souscription n a pas aboutie.";
  1175.             $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  1176.             $entityManager->persist($log);
  1177.             $entityManager->flush();
  1178.             return $this->redirectToRoute('app_souscription_auto');
  1179.         } else {
  1180.             $paiement $assurance->getPaiement();
  1181.             $idAssurance $assurance->getId();
  1182.             $external_id $paiement->getExternalId();
  1183.             $operateur $paiement->getMoyenPaiement()->getId();
  1184.             $typeOperation 1;
  1185.             // dd($idAssurance);
  1186.             $ch curl_init();
  1187.             curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/confirm/merchant/payment");
  1188.             curl_setopt($chCURLOPT_POSTFIELDS'{
  1189.                 "external_id" : ' . (int)$external_id ',
  1190.                 "typeOperation" : ' . (int)$typeOperation ',
  1191.                 "operateur" : ' . (int)$operateur ',
  1192.                 "idAssurance" : ' . (int)$idAssurance '
  1193.             }');
  1194.             $headers = array(
  1195.                 "Content-Type: application/json",
  1196.                 "Accept: application/json",
  1197.             );
  1198.         
  1199.             curl_setopt($chCURLOPT_HTTPHEADER$headers);
  1200.             //for debug only!
  1201.             curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  1202.             curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  1203.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1204.             $server_output curl_exec($ch);
  1205.             curl_close($ch);
  1206.             $confirmPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  1207.             if ($confirmPaiement==null) {
  1208.                 # code...
  1209.                 $statut null;
  1210.               }else{
  1211.                 $statut $confirmPaiement['status'];
  1212.               }
  1213.             if ($statut == 200) {
  1214.                 $this->addFlash('success''Félicitations, votre souscription est réussie avec succès.');
  1215.                 $iduser null;
  1216.                 $idclient $assurance->getIdClient();
  1217.                 $action "Souscription Automobile";
  1218.                 $msg_send "paiement souscription";
  1219.                 $msg_get "Félicitations, votre souscription est réussie avec succès";
  1220.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  1221.                 $entityManager->persist($log);
  1222.     
  1223.                 $entityManager->flush();
  1224.                 return $this->redirectToRoute('app_home');
  1225.             } else {
  1226.                 if ($statut == null) { 
  1227.                          $this->addFlash('error''Erreur système veuillez réessayer plutard.');
  1228.                 $iduser null;
  1229.                 $idclient $assurance->getIdClient();
  1230.                 $action "Souscription Automobile";
  1231.                 $msg_send "paiement souscription";
  1232.                 $msg_get "Erreur système veuillez réessayer plutard.";
  1233.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  1234.                 $entityManager->persist($log);
  1235.     
  1236.                 $entityManager->flush();
  1237.                 return $this->redirectToRoute('app_home');
  1238.                 }else{
  1239.                     $sess $session->get('number') - 1;
  1240.                     $session->set('number'$sess);
  1241.     
  1242.                     return $this->render('souscription/details/detailsAssuranceAuto.html.twig', [
  1243.                         'paiement' => $paiement,
  1244.                         'assurance' => $assurance,
  1245.                     ]);
  1246.                 }
  1247.               
  1248.             }
  1249.         }
  1250.         return $this->render('souscription/details/detailsAssuranceAuto.html.twig', [
  1251.             'paiement' => $paiement,
  1252.             'assurance' => $assurance,
  1253.         ]);
  1254.     }
  1255.     #[Route('/souscription/assurances/voyage'name'app_souscription_Voyage')]
  1256.     public function indexVoyage(
  1257.         EntityManagerInterface $entityManager,
  1258.         SessionInterface $session,
  1259.         Request $request,
  1260.         FileUploader $uploader
  1261.     ): Response {
  1262.         // dd($session);
  1263.         $today date("Y-m-d");
  1264.         // $ch = curl_init();
  1265.         // curl_setopt($ch, CURLOPT_URL, "https://carenapi235679814.caren-niger.com/api/client/getListeZoneVoyage");
  1266.         // $headers = array(
  1267.         //     "Content-Type: application/json",
  1268.         //     "Accept: application/json",
  1269.         // );
  1270.         // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  1271.         // //for debug only!
  1272.         // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1273.         // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1274.         // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1275.         // $server_output = curl_exec($ch);
  1276.         // curl_close($ch);
  1277.          $zones $entityManager
  1278.             ->getRepository(ZoneVoyage::class)
  1279.             ->findBy(['statut' => '1']);
  1280.         // dd($zones);
  1281.         // $zoneVoyage = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $server_output), true);
  1282.         // dd($zoneVoyage);
  1283.         // if ($zoneVoyage && array_key_exists('status', $zoneVoyage)) {
  1284.         //     $this->addFlash('ErrorAPI', 'Erreur système veuillez réessayer plutard.');
  1285.         //     return $this->redirectToRoute('app_home');
  1286.         // } else {
  1287.         //     if ($zoneVoyage['statut'] != 200) {
  1288.         //         $this->addFlash('ErrorAPI', 'Erreur système veuillez réessayer plutard.');
  1289.         //         return $this->redirectToRoute('app_home');
  1290.         //     }
  1291.         // }
  1292.         // $zoneVoyageData = $zoneVoyage['zones'];
  1293.         $zoneVoyageData $zones;
  1294.         if ($request->request->count() > 0) {
  1295.             $nom trim($request->request->get("nom"));
  1296.             $session->set('nom'$nom);
  1297.             $prenom trim($request->request->get("prenom"));
  1298.             $session->set('prenom'$prenom);
  1299.             $telephone trim($request->request->get("phone"));
  1300.             $session->set('telephone'$telephone);
  1301.             $email trim($request->request->get("email"));
  1302.             $session->set('email'$email);
  1303.             $numPasseport trim($request->request->get("reference"));
  1304.             $session->set('numPasseport'$numPasseport);
  1305.             $dateExp trim($request->request->get("expiration"));
  1306.             $session->set('dateExp'$dateExp);
  1307.             // $photoPass = $request->files->get("photoPass");
  1308.             // $photoPass = trim($request->request->get("file"));
  1309.             $photoPass trim($request->files->get("photopass"));
  1310.             $session->set('photoPass'$photoPass);
  1311.             $zone trim($request->request->get("zone"));
  1312.             $session->set('zone'$zone);
  1313.             $DateDep trim($request->request->get("dateDepart"));
  1314.             $session->set('DateDep'$DateDep);
  1315.             $nbrJour trim($request->request->get("nbrJour"));
  1316.             $session->set('nbrJour'$nbrJour);
  1317.             $ville trim($request->request->get("destination"));
  1318.             $session->set('ville'$ville);
  1319.             $motif trim($request->request->get("motifVoya"));
  1320.             $session->set('motif'$motif);
  1321.             $compagnie trim($request->request->get("compagnieTrans"));
  1322.             $session->set('compagnie'$compagnie);
  1323.             $address trim($request->request->get("addressSejour"));
  1324.             $session->set('address'$address);
  1325.             $photoPass $request->files->get("file");
  1326.             // dd($dateExp,$DateDep,$nbrJour);
  1327.             if ($dateExp <= $DateDep) {
  1328.                 $this->addFlash('validiter''Passeport Invalide", "La validité de votre passeport ne couvre pas votre voyage.');
  1329.                 return $this->redirectToRoute('app_souscription_Voyage');
  1330.             } else {
  1331.                 $dateVali date('Y-m-d'strtotime($DateDep ' + 90 DAY'));
  1332.                 if ($dateVali >= $dateExp) {
  1333.                     $this->addFlash('validiter''Passeport Invalide", "La validité de votre passeport ne couvre pas votre voyage.');
  1334.                     return $this->redirectToRoute('app_souscription_Voyage');
  1335.                 } else {
  1336.                     // $ch = curl_init();
  1337.                     // curl_setopt($ch, CURLOPT_URL, "https://carenapi235679814.caren-niger.com/api/getTarifVoyage");
  1338.                     // curl_setopt($ch, CURLOPT_POSTFIELDS, '{
  1339.                     //     "idZone" : ' . (int)$zone . ',
  1340.                     //     "duree" : ' . (int)$nbrJour . '
  1341.                     // }');
  1342.                     // $headers = array(
  1343.                     //     "Content-Type: application/json",
  1344.                     //     "Accept: application/json",
  1345.                     // );
  1346.                     // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  1347.                     // //for debug only!
  1348.                     // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1349.                     // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1350.                     // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1351.                     // $server_output = curl_exec($ch);
  1352.                     // curl_close($ch);
  1353.                     // $tarif = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $server_output), true);
  1354.                     // 
  1355.            $dureeVoyage $entityManager->getRepository(DureeVoyage::class)->findBy(
  1356.                 ['statut' => 1]
  1357.             );
  1358.            $duree = (int)$nbrJour;
  1359.            $idZone =  (int)$zone;
  1360.             foreach ($dureeVoyage as $value) {
  1361.                 if (($duree >= $value->getDebut()) && ($duree <= $value->getFin())) {
  1362.                     $idDuree[] = $value;
  1363.                 }
  1364.             }
  1365.             $tarif $entityManager->getRepository(TarifVoyage::class)->findOneBy(
  1366.                 [
  1367.                     'typeTarif' => $idZone,
  1368.                     'dureeVoyage' => $idDuree[0]->getId()
  1369.                 ]
  1370.             );
  1371.             // if ($tarif) {
  1372.             //     return $this->json([
  1373.             //         'statut' => 200,
  1374.             //         'montant' => $tarif->getMontant(),
  1375.             //         'idTarif' => $tarif->getId(),
  1376.             //     ], 200);
  1377.             // } else {
  1378.             //     return $this->json([
  1379.             //         'statut' => 201,
  1380.             //         'message' => "Aucune tarification trouvée...",
  1381.             //     ], 200);
  1382.             // }
  1383.                     // dd($tarif);
  1384.                     // if ($tarif && array_key_exists('status', $tarif)) {
  1385.                     //     $this->addFlash('ErrorAPI', 'Erreur système veuillez réessayer plutard.');
  1386.                     //     return $this->redirectToRoute('app_home');
  1387.                     // } else {
  1388.                     //     if ($tarif['statut'] != 200) {
  1389.                     //         $this->addFlash('ErrorAPI', $tarif['message']);
  1390.                     //         return $this->redirectToRoute('app_souscription_Voyage');
  1391.                     //     }
  1392.                     // }
  1393.                     // $tarifStatut = $tarif['statut'];
  1394.                     if ($tarif) {
  1395.                         $montant $tarif->getMontant();
  1396.                         $ch curl_init();
  1397.                         curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/clientCaren");
  1398.                         curl_setopt($chCURLOPT_POST1);
  1399.                         curl_setopt($chCURLOPT_POSTFIELDS'{
  1400.                         "nom" : "' $nom '",
  1401.                         "prenom" : "' $prenom '",
  1402.                         "telephone" : "' $telephone '"
  1403.                         }');
  1404.                         $headers = array(
  1405.                             "Content-Type: application/json",
  1406.                             "Accept: application/json",
  1407.                         );
  1408.                         curl_setopt($chCURLOPT_HTTPHEADER$headers);
  1409.                         //for debug only!
  1410.                         curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  1411.                         curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  1412.                         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1413.                         $server_output curl_exec($ch);
  1414.                         curl_close($ch);
  1415.                         $clientCaren json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  1416.                         // if ($clientCaren && array_key_exists('status', $clientCaren)) {
  1417.                         //     $this->addFlash('ErrorAPI', 'Erreur système veuillez réessayer plutard.');
  1418.                         //     $iduser = null;
  1419.                         //     $idclient = null;
  1420.                         //     $action = "Souscription Voyage";
  1421.                         //     $msg_send = "Demande souscription";
  1422.                         //     $msg_get = "Erreur système veuillez réessayer plutard.";
  1423.                         //     $log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);
  1424.                         //     $entityManager->persist($log);
  1425.                 
  1426.                         //     $entityManager->flush();
  1427.                         //     return $this->redirectToRoute('app_home');
  1428.                         // } else {
  1429.                         //        // dd($clientCaren);
  1430.                         //     // if ($clientCaren['statut'] != 200) {
  1431.                         //     //     $this->addFlash('ErrorAPI', 'Erreur système veuillez réessayer plutard.');
  1432.                         //     //     return $this->redirectToRoute('app_home');
  1433.                         //     // }
  1434.                         // }
  1435.                         // $clientStatut = $clientCaren['statut'];
  1436.                         // $client = $clientCaren['client'];
  1437.                         // $typeClient = $client['idTypeClient'];
  1438.                         $infoTarif $tarif;
  1439.                         // if ($client && $typeClient['id'] == 1) {
  1440.                         //     $messageErr = $clientCaren['message'];
  1441.                         //     return $this->render('authentication/login.html.twig', [
  1442.                         //         'messageErr' => $messageErr,
  1443.                         //     ]);
  1444.                         // } else {
  1445.                          // dd($client);
  1446.                         $client $entityManager->getRepository(Client::class)->findOneBy(['telephone' => $telephone'idTypeClient' => 2]);
  1447.                         if ($client) {
  1448.                             // $client = $entityManager->getRepository(Client::class)->findOneBy(['statut' => 1, 'telephone' => $telephone, 'id_type_client' => 2]);
  1449.                             $infoVille $entityManager->getRepository(Ville::class)->findOneBy(['statut' => 1'id' => (int)$ville]);
  1450.                             $dateRet date('Y-m-d'strtotime($DateDep '' . (int)$nbrJour ' day'));
  1451.                             $dateR date('Y-m-d'strtotime($dateRet ' - 1 DAY'));
  1452.                             $dateDepart = (\DateTime::createFromFormat('Y-m-d H:i:s'$DateDep '00:00:00'));
  1453.                             $dateRetour = (\DateTime::createFromFormat('Y-m-d H:i:s'$dateR '00:00:00'));
  1454.                             // dd($dateDepart, $dateRetour);
  1455.                             $assuranceVoyage = new AssuranceVoyage;
  1456.                             $assuranceVoyage->setIdClient($client)
  1457.                                 ->setNomBeneficiaire($nom)
  1458.                                 ->setPrenomBeneficiaire($prenom)
  1459.                                 ->setTelephoneBeneficiaire($telephone)
  1460.                                 ->setCanal("WEB")
  1461.                                 ->setIdVille($infoVille)
  1462.                                 ->setIdTarif($infoTarif)
  1463.                                 ->setNumeroPassport($numPasseport)
  1464.                                 ->setDateExpPassport(\DateTime::createFromFormat('Y-m-d H:i:s'$dateExp '00:00:00'))
  1465.                                 ->setDateDepart($dateDepart)
  1466.                                 ->setNombreJour($nbrJour)
  1467.                                 ->setMotifVoyage($motif)
  1468.                                 ->setCompagnie($compagnie)
  1469.                                 ->setAdresseSejour($address)
  1470.                                 ->setDateRetour($dateRetour)
  1471.                                 ->setMontant($montant)
  1472.                                 ->setCreatedAt(new DateTimeImmutable())
  1473.                                 ->setStatut(0);
  1474.                        $mat "Document";
  1475.                             $array = array("png""PNG","jpg","JPG","jpeg","JPEG");
  1476.       
  1477.                             $filename2 $photoPass->getClientOriginalName();
  1478.                             $filename2 explode('.' $filename2);
  1479.                             $filename2 $mat.'photoPass_'.$assuranceVoyage->getId().'.'.$filename2[1];
  1480.                             $extension=substr(strrchr($filename2,'.'),1);
  1481.                             if ($photoPass->getSize() > (1024 1024)) {
  1482.                                 $this->addFlash('ErreurSous'"Le fichier ne doit pas dépasser 5 Mo");
  1483.                                 return $this->redirectToRoute('app_souscription_Voyage', [], Response::HTTP_SEE_OTHER);
  1484.                             }
  1485.                             if (in_array($extension$arraytrue))
  1486.                             {
  1487.                                 // $uploader->upload($upload7, $document, $filename);
  1488.                                 //$uploader->upload("../public/images/assurances", $assurance, $filename);
  1489.                                 //$uploader->upload("../public/images/permis", $permis, $filename1);
  1490.                                 $uploaderImag=$uploader->upload("../public/images/carteGrises"$photoPass$filename2);
  1491.                                 if ($uploaderImag==400) {
  1492.                                     # code...
  1493.                                     $this->addFlash('ErreurSous'"Veuillez recharger une image qui ne doit pas dépasser 5 Mo et en jpg ou png");
  1494.                                     return $this->redirectToRoute('app_souscription_Voyage', [], Response::HTTP_SEE_OTHER);
  1495.                                 }
  1496.                                 // $protocol = 'http';  
  1497.                                 $protocol 'https'
  1498.                                 $HTTP_HOST $_SERVER['HTTP_HOST'];
  1499.                                    
  1500.                                 $lienDocument2 $protocol'://'.$HTTP_HOST.'/'.'images/carteGrises/'.$filename2;
  1501.                                 }else{ 
  1502.                             
  1503.                                 $this->addFlash('ErreurSous'"Ce format de fichier pour l'image n'est pas accepté par le système!!");
  1504.                                 return $this->redirectToRoute('app_souscription_Voyage', [], Response::HTTP_SEE_OTHER);
  1505.                         
  1506.                             }
  1507.                             $assuranceVoyage->setPhotoPassport($lienDocument2);
  1508.                             
  1509.                             $paiement =  new Paiement();
  1510.                             $statutPaiement $entityManager->getRepository(StatutPaiement::class)->find(1);
  1511.                             $paiement->setMontant($assuranceVoyage->getMontant())
  1512.                                 ->setStatut(0)
  1513.                                 ->setStatutPaiement($statutPaiement)
  1514.                                 ->setCreatedAt(new \DateTimeImmutable('now'));
  1515.                             $entityManager->persist($paiement);
  1516.                             // dd($assuranceVoyage);
  1517.                             $assuranceVoyage->setIdPaiement($paiement);
  1518.                             $entityManager->persist($assuranceVoyage);
  1519.                             $entityManager->flush();
  1520.                             $this->addFlash('initiation''');
  1521.                             $iduser null;
  1522.                             $idclient $client;
  1523.                             $action "Souscription Voyage";
  1524.                             $msg_send "Demande souscription";
  1525.                             $msg_get "Demande souscription éffectuée avec succés.";
  1526.                             $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  1527.                             $entityManager->persist($log);
  1528.                 
  1529.                             $entityManager->flush();
  1530.                             $session->clear();
  1531.                             return $this->render('souscription/payement/payementVoyage.html.twig', [
  1532.                                 'assuranceVoyage' => $assuranceVoyage,
  1533.                                 'dateExp' => $dateExp,
  1534.                                 'dateDep' => $DateDep,
  1535.                                 'dateRet' => $dateR,
  1536.                             ]);
  1537.                         }
  1538.                         // }
  1539.                     } else {
  1540.                         $this->addFlash('noTarif''Aucune tarification trouvée, veuillez rééssayer.');
  1541.                 $iduser null;
  1542.                 $idclient null;
  1543.                 $action "Souscription Voyage";
  1544.                 $msg_send "Demande souscription";
  1545.                 $msg_get "Aucune tarification trouvée, veuillez rééssayer.";
  1546.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  1547.                 $entityManager->persist($log);
  1548.     
  1549.                 $entityManager->flush();
  1550.                         return $this->redirectToRoute('app_souscription_Voyage');
  1551.                     }
  1552.                 }
  1553.             }
  1554.         }
  1555.         return $this->render('souscription/indexVoyage.html.twig', [
  1556.             'zoneVoyage' => $zoneVoyageData,
  1557.             'messageError' => '',
  1558.             'today' => $today,
  1559.         ]);
  1560.     }
  1561.     #[Route('/liste_ville/filtre'name'liste_type'methods: ['POST'])]
  1562.     public function fitreVille(Request $requestVilleRepository $villeRepository)
  1563.     {
  1564.         if ($request->isXmlHttpRequest()) {
  1565.             $ville $request->request->get('zone');
  1566.             $retour "";
  1567.             $ch curl_init();
  1568.             curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/client/getListeVille");
  1569.             curl_setopt($chCURLOPT_POSTFIELDS'{
  1570.             "idZone": ' . (int)$ville '
  1571.         }');
  1572.             $headers = array(
  1573.                 "Content-Type: application/json",
  1574.                 "Accept: application/json",
  1575.             );
  1576.             curl_setopt($chCURLOPT_HTTPHEADER$headers);
  1577.             //for debug only!
  1578.             curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  1579.             curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  1580.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1581.             $server_output curl_exec($ch);
  1582.             curl_close($ch);
  1583.             $villes json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  1584.             if ($villes && array_key_exists('status'$villes)) {
  1585.                 $this->addFlash('ErrorAPI''Erreur système veuillez réessayer plutard.');
  1586.                 return $this->redirectToRoute('app_home');
  1587.             } else {
  1588.                 if ($villes['statut'] != 200) {
  1589.                     $this->addFlash('ErrorAPI''Erreur système veuillez réessayer plutard.');
  1590.                     return $this->redirectToRoute('app_home');
  1591.                 }
  1592.             }
  1593.             $listeVille $villes['villes'];
  1594.             
  1595.             foreach ($listeVille as $enreg) {
  1596.                 $id $enreg['id'];
  1597.                 $libelle $enreg['libelle'];
  1598.                 $retour .= "<option value='$id'>$libelle</option>";
  1599.             }
  1600.             $response = new Response(json_encode($retour));
  1601.             return $response;
  1602.         }
  1603.     }
  1604.     #[Route('/liste_tarif/filtre'name'liste_getTarif'methods: ['POST''GET'])]
  1605.     public function fitreTarifGet(Request $requestPuissanceRepository $puissanceRepository)
  1606.     {
  1607.         if ($request->isXmlHttpRequest()) {
  1608.             $zone 1;
  1609.             $classe 1;
  1610.             $puissance $request->request->get('puissance');
  1611.             $code $request->request->get('code');
  1612.             // $classe = $request->request->get('classe');
  1613.             // $zone = $request->request->get('zone');
  1614.             $duree $request->request->get('duree');
  1615.             $energie $request->request->get('energie');
  1616.             $usage $request->request->get('usage');
  1617.             if ($usage == 1) {
  1618.                 $code 101;
  1619.             } else if ($usage == 2) {
  1620.                 $code 105;
  1621.             }
  1622.             $retour "";
  1623.             $ch curl_init();
  1624.             curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/getTarif");
  1625.             curl_setopt($chCURLOPT_POSTFIELDS'{
  1626.                 "ENERGIE": ' . (int)$energie ',
  1627.                 "ZONE": ' $zone ',
  1628.                 "CLASSE": ' $classe ',
  1629.                 "DUREE": ' . (int)$duree ',
  1630.                 "PUISSANCE": ' $puissance ',
  1631.                 "CODE": ' $code '
  1632.         }');
  1633.             $headers = array(
  1634.                 "Content-Type: application/json",
  1635.                 "Accept: application/json",
  1636.             );
  1637.             curl_setopt($chCURLOPT_HTTPHEADER$headers);
  1638.             //for debug only!
  1639.             curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  1640.             curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  1641.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1642.             $server_output curl_exec($ch);
  1643.             curl_close($ch);
  1644.             $retour json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  1645.             $response = new Response(json_encode($retour));
  1646.             return $response;
  1647.         }
  1648.     }
  1649.     #[Route('/liste_puissance/filtre'name'liste_puissance_type'methods: ['POST'])]
  1650.     public function fitrePuissance(Request $requestPuissanceRepository $puissanceRepository)
  1651.     {
  1652.         if ($request->isXmlHttpRequest()) {
  1653.             $usage $request->request->get('usage');
  1654.             $retour "";
  1655.             $ch curl_init();
  1656.             curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/client/getListePuissance");
  1657.             curl_setopt($chCURLOPT_POSTFIELDS'{
  1658.             "usage": ' . (int)$usage '
  1659.         }');
  1660.             $headers = array(
  1661.                 "Content-Type: application/json",
  1662.                 "Accept: application/json",
  1663.             );
  1664.             curl_setopt($chCURLOPT_HTTPHEADER$headers);
  1665.             //for debug only!
  1666.             curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  1667.             curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  1668.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1669.             $server_output curl_exec($ch);
  1670.             curl_close($ch);
  1671.             $puissances json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  1672.             if ($puissances && array_key_exists('status'$puissances)) {
  1673.                 $this->addFlash('ErrorAPI''Erreur système veuillez réessayer plutard.');
  1674.                 return $this->redirectToRoute('app_home');
  1675.             } else {
  1676.                 if ($puissances['statut'] != 200) {
  1677.                     $this->addFlash('ErrorAPI''Erreur système veuillez réessayer plutard.');
  1678.                     return $this->redirectToRoute('app_home');
  1679.                 }
  1680.             }
  1681.             $listePuissance $puissances['puissances'];
  1682.             foreach ($listePuissance as $enreg) {
  1683.                 $id $enreg['id'];
  1684.                 $libelle $enreg['p2'] . ' CV ';
  1685.                 $retour .= "<option value='$id'>$libelle</option>";
  1686.             }
  1687.             $response = new Response(json_encode($retour));
  1688.             return $response;
  1689.         }
  1690.     }
  1691.     #[Route('/souscription/habitation/payement/{id}'name'app_payement_souscriptionHabitation'methods: ['POST''GET'])]
  1692.     public function payementhabitation(EntityManagerInterface $entityManagerSessionInterface $sessionRequest $requestAssuranceHabitation $assurance): Response
  1693.     {
  1694.        // if ($request->request->count() > 0 && $request->request->get("souscription") == "souscription") {
  1695.         if($request->request->count() >)
  1696.         {
  1697.             $payement $request->request->get("payement");
  1698.             $telephone2 $request->request->get("phone2");
  1699.             $paymentOptions $request->request->get('paymentOptions');
  1700.             $operateur $request->request->get('operateur');
  1701.             $phonePayment trim($request->request->get('phonePayment'));
  1702.             $ipay_number trim($request->request->get('ipay_number'));
  1703.             if($operateur == 2){
  1704.               //  $phonePayment = "40410000000";
  1705.                 $phonePayment str_replace(" """$ipay_number);
  1706.                 
  1707.              }else{
  1708.                  $phonePayment str_replace(" """$phonePayment);
  1709.              }
  1710.             $indicatif "227";
  1711.             $typeOperation 3;
  1712.             
  1713.             $idAssurance $assurance->getId();
  1714.             if($assurance->getIdPaiement()!=null && $assurance->getIdPaiement()->getMoyenPaiement()!=null && $assurance->getIdPaiement()->getExternalId()!=null ) {
  1715.                     $paiement $assurance->getIdPaiement();
  1716.                     $idAssurance $assurance->getId();
  1717.                     $external_id $paiement->getExternalId();
  1718.         
  1719.                     $typeOperation 3;
  1720.         
  1721.                     $ch curl_init();
  1722.         
  1723.                     curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/confirm/merchant/payment");
  1724.                     curl_setopt($chCURLOPT_POSTFIELDS'{
  1725.                         "external_id" : ' . (int)$external_id ',
  1726.                         "typeOperation" : ' . (int)$typeOperation ',
  1727.                         "operateur" : ' . (int)$operateur ',
  1728.                         "idAssurance" : ' . (int)$idAssurance '
  1729.                     }');
  1730.                     $headers = array(
  1731.                         "Content-Type: application/json",
  1732.                         "Accept: application/json",
  1733.         
  1734.                     );
  1735.                 
  1736.         
  1737.                     curl_setopt($chCURLOPT_HTTPHEADER$headers);
  1738.                     //for debug only!
  1739.                     curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  1740.                     curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  1741.                     curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1742.         
  1743.                     $server_output curl_exec($ch);
  1744.         
  1745.                     curl_close($ch);
  1746.         
  1747.                     $confirmPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  1748.                     if ($confirmPaiement==null) {
  1749.                       # code...
  1750.                       $statut null;
  1751.                     }else{
  1752.                       $statut $confirmPaiement['status'];
  1753.                     }
  1754.                   }else{
  1755.                       $statut=null;
  1756.                   }
  1757.         
  1758.                   if ($statut == 200) { 
  1759.                     $session->set('number'0);
  1760.         
  1761.                     $this->addFlash('success''Félicitations, votre souscription est réussie avec succès.');
  1762.                     $iduser null;
  1763.                     $idclient $assurance->getIdClient();
  1764.                     $action "Souscription Automobile";
  1765.                     $msg_send "paiement souscription";
  1766.                     $msg_get "Félicitations, votre souscription est réussie avec succès";
  1767.                     $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  1768.                     $entityManager->persist($log);
  1769.         
  1770.                     $entityManager->flush();
  1771.                     return $this->redirectToRoute('app_home');
  1772.                   } else {
  1773.         
  1774.                     $ch curl_init();
  1775.         
  1776.                     curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/get/merchant/payment");
  1777.                     curl_setopt($chCURLOPT_POSTFIELDS'{
  1778.                         "msisdn" : "' $phonePayment '",
  1779.                         "idAssurance" : ' . (int)$idAssurance ',
  1780.                         "indicatif" : ' $indicatif ',
  1781.                         "typeOperation" : ' . (int)$typeOperation ',
  1782.                         "operateur" : ' . (int)$operateur '
  1783.                     }');
  1784.                     $headers = array(
  1785.                         "Content-Type: application/json",
  1786.                         "Accept: application/json",
  1787.         
  1788.                     );
  1789.         
  1790.                     curl_setopt($chCURLOPT_HTTPHEADER$headers);
  1791.                     //for debug only!
  1792.                     curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  1793.                     curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  1794.                     curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1795.         
  1796.                     $server_output curl_exec($ch);
  1797.         
  1798.                     curl_close($ch);
  1799.         
  1800.                   $initiationPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  1801.         //    dd($initiationPaiement);
  1802.                    if($initiationPaiement !=null){
  1803.         
  1804.                     $statut $initiationPaiement['status'];
  1805.                                 if($operateur == 2){
  1806.                                     if ($statut == 200) {
  1807.                                     if ($initiationPaiement['result']['status'] == "initiated") {
  1808.                                         return new RedirectResponse($initiationPaiement['result']['page_url']);
  1809.                         
  1810.                                        // $session->set('number', 4);
  1811.                 
  1812.                                         //return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  1813.                 
  1814.                                     } else {
  1815.                                         $this->addFlash('ErreurSous'$initiationPaiement['message']);
  1816.                 
  1817.                                         $session->set('number'0);
  1818.                                     }
  1819.                                     }else{
  1820.                                         $this->addFlash('ErreurSous'$initiationPaiement['message']);
  1821.                 
  1822.                                         $session->set('number'0);
  1823.                                     }
  1824.                                     
  1825.                                 }else{
  1826.                                         if ($statut == 200) {
  1827.                         
  1828.                                             $session->set('number'4);
  1829.                     
  1830.                                             return $this->redirectToRoute('details_souscriptionHabitationClient',['id'=>$idAssurance]);
  1831.                     
  1832.                                         } else {
  1833.                                             $this->addFlash('ErreurSous'$initiationPaiement['message']);
  1834.                     
  1835.                                             $session->set('number'0);
  1836.                                         }
  1837.                                 }
  1838.         
  1839.                            
  1840.         
  1841.                         }else{
  1842.         
  1843.                             $this->addFlash('ErreurSous'"Veuillez réessayer...");
  1844.         
  1845.         
  1846.                             $session->set('number'0);
  1847.         
  1848.                         }
  1849.         
  1850.                         return $this->redirectToRoute('app_payement_souscriptionHabitation',['id'=>$idAssurance]);
  1851.         
  1852.                     }
  1853.        }
  1854.        
  1855.         return $this->render('souscription/payement/payementHabitation.html.twig', [
  1856.             'assuranceHabitation' => $assurance,
  1857.         ]);
  1858.      
  1859.     }
  1860.     #[Route('/souscription/voyage/payement/{id}'name'app_payement_souscriptionVoyage'methods: ['POST''GET'])]
  1861.     public function payementVoyage(EntityManagerInterface $entityManagerSessionInterface $sessionRequest $requestAssuranceVoyage $assurance): Response
  1862.     {
  1863.        // if ($request->request->count() > 0 && $request->request->get("souscription") == "souscription") {
  1864.         if($request->request->count() >)
  1865.         {
  1866.             $payement $request->request->get("payement");
  1867.             $telephone2 $request->request->get("phone2");
  1868.             $paymentOptions $request->request->get('paymentOptions');
  1869.             $operateur $request->request->get('operateur');
  1870.             $phonePayment trim($request->request->get('phonePayment'));
  1871.             $ipay_number trim($request->request->get('ipay_number'));
  1872.             if($operateur == 2){
  1873.               //  $phonePayment = "40410000000";
  1874.                 $phonePayment str_replace(" """$ipay_number);
  1875.                 
  1876.              }else{
  1877.                  $phonePayment str_replace(" """$phonePayment);
  1878.              }
  1879.             $indicatif "227";
  1880.             $typeOperation 2;
  1881.             
  1882.             $idAssurance $assurance->getId();
  1883.             if($assurance->getIdPaiement()!=null && $assurance->getIdPaiement()->getMoyenPaiement()!=null && $assurance->getIdPaiement()->getExternalId()!=null ) {
  1884.                     $paiement $assurance->getIdPaiement();
  1885.                     $idAssurance $assurance->getId();
  1886.                     $external_id $paiement->getExternalId();
  1887.         
  1888.                     $typeOperation 2;
  1889.         
  1890.                     $ch curl_init();
  1891.         
  1892.                     curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/confirm/merchant/payment");
  1893.                     curl_setopt($chCURLOPT_POSTFIELDS'{
  1894.                         "external_id" : ' . (int)$external_id ',
  1895.                         "typeOperation" : ' . (int)$typeOperation ',
  1896.                         "operateur" : ' . (int)$operateur ',
  1897.                         "idAssurance" : ' . (int)$idAssurance '
  1898.                     }');
  1899.                     $headers = array(
  1900.                         "Content-Type: application/json",
  1901.                         "Accept: application/json",
  1902.         
  1903.                     );
  1904.                 
  1905.         
  1906.                     curl_setopt($chCURLOPT_HTTPHEADER$headers);
  1907.                     //for debug only!
  1908.                     curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  1909.                     curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  1910.                     curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1911.         
  1912.                     $server_output curl_exec($ch);
  1913.         
  1914.                     curl_close($ch);
  1915.         
  1916.                     $confirmPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  1917.                     if ($confirmPaiement==null) {
  1918.                       # code...
  1919.                       $statut null;
  1920.                     }else{
  1921.                       $statut $confirmPaiement['status'];
  1922.                     }
  1923.                   }else{
  1924.                       $statut=null;
  1925.                   }
  1926.         
  1927.                   if ($statut == 200) { 
  1928.                     $session->set('number'0);
  1929.         
  1930.                     $this->addFlash('success''Félicitations, votre souscription est réussie avec succès.');
  1931.                     $iduser null;
  1932.                     $idclient $assurance->getIdClient();
  1933.                     $action "Souscription Automobile";
  1934.                     $msg_send "paiement souscription";
  1935.                     $msg_get "Félicitations, votre souscription est réussie avec succès";
  1936.                     $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  1937.                     $entityManager->persist($log);
  1938.         
  1939.                     $entityManager->flush();
  1940.                     return $this->redirectToRoute('app_home');
  1941.                   } else {
  1942.         
  1943.                     $ch curl_init();
  1944.         
  1945.                     curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/get/merchant/payment");
  1946.                     curl_setopt($chCURLOPT_POSTFIELDS'{
  1947.                         "msisdn" : "' $phonePayment '",
  1948.                         "idAssurance" : ' . (int)$idAssurance ',
  1949.                         "indicatif" : ' $indicatif ',
  1950.                         "typeOperation" : ' . (int)$typeOperation ',
  1951.                         "operateur" : ' . (int)$operateur '
  1952.                     }');
  1953.                     $headers = array(
  1954.                         "Content-Type: application/json",
  1955.                         "Accept: application/json",
  1956.         
  1957.                     );
  1958.         
  1959.                     curl_setopt($chCURLOPT_HTTPHEADER$headers);
  1960.                     //for debug only!
  1961.                     curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  1962.                     curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  1963.                     curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1964.         
  1965.                     $server_output curl_exec($ch);
  1966.         
  1967.                     curl_close($ch);
  1968.         
  1969.                   $initiationPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  1970.                    if($initiationPaiement !=null){
  1971.         
  1972.                     $statut $initiationPaiement['status'];
  1973.                                 if($operateur == 2){
  1974.                                     if ($initiationPaiement['result']['status'] == "initiated") {
  1975.                                         return new RedirectResponse($initiationPaiement['result']['page_url']);
  1976.                         
  1977.                                        // $session->set('number', 4);
  1978.                 
  1979.                                         //return $this->redirectToRoute('details_souscriptionAutoClient',['id'=>$idAssurance]);
  1980.                 
  1981.                                     } else {
  1982.                                         $this->addFlash('ErreurSous'$initiationPaiement['message']);
  1983.                 
  1984.                                         $session->set('number'0);
  1985.                                     }
  1986.                                     
  1987.                                 }else{
  1988.                                         if ($statut == 200) {
  1989.                         
  1990.                                             $session->set('number'4);
  1991.                     
  1992.                                             return $this->redirectToRoute('details_souscriptionVoyageClient',['id'=>$idAssurance]);
  1993.                     
  1994.                                         } else {
  1995.                                             $this->addFlash('ErreurSous'$initiationPaiement['message']);
  1996.                     
  1997.                                             $session->set('number'0);
  1998.                                         }
  1999.                                 }
  2000.         
  2001.                            
  2002.         
  2003.                         }else{
  2004.         
  2005.                             $this->addFlash('ErreurSous'"Veuillez réessayer...");
  2006.         
  2007.         
  2008.                             $session->set('number'0);
  2009.         
  2010.                         }
  2011.         
  2012.                         return $this->redirectToRoute('app_payement_souscriptionVoyage',['id'=>$idAssurance]);
  2013.         
  2014.                     }
  2015.        }
  2016.        
  2017.         return $this->render('souscription/payement/payementVoyage.html.twig', [
  2018.             'assuranceVoyage' => $assurance,
  2019.         ]);
  2020.      
  2021.     }
  2022.     #[Route('/souscriptionVoyage/old/VoyagePayement/{id}'name'app_payement_souscriptionVoyageOld'methods: ['POST''GET'])]
  2023.     public function payementVoyageOld(EntityManagerInterface $entityManagerSessionInterface $sessionRequest $requestAssuranceVoyage $assuranceVoyage): Response
  2024.     {
  2025.         if ($request->request->count() > && $request->request->get("souscriptionVoyage") == "souscriptionVoyage") {
  2026.             $payement $request->request->get("payement");
  2027.             $telephone2 $request->request->get("phone2");
  2028.             $idAssurance $assuranceVoyage->getId();
  2029.             // dd($assuranceVoyage, $payement, $telephone2);
  2030.             $ch curl_init();
  2031.             curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/getPaiement");
  2032.             curl_setopt($chCURLOPT_POSTFIELDS'{
  2033.                 "msisdn" : "' $telephone2 '",
  2034.                 "type_op" : 2,
  2035.                 "id_op" : ' . (int)$idAssurance ',
  2036.                 "operateur" : ' . (int)$payement '
  2037.             }');
  2038.             $headers = array(
  2039.                 "Content-Type: application/json",
  2040.                 "Accept: application/json",
  2041.             );
  2042.             curl_setopt($chCURLOPT_HTTPHEADER$headers);
  2043.             //for debug only!
  2044.             curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  2045.             curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  2046.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  2047.             $server_output curl_exec($ch);
  2048.             curl_close($ch);
  2049.             $initiationPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  2050.             if ($initiationPaiement && array_key_exists('status'$initiationPaiement)) {
  2051.                 $this->addFlash('ErrorAPI''Erreur système veuillez réessayer plutard.');
  2052.                 $iduser null;
  2053.                 $idclient $assuranceVoyage->getIdClient();
  2054.                 $action "Souscription Voyage";
  2055.                 $msg_send "paiement souscription";
  2056.                 $msg_get "Erreur système veuillez réessayer plutard..";
  2057.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2058.                 $entityManager->persist($log);
  2059.     
  2060.                 $entityManager->flush();
  2061.                 return $this->redirectToRoute('app_home');
  2062.             } else {
  2063.                 // if ($initiationPaiement['statut'] != 200) {
  2064.                 //     $this->addFlash('ErrorAPI', 'Erreur système veuillez réessayer plutard.');
  2065.                 //     return $this->redirectToRoute('app_home');
  2066.                 // }
  2067.             }
  2068.             $statut $initiationPaiement['statut'];
  2069.             // dd($statut);
  2070.             if ($statut == 200) {
  2071.                 $session->set('number'2);
  2072.                 return $this->redirectToRoute('details_souscriptionVoyage', ['id' => $idAssurance]);
  2073.             } else {
  2074.                 return $this->redirectToRoute('app_payement_souscriptionVoyage', ['id' => $idAssurance]);
  2075.             }
  2076.         }
  2077.         return $this->redirectToRoute('app_home');
  2078.     }
  2079.     #[Route('/details_souscriptionVoyage/{id}'name'details_souscriptionVoyage')]
  2080.     public function details_souscriptionVoyage(EntityManagerInterface $entityManager$idSessionInterface $sessionRequest $requestAssuranceVoyage $assuranceVoyage): Response
  2081.     {
  2082.         if ($session->get('number') == 0) {
  2083.             $session->clear();
  2084.             $this->addFlash('attentePaiement''Erreur, le paiement de votre souscription n a pas aboutie.');
  2085.             $iduser null;
  2086.             $idclient $assuranceVoyage->getIdClient();
  2087.             $action "Souscription Voyage";
  2088.             $msg_send "paiement souscription";
  2089.             $msg_get "Erreur, le paiement de votre souscription n a pas aboutie.";
  2090.             $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2091.             $entityManager->persist($log);
  2092.             $entityManager->flush();
  2093.             return $this->redirectToRoute('app_souscription_Voyage');
  2094.         } else {
  2095.             $paiement $assuranceVoyage->getIdPaiement();
  2096.             $idAssurance $assuranceVoyage->getId();
  2097.             $external_id $paiement->getExternalId();
  2098.             $ch curl_init();
  2099.             curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/confirmPaiement");
  2100.             curl_setopt($chCURLOPT_POSTFIELDS'{
  2101.                     "external_id" : ' . (int)$external_id ',
  2102.                     "type_op" : 2,
  2103.                     "id_op" : ' $idAssurance '
  2104.                 }');
  2105.             $headers = array(
  2106.                 "Content-Type: application/json",
  2107.                 "Accept: application/json",
  2108.             );
  2109.             curl_setopt($chCURLOPT_HTTPHEADER$headers);
  2110.             //for debug only!
  2111.             curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  2112.             curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  2113.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  2114.             $server_output curl_exec($ch);
  2115.             curl_close($ch);
  2116.             $confirmPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  2117.             // dd($confirmPaiement);
  2118.             if ($confirmPaiement && array_key_exists('status'$confirmPaiement)) {
  2119.                 $this->addFlash('ErrorAPI''Erreur système veuillez réessayer plutard.');
  2120.                 $iduser null;
  2121.                 $idclient $assuranceVoyage->getIdClient();
  2122.                 $action "Souscription Voyage";
  2123.                 $msg_send "paiement souscription";
  2124.                 $msg_get "Erreur système veuillez réessayer plutard.";
  2125.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2126.                 $entityManager->persist($log);
  2127.     
  2128.                 $entityManager->flush();
  2129.                 return $this->redirectToRoute('app_home');
  2130.             } else {
  2131.                 // if ($confirmPaiement['statut'] != 200) {
  2132.                 //     $this->addFlash('ErrorAPI', 'Erreur système veuillez réessayer plutard.');
  2133.                 //     return $this->redirectToRoute('app_home');
  2134.                 // }
  2135.             }
  2136.             $statut $confirmPaiement['statut'];
  2137.             // dd($statut);
  2138.             if ($statut == 200) {
  2139.                 $this->addFlash('souscription''Félicitations, votre souscription est réussie avec succès.');
  2140.                 $iduser null;
  2141.                 $idclient $assuranceVoyage->getIdClient();
  2142.                 $action "Souscription Voyage";
  2143.                 $msg_send "paiement souscription";
  2144.                 $msg_get "Félicitations, votre souscription est réussie avec succès.";
  2145.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2146.                 $entityManager->persist($log);
  2147.     
  2148.                 $entityManager->flush();
  2149.                 return $this->redirectToRoute('app_home');
  2150.             } else {
  2151.                 $sess $session->get('number') - 1;
  2152.                 $session->set('number'$sess);
  2153.                 return $this->render('souscription/details/detailsAssuranceVoyage.html.twig', [
  2154.                     'paiement' => $paiement,
  2155.                     'assuranceVoyage' => $assuranceVoyage,
  2156.                 ]);
  2157.             }
  2158.             return $this->render('souscription/details/detailsAssuranceVoyage.html.twig', [
  2159.                 'paiement' => $paiement,
  2160.                 'assuranceVoyage' => $assuranceVoyage,
  2161.             ]);
  2162.         }
  2163.     }
  2164.     #[Route('/souscription/habitation'name'app_souscription_Habitation')]
  2165.     public function indexHabitation(
  2166.         EntityManagerInterface $entityManager,
  2167.         SessionInterface $session,
  2168.         Request $request,
  2169.     ): Response {
  2170.     
  2171.         $ch curl_init();
  2172.         curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/client/getListeFormule");
  2173.         $headers = array(
  2174.             "Content-Type: application/json",
  2175.             "Accept: application/json",
  2176.         );
  2177.         curl_setopt($chCURLOPT_HTTPHEADER$headers);
  2178.         //for debug only!
  2179.         curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  2180.         curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  2181.         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  2182.         $server_output curl_exec($ch);
  2183.         curl_close($ch);
  2184.         $response json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  2185.         if ($response && array_key_exists('status'$response)) {
  2186.             $this->addFlash('ErrorAPI''Erreur système veuillez réessayer plutard.');
  2187.             $iduser null;
  2188.             $idclient null;
  2189.             $action "Souscription Habitation";
  2190.             $msg_send "demande souscription";
  2191.             $msg_get "Erreur système veuillez réessayer plutard.";
  2192.             $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2193.             $entityManager->persist($log);
  2194.             $entityManager->flush();
  2195.             return $this->redirectToRoute('app_home');
  2196.         } else {
  2197.             if ($response['statut'] != 200) {
  2198.                 $this->addFlash('ErrorAPI''Erreur système veuillez réessayer plutard.');
  2199.                 $iduser null;
  2200.                 $idclient null;
  2201.                 $action "Souscription Habitation";
  2202.                 $msg_send "demande souscription";
  2203.                 $msg_get "Erreur système veuillez réessayer plutard.";
  2204.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2205.                 $entityManager->persist($log);
  2206.     
  2207.                 $entityManager->flush();
  2208.                 return $this->redirectToRoute('app_home');
  2209.             }
  2210.         }
  2211.         $listeFormule $response['formules'];
  2212.         // dd($listeFormule);
  2213.         if ($request->request->count() > 0) {
  2214.             $formule trim($request->request->get("formule"));
  2215.             $nom trim($request->request->get("nom"));
  2216.             $prenom trim($request->request->get("prenom"));
  2217.             $telephone trim($request->request->get("phone"));
  2218.             $quartier =trim($request->request->get("quartier"));
  2219.             $ilot trim($request->request->get("ilot"));
  2220.             $parcelle trim($request->request->get("parcelle"));
  2221.             $ch curl_init();
  2222.             curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/getTarifHabitation");
  2223.             curl_setopt($chCURLOPT_POSTFIELDS'{
  2224.                 "idFormule" : ' . (int)$formule '
  2225.             }');
  2226.             $headers = array(
  2227.                 "Content-Type: application/json",
  2228.                 "Accept: application/json",
  2229.             );
  2230.             curl_setopt($chCURLOPT_HTTPHEADER$headers);
  2231.             //for debug only!
  2232.             curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  2233.             curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  2234.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  2235.             $server_output curl_exec($ch);
  2236.             curl_close($ch);
  2237.             $tarif json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  2238.             if ($tarif && array_key_exists('status'$tarif)) {
  2239.                 $this->addFlash('ErrorAPI''Erreur système veuillez réessayer plutard.');
  2240.                 $iduser null;
  2241.                 $idclient null;
  2242.                 $action "Souscription Habitation";
  2243.                 $msg_send "demande souscription";
  2244.                 $msg_get "Erreur système veuillez réessayer plutard.";
  2245.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2246.                 $entityManager->persist($log);
  2247.     
  2248.                 $entityManager->flush();
  2249.                 return $this->redirectToRoute('app_home');
  2250.             } else {
  2251.                 if ($tarif['statut'] != 200) {
  2252.                     $this->addFlash('ErrorAPI''Erreur système veuillez réessayer plutard.');
  2253.                     $iduser null;
  2254.                     $idclient null;
  2255.                     $action "Souscription Habitation";
  2256.                     $msg_send "demande souscription";
  2257.                     $msg_get "Erreur système veuillez réessayer plutard.";
  2258.                     $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2259.                     $entityManager->persist($log);
  2260.         
  2261.                     $entityManager->flush();
  2262.                     return $this->redirectToRoute('app_home');
  2263.                 }
  2264.             }
  2265.             $tarifStatut $tarif['statut'];
  2266.             if ($tarifStatut == 200) {
  2267.                 $montant $tarif['montant'];
  2268.                 $description $tarif['description'];
  2269.                 $ch curl_init();
  2270.                 curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/clientCaren");
  2271.                 curl_setopt($chCURLOPT_POST1);
  2272.                 curl_setopt($chCURLOPT_POSTFIELDS'{
  2273.                 "nom" : "' $nom '",
  2274.                 "prenom" : "' $prenom '",
  2275.                 "telephone" : "' $telephone '"
  2276.                 }');
  2277.                 $headers = array(
  2278.                     "Content-Type: application/json",
  2279.                     "Accept: application/json",
  2280.                 );
  2281.                 curl_setopt($chCURLOPT_HTTPHEADER$headers);
  2282.                 //for debug only!
  2283.                 curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  2284.                 curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  2285.                 curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  2286.                 $server_output curl_exec($ch);
  2287.                 curl_close($ch);
  2288.                 $clientCaren json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  2289.                 // if ($clientCaren && array_key_exists('status', $clientCaren)) {
  2290.                 //     $this->addFlash('ErrorAPI', 'Erreur système veuillez réessayer plutard.');
  2291.                 //     $iduser = null;
  2292.                 //     $idclient = null;
  2293.                 //     $action = "Souscription Habitation";
  2294.                 //     $msg_send = "demande souscription";
  2295.                 //     $msg_get = "Erreur système veuillez réessayer plutard.";
  2296.                 //     $log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);
  2297.                 //     $entityManager->persist($log);
  2298.         
  2299.                 //     $entityManager->flush();
  2300.                 //     return $this->redirectToRoute('app_home');
  2301.                 // } else {
  2302.                 //     if ($clientCaren['statut'] != 200 && $clientCaren['statut'] != 400) {
  2303.                 //         $this->addFlash('ErrorAPI', 'Erreur système veuillez réessayer plutard.');
  2304.                 //         $iduser = null;
  2305.                 //         $idclient = null;
  2306.                 //         $action = "Souscription Habitation";
  2307.                 //         $msg_send = "demande souscription";
  2308.                 //         $msg_get = "Erreur système veuillez réessayer plutard.";
  2309.                 //         $log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);
  2310.                 //         $entityManager->persist($log);
  2311.             
  2312.                 //         $entityManager->flush();
  2313.                 //         return $this->redirectToRoute('app_home');
  2314.                 //     }
  2315.                 // }
  2316.                 // $clientStatut = $clientCaren['statut'];
  2317.                 // $client = $clientCaren['client'];
  2318.                 // $typeClient = $client['idTypeClient'];
  2319.                 $infoTarif $entityManager->getRepository(TarifHabitation::class)->find($tarif['idTarif']);
  2320.                 // dd($client);
  2321.                 // if ($client && $typeClient['id'] == 1) {
  2322.                 //     $messageErr = $clientCaren['message'];
  2323.                 //     return $this->render('authentication/login.html.twig', [
  2324.                 //         'messageErr' => $messageErr,
  2325.                 //     ]);
  2326.                 // } else {
  2327.                     $idClient $entityManager->getRepository(Client::class)->findOneBy(['telephone' => $telephone'idTypeClient' => 2]);
  2328.                 if ($idClient) {
  2329.                     $assuranceHabitation = new AssuranceHabitation;
  2330.                     $assuranceHabitation->setIdTarif($infoTarif)
  2331.                         ->setIdClient($idClient)
  2332.                         ->setNomBeneficiaire($nom)
  2333.                         ->setPrenomBeneficiaire($prenom)
  2334.                         ->setTelephoneBeneficiaire($telephone)
  2335.                         ->setCanal("WEB")
  2336.                         ->setQuartier($quartier)
  2337.                         ->setIlot($ilot)
  2338.                         ->setParcelle($parcelle)
  2339.                         ->setCreatedAt(new DateTimeImmutable())
  2340.                         ->setStatut(0);
  2341.                     // dd($assuranceHabitation);
  2342.                     $paiement =  new Paiement();
  2343.                     $statutPaiement $entityManager->getRepository(StatutPaiement::class)->find(1);
  2344.                     $paiement->setMontant($montant)
  2345.                         ->setStatut(0)
  2346.                         ->setStatutPaiement($statutPaiement)
  2347.                         ->setCreatedAt(new \DateTimeImmutable('now'));
  2348.                     $entityManager->persist($paiement);
  2349.                     // dd($paiement);
  2350.                     $assuranceHabitation->setIdPaiement($paiement);
  2351.                     $entityManager->persist($assuranceHabitation);
  2352.                     $entityManager->flush();
  2353.                     $iduser null;
  2354.                     $idclient null;
  2355.                     $action "Souscription Habitation";
  2356.                     $msg_send "Demande souscription";
  2357.                     $msg_get "Demande souscription éffectuée avec succés";
  2358.                     $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2359.                     $entityManager->persist($log);
  2360.         
  2361.                     $entityManager->flush();
  2362.                     $this->addFlash('initiation''');
  2363.                     return $this->render('souscription/payement/payementHabitation.html.twig', [
  2364.                         'assuranceHabitation' => $assuranceHabitation
  2365.                     ]);
  2366.                 }else{
  2367.                     $this->addFlash('noTarif''Operation non aboutie, veuillez rééssayer.');
  2368.                     $iduser null;
  2369.                     $idclient null;
  2370.                     $action "Souscription Habitation";
  2371.                     $msg_send "demande souscription";
  2372.                     $msg_get "Operation non aboutie, veuillez rééssayer.";
  2373.                     $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2374.                     $entityManager->persist($log);
  2375.         
  2376.                     $entityManager->flush();
  2377.                     return $this->redirectToRoute('app_souscription_Habitation');
  2378.                 }
  2379.                 // }
  2380.             } else {
  2381.                 $this->addFlash('noTarif''Aucune tarification trouvée, veuillez rééssayer.');
  2382.                 $iduser null;
  2383.                 $idclient null;
  2384.                 $action "Souscription Habitation";
  2385.                 $msg_send "demande souscription";
  2386.                 $msg_get "Aucune tarification trouvée, veuillez rééssayer.";
  2387.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2388.                 $entityManager->persist($log);
  2389.     
  2390.                 $entityManager->flush();
  2391.                 return $this->redirectToRoute('app_souscription_Habitation');
  2392.             }
  2393.         }
  2394.         return $this->render('souscription/indexHabitation.html.twig', [
  2395.             'formules' => $listeFormule
  2396.         ]);
  2397.     }
  2398.     #[Route('/souscription/habitation/Old/HabitationPayement/{id}'name'app_payement_souscriptionHabitationOld'methods: ['POST''GET'])]
  2399.     public function payementHabitationOld(EntityManagerInterface $entityManagerSessionInterface $sessionRequest $requestAssuranceHabitation $assuranceHabitation): Response
  2400.     {
  2401.         if ($request->request->count() > && $request->request->get("souscriptionHabitation") == "souscriptionHabitation") {
  2402.             $payement $request->request->get("payement");
  2403.             $telephone2 $request->request->get("phone2");
  2404.             $idAssurance $assuranceHabitation->getId();
  2405.             // dd($assuranceHabitation, $payement, $telephone2);
  2406.             $ch curl_init();
  2407.             curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/getPaiement");
  2408.             curl_setopt($chCURLOPT_POSTFIELDS'{
  2409.                 "msisdn" : "' $telephone2 '",
  2410.                 "type_op" : 3,
  2411.                 "id_op" : ' . (int)$idAssurance ',
  2412.                 "operateur" : ' . (int)$payement '
  2413.             }');
  2414.             $headers = array(
  2415.                 "Content-Type: application/json",
  2416.                 "Accept: application/json",
  2417.             );
  2418.             curl_setopt($chCURLOPT_HTTPHEADER$headers);
  2419.             //for debug only!
  2420.             curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  2421.             curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  2422.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  2423.             $server_output curl_exec($ch);
  2424.             curl_close($ch);
  2425.             $initiationPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  2426.             if ($initiationPaiement && array_key_exists('status'$initiationPaiement)) {
  2427.                 $this->addFlash('ErrorAPI''Erreur système veuillez réessayer plutard.');
  2428.                 $iduser null;
  2429.                 $idclient $assuranceHabitation->getIdClient();
  2430.                 $action "Souscription Habitation";
  2431.                 $msg_send "paiement souscription";
  2432.                 $msg_get "Erreur système veuillez réessayer plutard";
  2433.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2434.                 $entityManager->persist($log);
  2435.     
  2436.                 $entityManager->flush();
  2437.                 return $this->redirectToRoute('app_home');
  2438.             } else {
  2439.                 // if ($initiationPaiement['statut'] != 200) {
  2440.                 //     $this->addFlash('ErrorAPI', 'Erreur système veuillez réessayer plutard.');
  2441.                 //     return $this->redirectToRoute('app_home');
  2442.                 // }
  2443.             }
  2444.             $statut $initiationPaiement['statut'];
  2445.             // dd($statut);
  2446.             if ($statut == 200) {
  2447.                 $session->set('number'2);
  2448.                 return $this->redirectToRoute('details_souscriptionHabitation', ['id' => $idAssurance]);
  2449.             } else {
  2450.                 return $this->redirectToRoute('app_payement_souscriptionHabitation', ['id' => $idAssurance]);
  2451.             }
  2452.         }
  2453.         return $this->redirectToRoute('app_home');
  2454.     }
  2455.     #[Route('/details_souscriptionHabitation/{id}'name'details_souscriptionHabitation')]
  2456.     public function details_souscriptionHabitation(EntityManagerInterface $entityManager$idSessionInterface $sessionRequest $requestAssuranceHabitation $assuranceHabitation): Response
  2457.     {
  2458.         if ($session->get('number') == 0) {
  2459.             $session->clear();
  2460.             $this->addFlash('attentePaiement''Erreur, le paiement de votre souscription n a pas aboutie.');
  2461.             $iduser null;
  2462.             $idclient $assuranceHabitation->getIdClient();
  2463.             $action "Souscription Habitation";
  2464.             $msg_send "paiement souscription";
  2465.             $msg_get "Erreur, le paiement de votre souscription n a pas aboutie";
  2466.             $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2467.             $entityManager->persist($log);
  2468.             $entityManager->flush();
  2469.             return $this->redirectToRoute('app_souscription_Voyage');
  2470.         } else {
  2471.             $paiement $assuranceHabitation->getIdPaiement();
  2472.             $idAssurance $assuranceHabitation->getId();
  2473.             $external_id $paiement->getExternalId();
  2474.             $ch curl_init();
  2475.             curl_setopt($chCURLOPT_URL"https://carenapi235679814.caren-niger.com/api/confirmPaiement");
  2476.             curl_setopt($chCURLOPT_POSTFIELDS'{
  2477.                 "external_id" : ' . (int)$external_id ',
  2478.                 "type_op" : 3,
  2479.                 "id_op" : ' $idAssurance '
  2480.             }');
  2481.             $headers = array(
  2482.                 "Content-Type: application/json",
  2483.                 "Accept: application/json",
  2484.             );
  2485.             curl_setopt($chCURLOPT_HTTPHEADER$headers);
  2486.             //for debug only!
  2487.             curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  2488.             curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  2489.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  2490.             $server_output curl_exec($ch);
  2491.             curl_close($ch);
  2492.             $confirmPaiement json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  2493.             if ($confirmPaiement && array_key_exists('status'$confirmPaiement)) {
  2494.                 $this->addFlash('ErrorAPI''Erreur système veuillez réessayer plutard.');
  2495.                 $iduser null;
  2496.                 $idclient $assuranceHabitation->getIdClient();
  2497.                 $action "Souscription Habitation";
  2498.                 $msg_send "paiement souscription";
  2499.                 $msg_get "Erreur système veuillez réessayer plutard";
  2500.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2501.                 $entityManager->persist($log);
  2502.     
  2503.                 $entityManager->flush();
  2504.                 return $this->redirectToRoute('app_home');
  2505.             } else {
  2506.                 // if ($confirmPaiement['statut'] != 200) {
  2507.                 //     $this->addFlash('ErrorAPI', 'Erreur système veuillez réessayer plutard.');
  2508.                 //     return $this->redirectToRoute('app_home');
  2509.                 // }
  2510.             }
  2511.             $statut $confirmPaiement['statut'];
  2512.             // dd($statut);
  2513.             if ($statut == 200) {
  2514.                 $this->addFlash('souscription''Félicitations, votre souscription est réussie avec succès.');
  2515.                 $iduser null;
  2516.                 $idclient $assuranceHabitation->getIdClient();
  2517.                 $action "Souscription Habitation";
  2518.                 $msg_send "paiement souscription";
  2519.                 $msg_get "Félicitations, votre souscription est réussie avec succès.";
  2520.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2521.                 $entityManager->persist($log);
  2522.     
  2523.                 $entityManager->flush();
  2524.                 return $this->redirectToRoute('app_home');
  2525.             } else {
  2526.                 $sess $session->get('number') - 1;
  2527.                 $session->set('number'$sess);
  2528.                 return $this->render('souscription/details/detailsAssuranceHabitation.html.twig', [
  2529.                     'paiement' => $paiement,
  2530.                     'assuranceHabitation' => $assuranceHabitation,
  2531.                 ]);
  2532.             }
  2533.         }
  2534.         return $this->render('souscription/details/detailsAssuranceHabitation.html.twig', [
  2535.             'paiement' => $paiement,
  2536.             'assuranceHabitation' => $assuranceHabitation,
  2537.         ]);
  2538.     }
  2539.     #[Route('/{id}/deleteAssuranceAuto'name'deleteAssuranceAuto'methods: ['GET''POST'])]
  2540.     public function deleteAuto(Request $requestAssurance $assuranceEntityManagerInterface $entityManagerSessionInterface $session): Response
  2541.     {
  2542.         $statut $assurance->getStatut();
  2543.         $assurance->setStatut(2);
  2544.         $entityManager->persist($assurance);
  2545.         $entityManager->flush();
  2546.         $iduser null;
  2547.         $idclient $assurance->getIdClient();
  2548.         $action "Souscription Automobile";
  2549.         $msg_send "suppression souscription";
  2550.         $msg_get "Réussie avec succès.";
  2551.         $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2552.         $entityManager->persist($log);
  2553.         $entityManager->flush();
  2554.         $session->clear();
  2555.         return $this->redirectToRoute('app_home');
  2556.     }
  2557.     #[Route('/{id}/deleteAssuranceVoyage'name'deleteAssuranceVoyage'methods: ['GET''POST'])]
  2558.     public function deleteVoyage(Request $requestAssuranceVoyage $assuranceVoyageEntityManagerInterface $entityManagerSessionInterface $session): Response
  2559.     {
  2560.         $statut $assuranceVoyage->getStatut();
  2561.         $assuranceVoyage->setStatut(2);
  2562.         $entityManager->persist($assuranceVoyage);
  2563.         $entityManager->flush();
  2564.                $iduser null;
  2565.                 $idclient $assuranceVoyage->getIdClient();
  2566.                 $action "Souscription Voyage";
  2567.                 $msg_send "suppression souscription";
  2568.                 $msg_get "Réussie avec succès.";
  2569.                 $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2570.                 $entityManager->persist($log);
  2571.     
  2572.                 $entityManager->flush();
  2573.         $session->clear();
  2574.         return $this->redirectToRoute('app_home');
  2575.     }
  2576.     #[Route('/{id}/deleteAssuranceHabitation'name'deleteAssuranceHabitation'methods: ['GET''POST'])]
  2577.     public function deleteHabitation(Request $requestAssuranceHabitation $assuranceHabitationEntityManagerInterface $entityManager): Response
  2578.     {
  2579.         $statut $assuranceHabitation->getStatut();
  2580.         $assuranceHabitation->setStatut(2);
  2581.         $entityManager->persist($assuranceHabitation);
  2582.         $entityManager->flush();
  2583.         
  2584.         $iduser null;
  2585.         $idclient $assuranceHabitation->getIdClient();
  2586.         $action "Souscription Habitation";
  2587.         $msg_send "suppression souscription";
  2588.         $msg_get "Réussie avec succès.";
  2589.         $log $this->log($action$msg_send$msg_get$iduser,$idclient);
  2590.         $entityManager->persist($log);
  2591.         $entityManager->flush();
  2592.         return $this->redirectToRoute('app_home');
  2593.     }
  2594.     #[Route('/assurance/autoSouscriptionRetryPayement/{id}'name'app_retrySouscriptionPayement_auto'methods: ['POST''GET'])]
  2595.     public function retryPayementSouscriptionAuto(EntityManagerInterface $entityManagerSessionInterface $sessionRequest $requestAssurance $assurance): Response
  2596.     {
  2597.         $montant $assurance->getMontantAssurance();
  2598.         $montantLivraison $assurance->getMontantLivraison();
  2599.         $montantTotal $assurance->getMontantTotal();
  2600.         // dd($montant, $montantLivraison, $montantTotal);
  2601.         $this->addFlash('initiation''');
  2602.         return $this->render('souscription/payement/payementAuto.html.twig', [
  2603.             'souscription' => $assurance,
  2604.             'montant' => $montant,
  2605.             'montantLivraison' => $montantLivraison,
  2606.             'montantTotal' => $montantTotal
  2607.         ]);
  2608.     }
  2609.     #[Route('/assurance/voyaSouscriptionRetryPayement/{id}'name'app_retrySouscriptionPayement_voya'methods: ['POST''GET'])]
  2610.     public function retryPayementSouscriptionVoya(EntityManagerInterface $entityManagerSessionInterface $sessionRequest $requestassuranceVoyage $assuranceVoyage): Response
  2611.     {
  2612.         // dd($assuranceVoyage);
  2613.         $this->addFlash('initiation''');
  2614.         $dateExp $assuranceVoyage->getDateExpPassport();
  2615.         $dateDep $assuranceVoyage->getDateDepart();
  2616.         $dateR $assuranceVoyage->getDateRetour();
  2617.         // dd($dateExp, $dateDepart, $dateR);
  2618.         return $this->render('souscription/payement/payementVoyage.html.twig', [
  2619.             'assuranceVoyage' => $assuranceVoyage,
  2620.             'dateExp' => $dateExp->format('d/m/Y'),
  2621.             'dateDep' => $dateDep->format('d/m/Y'),
  2622.             'dateRet' => $dateR->format('d/m/Y')
  2623.         ]);
  2624.     }
  2625.     #[Route('/assurance/habiSouscriptionRetryPayement/{id}'name'app_retrySouscriptionPayement_habi'methods: ['POST''GET'])]
  2626.     public function retryPayementSouscriptionHabi(EntityManagerInterface $entityManagerSessionInterface $sessionRequest $requestAssuranceHabitation $assuranceHabitation): Response
  2627.     {
  2628.         // dd($assuranceHabitation);
  2629.         $this->addFlash('initiation''');
  2630.         return $this->render('souscription/payement/payementHabitation.html.twig', [
  2631.             'assuranceHabitation' => $assuranceHabitation,
  2632.         ]);
  2633.     }
  2634.     public function log($action$msg_send$msg_get$iduser$idclient)
  2635.     {
  2636.       $log = new Log();
  2637.       $date = new \DateTime('now');
  2638.       $ip $_SERVER['REMOTE_ADDR'];
  2639.       if($iduser){
  2640.         $log->setUser($iduser);
  2641.       }
  2642.       if($idclient){
  2643.         $log->setClient($idclient);
  2644.       }
  2645.       $log->setAction($action);
  2646.       $log->setDate($date);
  2647.       $log->setIp($ip);
  2648.       $log->setCanal("web");
  2649.       $log->setMsgSend($msg_send);
  2650.       $log->setMsgGet($msg_get);
  2651.       return $log;
  2652.     }
  2653.     function merchantIpay($amount$title$reference$description$token)
  2654.     {
  2655.         // "amount": "50",
  2656.         // "title": "Test",
  2657.         // "reference": "werdsa234ewqq1612",
  2658.         // "description": "....",
  2659.         // "shouldExpire": true,
  2660.         $on_success_redirection_url"https://example.com";
  2661.         $on_failed_redirection_url "https://example.com";
  2662.         $shouldExpire true;
  2663.         $currency "XOF";
  2664.         $country "NE";
  2665.         $ch curl_init();
  2666.         curl_setopt($chCURLOPT_URL"https://api.i-pay.money/api/v1/external_payments");
  2667.         //curl_setopt($ch, CURLOPT_URL, "https://i-pay.money/api/v1/payments");
  2668.         curl_setopt($chCURLOPT_POST1);
  2669.         curl_setopt($chCURLOPT_POSTFIELDS'{
  2670.             "amount": "' $amount '",
  2671.             "title": "' $title '",
  2672.             "reference": "' $reference '",
  2673.             "description": "' $description '",
  2674.             "shouldExpire": "' $shouldExpire '",
  2675.             "on_success_redirection_url": "' $on_success_redirection_url '",
  2676.             "on_failed_redirection_url": "' $on_failed_redirection_url '"
  2677.            
  2678.         }');
  2679.         curl_setopt($chCURLOPT_TIMEOUT30);
  2680.         curl_setopt($chCURLOPT_CONNECTTIMEOUT30);
  2681.         $headers = array(
  2682.             'Ipay-Payment-Type: external_payment',
  2683.             'Ipay-Target-Environment: sandbox',
  2684.             'Content-Type: application/json',
  2685.             'Authorization: Bearer ' $token,
  2686.             // 'Cookie: SERVERID=s116'
  2687.             // "Authorization: Token 06bf9e40ae925464a2421365f928fecb4bebe539",
  2688.         );
  2689.         curl_setopt($chCURLOPT_HTTPHEADER$headers);
  2690.         //for debug only!
  2691.         curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
  2692.         curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  2693.         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  2694.         $server_output curl_exec($ch);
  2695.         curl_close($ch);
  2696.         $coc_user json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/'''$server_output), true);
  2697.         return $coc_user;
  2698.     }
  2699. }