src/Controller/AccountFormController.php line 1044

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Exception;
  4. use App\Entity\Image;
  5. use App\Form\TestType;
  6. use App\Form\ImageType;
  7. use App\Entity\AccountForm;
  8. use App\Entity\ImageProfil;
  9. use App\Entity\ImageGallery;
  10. use App\Form\AccountFormType;
  11. use App\Form\ImageSingleType;
  12. use App\Form\ImageGalleryType;
  13. use PhpParser\Node\Stmt\TryCatch;
  14. use App\Repository\UserRepository;
  15. use App\Form\ImageGalleryItemsType;
  16. use App\Repository\ImageRepository;
  17. use App\Repository\OrdersRepository;
  18. use Symfony\Component\Asset\Package;
  19. use App\Service\Payment\StripeService;
  20. use Doctrine\ORM\PersistentCollection;
  21. use App\Service\Payment\MangopayService;
  22. use App\Service\PushNotificationService;
  23. use App\Repository\AccountFormRepository;
  24. use App\Repository\ImageProfilRepository;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Stripe\Exception\UnexpectedValueException;
  27. use Symfony\Component\HttpFoundation\Response;
  28. use Symfony\Component\Routing\Annotation\Route;
  29. use App\Repository\ItemsGalleryVitrineRepository;
  30. use Symfony\Component\HttpFoundation\JsonResponse;
  31. use Stripe\Exception\SignatureVerificationException;
  32. use Symfony\Component\Serializer\Encoder\JsonDecode;
  33. use App\Repository\SubscriptionPushServiceRepository;
  34. use Symfony\Component\HttpFoundation\Session\Session;
  35. use Symfony\Component\Routing\Generator\UrlGenerator;
  36. use Symfony\Component\HttpFoundation\StreamedResponse;
  37. use Symfony\Component\Form\Extension\Core\Type\DateType;
  38. use Symfony\Component\Form\Extension\Core\Type\FileType;
  39. use Symfony\Component\Form\Extension\Core\Type\TextType;
  40. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  41. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  42. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  43. use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
  44. use Doctrine\ORM\EntityManager;
  45. use Doctrine\ORM\EntityManagerInterface;
  46. use Doctrine\ORM\Mapping\Entity;
  47. use Stripe\Stripe;
  48. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  49. use Symfony\Bundle\MakerBundle\Str;
  50. use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
  51. use Symfony\Component\HttpFoundation\File\Exception\FileException;
  52. use Symfony\Component\Validator\Validator\ValidatorInterface;
  53. class AccountFormController extends AbstractController
  54. {
  55.     private $stripeApi;
  56.     public function __construct(UrlGeneratorInterface $urlGeneratorInterfaceEntityManagerInterface $em)
  57.     {
  58.       $this->stripeApi = new StripeService($urlGeneratorInterface,$em);    
  59.     }
  60.   /**
  61.      * @Route("/setMangoPayCredentials", name="register.mangopay")
  62.      */
  63.     public function setMangoPayCredentials(AccountFormRepository $accountFormRepositoryMangopayService $mangopayService)
  64.     {
  65.       $accountForms $accountFormRepository->findAll();
  66.       foreach($accountForms as $accountForm ){
  67.         if (!$accountForm->getMangopayUserId()){
  68.           //$mangoPayUser = $mangopayService->createMangoUserLegal($accountForm);
  69.           //$mangopayService->createWallet()
  70.         };
  71.       }
  72.       return new JsonResponse("Modifications effectuées");
  73.     }
  74.   /**
  75.    * @Route("/get-start/{id}", name="register.start" )
  76.    */
  77.   public function getStart($idrequest $requestAccountFormRepository $accountFormRepository)
  78.   {
  79.     // ceci est un test git remote 
  80.     // get the user which are rated the pro from the database
  81.     $accountForm $accountFormRepository->find($id);
  82.     $arrStart  $accountForm->getStart();
  83.     //$arrUserRating = (empty($arrStart)) ? ['users'] :json_decode($arrStart,true);
  84.     $arrUserRating = [];
  85.     $arrUserRating['users'] = 0;
  86.     $sumStart 0;
  87.     // get the number of starts form the input 
  88.     $start $request->request->get('start');
  89.     // get the logged user's id 
  90.     if($this->getUser() !== null){
  91.       $userId =$this->getUser()->getId();
  92.       // if user already rate the pro
  93.       if($arrUserRating !== null){
  94.         $userHasRated array_key_exists($userId$arrUserRating);
  95.         if($userHasRated){
  96.           $this->addFlash('notice''Votre avis est déjà enregistré');
  97.         } 
  98.       }
  99.         if($start !== null && $userId !== null ){
  100.           // set the $arrUserRating
  101.          /* if(empty($arrUserRating)){
  102.             $arrUserRating[''] = array('users');
  103.           }*/
  104.           $arrUserRating['users'] += ['Id' => $userId'startGiven' => $start];
  105.           $arrUserRatingDecoded json_encode($arrUserRating);
  106.           $accountForm->setStart($arrUserRatingDecoded);
  107.           $em $this->getDoctrine()->getManager();
  108.           $em->persist($accountForm);
  109.           $em->flush();
  110.         }
  111.     }
  112.     //$arrStartUpdated = json_decode($arrStartUpdated);
  113.     //$arrStartUpdated = ($arrStartUpdated !== null) ? $arrStartUpdated: array();
  114.     //dd($arrUserRating['users']['startGiven']);
  115.     $nbStart count($arrUserRating);
  116.     if($nbStart 0){
  117.       foreach( $arrUserRating as $userRating ){
  118.         $sumStart += $userRating['startGiven'];
  119.       }
  120.       $averageStart $sumStart/$nbStart;
  121.       $startReviews[] =array('average_start' => round($averageStart), 'nb_start' => $nbStart'sumStart' => $sumStart); 
  122.     }else{
  123.       $startReviews[] =array('average_start' => 0'nb_start' => 0'sumStart' => 0); 
  124.     }
  125.   
  126.     $startReviews json_encode($startReviews);
  127.     return new Response($startReviews);
  128.   }
  129.   /**
  130.   *
  131.   *@Route("/account-register/shop/{id}", name="account.shop.register", methods={"GET", "POST"})
  132.   */
  133.   public function AccountShopRegister(Request $requestAccountFormRepository $accountFormRepositoryUserRepository $UserRepository$idSubscriptionPushServiceRepository $subscriptionPushServiceRepositoryPushNotificationService $pushNotificationServiceImageProfilRepository $imageProfilRepository)
  134.     {
  135.     $this->denyAccessUnlessGranted('ROLE_USER');
  136.         $accountForm $accountFormRepository->find($id);
  137.         $userFecht $this->getUser();
  138.         if ( $accountForm )
  139.         {
  140.           $accountForm->setUser($userFecht);
  141.           $userHasAccountUser true
  142.           $hasStripeAccountConnected $accountForm->getStripeAccountConnectedId();
  143.           $form $this->createForm(AccountFormType::class, $accountForm);
  144.         } 
  145.           else 
  146.         {
  147.           $userHasAccountUser false;
  148.           $AccountForm = new AccountForm();
  149.           $AccountForm->setNom($userFecht->getLastname());
  150.           $AccountForm->setPrenom($userFecht->getFirstname());
  151.           $AccountForm->setTelephone($userFecht->getPhone());
  152.           $form $this->createForm(AccountFormType::class, $AccountForm);
  153.           $hasStripeAccountConnected null;
  154.         }
  155.           $form->handleRequest($request);
  156.           if ($form->isSubmitted() && $form->isValid())
  157.           {
  158.                $newAccountForm $form->getData();
  159.                //$identityProof = $form->get('identityProof')->getData();
  160.                $EntityManager $this->getDoctrine()->getManager();    
  161.                
  162.                if( !$userHasAccountUser ){
  163.                  $userFecht->setAccountForm($newAccountForm);
  164.                  $newAccountForm->setUser($userFecht);
  165.                 }  
  166.                 try{
  167.                   $email $userFecht->getEmail();
  168.                   $newAccountForm->setMail($email);
  169.                   $EntityManager->persist($userFecht);
  170.                   $EntityManager->persist($newAccountForm);
  171.                   $EntityManager->flush();
  172.                   if($hasStripeAccountConnected === null){
  173.                     $this->stripeApi->createStripeAccountConnected($newAccountForm);
  174.                   }
  175.                   // $image = $imageProfilRepository->findBy(['user' => $newAccountForm->getUser()->getId()]);
  176.                   //$imageUrl = ($image != null ) ? "https://coasttocorner.com/images/profils/{$AccountForm->getUser()->getEmail()}/{$image[0]->getUrlImage()}" : '';
  177.                   //$payload = ['title'=> "Nouveau Restaurant : {$newAccountForm->getMarque()} ",'body' => " Localisation : {$newAccountForm->getVille()} {$newAccountForm->getCodePostal()} \n{$newAccountForm->getDescription()} ", 'url' => "https://coasttocorner.com/category/{$newAccountForm->getCategory()}/store{$newAccountForm->getId()}", 'image' => $imageUrl]; 
  178.                   //$pushNotificationService->pushNotification($subscriptionPushServiceRepository, $payload);
  179.                  return $this->redirectToRoute('profil.user');
  180.            } catch(Exception $e){
  181.             echo $e->getMessage();
  182.             $this->addFlash('error''Une erreur est survenue lors de la création de votre compte professionnel : '.$e->getMessage().'. Veuillez réessayer.');
  183.           }
  184.         } else{
  185.           //var_dump($form);
  186.           //die(); 
  187.         }
  188.         return $this->render('account.html.twig', [
  189.             'form' => $form->createView(),
  190.         ]);
  191.       }
  192.   /**
  193.    * 
  194.    * @Route("/update/account-connected",name="updateAccountConnected",methods={"GET","POST"})
  195.    */
  196.   public function updateAccountConnected(AccountFormRepository $accountFormRepositoryStripeService $stripeApi){
  197.     $user $this->getUser();
  198.     $accountForm $accountFormRepository->findOneBy(['user'=> $user->getId()]);
  199.     $accountConnectedId $stripeApi->createStripeAccountConnected($accountForm);
  200.     $accountForm->setStripeAccountConnectedId($accountConnectedId);
  201.     return new JsonResponse("Modifications effectuées");
  202.   }
  203.   /**
  204.    * 
  205.    * @Route("/update/account-connected",name="updateAccountConnected",methods={"GET","POST"})
  206.    */
  207. public function verificationSession(AccountFormRepository $accountFormRepositoryStripeService $stripeApi){
  208.   $user $this->getUser();
  209.   $accountForm $accountFormRepository->findOneBy(['user'=> $user->getId()]);
  210.   $accountConnected $accountForm->getStripeAccountConnectedId();
  211.   $session $stripeApi->verificationSession($accountConnected);
  212.   return $this->redirect($session->url);
  213. }
  214. /**
  215.  * @Route("/update/verification-session/{accountConnected}",name="updateVerificationSession",methods={"GET","POST"})
  216.  */
  217. public function updateVerificationSession(AccountFormRepository $accountFormRepositoryStripeService $stripeApi$accountConnected){
  218.   $account $stripeApi->updateVerificationSession($accountConnected);
  219.   return new JsonResponse("Modifications effectuées");
  220. }
  221.   /**
  222.    * 
  223.    * @Route("/create-kyc/", name="kyc", methods={"GET","POST"})
  224.    */
  225.   public function createKyc(AccountFormRepository $accountFormRepositoryMangopayService $mangopayService){
  226.     $this->denyAccessUnlessGranted('ROLE_USER');
  227.     $user $this->getUser();
  228.     $accountForm $accountFormRepository->findBy(array('user' => $user->getId()));
  229.     if (!$accountForm){
  230.       return  new Response('Veuillez créer un compte professionel avant de compléter votre dossier professionnel en vous rendant sur <a href='.$this->generateUrl("account.shop.register", array('id'=>$user->getId())).'> créer mon compte restaurant/épicerie</a>.');
  231.     }
  232.     $mangoPayUserId $accountForm[0]->getMangopayUserId();
  233.     $kyc $mangopayService->createKyc($mangoPayUserId);
  234.     return new Response("<p>Votre kyc a été créé avec succès.</p>");
  235.   }
  236.   /**
  237.    * 
  238.    * @Route("/create-page-kyc/", name="page-kyc", methods={"GET","POST"})
  239.    */
  240.   public function CreateKycPageFromFile(AccountFormRepository $accountFormRepositoryMangopayService $mangopayService){
  241.     $this->denyAccessUnlessGranted('ROLE_USER');
  242.     $user $this->getUser();
  243.     $accountForm $accountFormRepository->findBy(array('user' => $user->getId()));
  244.     if (!$accountForm){
  245.       return  new Response('Veuillez créer un compte professionel avant de compléter votre dossier professionnel en vous rendant sur <a href='.$this->generateUrl("account.shop.register", array('id'=>$user->getId())).'> créer mon compte restaurant/épicerie</a>.');
  246.     }
  247.     $mangoPayUserId $accountForm[0]->getMangopayUserId();
  248.     $kyc $mangopayService->createKyc($mangoPayUserId);
  249.     $mangopayService->CreateKycPageFromFile($mangoPayUserId$kyc'' );
  250.     return new Response("<p>Votre kyc a été créé avec succès.</p>");
  251.   }
  252.   /**
  253.   *
  254.   *@Route("/account-register/shop/image-gallery/{id}", name="account.shop.image.gallery.register", methods={"GET", "POST"})
  255.   */
  256.   public function AccountShopImageGalleryRegister(Request $requestUserRepository $UserRepositoryImageRepository $ImageRepository,ImageRepository $imageRepository,ItemsGalleryVitrineRepository $ItemsGalleryVitrineRepository$id)
  257.     {
  258.         // creates a task and gives it some dummy data for this example
  259.         $userFecht $UserRepository->find($id);
  260.         $userId $userFecht->getId();
  261.         $AccountForm $userFecht->getAccountForm();
  262.         // Display mains images 
  263.        // $ImageFecht = $ImageRepository->findOneBy( ["accountForm" => $AccountForm->getId()], ["position" => 1]) ;
  264.         $ImageFecht_1 $ImageRepository->findImageByPosition($AccountForm->getId(), );
  265.         $ImageFecht_2 $ImageRepository->findImageByPosition($AccountForm->getId(), );
  266.         $ImageFecht_3 $ImageRepository->findImageByPosition($AccountForm->getId(), );
  267.         $ImageFecht_4 $ImageRepository->findImageByPosition($AccountForm->getId(), );
  268.         $ImageFecht_5 $ImageRepository->findImageByPosition($AccountForm->getId(), );
  269.         $ListImage = array($ImageFecht_1$ImageFecht_2$ImageFecht_3$ImageFecht_4$ImageFecht_5);
  270.         $EntityManager $this->getDoctrine()->getManager();    
  271.         //$ImagePosition = $ImageRepository->findBy( ["accountForm" => $id]);
  272.         //dump($ImageFecht);
  273.         if($ImageFecht_1 != null)
  274.         {
  275.           $Image1 $ImageFecht_1;
  276.         }
  277.         else{
  278.           $Image1 = new Image();
  279.         }
  280.         $Image2 = new Image();
  281.         $Image3 = new Image();
  282.         $Image4 = new Image();
  283.         $Image5 = new Image();
  284.         $Image1->setAccountForm($AccountForm);
  285.         $Image1->setPosition(1);
  286.         $Image2->setAccountForm($AccountForm);
  287.         $Image2->setPosition(2);
  288.         $Image3->setAccountForm($AccountForm);
  289.         $Image3->setPosition(3);
  290.         $Image4->setAccountForm($AccountForm);
  291.         $Image4->setPosition(4);
  292.         $Image5->setAccountForm($AccountForm);
  293.         $Image5->setPosition(5);
  294.         if( $AccountForm->getImage() !== null )
  295.         {
  296.           $Image $AccountForm->getImage();
  297.         }
  298.         if ( $AccountForm !== null  && !$AccountForm->getImage() )
  299.         {
  300.           //$formImage1 = $this->createForm(ImageType::class, $Image1);
  301.           $formImage2 $this->get('form.factory')->createNamed('image2'ImageType::class, $Image2 );
  302.           $formImage3 $this->get('form.factory')->createNamed('image3'ImageType::class, $Image3 );
  303.           $formImage4 $this->get('form.factory')->createNamed('image4'ImageType::class, $Image4 );
  304.           $formImage5 $this->get('form.factory')->createNamed('image5'ImageType::class, $Image5 );
  305.           //$imageCollection = array($formImage1, $formImage2, $formImage3, $formImage4,$formImage5);
  306.         
  307.         
  308.         if(!empty($ListImage) && $AccountForm !== null 
  309.         {
  310.           if( $AccountForm !== null &&  $ImageFecht_1 )
  311.           {
  312.             $formImage1 $this->get('form.factory')->createNamed('image1'ImageType::class, $ImageFecht_1 );
  313.           }
  314.           else
  315.           {
  316.             $formImage1 $this->get('form.factory')->createNamed('image1'ImageType::class, $Image1 );
  317.           } 
  318.           if( $AccountForm !== null &&  $ImageFecht_2 )
  319.           {
  320.             $formImage2 $this->get('form.factory')->createNamed('image2'ImageType::class, $ImageFecht_2 );
  321.           }
  322.           else
  323.           {
  324.             $formImage2 $this->get('form.factory')->createNamed('image2'ImageType::class, $Image2 );
  325.           } 
  326.           if( $AccountForm !== null &&  $ImageFecht_3 )
  327.           {
  328.             $formImage3 $this->get('form.factory')->createNamed('image3'ImageType::class, $ImageFecht_3 );
  329.           }
  330.           else
  331.           {
  332.             $formImage3 $this->get('form.factory')->createNamed('image3'ImageType::class, $Image3 );
  333.           } 
  334.           if( $AccountForm !== null &&  $ImageFecht_4 )
  335.           {
  336.             $formImage4 $this->get('form.factory')->createNamed('image4'ImageType::class, $ImageFecht_4 );
  337.           }
  338.           else
  339.           {
  340.             $formImage4 $this->get('form.factory')->createNamed('image4'ImageType::class, $Image4 );
  341.           } 
  342.           if( $AccountForm !== null &&  $ImageFecht_5 )
  343.           {
  344.             $formImage5 $this->get('form.factory')->createNamed('image5'ImageType::class, $ImageFecht_5 );
  345.           }
  346.           else
  347.           {
  348.             $formImage5 $this->get('form.factory')->createNamed('image5'ImageType::class, $Image5 );
  349.           } 
  350.         }
  351.           else 
  352.         {
  353.           return $this->redirectToRoute('profil.user');
  354.         }
  355.   
  356.            $formImage1->handleRequest($request);
  357.            $formImage2->handleRequest($request);
  358.            $formImage3->handleRequest($request);
  359.            $formImage4->handleRequest($request);
  360.            $formImage5->handleRequest($request);
  361.          
  362.           if ($formImage1->isSubmitted() && $formImage1->isValid())
  363.           {
  364.             $ImageGallery $formImage1->getData();
  365.             $ImageGallery->setAccountForm($AccountForm);
  366.             $EntityManager->persist($ImageGallery);
  367.             $EntityManager->persist($AccountForm);
  368.             $EntityManager->flush();
  369.               if(!is_dir(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}"))
  370.               {
  371.                if(!is_dir(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}")){
  372.                 mkdirdirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}"0777true);
  373.                }
  374.                 mkdirdirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}"0777true);
  375.               }
  376.               /* Create the directory principale for the princiaple image */ 
  377.                
  378.               if(!is_dir(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/primary_image"))
  379.               {
  380.                // dd($AccountForm->getMail());
  381.                 mkdirdirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/primary_image"0777true);
  382.               }
  383.               
  384.               if(!file_exists(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}"))
  385.               {
  386.                 @rename(dirname(__DIR__2)."/public_html/images/categories/{$ImageGallery->getUrlImage()}"dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}");
  387.               
  388.                 $path_file_image dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}";
  389.                 // redimension image 
  390.                 /*if(file_exists($path_file_image) )
  391.                 {
  392.                   if(pathinfo($path_file_image, PATHINFO_EXTENSION) === ('jpg' || 'jpeg' || 'JPG' || 'JPEG'))
  393.                   {
  394.                     $filename = imagecreatefromjpeg($path_file_image);
  395.                   }
  396.                   else
  397.                   {
  398.                     $filename = imagecreatefrompng($path_file_image);
  399.                   }
  400.                   $max_resolution = 600;
  401.                   //resolution
  402.                   $original_width = imagesx($filename);
  403.                   $original_height = imagesy($filename);
  404.     
  405.                   //ratio 
  406.                   //try width first
  407.                   $ratio = $max_resolution /  $original_width;
  408.                   $new_width = $max_resolution;
  409.                   $new_height = $original_height * $ratio;
  410.     
  411.                   //if height failed
  412.                   if($new_height > $max_resolution)
  413.                   {
  414.                     $ratio = $max_resolution /  $original_height;
  415.                     $new_height = $max_resolution;
  416.                     $new_width = $original_width * $ratio;               
  417.                   }
  418.     
  419.     
  420.                   $new_img = imagecreatetruecolor($new_width,$new_height);
  421.                   imagecopyresampled($new_img, $filename,0,0,0,0,$new_width,$new_height, $original_width, $original_height);
  422.                   if(pathinfo($path_file_image, ['PATHINFO_EXTENSION']) === ('jpg' || 'jpeg' || 'JPG' || 'JPEG'))
  423.                   {
  424.                     imagejpeg($new_img,$path_file_image);
  425.                   }
  426.                   else
  427.                   {
  428.                     imagepng($new_img,$path_file_image);
  429.                   }
  430.                  }*/
  431.              
  432.            
  433.             }
  434.             if( $formImage2->isSubmitted() && $formImage2->isValid() )
  435.               {
  436.                 $ImageGallery $formImage2->getData();
  437.                 $EntityManager->persist($ImageGallery);
  438.                 $EntityManager->flush();
  439.               }
  440.            if ($formImage2->isSubmitted() && $formImage2->isValid())
  441.              {
  442.                 $ImageGallery $formImage2->getData();
  443.                 $ImageGallery->setAccountForm($AccountForm);
  444.                 $EntityManager->persist($ImageGallery);
  445.                 $EntityManager->persist($AccountForm);
  446.                 $EntityManager->flush();
  447.                 if(!is_dir(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}"))
  448.                 {
  449.                   
  450.                   mkdirdirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}");
  451.                 }
  452.   
  453.                 /* Create the directory principale for the princiaple image */ 
  454.                  
  455.                 if(!is_dir(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/primary_image"))
  456.                 {
  457.                   
  458.                   mkdirdirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/primary_image");
  459.                 }
  460.                 
  461.   
  462.                 if(!file_exists(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}"))
  463.                 {
  464.                   @rename(dirname(__DIR__2)."/public_html/images/categories/{$ImageGallery->getUrlImage()}"dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}");
  465.                 
  466.                   $path_file_image dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}";
  467.   
  468.                   // redimension image 
  469.   
  470.                  /* if(file_exists($path_file_image))
  471.                   {
  472.                     $filename = imagecreatefromjpeg($path_file_image);
  473.                     $max_resolution = 900;
  474.                     //resolution
  475.                     $original_width = imagesx($filename);
  476.                     $original_height = imagesy($filename);
  477.       
  478.                     //ratio 
  479.                     //try width first
  480.                     $ratio = $max_resolution /  $original_width;
  481.                     $new_width = $max_resolution;
  482.                     $new_height = $original_height * $ratio;
  483.       
  484.                     //if height failed
  485.                     if($new_height > $max_resolution)
  486.                     {
  487.                       $ratio = $max_resolution /  $original_height;
  488.                       $new_height = $max_resolution;
  489.                       $new_width = $original_width * $ratio;               
  490.                     }
  491.       
  492.       
  493.                     $new_img = imagecreatetruecolor($new_width,$new_height);
  494.                     imagecopyresampled($new_img, $filename,0,0,0,0,$new_width,$new_height, $original_width, $original_height);
  495.                     imagejpeg($new_img,$path_file_image);
  496.                     */
  497.                     /*
  498.                     $cropperResult = $_POST["cropperResult"];
  499.                     dump($cropperResult);
  500.                     $cropperResult = json_decode($cropperResult);
  501.                     $im = imagecreatefromjpeg($path_file_image);
  502.                     $size = min(imagesx($im), imagesy($im));
  503.                     $im2 = imagecrop($im, [ 'x' => $cropperResult->x, 'y' => $cropperResult->y, 'width' => $cropperResult->width, 'height' => $cropperResult->height ]);
  504.                     if ($im2 !== FALSE) {
  505.                         imagejpeg($im2, $path_file_image);
  506.                     }
  507.                    }*/
  508.                
  509.             }
  510.             
  511.             if ($formImage3->isSubmitted() && $formImage3->isValid())
  512.             {
  513.               $ImageGallery $formImage3->getData();
  514.               $ImageGallery->setAccountForm($AccountForm);
  515.               $EntityManager->persist($ImageGallery);
  516.               $EntityManager->persist($AccountForm);
  517.               $EntityManager->flush();
  518.   
  519.               if(!is_dir(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}"))
  520.               {
  521.                 
  522.                 mkdirdirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}");
  523.               }
  524.               /* Create the directory principale for the princiaple image */ 
  525.                
  526.               if(!is_dir(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/primary_image"))
  527.               {
  528.                 
  529.                 mkdirdirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/primary_image");
  530.               }
  531.               
  532.               if(!file_exists(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}"))
  533.               {
  534.                 @rename(dirname(__DIR__2)."/public_html/images/categories/{$ImageGallery->getUrlImage()}"dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}");
  535.               
  536.                 $path_file_image dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}";
  537.                 // redimension image 
  538.                 /*if(file_exists($path_file_image))
  539.                 {
  540.                   $filename = imagecreatefromjpeg($path_file_image);
  541.                   $max_resolution = 600;
  542.                   //resolution
  543.                   $original_width = imagesx($filename);
  544.                   $original_height = imagesy($filename);
  545.     
  546.                   //ratio 
  547.                   //try width first
  548.                   $ratio = $max_resolution /  $original_width;
  549.                   $new_width = $max_resolution;
  550.                   $new_height = $original_height * $ratio;
  551.     
  552.                   //if height failed
  553.                   if($new_height > $max_resolution)
  554.                   {
  555.                     $ratio = $max_resolution /  $original_height;
  556.                     $new_height = $max_resolution;
  557.                     $new_width = $original_width * $ratio;               
  558.                   }
  559.     
  560.     
  561.                   $new_img = imagecreatetruecolor($new_width,$new_height);
  562.                   imagecopyresampled($new_img, $filename,0,0,0,0,$new_width,$new_height, $original_width, $original_height);
  563.                   imagejpeg($new_img,$path_file_image);
  564.                  }*/
  565.                 
  566.               }
  567.               
  568.               if ($formImage4->isSubmitted() && $formImage4->isValid())
  569.               {
  570.                 $ImageGallery $formImage4->getData();
  571.                 $ImageGallery->setAccountForm($AccountForm);
  572.                 $EntityManager->persist($ImageGallery);
  573.                 $EntityManager->persist($AccountForm);
  574.                 $EntityManager->flush();
  575.     
  576.                 if(!is_dir(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}"))
  577.                 {
  578.                   
  579.                   mkdirdirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}");
  580.                 }
  581.   
  582.                 /* Create the directory principale for the princiaple image */ 
  583.                  
  584.                 if(!is_dir(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/primary_image"))
  585.                 {
  586.                   
  587.                   mkdirdirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/primary_image");
  588.                 }
  589.                 
  590.   
  591.                 if(!file_exists(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}"))
  592.                 {
  593.                   @rename(dirname(__DIR__2)."/public_html/images/categories/{$ImageGallery->getUrlImage()}"dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}");
  594.                 
  595.                   $path_file_image dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}";
  596.   
  597.                   // redimension image 
  598.   
  599.                   if(file_exists($path_file_image))
  600.                   {
  601.                     $filename imagecreatefromjpeg($path_file_image);
  602.                     $max_resolution 600;
  603.                     //resolution
  604.                     $original_width imagesx($filename);
  605.                     $original_height imagesy($filename);
  606.       
  607.                     //ratio 
  608.                     //try width first
  609.                     $ratio $max_resolution /  $original_width;
  610.                     $new_width $max_resolution;
  611.                     $new_height $original_height $ratio;
  612.       
  613.                     //if height failed
  614.                     if($new_height $max_resolution)
  615.                     {
  616.                       $ratio $max_resolution /  $original_height;
  617.                       $new_height $max_resolution;
  618.                       $new_width $original_width $ratio;               
  619.                     }
  620.       
  621.       
  622.                     $new_img imagecreatetruecolor($new_width,$new_height);
  623.                     imagecopyresampled($new_img$filename,0,0,0,0,$new_width,$new_height$original_width$original_height);
  624.                     imagejpeg($new_img,$path_file_image);
  625.                    }
  626.                   } 
  627.                 }
  628.                  if ($formImage5->isSubmitted() && $formImage5->isValid())
  629.                 {
  630.                   $ImageGallery $formImage5->getData();
  631.                   $ImageGallery->setAccountForm($AccountForm);
  632.                   $EntityManager->persist($ImageGallery);
  633.                   $EntityManager->persist($AccountForm);
  634.                   $EntityManager->flush();
  635.       
  636.                      if(!is_dir(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}"))
  637.               {
  638.                 
  639.                 mkdirdirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}");
  640.               }
  641.               /* Create the directory principale for the princiaple image */ 
  642.                
  643.               if(!is_dir(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/primary_image"))
  644.               {
  645.                 
  646.                 mkdirdirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/primary_image");
  647.               }
  648.               
  649.               if(!file_exists(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}"))
  650.               {
  651.                 @rename(dirname(__DIR__2)."/public_html/images/categories/{$ImageGallery->getUrlImage()}"dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}");
  652.               
  653.                 $path_file_image dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$ImageGallery->getUrlImage()}";
  654.                 // redimension image 
  655.                 /*if(file_exists($path_file_image))
  656.                 {
  657.                   $filename = imagecreatefromjpeg($path_file_image);
  658.                   $max_resolution = 600;
  659.                   //resolution
  660.                   $original_width = imagesx($filename);
  661.                   $original_height = imagesy($filename);
  662.     
  663.                   //ratio 
  664.                   //try width first
  665.                   $ratio = $max_resolution /  $original_width;
  666.                   $new_width = $max_resolution;
  667.                   $new_height = $original_height * $ratio;
  668.     
  669.                   //if height failed
  670.                   if($new_height > $max_resolution)
  671.                   {
  672.                     $ratio = $max_resolution /  $original_height;
  673.                     $new_height = $max_resolution;
  674.                     $new_width = $original_width * $ratio;               
  675.                   }
  676.     
  677.     
  678.                   $new_img = imagecreatetruecolor($new_width,$new_height);
  679.                   imagecopyresampled($new_img, $filename,0,0,0,0,$new_width,$new_height, $original_width, $original_height);
  680.                   imagejpeg($new_img,$path_file_image);
  681.                  }*/
  682.                 
  683.               }
  684.         /* Manager Images Gallery */
  685.       $imagesGalleryFetch $ItemsGalleryVitrineRepository->findBy(['accountForm' => $AccountForm->getId()]);
  686.       $formImageGallery $this->createForm(ImageGalleryItemsType::class);
  687.       $formImageGallery->handleRequest($request);
  688.       if($formImageGallery->isSubmitted() && $formImageGallery->isValid())
  689.       {
  690.         $imagesGallery $formImageGallery->getData();
  691.         foreach ($imagesGallery as $containerImagesGallery)
  692.         {
  693.           foreach($containerImagesGallery as $images)
  694.           {
  695.             $images $images->setAccountForm($AccountForm);
  696.             $EntityManager->persist($images);
  697.             try{
  698.               $EntityManager->flush();
  699.             } catch(UniqueConstraintViolationException $e)
  700.             {
  701.               $this->addFlash('warning''Vous avez déjà enregistré cette image');
  702.             }
  703.             if(!file_exists(dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$images->getUrlImage()}"))
  704.             {
  705.                 rename(dirname(__DIR__2)."/public_html/images/categories/{$images->getUrlImage()}"dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$images->getUrlImage()}");
  706.               
  707.                 $path_file_image dirname(__DIR__2)."/public_html/images1/categories/{$AccountForm->getCategory()}/store_{$AccountForm->getMail()}/{$images->getUrlImage()}";
  708.             } 
  709.           }
  710.         }
  711.       }
  712.                  
  713.         return $this->render('account.image-gallery.html.twig', [
  714.           'imagesGalleryFetch' => $imagesGalleryFetch,
  715.           'formImagesGallery' => $formImageGallery->createView(),
  716.             'FormImage1' => $formImage1->createView(),
  717.             'FormImage2' => $formImage2->createView(),
  718.             'FormImage3' => $formImage3->createView(),
  719.             'FormImage4' => $formImage4->createView(),
  720.             'FormImage5' => $formImage5->createView(),
  721.         ]);
  722.   }
  723.   /**
  724.    * @Route("account-register/products-manager", name="products-manager")
  725.    */
  726.   public function productsManager(ItemsGalleryVitrineRepository $itemsGalleryVitrineRepositoryRequest $request,ValidatorInterface $validator )
  727.   {
  728.     $this->denyAccessUnlessGranted('ROLE_BUSINESS');
  729.     $user $this->getUser();
  730.     $accountForm $user->getAccountForm();
  731.     $EntityManager $this->getDoctrine()->getManager();    
  732.     $imagesGalleryFetch $itemsGalleryVitrineRepository->findBy(['accountForm' => $accountForm->getId()]);
  733.     $formImageGallery $this->createForm(ImageGalleryItemsType::class);
  734.     $formImageGallery->handleRequest($request);
  735.     if($formImageGallery->isSubmitted() && $formImageGallery->isValid())
  736.     {
  737.       $imagesGallery $formImageGallery->getData();
  738.      /* var_dump($imagesGallery);
  739.       die();*/
  740.       foreach ($imagesGallery as $containerImagesGallery)
  741.       {
  742.         foreach($containerImagesGallery as $images)
  743.         {
  744.           $images $images->setAccountForm($accountForm);
  745.           $images->setUpdatedAt(new \DateTime('now'));
  746.           $errors $validator->validate($images);
  747.         if (count($errors) > 0) {
  748.             foreach ($errors as $error) {
  749.                 echo $error->getMessage() . "<br>";
  750.             }
  751.         }
  752.          // dd($images);
  753.           $EntityManager->persist($images);
  754.           try{
  755.             $EntityManager->flush();
  756.           } catch(UniqueConstraintViolationException $e)
  757.           {
  758.             $this->addFlash('warning''Vous avez déjà enregistré cette image');
  759.           }
  760.           if(!file_exists(dirname(__DIR__2)."/public_html/images1/categories/{$accountForm->getCategory()}/store_{$accountForm->getMail()}/{$images->getUrlImage()}"))
  761.           {
  762.               @rename(dirname(__DIR__2)."/public_html/images/categories/{$images->getUrlImage()}"dirname(__DIR__2)."/public_html/images1/categories/{$accountForm->getCategory()}/store_{$accountForm->getMail()}/{$images->getUrlImage()}");
  763.             
  764.               $path_file_image dirname(__DIR__2)."/public_html/images1/categories/{$accountForm->getCategory()}/store_{$accountForm->getMail()}/{$images->getUrlImage()}";
  765.           } 
  766.         }
  767.       }
  768.     }
  769.           return $this->render('products.manager.html.twig',[
  770.             'formImagesGallery' => $formImageGallery->createView(),
  771.             'imagesGalleryFetch' => $imagesGalleryFetch
  772.           ]);
  773.   }
  774.   /**
  775.    * @Route("account-register/shop/delete-image/{id}", name="delete.image", methods={ "GET", "POST" } )
  776.    *
  777.    */
  778.     public function deleteImage($idRequest $requestUserRepository $UserRepositoryImageRepository $ImageRepositoryAccountFormRepository $AccountFormRepository)
  779.     {
  780.       $this->denyAccessUnlessGranted('ROLE_USER');
  781.       $Image $ImageRepository->find($id);
  782.       if($Image !== null)
  783.       {
  784.         $EntityManager $this->getDoctrine()->getManager();    
  785.         $AccountForm $Image->getAccountForm();
  786.         if($AccountForm !== null)
  787.         {
  788.           $AccountFormHasDeleted $AccountFormRepository->find($AccountForm->getId());
  789.           $AccountFormHasDeleted $AccountFormHasDeleted->setUser(null);
  790.           $EntityManager->persist($AccountFormHasDeleted);
  791.           $EntityManager->flush(); 
  792.           $EntityManager->remove($Image);
  793.         }
  794.       }
  795.       return $this->redirectToRoute('account.shop.image.gallery.register', ['id' => $UserRepository->find($this->getUser()->getId())->getId()]);
  796.     }
  797.   /**
  798.   *@Route("delete-account/{id}", name="delete.account", methods={ "GET", "POST" } )
  799.   *
  800.   */
  801.     public function deleteAccount($idRequest $requestUserRepository $UserRepositorySession $sessionAccountFormRepository $AccountFormRepositoryAccountForm $AccountFormStripeService $stripeService)
  802.     {
  803.       $this->denyAccessUnlessGranted('ROLE_USER');
  804.       $User $UserRepository->find($id); 
  805.       $AccountForm $User->getAccountform();
  806.       if($AccountForm && $AccountForm !== NULL )
  807.       {
  808.         $customerStripeId $stripeService->listSubscriptions($User->getCustomerStripeId());
  809.         if($customerStripeId)
  810.         {
  811.           $stripeService->cancelSubscription($customerStripeId,$User);
  812.           $this->addFlash('success''Votre abonnement a bien été annulé.');
  813.         }
  814.       }
  815.       $EntityManager $this->getDoctrine()->getManager();    
  816. //    deleted $AccountForm related at $User    
  817.      
  818.         if($AccountForm !== null)
  819.          { 
  820.           $AccountFormHasDeleted $User->getAccountform();
  821.           $UserWithAccountFormNull $User->setAccountform(null);
  822.           //$AccountFormHasDeleted = $AccountFormRepository->find($AccountFormHasDeleted->getId());
  823.           $AccountFormHasDeleted$AccountFormHasDeleted->setUser(null);
  824.           if(!empty($AccountFormHasDeleted->getImage()))
  825.           { 
  826.             $images $AccountFormHasDeleted->getImage();
  827.             foreach($images as $img)
  828.             {
  829.               $AccountFormHasDeleted->removeImage($img);
  830.             }
  831.           }
  832.           if($AccountFormHasDeleted->getOpeningHours())
  833.           {
  834.             $OpeningHours $AccountFormHasDeleted->getOpeningHours()->setAccountForm(null);
  835.             $AccountFormHasDeleted $AccountFormHasDeleted->setOpeningHours(null);
  836.             $EntityManager->persist($OpeningHours);
  837.           }
  838.           $EntityManager->persist($AccountFormHasDeleted);
  839.           $EntityManager->flush(); 
  840.           $EntityManager->remove($AccountFormHasDeleted);
  841.          }
  842.       $EntityManager->flush(); 
  843.       
  844.       $this->get('security.token_storage')->setToken(null);
  845.       $session->invalidate();
  846.       $this->switchAccount($request);
  847.       return $this->render('delete.account.html.twig');
  848.     }
  849.     /**
  850.      * @Route("get-items-gallery-vitrine/{idAccountForm}", name="items.vitrine")
  851.      */
  852.     public function getItemsVitrine(ItemsGalleryVitrineRepository $itemsGalleryVitrineRepository$idAccountForm)
  853.     {
  854.       $itemsGalleryVitrine $itemsGalleryVitrineRepository->findBy(['accountForm'=> $idAccountForm]);
  855.       return $this->render('items.gallery.vitrine.html.twig', ['itemsGalleryVitrine' => $itemsGalleryVitrine]);
  856.     }
  857.     /**
  858.   *@Route("delete-shop/{id}", name="delete.shop", methods={ "GET", "POST" } )
  859.   *
  860.   */
  861.   public function deleteShop($idRequest $requestUserRepository $UserRepositoryAccountFormRepository $AccountFormRepositoryStripeService $stripeService)
  862.   {
  863.     $this->denyAccessUnlessGranted('ROLE_USER');
  864.     $User $UserRepository->find($id); 
  865.     $AccountForm $User->getAccountform();
  866.     if($AccountForm !== NULL )
  867.     {
  868.       $subscriptionIds $stripeService->listSubscriptions($User->getCustomerStripeId());
  869.       //dd($subscriptionId);
  870.       if(!$subscriptionIds->isEmpty())
  871.       {
  872.         foreach($subscriptionIds as $subscriptionId){
  873.           $stripeService->cancelSubscription($subscriptionId->id,$User);
  874.         }
  875.         $this->addFlash('success''Votre abonnement a bien été annulé.');
  876.       }
  877.       $AccountFormHasDeleted $AccountFormRepository->find($AccountForm->getId());
  878.       //dd($AccountFormHasDeleted);
  879.       $AccountFormHasDeleted $AccountFormHasDeleted->setUser(null);
  880.       $EntityManager $this->getDoctrine()->getManager();  
  881.       $images $AccountFormHasDeleted->getImage();
  882.       foreach($images as $image)
  883.       {
  884.         $EntityManager->remove($image);
  885.       }
  886.       $userAccount $User->setAccountform(null);
  887.       $EntityManager->persist($userAccount);
  888.       $EntityManager->remove($AccountFormHasDeleted);      
  889.       $EntityManager->flush();
  890.       $this->addFlash('success''Votre boutique a bien été cloturée.');
  891.       $this->switchAccount($request);
  892.       //return $this->render('successDeleteShop.html.twig');
  893.     }
  894.     return $this->render('successDeleteShop.html.twig');
  895.   }
  896.   /**
  897.    * @Route("/account-register/shop/dashboard-stripe/{connectedAccountId}", name="account.shop.dashboard.stripe", methods={"GET", "POST"})
  898.    */
  899.   public function dashboardStripe($connectedAccountIdStripeService $stripeServiceurlGeneratorInterface $urlGeneratorInterface){
  900.     try {
  901.         // Replace `$connectedAccountId` with the actual ID of the connected account
  902.         $loginLink $this->stripeApi->getLoginLink($connectedAccountId);
  903.         // Redirect the user to the dashboard login link
  904.         header('Location: ' $loginLink->url);
  905.         exit();
  906.     } catch (\Stripe\Exception\ApiErrorException $e) {
  907.         // Log and handle errors
  908.         error_log('Stripe API Error: ' $e->getMessage());
  909.         exit('An error occurred while generating the dashboard login link.');
  910.     }
  911.   }
  912.   /**
  913.    * @Route("/account-register/subscription", name="account.shop.subscription", methods={"GET", "POST"})
  914.    */
  915.    public function createSubscription(StripeService $stripeService){
  916.     $user $this->getUser();
  917.     if (!$user) {
  918.       $this->addFlash('error''Vous devez être connecté pour accéder à cette page');
  919.       return $this->redirectToRoute('profil.user');
  920.     }
  921.     $customerEmail $user->getEmail();
  922.     $subscription $stripeService->createCheckoutSessionSubscription($user);
  923.     return $this->redirect($subscription->url);
  924.    } 
  925.    
  926.    /**
  927.    * @Route("/account-register/ads-first", name="account.shop.ads.first", methods={"GET", "POST"})
  928.    */
  929.    public function createAdsFirst(StripeService $stripeService){
  930.     $user $this->getUser();
  931.     if (!$user) {
  932.       $this->addFlash('error''Vous devez être connecté pour accéder à cette page');
  933.       return $this->redirectToRoute('profil.user');
  934.     }
  935.     $customerEmail $user->getEmail();
  936.    // $subscription = $stripeService->createCheckoutSessionAds($user);
  937.     $subscriptionId $user->getAccountForm()->getSubscription();
  938.     $subscription $stripeService->updateSubscription($user$subscriptionId);
  939.     //return $this->redirect($subscription->url);
  940.     return $this->redirectToRoute('profil.user');
  941.    } 
  942.    /**
  943.     * @Route("/account-register/plan", name="account.shop.plan", methods={"GET", "POST"})
  944.     */
  945.     public function viewPlan(){
  946.       $user $this->getUser();
  947.       $logged true;
  948.       if (!$user) {
  949.         $this->addFlash('error''Vous devez être connecté pour pouvoir souscrire à l\'offre Premium');
  950.         $logged false;
  951.       }
  952.       return $this->render('view.plan.html.twig', ['logged' => $logged]);       
  953.   }
  954.   /**
  955.    * @Route("/event-account-connected/{typeAccount}", name="account.shop.event.account.connected", methods={"GET", "POST"})
  956.    */
  957.    public function eventAccountConnected($typeAccountAccountFormRepository $accountFormRepositoryRequest $requestEntityManagerInterface $entityManager){
  958.     $this->stripeApi->stripeWebhookHandler($typeAccount$accountFormRepository$request$entityManager);
  959.     return new Response('Webhook received');
  960.   }
  961.   /**
  962.    * @Route("switch-account", name="switch.account")
  963.    */
  964.    public function switchAccount(Request $request){
  965.      $session $request->getSession();
  966.     $profil $session->get('profil');
  967.     if($profil ==='jobber'){
  968.       $session->set('profil','customer');
  969.     }
  970.     else{
  971.       $session->set('profil','jobber');
  972.     }
  973.     
  974.     $profil $request->getSession()->get('profil');
  975.     return new JsonResponse(['profil'=>$profil]);
  976.   }
  977.   /**
  978.    * @Route("profil-account-session", name="profil.account.session")
  979.    */
  980.    public function profilAccount(Request $request){
  981.     $profil $request->getSession()->get('profil');
  982.     return new JsonResponse(['profil'=>$profil]);
  983.   }
  984.   /**
  985.    * @Route("dashboard-stripe-customer", name="dashboard.stripe.customer")
  986.    */
  987.     public  function dashboardStripeCustomer(StripeService $stripeService){
  988.       $user $this->getUser();
  989.       $loginLink $stripeService->getBillingPortalCustomer($user);
  990.       return $this->redirect($loginLink->url);
  991.     }
  992.     /**
  993.        * @Route("payment-success-ads", name="payment.success.ads", methods={"GET", "POST"})
  994.        */
  995.       public function paymentSuccess(Request $requestStripeService $stripeService){
  996.         $user $this->getUser();
  997.         return $this->render('payment_success_ads.html.twig', ['user' => $user]);
  998.     }
  999. }