Linux SRV-16 6.18.44-paas #1 SMP PREEMPT_DYNAMIC Thu Aug 13 10:08:12 UTC 2026 x86_64
/
srv
/
data
/
web
/
vhosts
/
www.humitest.fr
/
htdocs
/
src
/
Controller
/
front
/
/srv/data/web/vhosts/www.humitest.fr/htdocs/src/Controller/front/PaymentController.php
<?php namespace App\Controller\front; use App\Entity\Command; use App\Services\Mailer; use App\Services\MyService; use App\Entity\CommandProduct; use App\Services\StripeService; use App\Services\GeneratePdfService; use Symfony\Component\Asset\Package; use App\Repository\CommandRepository; use App\Repository\ProductRepository; use App\Repository\ConfigurationRepository; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy; class PaymentController extends AbstractController { const PAYEMENT_STATE_ERROR = "Erreur payement"; const PAYEMENT_STATE_SUCCESSS = "Payement effectué"; const PAYEMENT_STATE_CANCELED = "Commande Annulée"; /** * @Route("/paiement", name="product_payment") */ public function payement(Session $session, ProductRepository $productRepository, ConfigurationRepository $configurationRepository, Request $request, RouterInterface $router, CommandRepository $commandRepository) { $session->set("disabled-cart", "true"); $data = $session->get('information'); $myService = new MyService($productRepository, $session, $configurationRepository); $products = $myService->getCart(); $poidsTotalLivraison = 0; foreach ($products as $product) { $poids = (float)$product['object']->getPoidsKg() * $product["qtt"]; $poidsTotalLivraison += $poids; } $carts = $session->get('carts'); $cart_total = $session->get('cart_total'); $pk_stripe = $this->getParameter('conf_pk_stripe'); //Message d'erreur $message = " Attention, le poids total de votre commande est trop élevé, veuillez contacter notre service commercial."; $maxWeight = 0; switch ($data["country"]) { case "FR": $delivery = (float)$configurationRepository->deliveryByZone($poidsTotalLivraison, "'France'")["value"]; $maxWeight = (float)$configurationRepository->poidsFrMax()[1]; break; case "RE": case "GP": case "MQ": case "GF": $delivery = (float)$configurationRepository->deliveryByZone($poidsTotalLivraison, "'Dom'")["value"]; $maxWeight = (float)$configurationRepository->poidsDomMax()[1]; break; default: $delivery = (float)$configurationRepository->deliveryByZone($poidsTotalLivraison, "'Europe'")["value"]; $maxWeight = (float)$configurationRepository->poidsEuropeMax()[1]; break; } $tva = $configurationRepository->findOneByName('tva'); $tauxTva = (float)$tva->getValue(); $totalWithoutSolde = $myService->getTotal(); if ($data['discount'] != null) { $totalHt = $myService->getTotalWithDiscount(); $totalHtWithDelivery = $totalHt + $delivery; $montantTva = $totalHtWithDelivery * $tauxTva; $ttc = $montantTva + $totalHtWithDelivery; } if ($data['solde'] != null) { $totalHt = $myService->getTotal($data['solde']); $totalHtWithDelivery = $totalHt + $delivery; $montantTva = $totalHtWithDelivery * $tauxTva; $ttc = $montantTva + $totalHtWithDelivery; } if ($data['solde'] == null and $data['discount'] == null) { $totalHt = $myService->getTotal(); $totalHtWithDelivery = $totalHt + $delivery; $montantTva = $totalHtWithDelivery * $tauxTva; $ttc = $totalHtWithDelivery + $montantTva; } $command = new Command; $idLastOrder = $commandRepository->derniereCommande(); $idNewOrder = $idLastOrder + 1; $data = $session->get('information'); if ($idNewOrder <= 99) { $productKey = "MAIN-" . "000" . $idNewOrder; } else if ($idNewOrder <= 999) { $productKey = "MAIN-" . "00" . $idNewOrder; } else if ($idNewOrder <= 9999) { $productKey = "MAIN-" . "0" . $idNewOrder; } else { $productKey = "MAIN-" . $idNewOrder; } $PBX_CMD = $productKey; $data['productKey'] = $productKey; $myService = new MyService($productRepository, $session, $configurationRepository); $products = $myService->getCart(); $em = $this->getDoctrine()->getManager(); $command->setPayementStatus(self::PAYEMENT_STATE_ERROR); $command->setOrderKey($data['productKey']); $command->setCompanyName($data['companyName']); $command->setFirstname($data['firstname']); $command->setLastname($data['lastname']); $command->setEmail($data['email']); $command->setPhone($data['phone']); $command->setAddress($data['address']); $command->setZipcode($data['zipcode']); $command->setCity($data['city']); $command->setCountry($data['country']); $command->setStripeKey("null"); $command->setNoteCommande($data['noteCommande']); $command->setTotalOrderTTC($ttc); $command->setDelivery($delivery); $command->setTva($tva->getValue()); $command->setTotalHt($totalHt); $command->setBilling("no-billing-yet"); foreach ($products as $product) { $commandProduct = new CommandProduct; $commandProduct->setQuantity($product['qtt']); $commandProduct->setPrice($product['object']->getPrice()); $commandProduct->setProduct($product['object']); $em->persist($commandProduct); $command->addCommandProduct($commandProduct); } $em->persist($command); $em->flush(); if (!empty($carts) && !empty($data) && !empty($cart_total)) { $absPath = $this->getParameter('kernel.project_dir') . '/public/'; $package = new Package(new JsonManifestVersionStrategy($absPath . 'build/manifest.json')); $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath(); $data['image'] = $baseurl . $package->getUrl('build/images/default-image.png'); $data['name'] = $this->getParameter('conf_company_name'); $data['description'] = 'Paiement de ' . $data['firstname'] . ' ' . $data['lastname']; $amount = round($ttc, 2); $data['amount'] = $amount * 100; $data['success_url'] = $baseurl . $router->generate('payment_success', ["id" => $command->getId()]); $data['cancel_url'] = $baseurl . $router->generate('payment_cancel'); // dd($data["success_url"]); $session->set('information', $data); } else { $msg = 'Vous n\'avez pas accès à cette page'; $this->addFlash('danger', $msg); return $this->redirectToRoute('cart'); } if (!empty($data)) { $sk_stripe = $this->getParameter('conf_sk_stripe'); $stripeSevice = new StripeService($sk_stripe); $checkout = $stripeSevice->checkout($data); $data['delivery'] = $delivery; $data['tva'] = $montantTva; $data['rateVat'] = $tauxTva * 100; $data['totalHt'] = $totalHt; $data['totalTtc'] = $ttc; $data['stripeKey'] = $checkout->payment_intent; $data['totalWithoutSolde'] = $totalWithoutSolde; $session->set('information', $data); } //PAYBOX DATAS $PBX_SITE = "1600847"; $PBX_RANG = "001"; $PBX_IDENTIFIANT = "38021356"; // PAYBOX DATAS TEST /*$PBX_SITE = "1999888"; $PBX_RANG = "32"; $PBX_IDENTIFIANT = "2";*/ $PBX_TOTAL = $ttc * 100; $PBX_DEVISE = 978; $session->set('information', $data); $delivery = $myService->getDelivery(); $tva = $configurationRepository->findOneByName('tva'); $data['conf_server_email'] = $this->getParameter('conf_server_email'); $data['conf_company_name'] = $this->getParameter('conf_company_name'); $data['conf_company_business'] = $this->getParameter('conf_company_business'); $data['conf_company_siret'] = $this->getParameter('conf_company_siret'); $data['conf_company_phone'] = $this->getParameter('conf_company_phone1'); $data['conf_company_email'] = $this->getParameter('conf_company_email'); $data['conf_company_email2'] = $this->getParameter('conf_company_email2'); $data['conf_company_address'] = $this->getParameter('conf_company_address'); $data['conf_company_zipcode'] = $this->getParameter('conf_company_zipcode'); $data['conf_company_city'] = $this->getParameter('conf_company_city'); $data['conf_company_country'] = $this->getParameter('conf_company_country'); $data["company"] = ($this->getUser()) ? $this->getUser()->getCompany() : null; $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath(); $data['url_website'] = $baseurl; $data['productKey'] = $productKey; $data['delivery'] = $delivery; $data['products'] = $products; $id = $command->getId(); $PBX_PORTEUR = $data['email']; $PBX_RETOUR = "Mt:M;Ref:R;Auto:A;Erreur:E;"; $PBX_HASH = "SHA512"; $PBX_TIME = urlencode(date("c")); // Nouvelle clée $secretKeyLive = "E5C0B37F5022ED99DBBC4F7F21B17CDF20B86D5D2F0FBE4B1C57218BAB21FC4BD431835537EA49242AE5519133EDF41E11880B28452A92CF2B6B408974E765CB"; $PBX_EFFECTUE = $router->generate("payment_success", ["id" => $command->getId()]); $msg_paybox = "PBX_SITE=$PBX_SITE" . "&PBX_RANG=$PBX_RANG" . "&PBX_IDENTIFIANT=$PBX_IDENTIFIANT" . "&PBX_TOTAL=$PBX_TOTAL" . "&PBX_DEVISE=$PBX_DEVISE" . "&PBX_CMD=$PBX_CMD" . "&PBX_PORTEUR=$PBX_PORTEUR" . "&PBX_RETOUR=$PBX_RETOUR" . "&PBX_HASH=$PBX_HASH" . "&PBX_TIME=$PBX_TIME"; $binKey = pack("H*", $secretKeyLive); $PBX_HMAC = strtoupper(hash_hmac('sha512', $msg_paybox, $binKey)); return $this->render('front/product/payment.html.twig', [ 'tva' => $montantTva, 'delivery' => $delivery, 'totalHt' => $totalHt, 'totalWithoutSolde' => $totalWithoutSolde, 'ttc' => $ttc, 'information' => $data, 'products' => $products, 'slug' => 'cart', 'pk_stripe' => $pk_stripe, 'session_id' => $checkout->id, 'poidsTotal' => $poidsTotalLivraison, 'message' => $message, 'maxWeight' => $maxWeight, //paybox datas 'PBX_SITE' => $PBX_SITE, 'PBX_RANG' => $PBX_RANG, 'PBX_IDENTIFIANT' => $PBX_IDENTIFIANT, 'PBX_TOTAL' => $PBX_TOTAL, 'PBX_DEVISE' => $PBX_DEVISE, 'PBX_CMD' => $PBX_CMD, 'PBX_PORTEUR' => $PBX_PORTEUR, 'PBX_RETOUR' => $PBX_RETOUR, 'PBX_HASH' => $PBX_HASH, 'PBX_TIME' => $PBX_TIME, 'PBX_HMAC' => $PBX_HMAC, 'PBX_EFFECTUE' => $PBX_EFFECTUE ]); } /** * @Route("/paiement-accepte", name="payment_success", methods="GET") */ public function paymentSuccess(CommandRepository $commandRepository, Session $session, Request $request, Mailer $mailer, ProductRepository $productRepository, ConfigurationRepository $configurationRepository): Response { $session->set("disabled-cart", "false"); $orderKey = $request->query->get("Ref"); $command = $commandRepository->findOneBy(["orderKey" => $orderKey]); $command->setPayementStatus(self::PAYEMENT_STATE_SUCCESSS); $productKey = $command->getId(); while (strlen($productKey) < 4) { $productKey = "0" . $productKey; } $productKey = "MAIN-$productKey"; $data['conf_server_email'] = $this->getParameter('conf_server_email'); $data['conf_company_name'] = $this->getParameter('conf_company_name'); $data['conf_company_business'] = $this->getParameter('conf_company_business'); $data['conf_company_siret'] = $this->getParameter('conf_company_siret'); $data['conf_company_phone'] = $this->getParameter('conf_company_phone1'); $data['conf_company_email'] = $this->getParameter('conf_company_email'); $data['conf_company_email2'] = $this->getParameter('conf_company_email2'); $data['conf_company_address'] = $this->getParameter('conf_company_address'); $data['conf_company_zipcode'] = $this->getParameter('conf_company_zipcode'); $data['conf_company_city'] = $this->getParameter('conf_company_city'); $data['conf_company_country'] = $this->getParameter('conf_company_country'); $data["company"] = ($this->getUser()) ? $this->getUser()->getCompany() : null; $data["firstname"] = $command->getFirstname(); $data["lastname"] = $command->getLastname(); $data["address"] = $command->getAddress(); $data["zipcode"] = $command->getZipcode(); $data["city"] = $command->getCity(); $data["phone"] = $command->getPhone(); $data["productKey"] = $productKey; $data["totalHt"] = $command->getTotalHt(); $data["delivery"] = $command->getDelivery(); $data["tva"] = $command->getTva(); $myService = new MyService($productRepository, $session, $configurationRepository); $tva = $configurationRepository->findOneByName('tva'); $tauxTva = (float)$tva->getValue(); $totalWithoutSolde = $myService->getTotal(); $data["rateVat"] = $tauxTva * 100; $products = $myService->getCart(); $data["products"] = $products; $totalWithoutSolde = $myService->getTotal(); $data["totalWithoutSolde"] = $totalWithoutSolde; $data["totalTtc"] = $command->getTotalOrderTTC(); $data["email"] = $command->getEmail(); $absPath = $this->getParameter('kernel.project_dir') . '/public/'; $filename = $absPath . "upload/billing/BDC-" . $productKey . ".pdf"; $command->setBilling("BDC-" . $productKey . ".pdf"); // dd( $data); $generatePdfService = new GeneratePdfService; $template = $this->renderView('front/product/billing/billing.html.twig', [ 'data' => $data, ]); $generatePdfService->Pdf($filename, $template); $MailerConfirmation = 'front/product/mail/mail_confirmation.html.twig'; $MailerAdmin = 'front/product/mail/mail_admin.html.twig'; // MAILER // dd($data); $this->mailerConfirmation($mailer, $data, $MailerConfirmation, $filename); $this->mailerAdmin($mailer, $data, $MailerAdmin, $filename); // END MAILER $em = $this->getDoctrine()->getManager(); $em->persist($command); $em->flush(); $session->remove('information'); $session->remove('carts'); $this->addFlash('success', 'Paiement accepté ! Merci pour votre commande et votre confiance !'); return $this->redirectToRoute('home'); } /** * @Route("/paiement-cancel", name="payment_cancel", methods="GET") */ public function paymentCancel(RouterInterface $router, Session $session, Request $request, CommandRepository $commandRepository): Response { $orderKey = $request->query->get("Ref"); $command = $commandRepository->findOneBy(["orderKey" => $orderKey]); if ($request->query->get('Erreur') === "00001") { $command->setPayementStatus(self::PAYEMENT_STATE_CANCELED); } else { $command->setPayementStatus(self::PAYEMENT_STATE_ERROR); } $session->set("disabled-cart", "false"); $session->remove('information'); $session->remove('carts'); $this->addFlash('danger', 'Votre paiement a été decliné !'); return new RedirectResponse($router->generate('home')); } /** * @Route("/paiement-refuse/{id}", name="payment_refuse", methods="GET") */ public function paymentRefuse(RouterInterface $router, Session $session, Request $request, $id, CommandRepository $commandRepository): Response { $session->set("disabled-cart", "false"); $session->remove('information'); $session->remove('carts'); $command = $commandRepository->find($id); $command->setPayementStatus(self::PAYEMENT_STATE_CANCELED); $command->setStape(self::PAYEMENT_STATE_CANCELED); $em = $this->getDoctrine()->getManager(); $em->persist($command); $em->flush(); $this->addFlash('danger', 'Votre paiement a été decliné !'); return new RedirectResponse($router->generate('home')); } //////////////////////// //// ADMIN MAIL /////// ////////////////////// public function mailerAdmin($mailer, $data, $folder, $attachement) { $bodyMailContact = $mailer->createBodyMail($folder, ['data' => $data]); $mailer->sendMessage( $data['conf_company_name'], $data['conf_server_email'], $data['conf_company_email'], 'Une personne viens de faire un achat sur votre site ' . $data['conf_company_name'] . ' - ' . $data['productKey'], $bodyMailContact, $data['conf_company_email2'], $attachement ); } ////////////////////////// //// CONFIRMATION MAIL // //////////////////////// public function mailerConfirmation($mailer, $data, $folder, $attachement) { // on utilise le service Mailer créé précédemment $bodyMailConfirmation = $mailer->createBodyMail($folder, ['data' => $data]); $mailer->sendMessage( $data['conf_company_name'], $data['conf_server_email'], $data['email'], 'Confirmation - ' . $data['conf_company_name'] . ' - ' . $data['productKey'], $bodyMailConfirmation, null, $attachement ); } /** * @Route("/facture/{document}", name="app_facture_download") */ public function downloadDocument($document): BinaryFileResponse { $document = "../public/upload/billing/$document"; return new BinaryFileResponse($document); } }