src/Controller/OrderSuccessController.php line 105

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Order;
  4. use App\Services\Cart;
  5. use App\Services\Mail;
  6. use App\Entity\Forecast;
  7. use App\Entity\HistoriquePaiement;
  8. use App\Repository\CartRepository;
  9. use App\Repository\OrderRepository;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use App\Repository\EtatPaiementRepository;
  12. use App\Repository\TypepaiementRepository;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. /**
  18.  * @IsGranted("ROLE_USER")
  19.  */
  20. class OrderSuccessController extends AbstractController
  21. {
  22.     private $em;
  23.     public function __construct(EntityManagerInterface $em){
  24.         $this->em $em;
  25.     }
  26.     /**
  27.      * @Route("/commande/success/", name="order_validate")
  28.      * @Route("/commande/success/{reference}", name="order_validate_no_pay")
  29.      */
  30.     public function index(
  31.         EtatPaiementRepository $repo,
  32.         CartRepository $cartRepo,
  33.         TypepaiementRepository $typepaiementRepo,
  34.         OrderRepository $orderRepo,
  35.         $reference null
  36.         ): Response
  37.     {
  38.         $carts $cartRepo->findByUser($this->getUser());
  39.         if ($this->getUser()->getGrossiste()->getIsPaid() == && isset($_GET['payment_intent_client_secret'])) {
  40.             
  41.             $stripeSessionId    $_GET['payment_intent_client_secret'];
  42.             $order              $orderRepo->findOneByStripeSessionId($stripeSessionId);
  43.             $typepaiement       $typepaiementRepo->findOneById(1);
  44.             $etatPaiement       $repo->findOneById(1);
  45.             $hitorique_paiement = new HistoriquePaiement();
  46.             $order->setEtatpaiement($etatPaiement)
  47.                   ->setTypepaiement($typepaiement)
  48.                   ->setMontantPaye($order->getTotal())
  49.                   ->setDateLastPaiement(new \DateTime());
  50.             //insertion dans la table historique_paiement
  51.             $hitorique_paiement->setUser($this->getUser())
  52.                                ->setMyOrder($order)
  53.                                ->setMotantPaye($order->getTotal())
  54.                                ->setDatePaiement(new \DateTime())
  55.                                ->setTypepaiement($typepaiement)
  56.                                ->setIsValid(true);
  57.             $this->em->persist($hitorique_paiement);
  58.             
  59.             foreach ($carts as $cart) {
  60.                 $this->em->remove($cart);
  61.             }
  62.             $this->em->flush();
  63.             return $this->render('order_success/index.html.twig', [
  64.                 'order' => $order,
  65.             ]);
  66.         }else{
  67.             
  68.             foreach ($carts as $cart) {
  69.                 $this->em->remove($cart);
  70.             }
  71.             $hitorique_paiement = new HistoriquePaiement();
  72.             $order $orderRepo->findOneByReference($reference);
  73.             $hitorique_paiement->setUser($this->getUser())
  74.                                ->setMyOrder($order)
  75.                                ->setMotantPaye(0)
  76.                                ->setTypepaiement($order->getTypepaiement())
  77.                                ->setIsValid(false);
  78.             $this->em->persist($hitorique_paiement);
  79.             $this->em->flush();
  80.             return $this->render('order_success/index.html.twig', [
  81.                 'order' => $order,
  82.             ]);
  83.         }
  84.     }
  85.     /**
  86.      * @Route("/commande/success-prevision/", name="prevision_validate")
  87.      * @Route("/commande/success-prevision/{reference}", name="forcast_validate_no_pay")
  88.      */
  89.     public function forcastSuccess(
  90.         EtatPaiementRepository $repo
  91.         $reference null
  92.         CartRepository $cartRepo,
  93.         TypepaiementRepository $typepaiementRepo
  94.         ): Response
  95.     {
  96.         $carts              $cartRepo->findByUser($this->getUser());
  97.         $etatPaiement       $repo->findOneById(1);
  98.         $typepaiement       $typepaiementRepo->findOneById(1);
  99.         $hitorique_paiement = new HistoriquePaiement();
  100.         if ($this->getUser()->getGrossiste()->getIsPaid() == && isset($_GET['payment_intent_client_secret'])) {
  101.             $stripeSessionId $_GET['payment_intent_client_secret'];
  102.             $forcast         $this->em->getRepository(Forecast::class)->findOneByStripeSessionId($stripeSessionId);
  103.             $forcast->setEtatpaiement($etatPaiement)
  104.                     ->setTypepaiement($typepaiement)
  105.                     ->setStripeSessionId($stripeSessionId);
  106.                     //etatpaiement_id;
  107.             //insertion dans la table historique_paiement
  108.             $hitorique_paiement->setUser($this->getUser())
  109.                                ->setForecast($forcast)
  110.                                ->setMotantPaye($forcast->getTotal())
  111.                                ->setDatePaiement(new \DateTime())
  112.                                ->setTypepaiement($typepaiement)
  113.                                ->setIsValid(true);
  114.             $this->em->persist($hitorique_paiement);       
  115.         }else{
  116.             $forcast            $this->em->getRepository(Forecast::class)->findOneByReference($reference);
  117.             $hitorique_paiement = new HistoriquePaiement();
  118.             $order              $this->em->getRepository(Forecast::class)->findOneByReference($reference);
  119.             $hitorique_paiement->setUser($this->getUser())
  120.                                 ->setForecast($forcast)
  121.                                 ->setMotantPaye(0)
  122.                                 ->setTypepaiement($forcast->getTypepaiement())
  123.                                 ->setIsValid(false);
  124.             $this->em->persist($hitorique_paiement);
  125.         }
  126.         foreach ($carts as $cart) {
  127.             $this->em->remove($cart);
  128.         }
  129.         $this->em->flush();
  130.         
  131.         return $this->render('order_success/prevoir.html.twig', [
  132.             'order' => $forcast
  133.         ]);
  134.     }
  135. }