src/Manager/Purchase/PurchaseTunnelManager.php line 188

Open in your IDE?
  1. <?php
  2. namespace App\Manager\Purchase;
  3. use App\Entity\Management\Subscription\PaymentFutur;
  4. use App\Entity\Educational\Course;
  5. use App\Entity\Educational\Serie;
  6. use App\Entity\Management\Subscription\Discount;
  7. use App\Entity\Management\Subscription\Formule;
  8. use App\Entity\Management\Subscription\Offer;
  9. use App\Entity\Management\Subscription\Options;
  10. use App\Entity\Management\Subscription\OptionsSubscription;
  11. use App\Entity\Management\Subscription\RegisterInfosTunnel;
  12. use App\Entity\Management\Subscription\Subscription;
  13. use App\Entity\Management\Subscription\SubscriptionOptions;
  14. use App\Entity\Users\Child;
  15. use App\Entity\Users\Parents;
  16. use App\Entity\Users\StudentsParents;
  17. use App\Entity\Educational\Speciality;
  18. use App\Entity\Educational\Discipline;
  19. use App\Entity\Users\User;
  20. use App\Service\Mailer\SubscriptionMailer;
  21. use App\Service\StripeService;
  22. use Doctrine\ORM\EntityManagerInterface;
  23. use http\Client\Request;
  24. use Symfony\Component\HttpFoundation\RequestStack;
  25. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  26. class PurchaseTunnelManager
  27. {
  28.     private EntityManagerInterface $em;
  29.     private RequestStack $requestStack;
  30.     private $request;
  31.     private $passwordHasher;
  32.     private StripeService $stripeService;
  33.     private SubscriptionMailer $mailer;
  34.     public function __construct(
  35.         EntityManagerInterface $em,
  36.         RequestStack $requestStack,
  37.         UserPasswordHasherInterface $passwordHasher,
  38.         StripeService $stripeService,
  39.         SubscriptionMailer $mailer
  40.     )
  41.     {
  42.         $this->em = $em;
  43.         $this->requestStack = $requestStack;
  44.         $this->request = $this->requestStack->getCurrentRequest();
  45.         $this->passwordHasher = $passwordHasher;
  46.         $this->stripeService = $stripeService;
  47.         $this->mailer = $mailer;
  48.     }
  49.     public function summary($infos,Offer $offer)
  50.     {
  51.         $tab = [];
  52.        $i = 1;
  53.        foreach ($infos['parents_registration']['childrenForm'] as $child){
  54.            $tab[] = [
  55.                'firstname' => $child['firstname'],
  56.                'unitprice' => $offer->getPrice(),
  57.                'remise'    => $i==1?0:((1<$i && $i<4)?$i*10:30)
  58.            ];
  59.            $tab[$i-1]['price'] = round($tab[$i-1]['unitprice'] - $tab[$i-1]['unitprice'] * $tab[$i-1]['remise']/100,2);
  60.            $i++;
  61.        }
  62.        return $tab;
  63.     }
  64.     public function summaryEndEssaiGratuit($childrenIDS,Offer $offer)
  65.     {
  66.        $tab = [];
  67.        $i = 1;
  68.        foreach ($childrenIDS as $childID){
  69.            $child = $this->em->getRepository(Child::class)->find($childID);
  70.            $tab[] = [
  71.                'firstname' => $child->getFirstname(),
  72.                'unitprice' => $offer->getPrice(),
  73.                'remise'    => $i==1?0:((1<$i && $i<4)?$i*10:30)
  74.            ];
  75.            $tab[$i-1]['price'] = round($tab[$i-1]['unitprice'] - $tab[$i-1]['unitprice'] * $tab[$i-1]['remise']/100,2);
  76.            $i++;
  77.        }
  78.        return $tab;
  79.     }
  80.     public function totalPrice($nbr,$price){
  81.         $som = 0;
  82.         for($i=1;$i<=$nbr;$i++){
  83.             if(1<$i){
  84.                 $som= $som + ($price - ($price * (($i*10)/100)));
  85.                 }else{
  86.                 $som+=$price;
  87.                 }
  88.         }
  89.         return $som;
  90.     }
  91.     public function registrationParent($infos = [])
  92.     {
  93.         if(!empty($infos)){
  94.             $customInfos = $infos;
  95.         }else{
  96.             $session     = $this->requestStack->getSession();
  97.             $customInfos = $session->get('customInfosSecondStep')["parents_registration_second_step"];
  98.         }
  99.         $parents = new Parents();
  100.         $parents->setFirstname($customInfos["firstname"]);
  101.         $parents->setLastname($customInfos["lastname"]);
  102.         $parents->setUsername($customInfos["email"]["first"]);
  103.         $parents->setEmail($customInfos["email"]["first"]);
  104.        // $parents->setPhone($customInfos["phone"]);
  105.         $parents->setPassword($this->passwordHasher->hashPassword($parents,$customInfos["plainPassword"]));
  106.         $parents->setRoles(['ROLE_USER', 'ROLE_PARENTS']);
  107.         $parents->setPopinShareGoodDeal(true);
  108.         $parents->setIsCgu(true);
  109.         $parents->setOrigin(0);
  110.         $parents->setParentEmail($customInfos["email"]["first"]);
  111.         $parents->setLegalGuardianAuthorization(true);
  112.         $parents->setEmailValidationToken(0);
  113.         $parents->setEmailValidationTokenRequestedAt(new \DateTime('now'));
  114.         $parents->setStatus(200);
  115.         $parents->setEnabled(1);
  116.         return $parents;
  117.     }
  118.     public function createParentTunnel($customInfosSecondStep){
  119.         $parents = new Parents();
  120.         if( is_array($customInfosSecondStep["email"]) && array_key_exists("first",$customInfosSecondStep["email"])){
  121.             $email = $customInfosSecondStep["email"]["first"];
  122.         }else{
  123.             $email = $customInfosSecondStep["email"];
  124.         }
  125.         if(is_array($customInfosSecondStep["plainPassword"]) && array_key_exists("first",$customInfosSecondStep['plainPassword'])){
  126.             $password = $customInfosSecondStep['plainPassword']['first'];
  127.         }else{
  128.             $password = $customInfosSecondStep['plainPassword'];
  129.         }
  130.         $parents->setFirstname($customInfosSecondStep["firstname"]);
  131.         $parents->setLastname($customInfosSecondStep["lastname"]);
  132.         $parents->setUsername($email);
  133.         $parents->setEmail($email);
  134.         $parents->setCity($customInfosSecondStep["city"]);
  135.         $parents->setPostalCode($customInfosSecondStep["postalCode"]);
  136.        // $parents->setRegistrationProfile($customInfosSecondStep["registrationProfile"]);
  137.         if (array_key_exists("isNewsletter",$customInfosSecondStep) && $customInfosSecondStep["isNewsletter"] == true){
  138.             $isNewsletter = true;
  139.         }else{
  140.             $isNewsletter = false;
  141.         }
  142.         if (array_key_exists("phone",$customInfosSecondStep)){
  143.             $parents->setPhone($customInfosSecondStep['phone']);
  144.         }
  145.         $parents->setIsNewsletter($isNewsletter);
  146.         $parents->setPassword($this->passwordHasher->hashPassword($parents,$password));
  147.         $parents->setRoles(['ROLE_USER', 'ROLE_PARENTS']);
  148.         $parents->setPopinShareGoodDeal(true);
  149.         $parents->setIsCgu(true);
  150.         $parents->setOrigin(0);
  151.         $parents->setParentEmail($email);
  152.         $parents->setLegalGuardianAuthorization(true);
  153.         $parents->setEmailValidationToken(0);
  154.         $parents->setEmailValidationTokenRequestedAt(new \DateTime('now'));
  155.         $parents->setStatus(200);
  156.         $parents->setEnabled(1);
  157.         $parents->setIsVerified(true);
  158.         return $parents;
  159.     }
  160.     public function registrationParentEssaiGratuit()
  161.     {
  162.         $session               = $this->requestStack->getSession();
  163.         $customInfosSecondStep = $session->get('customInfosSecondStep')["parents_registration_second_step"];
  164.         return $this->createParentTunnel($customInfosSecondStep);
  165.     }
  166.     public function registrationStudent($data)
  167.     {
  168.         if(!empty($data)){
  169.             $child = new Child();
  170.             $child->setFirstname($data['firstname']);
  171.             $course = $this->em->getRepository(Course::class)->find($data['course']);
  172.             $serie = $this->em->getRepository(Serie::class)->findOneBySlug('generale');
  173.             $child->setCourse($course);
  174.             $child->setSerie($serie);
  175. //?offre=bac-francais
  176.             if(array_key_exists('phone',$data)){
  177.                 $child->setPhone($data['phone']);
  178.             }
  179.             if(array_key_exists('email',$data)){
  180.                 $child->setParentEmail($data["email"]);
  181.             }
  182.             $child->setEmail(uniqid()."@lbp.com");
  183.             $child->setUsername($child->getEmail());
  184.             $child->setRoles(['ROLE_STUDENT']);
  185.            // $child->setGender($data['gender']);
  186.             $child->setPassword($this->passwordHasher->hashPassword($child,uniqid()));
  187.             $child->setEmailValidationToken(0);
  188.             $child->setEmailValidationTokenRequestedAt(new \DateTime('now'));
  189.             $child->setIsVerified(true);
  190.             return $child;
  191.         }
  192.         return null;
  193.     }
  194.     public function registrationStudentEssaiGratuit($data)
  195.     {
  196.         if(!empty($data)){
  197.             $child = new Child();
  198.             $child->setFirstname($data['firstname']);
  199.             $course = $this->em->getRepository(Course::class)->find($data['course']);
  200.             $serie = $this->em->getRepository(Serie::class)->findOneBySlug('generale');
  201.             $child->setCourse($course);
  202.             $child->setSerie($serie);
  203.             $child->setEmail(uniqid()."@lbp.com");
  204.             $child->setUsername($child->getEmail());
  205.             $child->setRoles(['ROLE_STUDENT']);
  206.             $child->setIsVerified(true);
  207.            // $child->setGender($data['gender']);
  208.             $child->setPassword($this->passwordHasher->hashPassword($child,uniqid()));
  209.             $child->setEmailValidationToken(0);
  210.             $child->setEmailValidationTokenRequestedAt(new \DateTime('now'));
  211.             return $child;
  212.         }
  213.         return null;
  214.     }
  215.     public function registrationStudentProfilEleveEssaiGratuit($data)
  216.     {
  217.         $session = $this->requestStack->getSession();
  218.         $customInfosSecondStep = $session->get('customInfosSecondStep')["parents_registration_second_step"];
  219.         if(!empty($data)){
  220.             $child = new Child();
  221.             $child->setFirstname($data['firstname']);
  222.             $child->setLastname($customInfosSecondStep["lastname"]);
  223.             $child->setUsername($customInfosSecondStep["email"]);
  224.             $child->setEmail($customInfosSecondStep["email"]);
  225.             $child->setIsVerified(true);
  226.             $child->setParentEmail($customInfosSecondStep["email"]); // replaced ??
  227.             $child->setRegistrationProfile($customInfosSecondStep["registrationProfile"]);
  228.             if (array_key_exists("isNewsletter",$customInfosSecondStep) && $customInfosSecondStep["isNewsletter"] == true){
  229.                 $isNewsletter = true;
  230.             }else{
  231.                 $isNewsletter = false;
  232.             }
  233.             $child->setIsNewsletter($isNewsletter);
  234.             $course = $this->em->getRepository(Course::class)->find($data['course']);
  235.             $serie = $this->em->getRepository(Serie::class)->findOneBySlug('generale');
  236.             $child->setCourse($course);
  237.             $child->setSerie($serie);
  238.             $child->setRoles(['ROLE_STUDENT']);
  239.             $child->setPassword($this->passwordHasher->hashPassword($child,$customInfosSecondStep["plainPassword"]["first"]));
  240.             $child->setEmailValidationToken(0);
  241.             $child->setEmailValidationTokenRequestedAt(new \DateTime('now'));
  242.             return $child;
  243.         }
  244.         return null;
  245.     }
  246.     public function processCheckout(Parents $parents,$stripeId = null, $withoutPayment = false)
  247.     {
  248.         $session = $this->requestStack->getSession();
  249.         $childInfos = $session->get('customInfos')["parents_registration"]['childrenForm'];
  250.         $slug  = $session->get('customOffer');
  251.         $offer = $this->em->getRepository(Offer::class)->findOneBySlug($slug);
  252.         $i = 0;
  253.         $now = new \DateTime('now');
  254.         if (!empty($childInfos)) {
  255.             $this->em->persist($parents);
  256.             $this->em->flush();
  257.             if(!$withoutPayment && $offer->getCharge()){
  258.                 $pp = new PaymentFutur();
  259.                 $pp->setParents($parents);
  260.                 $pp->setIntentPayment($stripeId);
  261.                 $trial = clone $now;
  262.                 $trial->modify('+8 day');
  263.                 $pp->setDatePayment($trial);
  264.                 $this->em->persist($pp);
  265.                 $this->em->flush();
  266.             }
  267.             foreach ($childInfos as $infos) {
  268.                 $summary = $this->requestStack->getSession()->get('summary');
  269.                 $discount = null;
  270.                 if (isset($summary[$i]['discount'])) {
  271.                     $discount = $this->em->getRepository(Discount::class)->find($summary[$i]['discount']['id']);
  272.                 }
  273.                 if (!$withoutPayment) {
  274.                     if ($summary[$i]['remise'] != 0 && 0 < $i) {
  275.                         $title = $summary[$i]['remise'] == 20 ? 'lbp-rf-2' : 'lbp-rf-3';
  276.                         $discount = $this->em->getRepository(Discount::class)->findOneByStripeId($title);
  277.                     }
  278.                 }
  279.                 $child = $this->registrationStudent($infos);
  280.                 $child->setParentEmail($parents->getEmail());
  281.                 $this->em->persist($child);
  282.                 $this->em->flush();
  283.                 $SP = new StudentsParents();
  284.                 $SP->setStudent($child);
  285.                 $SP->setParents($parents);
  286.                 $this->em->persist($SP);
  287.                 $this->em->flush();
  288.                 $sub = new Subscription();
  289.                 $sub->setStudent($child);
  290.                 $sub->setGuardiant($parents);
  291.                 $sub->setOffer($offer);
  292.                 $sub->setPrice(isset($summary[$i]['price']) ? $summary[$i]['price'] : $offer->getPrice());
  293.                 $sub->setDiscount($discount);
  294.                 $sub->setSubscripted($now);
  295.                 if (!$withoutPayment) {
  296.                     if (!$offer->getCharge()) {
  297.                         $subscriptionStripe = $this->createSubscription($parents->getStripeId(), $discount);
  298.                         $sub->setStripeId($subscriptionStripe["id"]);
  299.                     } else {
  300.                         !$withoutPayment ? $sub->setPaymentFutur($pp) : null;
  301.                         $monthValid = $offer->getMonthValid();
  302.                         if (is_numeric($monthValid)) {
  303.                             $clone = clone $now;
  304.                             $clone->modify('+8 day')->modify(sprintf('+%d months', $monthValid));
  305.                             $sub->setUnSubscripted($clone);
  306.                         }
  307.                     }
  308.                 } else {
  309.                     $unSubscriptedDate = clone $now;
  310.                     $monthValid = $offer->getMonthValid();
  311.                     $monthValid ? $sub->setUnSubscripted($unSubscriptedDate->modify(sprintf('+%d months', $monthValid))) : null;
  312.                     $discountAptar = $this->em->getRepository(Discount::class)->findOneByStripeId('aptar');
  313.                     $sub->setDiscount($discountAptar);
  314.                     $parents->setRoles(['ROLE_PARENTS']);
  315.                     $child->addRoles(['ROLE_STUDENT']);
  316.                 }
  317.                 $sub->setBankStripe(true);
  318.                 $sub->setByChecked(false);
  319.                 $sub->setRenew(false);
  320.                 $sub->setIsMobile(false);
  321.                 $clone = clone $now;
  322.                 $sub->setTrialDate(!$withoutPayment ? $clone->modify('+8 day') : null);
  323.                 $this->em->persist($sub);
  324.                 $this->em->flush();
  325.                 $i++;
  326.             }
  327.             return true;
  328.         }
  329.         return false;
  330.     }
  331.     public function processCheckout2(Parents $parents,$paymentMethod,$paymentIntent)
  332.     {
  333.         $moreChildrenActive = false;
  334.         $session = $this->requestStack->getSession();
  335.         $allSubscrptionActive = $this->em->getRepository(Subscription::class)->getCurrentSubscriptionsByParent($parents);
  336.         if(count($allSubscrptionActive)>0){
  337.             $moreChildrenActive = true;
  338.         }
  339.         $childInfos = $session->get('customInfosSecondStep')["parents_registration_second_step"]['childrenForm'];
  340.         $slugOffer     = $session->get('slugOffer');
  341.         $slugDiscount  = $session->get('slugDiscount');
  342.         $discount = $pp = null;
  343.         $amount = 0;
  344.         $offer = $this->em->getRepository(Offer::class)->findOneBySlug($slugOffer);
  345.         $i = 0;
  346.         $now = new \DateTime('now');
  347.         $trial = clone $now;
  348.         $trial->modify('+7 day')->modify('-1 minutes');
  349.         if (!empty($childInfos) && $offer) {
  350.             if($offer->getCharge()){
  351.                 $pp = new PaymentFutur();
  352.                 $pp->setParents($parents);
  353.                 $pp->setDatePayment($trial);
  354.                 $this->em->persist($pp);
  355.                 $this->em->flush();
  356.             }
  357.             foreach ($childInfos as $infos) {
  358.                 $discount = $this->em->getRepository(Discount::class)->findOneByStripeId($slugDiscount);
  359.                 $child = $this->registrationStudent($infos);
  360.                 $child->setParentEmail($parents->getEmail());
  361.                 $child->setRoles(['ROLE_STUDENT']);
  362.                 if($offer->getTypeOffer() && $offer->getTypeOffer()->getSlug()=='visio'){
  363.                     $child->setRoles(['ROLE_STUDENT','ROLE_MENTORAT']);
  364.                 }
  365.                 $this->em->persist($child);
  366.                 $this->em->flush();
  367.                 $SP = new StudentsParents();
  368.                 $SP->setStudent($child);
  369.                 $SP->setParents($parents);
  370.                 $this->em->persist($SP);
  371.                 $this->em->flush();
  372.                 $sub = new Subscription();
  373.                 $sub->setSubscripted($now);
  374.                 $sub->setStudent($child);
  375.                 $sub->setGuardiant($parents);
  376.                 $sub->setOffer($offer);
  377.                 if( $discount ){
  378.                     if($i>0 || $moreChildrenActive){
  379.                         $discount = $discount->getMoreChildReduce();
  380.                     }
  381.                 }else{
  382.                     if($i>0 || $moreChildrenActive) {
  383.                         $discount = $this->em->getRepository(Discount::class)->findOneByStripeId('remise50percent');
  384.                     }
  385.                 }
  386.                 $sub->setDiscount($discount);
  387.                 $sub->setPrice($sub->getAmount());
  388.                 $sub->setTrialDate($trial);
  389.                 if(!$offer->getCharge()){
  390.                     $data = [
  391.                         "customer" => $parents->getStripeId(),
  392.                         "items"    => [['price'=>$offer->getStripeId()]],
  393.                         "trial_end"=> $trial->format('U'),
  394.                         //   "default_payment_method"=>$paymentMethod,
  395.                         "collection_method"=>"charge_automatically",
  396.                         "off_session"=> true,
  397.                         "payment_settings"=>[
  398.                             "payment_method_types"=>['sepa_debit', 'card'],
  399.                             "save_default_payment_method"=>"on_subscription",
  400.                             "payment_method_options"=>["card"=>["request_three_d_secure"=>"any"]]
  401.                         ]
  402.                     ];
  403.                     if(!is_null($discount)){
  404.                         $data = $discount?array_merge($data,['coupon' => strtoupper($discount->getStripeId())]):$data;
  405.                     }
  406.                     $subscriptionStripe = $this->stripeService->getStripeClient()->subscriptions->create($data);
  407.                     $sub->setStripeId($subscriptionStripe["id"]);
  408.                 }else{
  409.                     if($offer->getSlug()=='bac-francais'){
  410.                         $limit = \DateTime::createFromFormat('Y-m-d H:i:s', '2023-06-17 23:59:59');
  411.                         $sub->setUnSubscripted($limit);
  412.                         $sub->setPurchaseBacFrancaisAt($sub->getSubscripted());
  413.                     }
  414.                 }
  415.                 $sub->setBankStripe(true);
  416.                 $sub->setByChecked(false);
  417.                 $sub->setRenew(false);
  418.                 $sub->setIsMobile(false);
  419.                 $sub->setPrice($offer->getPrice());
  420.                 $sub->setPaymentFutur($pp);
  421.                 $this->em->persist($sub);
  422.                 $this->em->flush();
  423.                 $i++;
  424.                 if($offer->getSlug()=='bac-francais'){
  425.                     $this->mailer->bacFrancaisConfirmationMail($parents,$child);
  426.                 }
  427.                 $amount+=$sub->getAmount();
  428.             }
  429.             if(!is_null($pp)){
  430.                 $pp->setPrice($amount);
  431.                 $this->em->flush();
  432.             }
  433.             return true;
  434.         }
  435.         return false;
  436.     }
  437.     public function checkCouponForFirstSubscription($coupon)
  438.     {
  439.         $data   = $this->requestStack->getSession()->get('summary');
  440.         $one    = $this->em->getRepository(Discount::class)->getDiscount(strtoupper($coupon));
  441.         if(!is_null($one) && $one->actif() && $one->getStripeId()){
  442.             $data[0]['discount']=[
  443.                 'percent'  =>$one->getPercent(),
  444.                 'duration' => $one->getDuration(),
  445.                 'durationInMonths'=> $one->getDurationInMonths(),
  446.                 'id'      => $one->getId(),
  447.             ];
  448.             if(array_key_exists('price',$data[0])){
  449.                 $data[0]['price'] = round($data[0]['price'] - $data[0]['price'] * $one->getPercent()/100,2);
  450.             }
  451.             $this->requestStack->getSession()->set('summary',$data);
  452.             $som = 0;
  453.             if(array_key_exists('price',$data[0])){
  454.                 foreach ($data as $row){
  455.                     $som+=$row['price'];
  456.                 }
  457.             }
  458.             $offerIds = [];
  459.             if(!$one->getAllowOffer()->isEmpty()){
  460.                 foreach ($one->getAllowOffer() as $offer){
  461.                     $offerIds[]=$offer->getId();
  462.                 }
  463.             }
  464.             return [
  465.                 'code'=>$one->getStripeId(),
  466.                 'percent'=>$one->getPercent(),
  467.                 'percentMulti'=>$one->getMoreChildReduce()?$one->getMoreChildReduce()->getPercent():null,
  468.                 'price'=>array_key_exists('price',$data[0])?$data[0]['price']:0,
  469.                 'som'=>$som,
  470.                 'description'=>is_null($one->getDescription())?$one->getTitle():$one->getDescription(),
  471.                 'allowOffer'=>$offerIds
  472.             ];
  473.         }
  474.         return false;
  475.     }
  476.     public function createSubscription($clientStripeId,$discount=null){
  477.         $session = $this->requestStack->getSession();
  478.         $slug  = $session->get('customOffer');
  479.         $offer = $this->em->getRepository(Offer::class)->findOneBySlug($slug);
  480.         if($offer){
  481.             return $this->stripeService->createSubscriptionByData($clientStripeId,$offer->getStripeId(),[],true,$discount);
  482.         }
  483.         return false;
  484.     }
  485.     public function createSubscriptionEndEssaiGratuit($slug, $clientStripeId,$discount=null){
  486.         $offer = $this->em->getRepository(Offer::class)->findOneBySlug($slug);
  487.         if($offer){
  488.             // Trial FALSE
  489.             return $this->stripeService->createSubscriptionByData($clientStripeId,$offer->getStripeId(),[],false,$discount);
  490.         }
  491.         return false;
  492.     }
  493.     public function registerInfosTunnel($currentUser,$ritId = null){
  494.         $session = $this->requestStack->getSession();
  495.         if(!is_null($ritId)){
  496.             $rit = $this->em->getRepository(RegisterInfosTunnel::class)->find($ritId);
  497.         }else{
  498.             $rit = new RegisterInfosTunnel();
  499.         }
  500.         if($currentUser){
  501.             $rit->setCustomer($currentUser);
  502.             $rit->setEmailParents($currentUser->getEmail());
  503.         }else{
  504.             $parentsData  = $this->registrationParentEssaiGratuit();
  505.             $parentsInfosData = ['firstname'=>$parentsData->getFirstname(),'lastname'=>$parentsData->getLastname(),'phone'=>$parentsData->getPhone()];
  506.             $rit->setInfosParents($parentsInfosData);
  507.             $rit->setEmailParents($parentsData->getEmail());
  508.         }
  509.         $slugOffer     = $session->get('slugOffer');
  510.         $slugDiscount  = $session->get('slugDiscount');
  511.         $offer  = $this->em->getRepository(Offer::class)->findOneBySlug($slugOffer);
  512.         $coupon = $slugDiscount?$this->em->getRepository(Discount::class)->findOneByCodePromo($slugDiscount):null;
  513.         $rit->setOffer($offer);
  514.         $rit->setDiscount($coupon);
  515.         if(!$currentUser){
  516.             $infosChild   = $session->get('customInfosSecondStep')["parents_registration_second_step"]['childrenForm'];
  517.             if(is_array($infosChild) && !empty($infosChild)){
  518.                 $rit->setInfosChild($infosChild);
  519.             }
  520.         }
  521.         if(is_null($ritId)){
  522.             $this->em->persist($rit);
  523.         }
  524.         $this->em->flush();
  525.         return $rit;
  526.     }
  527. }