src/Controller/DefaultController.php line 112

Open in your IDE?
  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 App\Repository\CategoriesRepository;
  7. use App\Repository\AnnoncesRepository;
  8. use App\Repository\FavorisRepository;
  9. use App\Repository\PaysRepository;
  10. use App\Repository\VillesRepository;
  11. use App\Repository\UserRepository;
  12. use App\Repository\CommandesRepository;
  13. use App\Repository\FacturesRepository;
  14. use App\Repository\NotesEnseignesRepository;
  15. use App\Repository\NotesAnnoncesRepository;
  16. use App\Entity\Commandes;
  17. use App\Entity\Factures;
  18. use App\Entity\Alertes;
  19. use App\Entity\Villes;
  20. use App\Entity\Categories;
  21. use Datetime;
  22. use Spipu\Html2Pdf\Html2Pdf;
  23. use App\Entity\Favoris;
  24. use Stripe\Stripe;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Knp\Component\Pager\PaginatorInterface;
  27. use Doctrine\ORM\EntityManagerInterface;
  28. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  29. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  30. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  31. use App\Entity\User;
  32. use Symfony\Component\Form\Extension\Core\Type\TextType;
  33. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  34. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  35. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  36. use Symfony\Component\HttpFoundation\File\UploadedFile;
  37. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  38. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  39. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  40. use Symfony\Component\Form\Extension\Core\Type\FileType;
  41. use Symfony\Component\Form\Extension\Core\Type\DateType;
  42. use Symfony\Component\Validator\Constraints\NotBlank;
  43. use Symfony\Component\Validator\Constraints\Length;
  44. use DansMaCulotte\Monetico\Monetico;
  45. use DansMaCulotte\Monetico\Requests\PurchaseRequest;
  46. use DansMaCulotte\Monetico\Resources\BillingAddressResource;
  47. use DansMaCulotte\Monetico\Resources\ShippingAddressResource;
  48. use DansMaCulotte\Monetico\Resources\ClientResource;
  49. class DefaultController extends AbstractController
  50. {
  51.     private $entityManager;
  52.     private $stripeSecretKey;
  53.   
  54.     public function __construct(EntityManagerInterface $entityManager,string $stripeSecretKey)
  55.     {
  56.         $this->entityManager $entityManager;
  57.         $this->stripeSecretKey $stripeSecretKey;
  58.     }
  59.     /**
  60.      * @Route("/loginPopup", name="custom_login")
  61.      */
  62.     public function loginPopup(Request $requestUserPasswordEncoderInterface $passwordEncoder)
  63.     {
  64.         $referer $request->headers->get('referer');
  65.         // Vérifier si l'utilisateur est déjà connecté, rediriger vers une autre page si nécessaire
  66.         if ($this->getUser()) {
  67.             return $this->redirectToRoute(' ');
  68.         }
  69.         if ($request->isMethod('POST')) {
  70.             $email $request->request->get('email');
  71.             $password $request->request->get('password');
  72.             // Récupérer l'utilisateur depuis la source de données (base de données, API, etc.)
  73.             $user $this->getDoctrine()->getRepository(User::class)->findOneBy(['email' => $email]);
  74.             if (!$user) {
  75.                 throw new AuthenticationException('Adresse e-mail ou mot de passe incorrect.');
  76.             }
  77.             // Vérifier le mot de passe
  78.             $isPasswordValid $passwordEncoder->isPasswordValid($user$password);
  79.             if (!$isPasswordValid) {
  80.                 throw new AuthenticationException('Adresse e-mail ou mot de passe incorrect.');
  81.             }
  82.             // Authentifier l'utilisateur
  83.             $token = new UsernamePasswordToken($user$user->getPassword(), 'main'$user->getRoles());
  84.             $this->get('security.token_storage')->setToken($token);
  85.             // Rediriger l'utilisateur vers une page sécurisée après la connexion réussie
  86.             return $this->redirect($referer);
  87.         }
  88.     }
  89.     /**
  90.      * @Route("/", name="app_default")
  91.      */
  92.     public function index(Request $request): Response
  93.     {
  94.         $session $request->getSession();
  95.         $session->set('type''part');
  96.         return $this->render('default/index.html.twig', []);
  97.     }
  98.     /**
  99.      * @Route("/professionnels", name="professionnels")
  100.      */
  101.     public function professionnels(Request $request): Response
  102.     {
  103.         $session $request->getSession();
  104.         $session->set('type''pro');
  105.         return $this->render('default/indexPro.html.twig', []);
  106.     }
  107.     /**
  108.      * @Route("/achatCredit", name="achatCredit")
  109.      */
  110.     public function achatCredit(Request $request): Response
  111.     {
  112.    
  113.         return $this->render('default/achatCredit.html.twig', []);
  114.     }
  115.       /**
  116.      * @Route("/achatRecap", name="achatRecap")
  117.      */
  118.     public function achatRecap(Request $request): Response
  119.     {
  120.          $qt $_POST['quantite'];
  121.         return $this->render('default/achatRecap.html.twig', [
  122.             'qt'=>$qt
  123.         ]);
  124.     }
  125.       /**
  126.      * @Route("/paiementStripeForm", name="paiementStripeForm")
  127.      */
  128.     public function paiementStripeForm(Request $requestCommandesRepository $commandesRepo): Response
  129.     {
  130.         $uniq uniqid();
  131.         $session $request->getSession();
  132.         $session->set('orderIdTemp'$uniq);
  133.         $user $this->getUser();
  134.         $qt $_POST['qt'];
  135.         $total $qt;
  136.         
  137.             $commandes = new Commandes();
  138.             $commandes->setCreated(new DateTime());
  139.             $commandes->setQuantite($qt);
  140.             $commandes->setTotal($total);
  141.             $commandes->setUser($user);
  142.             $commandes->setUniqId($uniq);
  143.             $commandesRepo->add($commandestrue);
  144.      
  145.         return $this->render('default/paiement.html.twig', [
  146.            
  147.         ]);
  148.     }
  149.     
  150.     /**
  151.      * @Route("/stripe", name="stripe")
  152.      */
  153.     public function stripe(Request $requestCommandesRepository $commandesRepo): Response
  154.     {
  155.         
  156.         $session $request->getSession();
  157.         $uniq $session->get('orderIdTemp');
  158.         $commandes $commandesRepo->findOneBy(array('UniqId'=>$uniq));
  159.         $total $commandes->getTotal() * 100;
  160.       
  161.      
  162.             $description 'commande numéro '.$commandes->getId();
  163.              // Récupérer le token envoyé depuis le frontend
  164.         $token json_decode($request->getContent(), true)['token'];
  165.        
  166.         // clé secrète TEST
  167.         Stripe::setApiKey('sk_test_51OuD3FGwTslbSP9Q7fBBkAOs8ouF2U2uxofmuPoX7YiBuF7FIol7MGuCFFX59QjQs04mlLcJkNpw9jctLSfv1C8R002fM4y74R');
  168.          // clé secrète PRODUCTION
  169.          //Stripe::setApiKey('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');
  170.         try {
  171.         // Effectuer la charge avec le token
  172.         // Par exemple :
  173.          $charge = \Stripe\Charge::create([
  174.              'amount' => $total// Montant en centimes
  175.              'currency' => 'eur',
  176.              'source' => $token// Token de carte de crédit
  177.              'description' => $description,
  178.          ]);
  179.         // Ici, vous pouvez gérer la réponse de Stripe, puis renvoyer une réponse appropriée au frontend
  180.         return $this->json(['message' => 'Paiement effectué avec succès']);
  181.     } catch (CardException $e) {
  182.         // Si une exception liée à la carte se produit (par exemple, la carte est déclinée), capturez l'erreur
  183.         // et renvoyez le message d'erreur au frontend
  184.         return $this->json(['error' => $e->getMessage()], Response::HTTP_BAD_REQUEST);
  185.     } catch (ApiErrorException $e) {
  186.         // Si une autre exception Stripe se produit, capturez l'erreur
  187.         // et renvoyez un message d'erreur générique au frontend
  188.         return $this->json(['error' => 'Une erreur est survenue lors du traitement du paiement. Veuillez réessayer.'], Response::HTTP_INTERNAL_SERVER_ERROR);
  189.     }
  190.         
  191.        
  192.     }
  193.      /**
  194.      * @Route("/retourStripe/{etat}", name="retourStripe")
  195.      */
  196.     public function retourStripe(Request $request$etatCommandesRepository $commandesRepo,FacturesRepository $facturesRepoUserRepository $userRepo): Response
  197.     {
  198.         $session $request->getSession();
  199.         $uniq $session->get('orderIdTemp');
  200.         $commandes $commandesRepo->findOneBy(array('UniqId'=>$uniq));
  201.       
  202.      
  203.         if($etat == 'success')
  204.         {
  205.         
  206.             if($commandes->isPaye())
  207.             {
  208.               
  209.             }
  210.             else
  211.             {
  212.         $commandes->setPaye(1);
  213.         $commandesRepo->add($commandestrue);
  214.         $user $this->getUser();
  215.         $credit $user->getCredits() + $commandes->getQuantite();
  216.         $user->setCredits($credit);
  217.         $userRepo->add($usertrue);
  218.             $factureNew = new Factures();
  219.             $factureNew->setCreated(new DateTime());
  220.             $factureNew->setCommandes($commandes);
  221.             $factureNew->setUser($user);
  222.             $facturesRepo->add($factureNewtrue);
  223.         $template $this->renderView('default/facturesPdf.html.twig', [
  224.             'facture'=>$factureNew
  225.             
  226.         ]);
  227.     
  228.     
  229.         $numero date('Y').$factureNew->getId();
  230.         $html2pdf = new Html2Pdf();
  231.         $html2pdf->writeHTML($template);
  232.         $html2pdf->output('/var/www/vhosts/modixom.fr/httpdocs/public/factures/' $numero '.pdf''F');
  233.             
  234.        
  235.        
  236.         /*   $msg = $this->renderView(
  237.             // templates/emails/registration.txt.twig
  238.                 'default/confirmationEmail.html.twig',
  239.                 [
  240.                 'nom'=>$res->getUser()->getNom(),
  241.                 'prenom'=>$res->getUser()->getPrenom(),
  242.                 'nbPlaces'=>$res->getNbPlaces(),
  243.                 'type'=>'billet',
  244.                 'resa'=>$res
  245.                 ]
  246.             );
  247.         
  248.        
  249.     
  250.             // if (!empty($_POST['g-recaptcha-response'])){
  251.         $mj = new \Mailjet\Client('bce86e9943d59ded740db2a28c2f3083','a1db2837eee29a897454015828aba390',true,['version' => 'v3.1']);
  252.         $body = [
  253.             'Messages' => [
  254.                 [
  255.                     'From' => [
  256.                         'Email' => "noreply@lions-laclaireau.be",
  257.                         'Name' => "LIONS LACLAIREAU"
  258.                     ],
  259.                     'To' => [
  260.                         [
  261.                              'Email' => $res->getUser()->getEmail(),
  262.                             //'Email' => 'matthieu@aready.io',
  263.                         ]
  264.                     ],
  265.                    
  266.                     
  267.                         'Subject' => "Confirmation de réservation",
  268.                             
  269.                             'HTMLPart' => $msg
  270.     
  271.                 ]
  272.             ]
  273.         ];
  274.         $response = $mj->post(Resources::$Email, ['body' => $body]);
  275.         $response->success();
  276.     
  277.         $info = $response->getData();*/
  278.     }
  279.         
  280.         }
  281.         
  282.         return $this->renderForm('default/retourStripe.html.twig', [
  283.             'etat'=>$etat
  284.            
  285.             
  286.         ]);
  287.     }
  288.   /**
  289.      * @Route("/testpdf", name="testpdf")
  290.      */
  291.     public function testpdf(Request $requestFacturesRepository $facturesRepo): Response
  292.     {
  293.         $facture $facturesRepo->findOneById(1);
  294.     $template $this->renderView('default/facturesPdf.html.twig', [
  295.         'facture'=>$facture
  296.         
  297.     ]);
  298.     $html2pdf = new Html2Pdf();
  299.     $html2pdf->writeHTML($template);
  300.     $html2pdf->output('test.pdf');
  301.     }
  302.     /**
  303.      * @Route("/achatGenerationFacture", name="achatGenerationFacture")
  304.      */
  305.     public function achatGenerationFacture(Request $request): Response
  306.     {
  307.         $session $request->getSession();
  308.         $session->set('type''part');
  309.         return $this->render('default/achatGenerationFacture.html.twig', []);
  310.     }
  311.     /**
  312.      * @Route("/annonces", name="annonces")
  313.      */
  314.     public function annonces(CategoriesRepository $categoriesRepositoryFavorisRepository $favorisRepositoryRequest $requestAnnoncesRepository $annoncesRepositoryVillesRepository $villesRepositoryPaginatorInterface $paginatorNotesEnseignesRepository $notesEnseignesRepository): Response
  315.     {
  316.         $categoriesSearch '';
  317.         $citiesRes '';
  318.         if (isset($_GET['tri'])) {
  319.             $triSearch $_GET['tri'];
  320.         } else {
  321.             $triSearch '';
  322.         }
  323.         if (isset($_GET['nbParPage'])) {
  324.             $nbParPage $_GET['nbParPage'];
  325.         } else {
  326.             $nbParPage 25;
  327.         }
  328.         if (isset($_GET['pro'])) {
  329.             $pro $_GET['pro'];
  330.         } else {
  331.             $pro 0;
  332.         }
  333.         if (isset($_GET['motscles'])) {
  334.             $motscles $_GET['motscles'];
  335.         } else {
  336.             $motscles '';
  337.         }
  338.         $villes = array();
  339.         $citiesRes = array();
  340.         $em $this->getDoctrine()->getManager();
  341.         // A dupliquer sur toutes les methodes
  342.         $session $request->getSession();
  343.         $user $this->getUser();
  344.         $favorisUser = array();
  345.         if (empty($session->get('type'))) {
  346.             $session->set('type''part');
  347.         }
  348.         if ($user) {
  349.             $session->set('type'$user->getType());
  350.             $favoris $favorisRepository->findBy(array('User'=>$user));
  351.             foreach($favoris as $res)
  352.             {
  353.                 array_push($favorisUser,$res->getAnnonces()->getId());
  354.             }
  355.         }
  356.    
  357.         // Fin
  358.         if (isset($_GET['categories'])) {
  359.             $categoriesSearch $_GET['categories'];
  360.         } else {
  361.             $categoriesSearch = array();
  362.         }
  363.         if (isset($_GET['ville'])) {
  364.             $ville $_GET['ville'];
  365.         } else {
  366.             $ville '';
  367.         }
  368.         $villes $villesRepository->findOneById($ville);
  369.         if (isset($_GET['rayon'])) {
  370.             $distance $_GET['rayon'];
  371.         } else {
  372.             $distance 50;
  373.         }
  374.         // Il faut ajouter le repertoire doctrine/dql dans src
  375.         // Il faut ajouter les lignes dans services.yaml
  376.         // Il faut ajouter les lignes dans doctrine.yaml
  377.         if (!empty($villes)) {
  378.             // RECUPERER LES VILLES DANS UN RAYON
  379.             $lat $villes->getVilleLatitudeDeg();
  380.             $lng $villes->getVilleLongitudeDeg();
  381.             $formule '(6371 * ACOS(COS(RADIANS(:lat)) * COS(RADIANS(c.VilleLatitudeDeg)) * COS(RADIANS(c.VilleLongitudeDeg) - RADIANS(:lng)) + SIN(RADIANS(:lat)) * SIN(RADIANS(c.VilleLatitudeDeg))))';
  382.             $query $em->createQuery("
  383.                     SELECT c.id,c.VilleNom, $formule as dist 
  384.                     FROM App\Entity\Villes c
  385.                     WHERE $formule  <= :distance order by dist asc  ")->setParameters([
  386.                 'lat' => $lat,
  387.                 'lng' => $lng,
  388.                 'distance' => $distance,
  389.             ]);
  390.             $cities $query->getResult();
  391.             foreach ($cities as $resVille) {
  392.                 array_push($citiesRes$resVille['id']);
  393.             }
  394.         }
  395.         $annoncesReq $annoncesRepository->findByMultiCriteres($categoriesSearch$citiesRes$pro$triSearch$motscles);
  396.         $annonces = array();
  397.         $i = -1;
  398.         foreach ($annoncesReq as $res) {
  399.             $i++;
  400.             $annonces[$i]['id'] = $res->getId();
  401.             $annonces[$i]['booste'] = $res->isBooster();
  402.             $annonces[$i]['titre'] = $res->getTitre();
  403.             $annonces[$i]['enseigne'] = $res->getUser()->getRaisonSociale();
  404.             $annonces[$i]['images'] = $res->getImages()[0]->getLien();
  405.             $annonces[$i]['pourcentRemise'] = $res->getPourcentRemise();
  406.             $annonces[$i]['prix'] = $res->getPrix();
  407.             $pourcent $res->getPourcentRemise() / 100;
  408.             $annonces[$i]['newprix'] = $res->getPrix() * $pourcent;
  409.             $fin strtotime($res->getDateFin()->format('Y-m-d H:i:s'));
  410.             $debut strtotime(date('Y-m-d H:i:s'));
  411.             $diff abs($debut $fin); // abs pour avoir la valeur absolute, ainsi éviter d'avoir une différence négative
  412.             $retour = array();
  413.             $tmp $diff;
  414.             $retour['second'] = $tmp 60;
  415.             $tmp floor(($tmp $retour['second']) / 60);
  416.             $retour['minute'] = $tmp 60;
  417.             $tmp floor(($tmp $retour['minute']) / 60);
  418.             $retour['hour'] = $tmp 24;
  419.             $tmp floor(($tmp $retour['hour'])  / 24);
  420.             $retour['day'] = $tmp 24;
  421.             $annonces[$i]['heures'] = $tmp 24 $retour['hour'];
  422.             $annonces[$i]['minutes'] = $retour['minute'];
  423.             $annonces[$i]['secondes'] = $retour['second'];
  424.             // CALCUL DE LA MOYENNE DE LANNONCE
  425.             $sum 0;
  426.             $moy 0;
  427.             $y 0;
  428.             foreach ($res->getNotesAnnonces() as $res2) {
  429.                 $y++;
  430.                 $sum $sum $res2->getNote();
  431.             }
  432.             if ($y 0) {
  433.                 $moy $sum $y;
  434.                 $moyAnnonce = (round($moy 2) / 2);
  435.             } else {
  436.                 $moyAnnonce 0;
  437.             }
  438.             $annonces[$i]['moyAnnonce'] = $moyAnnonce;
  439.             // CALCUL DE LA MOYENNE DE ENSEIGNE
  440.             $sum 0;
  441.             $moy 0;
  442.             $y 0;
  443.             $notesEns $notesEnseignesRepository->findBy(array('Enseigne'=>$res->getUser()));
  444.         foreach ($notesEns as $res2) {
  445.                 $y++;
  446.                 $sum $sum $res2->getNote();
  447.             }
  448.             $maxNote $y 5;
  449.             if ($maxNote 0) {
  450.                 $noteEnseigne = ($sum 100) / $maxNote;
  451.             } else {
  452.                 $noteEnseigne 0;
  453.             }
  454.             $annonces[$i]['moyEnseigne'] = $noteEnseigne;
  455.         }
  456.         $pagination $paginator->paginate(
  457.             $annonces/* query NOT result */
  458.             $request->query->getInt('page'1), /*page number*/
  459.             $nbParPage /*limit per page*/
  460.         );
  461.         return $this->render('default/annonces.html.twig', [
  462.             'categories' => $categoriesRepository->findAll(),
  463.             'annonces' => $pagination,
  464.             'ville' => $ville,
  465.             'distance' => $distance,
  466.             'categoriesSearch' => $categoriesSearch,
  467.             'triSearch' => $triSearch,
  468.             'nbParPage' => $nbParPage,
  469.             'pro' => $pro,
  470.             'motscles' => $motscles,
  471.             'favorisUser'=>$favorisUser,
  472.         ]);
  473.     }
  474.     /**
  475.      * @Route("/detailAnonnce/{id}", name="detailAnonnce")
  476.      */
  477.     public function detailAnonnce(CategoriesRepository $categoriesRepositoryRequest $request$idAnnoncesRepository $annoncesRepositoryNotesEnseignesRepository $notesEnseignesRepository): Response
  478.     {
  479.         // A dupliquer sur toutes les methodes
  480.         $session $request->getSession();
  481.         $user $this->getUser();
  482.         if (empty($session->get('type'))) {
  483.             $session->set('type''part');
  484.         }
  485.         if ($user) {
  486.             $session->set('type'$user->getType());
  487.         }
  488.         // Fin
  489.         $annoncesReq $annoncesRepository->findOneById($id);
  490.         $annoncesReq->setNbvues($annoncesReq->getNbVues() + 1);
  491.         $annoncesRepository->add($annoncesReqtrue);
  492.         $annonces['id'] = $annoncesReq->getId();
  493.         
  494.         $annonces['booste'] = $annoncesReq->isBooster();
  495.         $annonces['titre'] = $annoncesReq->getTitre();
  496.         $annonces['enseigne'] = $annoncesReq->getUser()->getRaisonSociale();
  497.         $annonces['logo'] = $annoncesReq->getUser()->getLogo();
  498.         $annonces['adresse'] = $annoncesReq->getUser()->getAdresse();
  499.         $annonces['cp'] = $annoncesReq->getVilles()->getVilleCodePostal();
  500.         $annonces['telephone'] = $annoncesReq->getUser()->getTelephone();
  501.         $annonces['ville'] = $annoncesReq->getVilles()->getVilleNom();
  502.         $annonces['images'] = $annoncesReq->getImages()[0]->getLien();
  503.         $annonces['pourcentRemise'] = $annoncesReq->getPourcentRemise();
  504.         $annonces['prix'] = $annoncesReq->getPrix();
  505.         $annonces['description'] = $annoncesReq->getDescription();
  506.         $annonces['quantite'] = $annoncesReq->getQuantite();
  507.         $annonces['debut'] = $annoncesReq->getDateDebut()->format('d-m-Y H:i');
  508.         $annonces['fin'] = $annoncesReq->getDateFin()->format('d-m-Y H:i');
  509.         // $annonces['pourcentRemise'] = $annoncesReq->getPourcentRemise();
  510.         $pourcent $annoncesReq->getPourcentRemise() / 100;
  511.         $annonces['newprix'] = $annoncesReq->getPrix() * $pourcent;
  512.         $fin strtotime($annoncesReq->getDateFin()->format('Y-m-d H:i:s'));
  513.         $debut strtotime(date('Y-m-d H:i:s'));
  514.         $diff abs($debut $fin); // abs pour avoir la valeur absolute, ainsi éviter d'avoir une différence négative
  515.         $retour = array();
  516.         $tmp $diff;
  517.         $retour['second'] = $tmp 60;
  518.         $tmp floor(($tmp $retour['second']) / 60);
  519.         $retour['minute'] = $tmp 60;
  520.         $tmp floor(($tmp $retour['minute']) / 60);
  521.         $retour['hour'] = $tmp 24;
  522.         $tmp floor(($tmp $retour['hour'])  / 24);
  523.         $retour['day'] = $tmp 24;
  524.         $annonces['heures'] = $tmp 24 $retour['hour'];
  525.         $annonces['minutes'] = $retour['minute'];
  526.         $annonces['secondes'] = $retour['second'];
  527.         // CALCUL DE LA MOYENNE DE LANNONCE
  528.         $sum 0;
  529.         $moy 0;
  530.         $y 0;
  531.         foreach ($annoncesReq->getNotesAnnonces() as $res2) {
  532.             $y++;
  533.             $sum $sum $res2->getNote();
  534.         }
  535.         if ($y 0) {
  536.             $moy $sum $y;
  537.             $moyAnnonce = (round($moy 2) / 2);
  538.         } else {
  539.             $moyAnnonce 0;
  540.         }
  541.         $annonces['moyAnnonce'] = $moyAnnonce;
  542.         // CALCUL DE LA MOYENNE DE ENSEIGNE
  543.         $sum 0;
  544.         $moy 0;
  545.         $y 0;
  546.         
  547.         $notesEns $notesEnseignesRepository->findBy(array('Enseigne' => $annoncesReq->getUser()));
  548.         foreach ($notesEns as $res2) {
  549.             $y++;
  550.             $sum $sum $res2->getNote();
  551.         }
  552.         $maxNote $y 5;
  553.         if ($maxNote 0) {
  554.             $noteEnseigne = ($sum 100) / $maxNote;
  555.         } else {
  556.             $noteEnseigne 0;
  557.         }
  558.         $annonces['moyEnseigne'] = $noteEnseigne;
  559.         return $this->render('default/detailAnonnce.html.twig', [
  560.             'annonce' => $annoncesReq,
  561.             
  562.             'res' => $annonces // Ajoutez cette ligne pour passer la variable 'res' à la vue
  563.         ]);
  564.     }
  565.     /**
  566.      * @Route("/update-rating", name="update_rating", methods={"POST"})
  567.      */
  568.     
  569.     /**
  570.      * @Route("/inscription", name="inscription")
  571.      */
  572.     public function inscription(Request $requestPaysRepository $paysRepositoryUserRepository $userRepositoryVillesRepository $villesRepository): Response
  573.     {
  574.         $session $request->getSession();
  575.         $session->set('type'$_GET['type']);
  576.         if ($_GET['type'] == 'pro') {
  577.             $type 'pro';
  578.             $role = array("ROLE_PRO");
  579.             $credit 100;
  580.         } else {
  581.             $type 'part';
  582.             $role = array("ROLE_PART");
  583.             $credit 0;
  584.         }
  585.         if ($type == 'part') {
  586.             $client = new User();
  587.             $formClient $this->createFormBuilder($client)
  588.                 ->add('nom'TextType::class, array('label' => false))
  589.                 ->add('prenom'TextType::class, array('label' => false))
  590.                 ->add('adresse'TextType::class, array('label' => false))
  591.                 ->add('codePostal'TextType::class, array('label' => false))
  592.                 ->add('telephone'TextType::class, array('label' => false))
  593.                 ->add('email'EmailType::class, array('label' => false))
  594.                 ->add('password'PasswordType::class, array('label' => false))
  595.                 ->getForm();
  596.         } else {
  597.             $client = new User();
  598.             $formClient $this->createFormBuilder($client)
  599.                 ->add('nom'TextType::class, array('label' => false))
  600.                 ->add('prenom'TextType::class, array('label' => false))
  601.                 ->add('adresse'TextType::class, array('label' => false))
  602.                 ->add('codePostal'TextType::class, array('label' => false))
  603.                 ->add('telephone'TextType::class, array('label' => false))
  604.                 ->add('email'EmailType::class, array('label' => false))
  605.                 ->add('logo'FileType::class, array('label' => false))
  606.                 ->add('password'PasswordType::class, array('label' => false))
  607.                 ->add('raisonSociale'TextType::class, array('label' => false))
  608.                 ->add('siret'TextType::class, array('label' => false))
  609.                 ->add('tva'TextType::class, array('label' => false))
  610.                 ->getForm();
  611.         }
  612.         //on génère le html du formulair
  613.         $formClientView $formClient->createView();
  614.         //On crée l'action pour ajouter en bdd
  615.         $formClient->handleRequest($request);
  616.         //si le formClient est soumis
  617.         if ($formClient->isSubmitted()) {
  618.             $ville $villesRepository->findOneById($_POST['ville']);
  619.             $pays $paysRepository->findOneById($_POST['pays']);
  620.             $clientExist $userRepository->findOneBy(array('email' => $_POST['form']['email']));
  621.             if ($type == 'pro') {
  622.                 $file $formClient->get('logo')->getData();
  623.                 if ($file != 'null') {
  624.                     $path '/';
  625.                     $fileName uniqid() . '-' $file->getClientOriginalName();
  626.                     $file->move(
  627.                         $this->getParameter('logos_directory') . $path,
  628.                         $fileName
  629.                     );
  630.                     $client->setLogo($fileName);
  631.                 }
  632.             }
  633.             if (!empty($clientExist)) {
  634.                 return $this->redirectToRoute('inscription', ['erreur' => 'email''type' => $type], Response::HTTP_SEE_OTHER);
  635.             }
  636.             $pass password_hash($_POST['form']['password'], PASSWORD_BCRYPT);
  637.             $client->setPassword($pass);
  638.             $client->setType($type);
  639.             $client->setRoles($role);
  640.             $client->setCivilite($_POST['genre']);
  641.             $client->setPays($pays);
  642.             $client->setVilles($ville);
  643.             $client->setCredits($credit);
  644.             $client->setCreated(new DateTime());
  645.             $userRepository->add($clienttrue);
  646.             return $this->redirectToRoute('app_login', [], Response::HTTP_SEE_OTHER);
  647.         }
  648.         return $this->render('default/inscription.html.twig', [
  649.             'form' => $formClientView,
  650.             'pays' => $paysRepository->findAll()
  651.         ]);
  652.     }
  653.     /**
  654.      * @Route("/profil", name="profil")
  655.      */
  656.     public function profil(Request $requestPaysRepository $paysRepositoryUserRepository $userRepositoryVillesRepository $villesRepository): Response
  657.     {
  658.       
  659.         $client $userRepository->findOneById($this->getUser());
  660.         $oldLogo $client->getLogo();
  661.         
  662.         $type $client->getType();
  663.         if ($type == 'part') {
  664.            
  665.             $formClient $this->createFormBuilder($client)
  666.                 ->add('nom'TextType::class, array('label' => false))
  667.                 ->add('prenom'TextType::class, array('label' => false))
  668.                 ->add('adresse'TextType::class, array('label' => false))
  669.                 ->add('codePostal'TextType::class, array('label' => false))
  670.                 ->add('telephone'TextType::class, array('label' => false))
  671.                 ->add('email'EmailType::class, array('label' => false))
  672.                
  673.                 ->getForm();
  674.         } else {
  675.            
  676.             $formClient $this->createFormBuilder($client)
  677.                 ->add('nom'TextType::class, array('label' => false))
  678.                 ->add('prenom'TextType::class, array('label' => false))
  679.                 ->add('adresse'TextType::class, array('label' => false))
  680.                 ->add('codePostal'TextType::class, array('label' => false))
  681.                 ->add('telephone'TextType::class, array('label' => false))
  682.                 ->add('email'EmailType::class, array('label' => false))
  683.                 ->add('logo'FileType::class, array('label' => false'data_class' => null'required'=>false))
  684.                 
  685.                 ->add('raisonSociale'TextType::class, array('label' => false))
  686.                 ->add('siret'IntegerType::class, array('label' => false'required'=>false))
  687.                 ->add('tva'TextType::class, array('label' => false'required'=>false))
  688.                 ->getForm();
  689.         }
  690.         //on génère le html du formulair
  691.         $formClientView $formClient->createView();
  692.         //On crée l'action pour ajouter en bdd
  693.         $formClient->handleRequest($request);
  694.         //si le formClient est soumis
  695.         if ($formClient->isSubmitted()) {
  696.             $ville $villesRepository->findOneById($_POST['ville']);
  697.             $pays $paysRepository->findOneById($_POST['pays']);
  698.             $clientExist $userRepository->findOneBy(array('email' => $_POST['form']['email']));
  699.             if (!empty($clientExist)) {
  700.                 if($clientExist->getId() != $client->getId())
  701.                 {
  702.                 return $this->redirectToRoute('profil', ['erreur' => 'email'], Response::HTTP_SEE_OTHER);
  703.                 }
  704.             }
  705.             if ($type == 'pro') {
  706.                 $file $formClient->get('logo')->getData();
  707.                 if (!empty($file)) {
  708.                     $path '/';
  709.                     $fileName uniqid() . '-' $file->getClientOriginalName();
  710.                     $file->move(
  711.                         $this->getParameter('logos_directory') . $path,
  712.                         $fileName
  713.                     );
  714.                     $client->setLogo($fileName);
  715.                 }
  716.                 else
  717.                 {
  718.                     $client->setLogo($oldLogo);
  719.                 }
  720.             }
  721.             $client->setPays($pays);
  722.             $client->setVilles($ville);
  723.             
  724.             $userRepository->add($clienttrue);
  725.             return $this->redirectToRoute('profil', [], Response::HTTP_SEE_OTHER);
  726.         }
  727.         if(!empty($_POST['new1']))
  728.         {
  729.             $pass password_hash($_POST['new1'], PASSWORD_BCRYPT);
  730.             $client->setPassword($pass);
  731.             $userRepository->add($clienttrue);
  732.         }
  733.         
  734.         return $this->render('default/profil.html.twig', [
  735.             'pays'=>$paysRepository->findAll(),
  736.             'form' => $formClientView,
  737.         ]);
  738.     }
  739.     /**
  740.      * @Route("/favoris", name="favoris")
  741.      */
  742.     public function favoris(Request $request$id 1AnnoncesRepository $annoncesRepositoryFavorisRepository $favorisRepository): Response
  743.     {
  744.         $session $request->getSession();
  745.         $session->set('type''part');
  746.         $user $this->getUser();
  747.         $annonces = array();
  748.         $annoncesRes $favorisRepository->findBy(['User'=>$user]);
  749.         $annonces = array();
  750.         $i = -1;
  751.        
  752.             
  753.         foreach($annoncesRes as $res)
  754.         {
  755.             
  756.             $i++;
  757.             $annonces[$i]['id'] = $res->getAnnonces()->getId();
  758.             $annonces[$i]['booste'] = $res->getAnnonces()->isBooster();
  759.             $annonces[$i]['titre'] = $res->getAnnonces()->getTitre();
  760.             $annonces[$i]['enseigne'] = $res->getUser()->getRaisonSociale();
  761.             $annonces[$i]['images'] = $res->getAnnonces()->getImages()[0]->getLien();
  762.             $annonces[$i]['pourcentRemise'] = $res->getAnnonces()->getPourcentRemise();
  763.             $annonces[$i]['prix'] = $res->getAnnonces()->getPrix();
  764.             $pourcent $res->getAnnonces()->getPourcentRemise() / 100;
  765.             $annonces[$i]['newprix'] = $res->getAnnonces()->getPrix() * $pourcent;
  766.             $fin strtotime($res->getAnnonces()->getDateFin()->format('Y-m-d H:i:s'));
  767.             $debut strtotime(date('Y-m-d H:i:s'));
  768.             $diff abs($debut $fin); // abs pour avoir la valeur absolute, ainsi éviter d'avoir une différence négative
  769.             $retour = array();
  770.             $tmp $diff;
  771.             $retour['second'] = $tmp 60;
  772.             $tmp floor(($tmp $retour['second']) / 60);
  773.             $retour['minute'] = $tmp 60;
  774.             $tmp floor(($tmp $retour['minute']) / 60);
  775.             $retour['hour'] = $tmp 24;
  776.             $tmp floor(($tmp $retour['hour'])  / 24);
  777.             $retour['day'] = $tmp 24;
  778.             $annonces[$i]['heures'] = $tmp 24 $retour['hour'];
  779.             $annonces[$i]['minutes'] = $retour['minute'];
  780.             $annonces[$i]['secondes'] = $retour['second'];
  781.             // CALCUL DE LA MOYENNE DE LANNONCE
  782.             $sum 0;
  783.             $moy 0;
  784.             $y 0;
  785.             foreach ($res->getAnnonces()->getNotesAnnonces() as $res2) {
  786.                 $y++;
  787.                 $sum $sum $res2->getNote();
  788.             }
  789.             if ($y 0) {
  790.                 $moy $sum $y;
  791.                 $moyAnnonce = (round($moy 2) / 2);
  792.             } else {
  793.                 $moyAnnonce 0;
  794.             }
  795.             $annonces[$i]['moyAnnonce'] = $moyAnnonce;
  796.             // CALCUL DE LA MOYENNE DE ENSEIGNE
  797.             $sum 0;
  798.             $moy 0;
  799.             $y 0;
  800.             foreach ($res->getUser()->getNotesEnseignes() as $res2) {
  801.                 $y++;
  802.                 $sum $sum $res2->getNote();
  803.             }
  804.             $maxNote $y 5;
  805.             if ($maxNote 0) {
  806.                 $noteEnseigne = ($sum 100) / $maxNote;
  807.             } else {
  808.                 $noteEnseigne 0;
  809.             }
  810.             $annonces[$i]['moyEnseigne'] = $noteEnseigne;
  811.         }
  812.         return $this->render('default/favoris.html.twig', [
  813.             'annonce' => $annonces,
  814.             
  815.         ]);
  816.     }
  817.     /**
  818.      * @Route("/addFavoris", name="addFavoris")
  819.      */
  820.     public function addFavoris(Request $requestAnnoncesRepository $annoncesRepositoryFavorisRepository $favorisRepository): Response
  821.     {
  822.         $user $this->getUser();
  823.         $id $_POST['id'];
  824.         $etat $_POST['etat'];
  825.         
  826.         $annonce $annoncesRepository->findOneById($id);
  827.         if($etat == 'non active')
  828.         {
  829.         $favoris = new Favoris();
  830.         $favoris->setUser($user);
  831.         $favoris->setDate(new Datetime);
  832.         $favoris->setAnnonces($annonce);
  833.         $favorisRepository->add($favoristrue);
  834.         }
  835.         else
  836.         {
  837.             $favoris $favorisRepository->findOneBy(array('User'=>$user,'Annonces'=>$annonce));
  838.             
  839.             $favorisRepository->remove($favoristrue);
  840.         }
  841.         return new Response('ok');
  842.         
  843.     }
  844.       /**
  845.      * @Route("/addAlertes", name="addAlertes")
  846.      */
  847.    /**
  848.  * @Route("/addAlertes", name="addAlertes")
  849.  */
  850. public function addAlertes(Request $requestAnnoncesRepository $annoncesRepositoryFavorisRepository $favorisRepository): Response
  851. {
  852.     $entityManager $this->getDoctrine()->getManager();
  853.     $villeId $request->request->get('ville');
  854.     $rayon $request->request->get('rayon');
  855.     $categorieId $request->request->get('categorie');
  856.     $texte $request->request->get('texte');
  857.     $userId $this->getUser()->getId();
  858.     // Récupérer les instances des entités liées (Villes, Categories, User)
  859.     $ville $entityManager->getRepository(Villes::class)->find($villeId);
  860.     $categorie $entityManager->getRepository(Categories::class)->find($categorieId);
  861.     $user $entityManager->getRepository(User::class)->find($userId);
  862.     // Créer une nouvelle alerte avec les données du formulaire
  863.     $alerte = new Alertes();
  864.     $alerte->setVilles($ville);
  865.     $alerte->setRayon($rayon);
  866.     $alerte->setCategories($categorie);
  867.     $alerte->setTexte($texte);
  868.     $alerte->setUser($user);
  869.     // Enregistrer l'alerte dans la base de données
  870.     $entityManager->persist($alerte);
  871.     $entityManager->flush();
  872.     // Retourner une réponse indiquant que l'alerte a été ajoutée avec succès
  873.     return new Response("Alerte ajoutée avec succès"Response::HTTP_CREATED);
  874. }
  875.       /**
  876.      * @Route("/contact", name="contact")
  877.      */
  878.     public function contact(Request $request): Response
  879.     {
  880.         $lienAnnonce '';
  881.         if(isset($_GET['id']))
  882.         {
  883.             $lienAnnonce =  $request->headers->get('referer');
  884.         }
  885.      
  886.         
  887.         return $this->render('default/contact.html.twig', [
  888.             'lienAnnonce'=>$lienAnnonce
  889.           
  890.             
  891.         ]);
  892.     }
  893.     /**
  894.      * @Route("/achatFacture", name="achatFacture")
  895.      */
  896.     
  897.      public function achatFacture(Request $request): Response
  898.      {
  899.         return $this->render('default/achatGenerationFacture.html.twig');
  900.      }
  901.      /**
  902.     * @Route("/notesEnseignes", name="notesEnseignes")
  903.     */
  904.     public function notesEnseignes(Request $requestNotesEnseignesRepository $notesEnseignesRepository): Response
  905.     {
  906.     $notes $notesEnseignesRepository->findBy(['Enseigne'=>$this->getUser()],['Date'=>'desc']);
  907.     // CALCUL DE LA MOYENNE DE ENSEIGNE
  908.     $sum 0;
  909.     $moy 0;
  910.     $y 0;
  911.     $noteEnseigne 0;
  912.     foreach ($notes as $res2) {
  913.         $y++;
  914.         $sum $sum $res2->getNote();
  915.     }
  916.     if ($y 0) {
  917.         $noteEnseigne $sum $y;
  918.     }
  919.     return $this->render('default/notesEnseignes.html.twig', [
  920.         'notes' => $notes,
  921.         'noteEnseigne' => $noteEnseigne
  922.     ]);
  923. }
  924.          /**
  925.      * @Route("/notesAnnonces/{id}", name="notesAnnonces")
  926.      */
  927.     public function notesAnnonces(Request $requestNotesAnnoncesRepository $notesAnnoncesRepository,$id): Response
  928.     {
  929.     
  930.         
  931.         $notes $notesAnnoncesRepository->findBy(['Annonces'=>$id],['Date'=>'desc']);
  932.         // CALCUL DE LA MOYENNE DE ENSEIGNE
  933.         $sum 0;
  934.         $moy 0;
  935.         $y 0;
  936.         $noteAnnonces 0;
  937.         foreach ($notes as $res2) {
  938.             $y++;
  939.             $sum $sum $res2->getNote();
  940.         }
  941.         if($y 0)
  942.         {
  943.         $noteAnnonces $sum/$y;
  944.         }
  945.        
  946.         return $this->render('default/notesAnnonces.html.twig', [
  947.             'notes'=>$notes,
  948.             'noteAnnonces'=>$noteAnnonces
  949.         
  950.            
  951.           
  952.             
  953.         ]);
  954.     }
  955.     
  956.      /**
  957.      * @Route("/mesAnnonces/{type}", name="mesAnnonces")
  958.      */
  959.     public function mesAnnonces(Request $requestAnnoncesRepository $annoncesRepositoryFavorisRepository $favorisRepository,$type): Response
  960.     {
  961.         $user $this->getUser();
  962.         $annonces = array();
  963.         if($type == 'encours')
  964.         {
  965.             $annoncesRes $annoncesRepository->findByAnnoncesEnCours($user->getId());
  966.         }
  967.         else
  968.         {
  969.             $annoncesRes $annoncesRepository->findByAnnoncesExpire($user->getId());
  970.         }
  971.         $annonces = array();
  972.         $i = -1;
  973.        
  974.             
  975.         foreach($annoncesRes as $res)
  976.         {
  977.             
  978.             $i++;
  979.             $annonces[$i]['id'] = $res->getId();
  980.             $annonces[$i]['booste'] = $res->isBooster();
  981.             $annonces[$i]['titre'] = $res->getTitre();
  982.             $annonces[$i]['enseigne'] = $res->getUser()->getRaisonSociale();
  983.             // Vérifier si l'annonce a des images
  984.             $image $res->getImages()[0] ?? null;
  985.             $annonces[$i]['images'] = $image $image->getLien() : null;
  986.             $annonces[$i]['pourcentRemise'] = $res->getPourcentRemise();
  987.             $annonces[$i]['prix'] = $res->getPrix();
  988.             $annonces[$i]['nbVues'] = $res->getNbVues();
  989.             $pourcent $res->getPourcentRemise() / 100;
  990.             $annonces[$i]['newprix'] = $res->getPrix() * $pourcent;
  991.             $fin strtotime($res->getDateFin()->format('Y-m-d H:i:s'));
  992.             $debut strtotime(date('Y-m-d H:i:s'));
  993.             $diff abs($debut $fin); // abs pour avoir la valeur absolute, ainsi éviter d'avoir une différence négative
  994.             $retour = array();
  995.             $tmp $diff;
  996.             $retour['second'] = $tmp 60;
  997.             $tmp floor(($tmp $retour['second']) / 60);
  998.             $retour['minute'] = $tmp 60;
  999.             $tmp floor(($tmp $retour['minute']) / 60);
  1000.             $retour['hour'] = $tmp 24;
  1001.             $tmp floor(($tmp $retour['hour'])  / 24);
  1002.             $retour['day'] = $tmp 24;
  1003.             $annonces[$i]['heures'] = $tmp 24 $retour['hour'];
  1004.             $annonces[$i]['minutes'] = $retour['minute'];
  1005.             $annonces[$i]['secondes'] = $retour['second'];
  1006.             // CALCUL DE LA MOYENNE DE LANNONCE
  1007.             $sum 0;
  1008.             $moy 0;
  1009.             $y 0;
  1010.             foreach ($res->getNotesAnnonces() as $res2) {
  1011.                 $y++;
  1012.                 $sum $sum $res2->getNote();
  1013.             }
  1014.             if ($y 0) {
  1015.                 $moy $sum $y;
  1016.                 $moyAnnonce = (round($moy 2) / 2);
  1017.             } else {
  1018.                 $moyAnnonce 0;
  1019.             }
  1020.             $annonces[$i]['moyAnnonce'] = $moyAnnonce;
  1021.             // CALCUL DE LA MOYENNE DE ENSEIGNE
  1022.             $sum 0;
  1023.             $moy 0;
  1024.             $y 0;
  1025.             foreach ($res->getUser()->getNotesEnseignes() as $res2) {
  1026.                 $y++;
  1027.                 $sum $sum $res2->getNote();
  1028.             }
  1029.             $maxNote $y 5;
  1030.             if ($maxNote 0) {
  1031.                 $noteEnseigne = ($sum 100) / $maxNote;
  1032.             } else {
  1033.                 $noteEnseigne 0;
  1034.             }
  1035.             $annonces[$i]['moyEnseigne'] = $noteEnseigne;
  1036.         }
  1037.         return $this->render('default/mesAnnonces.html.twig', [
  1038.             'annonces' => $annonces,
  1039.             'type'=>$type
  1040.             
  1041.         ]);
  1042.     }
  1043.       /**
  1044.      * @Route("/paiement", name="paiement")
  1045.      */
  1046.     public function paiement(): Response
  1047.     {
  1048.       
  1049.        
  1050.        /* $tpe = '7199003';
  1051.         $total = 62.73;
  1052.         $societe='MODIXOM';
  1053.         $version = "3.0";
  1054.         $email = 'cedric@aready.io';
  1055.         $ref = 'test1234';
  1056.         $context = array();
  1057.         $context['billing']['firstName'] ='test';
  1058.         $context['billing']['lastName'] ='test';
  1059.         $context['billing']['addressLine1'] ='test';
  1060.         $context['billing']['city'] ='test';
  1061.         $context['billing']['postalCode'] ='1234';
  1062.         $context['billing']['country'] ='FR';
  1063.         $context['shipping']['firstName'] ='test';
  1064.         $context['shipping']['lastName'] ='test';
  1065.         $context['shipping']['addressLine1'] ='test';
  1066.         $context['shipping']['city'] ='test';
  1067.         $context['shipping']['postalCode'] ='1234';
  1068.         $context['shipping']['country'] ='FR';
  1069.         $context['shipping']['email'] ='cedric@aready.io';
  1070.         $context['shipping']['phone'] ='+33785864783';
  1071.         $context['shipping']['shipIndicator'] ='billing_address';
  1072.         $context['shipping']['deliveryTimeframe'] ='two_day';
  1073.         $context['shipping']['firstUseDate'] ='2023-11-13';
  1074.         $context['shipping']['matchBillingAddress'] =true;
  1075.         $context['client']['email'] ='cedric@aready.io';
  1076.         $context['client']['phone'] ='+33785864783';
  1077.         $context['client']['birthCity'] ='Colmar';
  1078.         $context['client']['birthPostalCode'] ='68000';
  1079.         $context['client']['birthCountry'] ='FR';
  1080.         $context['client']['birthdate'] ='1987-03-27';
  1081.         $con = json_encode($context);
  1082.         $con2 = base64_encode($con);*/
  1083. echo "ok";
  1084. $date date('d/m/Y:h:i:s');
  1085. // contexte commande de la doc
  1086. $contextCmd 'ewogICAiYmlsbGluZyI6ewogICAgICAiZmlyc3ROYW1lIjoiSsOpcsOpbXkiLAogICAgICAibGFzdE5hbWUiOiJHcmltbSIsCiAgICAgICJhZGRyZXNzTGluZTEiOiIzIHJ1ZSBkZSBsJ8OpZ2xpc2UiLAogICAgICAiY2l0eSI6Ik9zdGhlaW0iLAogICAgICAicG9zdGFsQ29kZSI6IjY4MTUwIiwKICAgICAgImNvdW50cnkiOiJGUiIKICAgfSwKICAgInNoaXBwaW5nIjp7CiAgICAgICJmaXJzdE5hbWUiOiJKw6lyw6lteSIsCiAgICAgICJsYXN0TmFtZSI6IkdyaW1tIiwKICAgICAgImFkZHJlc3NMaW5lMSI6IjMgcnVlIGRlIGwnw6lnbGlzZSIsCiAgICAgICJjaXR5IjoiT3N0aGVpbSIsCiAgICAgICJwb3N0YWxDb2RlIjoiNjgxNTAiLAogICAgICAiY291bnRyeSI6IkZSIiwKICAgICAgImVtYWlsIjoiamVyZW02OEBob3RtYWlsLmNvbSIsCiAgICAgICJwaG9uZSI6IiszMy02MTIzNDU2NzgiLAogICAgICAic2hpcEluZGljYXRvciI6ImJpbGxpbmdfYWRkcmVzcyIsCiAgICAgICJkZWxpdmVyeVRpbWVmcmFtZSI6InR3b19kYXkiLAogICAgICAiZmlyc3RVc2VEYXRlIjoiMjAxNy0wMS0yNSIsCiAgICAgICJtYXRjaEJpbGxpbmdBZGRyZXNzIjp0cnVlCiAgIH0sCiAgICJjbGllbnQiOnsKICAgICAgImVtYWlsIjoiamVyZW02OEBob3RtYWlsLmNvbSIsCiAgICAgICJtb2JpbGVQaG9uZSI6IiszMy02MTIzNDU2NzgiLAogICAgICAiYmlydGhDaXR5IjoiQ29sbWFyIiwKICAgICAgImJpcnRoUG9zdGFsQ29kZSI6IjY4MDAwIiwKICAgICAgImJpcnRoQ291bnRyeSI6IkZSIiwKICAgICAgImJpcnRoZGF0ZSI6IjE5ODctMDMtMjciCiAgIH0KfQ==';
  1087. // Clé secrète du compte
  1088. $cle_secrete '9CC0C314AA4843441B1E1FB90A1BD992D4AD4A94'
  1089. // Générer sceau mac
  1090. $mac "TPE=7199003*contexte_commande=".$contextCmd."*date=".$date."*lgue=FR*mail=contact@modixom.fr*montant=62.73EUR*reference=MODIXOM1234*societe=modixom*texte-libre=ExempleTexteLibre*version=3.0";
  1091. echo $mac;
  1092.     // Calcul du sceau MAC avec HMAC-SHA1
  1093.     $sceau_mac hash_hmac('sha1'$mac$cle_secrete,false);
  1094.   
  1095.         return $this->render('default/paiement.html.twig', [
  1096.             "mac"=>$sceau_mac,
  1097.             'date'=>$date,
  1098.             'contextCmd'=>$contextCmd
  1099.            
  1100.         ]);
  1101.     }
  1102.     /**
  1103.      * @Route("/retourpaiement", name="retourpaiement")
  1104.      */
  1105.     public function retourpaiement(): Response
  1106.     {
  1107.         dd('ok');
  1108.     }
  1109. }