src/Controller/CommandeController.php line 707

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\InterventionRepository;
  4. use App\Traits\Autowired\Vendor\LoggerTrait;
  5. use App\Traits\Autowired\Vendor\SeoPageTrait;
  6. use App\Traits\Autowired\Vendor\TranslatorTrait;
  7. use Stripe\Exception\CardException;
  8. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpFoundation\Session\Session;
  15. use Symfony\Component\HttpKernel\Exception\HttpException;
  16. use App\Entity\Commande;
  17. use App\Entity\Intervention;
  18. use App\Entity\Setting;
  19. use App\Form\Type\CommandeType;
  20. use App\Form\Type\Step2Type;
  21. use App\Form\Type\Step3Type;
  22. use App\Form\Type\VisioStep1Type;
  23. use App\Traits\ClientManagerTrait;
  24. use App\Traits\CommandeManagerTrait;
  25. use App\Traits\DistanceManagerTrait;
  26. use App\Traits\DoctorManagerTrait;
  27. use App\Traits\InterventionManagerTrait;
  28. use App\Traits\LeMedecinServiceTrait;
  29. use App\Traits\NotificationManagerTrait;
  30. use App\Traits\PriceServiceTrait;
  31. use App\Traits\StripeServiceTrait;
  32. use App\Entity\Docteur;
  33. use App\Manager\UserManager;
  34. use App\Services\CommandeService;
  35. use App\Services\TeleconsultationService;
  36. use App\Traits\HubspotServiceTrait;
  37. use App\Traits\UserManagerTrait;
  38. use Symfony\Component\Form\FormInterface;
  39. use Symfony\Component\HttpFoundation\RedirectResponse;
  40. class CommandeController extends AbstractController
  41. {
  42.     use LoggerTrait;
  43.     private TeleconsultationService $teleconsultationService;
  44.     private CommandeService $commandeService;
  45.     public function __construct(
  46.         TeleconsultationService $teleconsultationService,
  47.         CommandeService $commandeService
  48.     ) {
  49.         $this->teleconsultationService $teleconsultationService;
  50.         $this->commandeService $commandeService;
  51.     }
  52.     use DistanceManagerTrait;
  53.     use StripeServiceTrait;
  54.     use DoctorManagerTrait;
  55.     use ClientManagerTrait;
  56.     use PriceServiceTrait;
  57.     use CommandeManagerTrait;
  58.     use InterventionManagerTrait;
  59.     use NotificationManagerTrait;
  60.     use LeMedecinServiceTrait;
  61.     use SeoPageTrait;
  62.     use TranslatorTrait;
  63.     use UserManagerTrait;
  64.     use HubspotServiceTrait;
  65.     /**
  66.      * Handle form submission for the Step3Type form.
  67.      *
  68.      * @param Request  $request   The request object
  69.      * @param Commande $commande  The Commande entity
  70.      *
  71.      * @return RedirectResponse  The redirect response
  72.      */
  73.     private function handleFormSubmission(FormInterface $formCommande $commande): RedirectResponse
  74.     {
  75.     }
  76.     #[Route('/fr/commande/mode'options: ['sitemap' => true])]
  77.     public function domicile(Request $request)
  78.     {
  79.         $titre "Urgence Docteurs : Choisissez Téléconsultation, Visio ou Consultation à Domicile";
  80.         $description "En téléconsultation, en visio ou à domicile, Urgence Docteurs vous offre des solutions médicales flexibles et adaptées à vos besoins médicaux en SOS.";
  81.         $this->seoPage
  82.             ->setTitle($titre)
  83.             ->addMeta('name''description'$description)
  84.             ->addMeta('property''og:title'$titre)
  85.             ->addMeta('property''og:description'$description)
  86.             ->addMeta('property''og:url'$this->generateUrl('app_commande_domicile'))
  87.             ->addMeta('property''twitter:title'$titre)
  88.             ->addMeta('property''twitter:description'$description);
  89.         $this->resetSession();
  90.         $em $this->getDoctrine()->getManager();
  91.         // Formulaire de commande
  92.         $commande = new Commande;
  93.         $formCommande $this->createForm(CommandeType::class, $commande, []);
  94.         $formCommande->handleRequest($request);
  95.         if ($formCommande->isSubmitted() && $formCommande->isValid()) {
  96.             $commande->setType(Intervention::TYPE_DOMICILE);
  97.             $client $this->clientManager->createByCommand($commande);
  98.             $commande->setClient($client);
  99.             $customer $this->stripeService->createCustomer($commande->getEmail());
  100.             $commande->setStripeCustomer($customer->id);
  101.             try {
  102.                 $contactId $this->hubspotService->createContact($commande);
  103.                 $commande->setHubspotContactId($contactId);
  104.                 $dealId $this->hubspotService->createTransactionStep1($commande);
  105.                 $commande->setHubspotDealId($dealId);
  106.             }
  107.             catch (\Exception $exception){
  108.                 $this->logger->error('Hubspot err:: ' $exception->getMessage(), [
  109.                     'exception' => $exception,
  110.                 ]);
  111.             }
  112.             $em->persist($commande);
  113.             $em->flush();
  114.             $this->get('session')->set('commande'$commande->getId());
  115.             return $this->redirectToRoute('app_commande_step2');
  116.         }
  117.         return $this->render(
  118.             'Commande/domicile.html.twig',
  119.             [
  120.                 'form' => $formCommande->createView(),
  121.                 'mode' => 'domicile'
  122.             ]
  123.         );
  124.     }
  125.     #[Route('/fr/commande/mode/visio'options: ['sitemap' => true])]
  126.     public function visio(Request $request)
  127.     {
  128.         $titre 'Téléconsultation Médicale en Visio - Urgence Docteurs Disponibles 24/7';
  129.         $description 'Avec Urgence Docteurs, accédez à une téléconsultation en visio sécurisée, 24/7. Obtenez des conseils médicaux et des prescriptions rapidement.';
  130.         $this->seoPage
  131.             ->setTitle($titre)
  132.             ->addMeta('name''description'$description)
  133.             ->addMeta('property''og:title'$titre)
  134.             ->addMeta('property''og:description'$description)
  135.             ->addMeta('property''og:url'$this->generateUrl('app_commande_visio', []))
  136.             ->addMeta('property''twitter:title'$titre)
  137.             ->addMeta('property''twitter:description'$description);
  138.         $em $this->getDoctrine()->getManager();
  139.         // Formulaire de commande
  140.         $commande = new Commande;
  141.         $formCommande $this->createForm(VisioStep1Type::class, $commande, []);
  142.         $formCommande->handleRequest($request);
  143.         if ($formCommande->isSubmitted() && $formCommande->isValid()) {
  144.             $commande->setType(Intervention::TYPE_VISIO);
  145.             $client $this->clientManager->createByCommand($commande);
  146.             $commande->setClient($client);
  147.             $customer $this->stripeService->createCustomer($commande->getEmail());
  148.             $commande->setStripeCustomer($customer->id);
  149.             try {
  150.                 $contactId $this->hubspotService->createContact($commande);
  151.                 $commande->setHubspotContactId($contactId);
  152.                 $dealId $this->hubspotService->createTransactionStep1($commande);
  153.                 $commande->setHubspotDealId($dealId);
  154.             }
  155.             catch(\Exception $exception){
  156.                 $this->logger->error('Hubspot err:: ' $exception->getMessage(), [
  157.                     'exception' => $exception,
  158.                 ]);
  159.             }
  160.             $em->persist($commande);
  161.             $em->flush();
  162.             $this->get('session')->set('commande'$commande->getId());
  163.             return $this->redirectToRoute('app_commande_step2');
  164.         }
  165.         return $this->render(
  166.             'Commande/visio.html.twig',
  167.             [
  168.                 'form' => $formCommande->createView(),
  169.                 'mode' => 'visio'
  170.             ]
  171.         );
  172.     }
  173.     #[Route('/fr/commande/step2')]
  174.     public function step2Action(Request $request)
  175.     {
  176.         $titre "Sélectionnez Votre spécialité et vos symptômes";
  177.         $description "Urgence Docteurs vous propose de choisir parmi un large choix de spécialités et de symptômes afin de vous prendre en charge dans les meilleurs conditions.";
  178.         $this->seoPage
  179.             ->setTitle($titre)
  180.             ->addMeta('name''description'$description)
  181.             ->addMeta('property''og:title'$titre)
  182.             ->addMeta('property''og:description'$description)
  183.             ->addMeta('property''og:url'$this->generateUrl('app_commande_step2', array(), true))
  184.             ->addMeta('property''twitter:title'$titre)
  185.             ->addMeta('property''twitter:description'$description);
  186.         $em $this->getDoctrine()->getManager();
  187.         $commandeId $this->get('session')->get('commande');
  188.         /** @var Commande $commande */
  189.         $commande $this->commandeManager->findOneBy(['id' => $commandeId]);
  190.         if (!$commande) {
  191.             return $this->redirectToRoute('app_cms_prendrerdv');
  192.         }
  193.         $form $this->createForm(Step2Type::class, null, ['type' => 'domicile']);
  194.         $form->handleRequest($request);
  195.         if ($form->isSubmitted() && $form->isValid()) {
  196.             $specialite $form->get('specialite')->getData();
  197.             $symptome $form->get('symptome')->getData();
  198.             $commande->setSpecialite($specialite);
  199.             $commande->setSymptome($symptome);
  200.             $em->persist($commande);
  201.             $em->flush();
  202.             return $this->redirectToRoute('app_commande_step3');
  203.         }
  204.         return $this->render(
  205.             'Commande/step2.html.twig',
  206.             [
  207.                 'form' => $form->createView(),
  208.                 'mode' => 'visio'
  209.             ]
  210.         );
  211.     }
  212.     #[Route('/fr/commande/step3')]
  213.     public function step3Action(Request $request): Response
  214.     {
  215.         $titre "Confirmez votre rendez-vous";
  216.         $description "Un médecin en SOS vous prend en charge d’ici quelques minutes afin de vous émettre une ordonnance et un arrêt maladie.";
  217.         $this->seoPage
  218.             ->setTitle($titre)
  219.             ->addMeta('name''description'$description)
  220.             ->addMeta('property''og:title'$titre)
  221.             ->addMeta('property''og:description'$description)
  222.             ->addMeta('property''og:url'$this->generateUrl('app_commande_step2', array(), true))
  223.             ->addMeta('property''twitter:title'$titre)
  224.             ->addMeta('property''twitter:description'$description);
  225.         $commande $this->commandeService->commandeBySession();
  226.         if (!$commande) {
  227.             return $this->redirectToRoute('app_cms_prendrerdv');
  228.         }
  229.         $form $this->createForm(Step3Type::class, null);
  230.         $form->handleRequest($request);
  231.         $paymentIntentRequest null;
  232.         if ($form->isSubmitted() && $form->isValid()) {
  233.             $this->commandeService->changeCommandeConverted($commande);
  234.             $cardToken $form->get('cardToken')->getData();
  235.             try {
  236.                 $paymentIntentRequest $request->request->get('paymentIntent');
  237.                 $result $this->teleconsultationService->modificationCommande($commande$cardToken$paymentIntentRequest);
  238.                 $price_special $this->priceService->getPrice($commande->getType(), $commande->getSpecialite());
  239.                 try {
  240.                     $this->hubspotService->updateTransaction($commande,$price_special);
  241.                 }
  242.                 catch (\Exception $exception){
  243.                     $this->logger->error('Hubspot err:: ' $exception->getMessage(), [
  244.                         'exception' => $exception,
  245.                     ]);
  246.                 }
  247.                 if (!empty($result)) {
  248.                     if ($result['redirectToRoute']) {
  249.                         return $this->redirectToRoute(
  250.                             $result['route'],
  251.                             $result['payload']
  252.                         );
  253.                     } else {
  254.                         return $this->redirect($result['route'], 302);
  255.                     }
  256.                 }
  257.                 return $this->redirectToRoute('app_commande_intervention');
  258.             }
  259.             catch (CardException $exception){
  260.                 [$price$priceSpecial$intent,$paymentIntent$isWeekend] = $this->commandeService->dataCommand($commande);
  261.                 return $this->render('Commande/step3.html.twig', [
  262.                     'weekend' => $isWeekend,
  263.                     'err' => strpos($exception->getMessage(), "Your card has insufficient funds") !== false "Paiement refusé. Fonds insuffisants." "Paiement refusé. Veuillez changer votre moyen de paiement",
  264.                     'specialiste' => $commande->getSpecialite()->getId() === 1,
  265.                     'form' => $form->createView(),
  266.                     'mode' => $commande->getType(),
  267.                     'price' => $price,
  268.                     'price_special'  => $priceSpecial,
  269.                     'paymentIntent' => $paymentIntent,
  270.                     'intent' => $intent
  271.                 ]);
  272.             }
  273.         }
  274.         [$price$priceSpecial$intent,$paymentIntent$isWeekend] = $this->commandeService->dataCommand($commande);
  275.         return $this->render('Commande/step3.html.twig', [
  276.             'weekend' => $isWeekend,
  277.             'specialiste' => $commande->getSpecialite()->getId() === 1,
  278.             'form' => $form->createView(),
  279.             'mode' => $commande->getType(),
  280.             'price' => $price,
  281.             'paymentIntent' => $paymentIntent,
  282.             'price_special'  => $priceSpecial,
  283.             'intent' => $intent
  284.         ]);
  285.     }
  286.     #[Route('/fr/commande/medecin-pas-trouve')]
  287.     public function doctorNotFound()
  288.     {
  289.         return $this->render(
  290.             'Commande/doctorNotFound.html.twig',
  291.             []
  292.         );
  293.     }
  294.     /**
  295.      * Etape 3 ( téléconsultation) : Simple page de confirmatiton
  296.      * Route : commande/validation
  297.      * @return Response
  298.      */
  299.     public function validationAction()
  300.     {
  301.         $titre $this->translator->trans('seo.commande.validation.titre');
  302.         $description $this->translator->trans('seo.commande.validation.description');
  303.         $this->seoPage
  304.             ->setTitle($titre)
  305.             ->addMeta('name''description'$description)
  306.             ->addMeta('property''og:title'$titre)
  307.             ->addMeta('property''og:description'$description)
  308.             ->addMeta('property''og:url'$this->generateUrl('commande_validation', array(), true))
  309.             ->addMeta('property''twitter:title'$titre)
  310.             ->addMeta('property''twitter:description'$description);
  311.         return $this->render('UrgenceDocteursUserBundle:Public:commande_validation.html.twig');
  312.     }
  313.     /**
  314.      * @param $reason
  315.      * @return Response
  316.      */
  317.     public function echecAction($reason)
  318.     {
  319.         $titre $this->translator->trans('seo.commande.echec.titre');
  320.         $description $this->translator->trans('seo.commande.echec.description');
  321.         $this->seoPage
  322.             ->setTitle($titre)
  323.             ->addMeta('name''description'$description)
  324.             ->addMeta('property''og:title'$titre)
  325.             ->addMeta('property''og:description'$description)
  326.             ->addMeta('property''og:url'$this->generateUrl('commande_echec', array('reason' => $reason), true))
  327.             ->addMeta('property''twitter:title'$titre)
  328.             ->addMeta('property''twitter:description'$description);
  329.         $this->get('session')->remove('intervention');
  330.         $noDocteurs false;
  331.         return $this->render(
  332.             'UrgenceDocteursUserBundle:Public:commande_echec.html.twig',
  333.             [
  334.                 'reason' => $reason,
  335.                 'noDocteurs' => $noDocteurs
  336.             ]
  337.         );
  338.     }
  339.     /**
  340.      *
  341.      * Route : commande/intervention
  342.      * Page after ask for teleconsultation or consultation
  343.      * @return Response
  344.      */
  345.     #[Route('/fr/commande/intervention')]
  346.     public function intervention()
  347.     {
  348.         /// START SEO..
  349.         $titre $this->translator->trans('Demande d\'intervention en cours');
  350.         $description $this->translator->trans('seo.commande_intervention.description');
  351.         $this->seoPage
  352.             ->setTitle($titre)
  353.             ->addMeta('name''description'$description)
  354.             ->addMeta('property''og:title'$titre)
  355.             ->addMeta('property''og:description'$description)
  356.             ->addMeta('property''og:url'$this->generateUrl('app_commande_intervention', array(), true))
  357.             ->addMeta('property''twitter:title'$titre)
  358.             ->addMeta('property''twitter:description'$description);
  359.         /// END SEO
  360.         /** @var Session $session */
  361.         $session $this->get('session');
  362.         $session->remove('iframe');
  363.         $interventionSession $session->get('intervention');
  364.         $interventionRepo $this->getDoctrine()->getRepository(Intervention::class);
  365.         /** @var Intervention $intervention */
  366.         $intervention $interventionRepo->findOneBy(['numeroReference' => $interventionSession]);
  367.         // protect null infos
  368.         if (!$intervention) {
  369.             $session->clear();
  370.             return $this->redirectToRoute('app_cms_prendrerdv');
  371.         }
  372.         $modeCommande $intervention->getModeIntervention();
  373.         $latitude null;
  374.         $longitude null;
  375.         return $this->render(
  376.             'Commande/intervention.html.twig',
  377.             [
  378.                 'intervention' => $intervention,
  379.                 'latitude' => $latitude,
  380.                 'longitude' => $longitude,
  381.                 'modeCommande' => $modeCommande,
  382.                 'error' => false
  383.             ]
  384.         );
  385.     }
  386.     /**
  387.      * Ajax call from page doctor search
  388.      * @return Response
  389.      */
  390.     #[Route('/fr/commande/intervention/reference')]
  391.     public function interventionReference(SessionInterface $sessionInterventionRepository $interventionRepository)
  392.     {
  393.         /** @var Intervention $intervention */
  394.         $intervention $session->get('intervention');
  395.         if (!$intervention) throw new HttpException(500'Error Ref');
  396.         $intervention $interventionRepository
  397.             ->findOneBy(['numeroReference' => $intervention]);
  398.         if (!$intervention) {
  399.             throw new HttpException(500'Error intervention');
  400.         }
  401.         $image null;
  402.         $docteur $intervention->getDocteur();
  403.         $user $this->userManager->getUserByDocteur($docteur);
  404.         $info = [
  405.             'etat' => $intervention->getEtat(),
  406.             'firstname' => ($intervention->getDocteur()) ? $user->getFirstname() : null,
  407.             'lastname' => ($intervention->getDocteur()) ? $user->getLastname() : null,
  408.             'phone' => ($intervention->getDocteur()) ? $user->getPhone() : null,
  409.             'latitude' => ($intervention->getDocteur()) ? $intervention->getDocteur()->getLatitude() : null,
  410.             'longitude' => ($intervention->getDocteur()) ? $intervention->getDocteur()->getLongitude() : null,
  411.             'urlVisio' => ($intervention->getDocteur()) ? $intervention->getDocteur()->getUrlClientVisio() : null,
  412.             'image' => $image
  413.         ];
  414.         return new JsonResponse($info);
  415.     }
  416.     #[Route('/fr/commande/intervention/cancel')]
  417.     public function interventionCancel()
  418.     {
  419.         $intervention $this->get('session')->get('intervention');
  420.         if (!$intervention) throw new HttpException(500'Error Ref');
  421.         $intervention $this->getDoctrine()
  422.             ->getManager()
  423.             ->getRepository('UrgenceDocteursPublicBundle:Intervention')
  424.             ->findBy(array('numeroReference' => $intervention));
  425.         $intervention $intervention[0];
  426.         if (!$intervention) throw new HttpException(500'Error intervention');
  427.         $etat $intervention->getEtat();
  428.         if ($etat == 'initConsultation' || $etat == 'endConsultation') throw new HttpException(403'intervention.enCours');
  429.         $intervention->setEtat('annule');
  430.         $this->getDoctrine()->getManager()->persist($intervention);
  431.         $this->getDoctrine()->getManager()->flush();
  432.         $this->launchCancel($intervention);
  433.         return new Response(json_encode(array('int' => $intervention->getId())));
  434.     }
  435.     /**
  436.      * @param $data
  437.      * @throws \Exception
  438.      */
  439.     private function launchCancel($data)
  440.     {
  441.         $onesignal $this->get('onesignal.docteur');
  442.         $infos = array(
  443.             'adresse' => $data->getAdresse(),
  444.             'codePostal' => $data->getCodePostal(),
  445.             'complement' => $data->getComplement(),
  446.             'symptomes' => $data->getSymptomes(),
  447.             'typeIntervention' => $data->getTypeIntervention(),
  448.             'numeroReference' => $data->getNumeroReference(),
  449.             'client' => $data->getClient(),
  450.             'specialite' => $data->getSpecialite()
  451.         );
  452.         $headings = array('en' => 'Urgence Docteurs Pro');
  453.         $contents = array('en' => 'Consultation en urgence annulée');
  454.         $dataNotif = array('type' => 'docteur.interventionCancel''infos' => $infos);
  455.         $include_player_ids = array();
  456.         $included_segments = array();
  457.         $excluded_segments = array();
  458.         $url '';
  459.         $docteur $data->getDocteur();
  460.         $user $this->userManager->getUserByDocteur($docteur);
  461.         // Retrieve Docteur =>
  462.         $include_player_ids[] = $user->getId();
  463.         $notification = array(
  464.             'headings' => $headings,
  465.             'contents' => $contents,
  466.             'data' => $dataNotif,
  467.             'include_player_ids' => $include_player_ids,
  468.             'included_segments' => $included_segments,
  469.             'excluded_segments' => $excluded_segments,
  470.             // 'url' => $url,
  471.             // 'send_after' => '2016-12-27 22:30:00 GMT+0800',
  472.             'ios_badgeType' => 'Increase',
  473.             'ios_badgeCount' => 1
  474.         );
  475.         $response $onesignal->sendMessage($notification);
  476.         $return json_encode($response);
  477.         // Email Part
  478.         $email $data->getClient()->getUser()->getEmail();
  479.         if (empty($email)) throw new HttpException(500'Email Empty');
  480.         // Set the price => montant
  481.         $prix $data->getPrix();
  482.         $montant 0;
  483.         $now = new \DateTime();
  484.         $dateIntervention $data->getHorodateCreation();
  485.         $dateIntervention->modify("+10 minutes");
  486.         if ($now $dateIntervention$montant round($prix 22);
  487.         // Send Email to the current User
  488.         $subjectPatient $this->translator->trans('mail.intervention.cancel.patient');
  489.         $subjectDocteur $this->translator->trans('mail.intervention.cancel.docteur');
  490.         $emailClient null;
  491.         if ($data->getTypeIntervention() == 'web') {
  492.             if ($data->getCommande()) $emailClient $data->getCommande()->getEmail();
  493.             else $emailClient null;
  494.         } else $emailClient $data->getClient()->getUser()->getEmail();
  495.         $mail = array(
  496.             'image' => $this->getParameter('mail.image'),
  497.             'url' => $this->getParameter('mail.url'),
  498.             'site' => $this->getParameter('mail.site'),
  499.             'author' => $this->getParameter('mail.author'),
  500.             'copyright' => $this->getParameter('mail.copyright')
  501.         );
  502.         // Envoi d'email => Patient
  503.         $message = (new \Swift_Message())
  504.             ->setSubject($subjectPatient)
  505.             ->setFrom($this->getParameter('admin_email'), $this->getParameter('site'))
  506.             ->setTo($emailClient)
  507.             ->setBody($this->renderView(
  508.                 'UrgenceDocteursUserBundle:Template:mail/Annulation_urgence_patient.html.twig',
  509.                 array(
  510.                     'sujet' => $subjectPatient,
  511.                     'montant' => $montant,
  512.                     'mail' => $mail
  513.                 )
  514.             ), 'text/html');
  515.         if ($this->getParameter('environment') == 'prod' && $emailClient$this->get('mailer')->send($message);
  516.         // Envoi d'email => Docteur
  517.         $message = (new \Swift_Message())
  518.             ->setSubject($subjectDocteur)
  519.             ->setFrom($this->getParameter('admin_email'), $this->getParameter('site'))
  520.             ->setTo($data->getDocteur()->getUser()->getEmail())
  521.             ->setBody($this->renderView(
  522.                 'UrgenceDocteursUserBundle:Template:mail/Annulation_urgence_docteur.html.twig',
  523.                 array(
  524.                     'sujet' => $subjectDocteur,
  525.                     'infos' => $infos,
  526.                     'montant' => $montant,
  527.                     'mail' => $mail
  528.                 )
  529.             ), 'text/html');
  530.         if ($this->getParameter('environment') == 'prod'$this->get('mailer')->send($message);
  531.         // Charge Stripe
  532.         if ($montant 0) {
  533.             $card $data->getCarteBancaire();
  534.             $client $data->getClient();
  535.             $email $client->getUser()->getEmail();
  536.             $stripeKey = ($this->getParameter('environment') == 'prod') ? $this->getParameter('stripe_live_key') : $this->getParameter('stripe_test_key');
  537.             \Stripe\Stripe::setApiKey($stripeKey);
  538.             try {
  539.                 $charge \Stripe\Charge::create(array(
  540.                     'customer' => $card->getCustomerToken(),
  541.                     'amount' => $montant 100,
  542.                     'currency' => 'eur',
  543.                     'description' => 'Annulation -> Customer for ' $email,
  544.                     'metadata' => array('order_id' => $data->getNumeroReference())
  545.                 ));
  546.             } catch (\Stripe\Exception\CardException $e) {
  547.                 // Since it's a decline, \Stripe\Error\Card will be caught
  548.                 $body $e->getJsonBody();
  549.                 $err $body['error'];
  550.                 throw new HttpException(500'Error Card');
  551.             } catch (\Stripe\Exception\RateLimitException $e) {
  552.                 // Too many requests made to the API too quickly
  553.                 throw new HttpException(500'too_many_request_too_quickly');
  554.             } catch (\Stripe\Exception\InvalidRequestException $e) {
  555.                 // Invalid parameters were supplied to Stripe's API
  556.                 throw new HttpException(500'invalid_parameter');
  557.             } catch (\Stripe\Exception\AuthenticationException $e) {
  558.                 // Authentication with Stripe's API failed
  559.                 // (maybe you changed API keys recently)
  560.                 throw new HttpException(500'authentification_failed');
  561.             } catch (\Stripe\Exception\ApiConnectionException $e) {
  562.                 // Network communication with Stripe failed
  563.                 throw new HttpException(500'network_communication_failed');
  564.             } catch (\Stripe\Exception\ApiErrorException $e) {
  565.                 // Display a very generic error to the user, and maybe send
  566.                 // yourself an email
  567.                 throw new HttpException(500'Global error');
  568.             } catch (\Exception $e) {
  569.                 // Something else happened, completely unrelated to Stripe
  570.                 throw new HttpException(500'Other error');
  571.             }
  572.         }
  573.     }
  574.     // Private utils function
  575.     private function resetSession()
  576.     {
  577.         //TO remove
  578.         $this->get('session')->remove('typeDay');
  579.         $this->get('session')->remove('typeHeure');
  580.         $this->get('session')->remove('infoCommande'); // Last Commande
  581.         $this->get('session')->remove('modeCommande'); // visio|physique
  582.         $this->get('session')->remove('typeCommande'); // now|later
  583.         $this->get('session')->remove('horaireCommande'); // horaire Info
  584.         $this->get('session')->remove('codeCommande'); // Code de sécurité
  585.         // end
  586.         $this->get('session')->remove('commande');
  587.         $this->get('session')->remove('intervention');
  588.         $this->get('session')->remove('iframe');
  589.     }
  590.     private function chargeVisio($intervention$lastCommande$montant)
  591.     {
  592.         $carte $intervention->getCarteBancaire()->getLastDigit();
  593.         $client $intervention->getClient();
  594.         $email $lastCommande->getEmail();
  595.         $card $intervention->getCarteBancaire();
  596.         $chargeToken $intervention->getChargeToken();
  597.         $stripeKey = ($this->getParameter('environment') == 'prod') ? $this->getParameter('stripe_live_key') : $this->getParameter('stripe_test_key');
  598.         \Stripe\Stripe::setApiKey($stripeKey);
  599.         try {
  600.             $charge \Stripe\Charge::create(array(
  601.                 'customer' => $card->getCustomerToken(),
  602.                 'amount' => $montant 100,
  603.                 'currency' => 'eur',
  604.                 'description' => 'Recu -> Customer for ' $email,
  605.                 'metadata' => array('order_id' => $intervention->getNumeroReference())
  606.             ));
  607.             return $charge;
  608.         } catch (CardException $e) {
  609.             // Since it's a decline, \Stripe\Error\Card will be caught
  610.             $body $e->getJsonBody();
  611.             $err $body['error'];
  612.             return array('reason' => 'card_declined');
  613.         } catch (RateLimitException $e) {
  614.             return array('reason' => 'too_many_request_too_quickly');
  615.         } catch (InvalidRequestException $e) {
  616.             return array('reason' => 'invalid_cb_parameter');
  617.         } catch (AuthenticationException $e) {
  618.             return array('reason' => 'authentification_failed');
  619.         } catch (ApiConnectionException $e) {
  620.             return array('reason' => 'network_communication_failed');
  621.         } catch (\Exception $e) {
  622.             return array('reason' => 'global_error');
  623.         }
  624.     }
  625. }