src/Controller/ServicePaymentController.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\InfoSanteSubscription;
  4. use App\Entity\InfoSanteTransaction;
  5. use App\Entity\LabbaikSubscriber;
  6. use App\Entity\LabbaikSubscription;
  7. use App\Entity\LabbaikTransaction;
  8. use App\Entity\SysCloseStatus;
  9. use App\Entity\SysSmsHistory;
  10. use App\Entity\SysTransaction;
  11. use App\Entity\SmartloyerTransaction;
  12. use App\Message\ServicePayment;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Doctrine\Persistence\ManagerRegistry;
  15. use PhpParser\Node\Stmt\TryCatch;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use Symfony\Component\HttpClient\HttpClient;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. class ServicePaymentController extends AbstractController
  21. {
  22.     /**
  23.      * @Route("/service/payment", name="service_payment")
  24.      */
  25.     public function index(): Response
  26.     {
  27.         
  28.         //$this->dispatchMessage(new ServicePayment(57632,"",$this->getDoctrine()));
  29.         $this->payment(59613,"",$this->getDoctrine());
  30.         return $this->render('service_payment/index.html.twig', [
  31.             'controller_name' => 'ServicePaymentController',
  32.         ]);
  33.     }
  34.     /**
  35.      * @Route("/service/checkPaymentStatus", name="service_payment_status")
  36.      */
  37.     public function checkPaymentStatus(): Response
  38.     {
  39.         $resultReponse "OK";
  40.         $entityManager $this->getDoctrine()->getManager();
  41.         $repoTrans $entityManager->getRepository(SysTransaction::class);
  42.         $transactions $repoTrans->findBy(['clientPayementStatus' => ['PENDING''PROCESSING'], 'isClosed' => false]);
  43.         
  44.         foreach($transactions as $transaction){
  45.             if($transaction->getIsSuccessTransaction() && !$transaction->getIsClosed()){
  46.                 $resultReponse $resultReponse " " strval($transaction->getId());
  47.                 
  48.                 
  49.                 $url "http://liveapi.caurispay.com:10110/v1/userrequest/checkpaymentstatus";
  50.                 $apiKey 'KEY-QV9PD8GYOVYYI94ZSCT3YOU9';
  51.                 $apiSecret 'qAAAAABpJ8jWlsaftS5f0A_6MbNHOjGARZ12SaHVzHgsoe4Mk9Wv8rOQi2aS5wVXZ83hRPLDl_cSf_ZmzwPub5FYD9Qe6XqW9NjolHlJLhd8yVBOppHA5B2rHvK_mdZLBcaqHWOJGcuw0_zyGn_iLTZw67IS-bBRLged';
  52.                 $clientId 'COM-YWY9Q0BU3';
  53.                 $timestamp = (string)time();
  54.                 $payload = [
  55.                     "merchantReference" => $transaction->getClientPayementReference(),
  56.                     "precessingReference" => $transaction->getAdditionalPayementReference(),
  57.                 ];
  58.                 /**
  59.                  * ⚠️ TRI + JSON COMPACT (OBLIGATOIRE)
  60.                  */
  61.                 $sortedPayload $this->ksortRecursive($payload);
  62.                 $body json_encode($sortedPayloadJSON_UNESCAPED_SLASHES);
  63.                 /**
  64.                  * SIGNATURE HMAC
  65.                  */
  66.                 $signature hash_hmac(
  67.                     'sha256',
  68.                     $timestamp $body,
  69.                     $apiSecret
  70.                 );
  71.                 $headers = [
  72.                     'X-API-KEY' => $apiKey,
  73.                     'X-CLIENT-ID' => $clientId,
  74.                     'X-CLINET-TIMESTEMP' => $timestamp// oui, la faute est voulue
  75.                     'X-CLIENT-SIGNATURE' => $signature,
  76.                     'X-Secure-Version' => 'no',
  77.                     'Content-Type' => 'application/json',
  78.                 ];
  79.            
  80.                 $client HttpClient::create([
  81.                         'verify_peer' => false,
  82.                         'verify_host' => false,
  83.                     ]);
  84.                 $response $client->request('POST'$url, [
  85.                     'headers' => $headers,
  86.                     'body' => $body,
  87.                     'timeout' => 300,
  88.                 ]);
  89.                 $statusCode $response->getStatusCode();
  90.                 $result['statusCode'] = $statusCode;
  91.             //var_dump("Response code ===>");
  92.             //var_dump($response->getStatusCode());
  93.             //var_dump($response->toArray());
  94.             //$result["isSuccess"] = false;
  95.             $result["statusCode"] = $response->getStatusCode();             
  96.                     
  97.             //    $url = "https://bridgeapi.caurispay.com/payement/requestStatus";
  98.             //    $client = HttpClient::create([
  99.             //        'headers' => [
  100.             //        'User-Agent' => 'ReservLine',
  101.             //        'Connection' => 'keep-alive',
  102.             //        //'Content-Length' => strlen($body),
  103.             //        //'Authorization' => $authorization,
  104.             //        //'Content-Type' => 'application/json',
  105.             //        'Content-Type: application/x-www-form-urlencoded'
  106.             //        ],
  107.             //        'verify_peer' => false,
  108.             //        'verify_host' => false,
  109.             //        'body' => ['requestReference' => $transaction->getClientPayementReference()]
  110.             //    ]);
  111.             //
  112.             //    //try{
  113.             //
  114.             //        //}catch(){
  115.                     
  116.                 //}
  117.             //    $response = $client->request('POST', $url,['timeout' => 400]);
  118.                 
  119.             //    //var_dump( $transaction->getClientPayementReference());
  120.             //    //var_dump($response->getStatusCode());
  121.             //    //var_dump($response->getInfo());
  122.             //     
  123.                 if($response->getStatusCode() == 200 or $response->getStatusCode() ==202){
  124.                     $requestResponse $response->toArray();
  125.                     $transaction->setClientPayementStatus($requestResponse["status"]);
  126.                     //var_dump( $requestResponse);
  127.                     if(strcmp($requestResponse["status"],"PENDING") != ){
  128.                         $transaction->setClientPayementTime(new \DateTime('now'));
  129.                         if (isset($requestResponse['message'])) {
  130.                             $transaction->setClientPayementComment($requestResponse["message"]);
  131.                         }
  132.                         $textMessageSMS "";
  133.                         $textMessageSMSGAZADMIN ="";
  134.                         $repoClosStatus $entityManager->getRepository(SysCloseStatus::class);
  135.                         
  136.                         if(strcmp($requestResponse["status"],"SUCCESS") == ){
  137.                             $closeStatus $repoClosStatus->findOneBy(["statusCode" => "PDPROCS"]); //TODO: Add service code in condition
  138.                             $transaction->setIsClientPaid(true);
  139.                             $transaction->setAdditionalPayementComment($requestResponse["operatorRefId"]);
  140.                             switch ($transaction->getService()->getCodeService()) {
  141.                                 case "TTBUS":
  142.                                     //$textMessageSMS = str_replace("%idResv%", $transaction->getReservationCode() , $transaction->getService()->getTextSuccessPayementSMS());
  143.                                     $textMessageSMS $transaction->getSmsMessage();
  144.                                     break;
  145.                                 case "RCHGAZ":
  146.                                     $textMessageSMS $transaction->getSmsMessage();
  147.                                     
  148.                                     //Send admin notification email
  149.                                     if($transaction->getEmailNotif() != null){
  150.                                         SysNotifController::sendEmailGazNotif($transaction->getReservationCode() . "-" $transaction->getMsisdn(), $transaction->getEmailNotif());
  151.                                         $textMessageSMSGAZADMIN $transaction->getEmailNotif();
  152.                                     }
  153.                                     break;
  154.                                 case "SLOYER":
  155.                                     //$textMessageSMS = str_replace("%idResv%", $transaction->getReservationCode() , $transaction->getService()->getTextSuccessPayementSMS());
  156.                                     //saction = new SmartloyerTransaction();
  157.                                     $sloyerTransactionRepo $entityManager->getRepository(SmartloyerTransaction::class);
  158.                                     $sloyerTransaction $sloyerTransactionRepo->findOneBy(["sysTransaction" => $transaction]);
  159.                                     
  160.                                     $url "https://smartloyer.com/apipayement/makePayement";
  161.                                     $client HttpClient::create([
  162.                                         'headers' => [
  163.                                         'User-Agent' => 'ReservLine',
  164.                                         'Connection' => 'keep-alive',
  165.                                         //'Content-Length' => strlen($body),
  166.                                         //'Authorization' => $authorization,
  167.                                         //'Content-Type' => 'application/json',
  168.                                         'Content-Type: application/x-www-form-urlencoded'
  169.                                     ],
  170.                                     'verify_peer' => false,
  171.                                     'verify_host' => false,
  172.                                     'body' => ['payementId' => $sloyerTransaction->getPayementId(),
  173.                                             'payementRef' =>  $sloyerTransaction->getPayementRef(),
  174.                                             'ussdSessionRef' => $transaction->getSessionId(),
  175.                                             'ussdPayementRef' => $transaction->getClientPayementReference(), 
  176.                                             'ussdSessionPhone' => $transaction->getMsisdn()]
  177.                                     ]);
  178.         
  179.                                     $response $client->request('POST'$url,['timeout' => 400]);
  180.                                     $result["statusCode"] = $response->getStatusCode();
  181.                                     //var_dump($result["statusCode"]);
  182.                                     if($result["statusCode"] == 200 or $result["statusCode"] ==202){
  183.                                         $requestResponse $response->toArray();
  184.                                         //var_dump($requestResponse);
  185.                                         if($requestResponse["success"]){
  186.                                             $sloyerTransaction->setIsPayementUpdate(true);
  187.                                             $sloyerTransaction->setPayementUpdateTime(new \DateTime('now'));
  188.                                             $textMessageSMS $transaction->getSmsMessage();
  189.                                             $transaction->setIsClosed(true);
  190.                                         }//TODO: Add log for the else statement
  191.                                     }else{
  192.                                         $transaction->setIsClosed(false);
  193.                                     }
  194.                                     break;
  195.                                 case "ESANTE":
  196.                                     $textMessageSMS $transaction->getService()->getTextSuccessPayementSMS();
  197.                                     $transaction->setIsClosed(true);
  198.                                     $repoInfoSanteTransaction $entityManager->getRepository(InfoSanteTransaction::class);
  199.                                     $infoSanteTransaction $repoInfoSanteTransaction->findOneBy(["sysTansaction" => $transaction ]);
  200.                                     $repoSubscription $entityManager->getRepository(InfoSanteSubscription::class);
  201.                                     $subscription $repoSubscription->findOneBy(["msisdn"=>$transaction->getMsisdn(), "categorie" =>$infoSanteTransaction->getCategorie()]);
  202.                                     $toDay = new \DateTime('now');
  203.                                     if($subscription == null){
  204.                                         $subscription = new InfoSanteSubscription();
  205.                                         $subscription->setMsisdn($transaction->getMsisdn());
  206.                                         $subscription->setCreationDate(new \DateTime('now'));
  207.                                         $subscription->setCategorie($infoSanteTransaction->getCategorie());
  208.                                         $subscription->setIsActif(true);
  209.                                         $subscription->setStartDate(new \DateTime('now'));
  210.                                         $subscription->setExpiryDate(new \DateTime('now'));
  211.                                     }
  212.                                     $subscription->setIsActif(true);
  213.                                     $subscription->setUpdateDate(new \DateTime('now'));
  214.                                     
  215.                                     if($subscription->getExpiryDate() < $toDay){
  216.                                         $subscription->setStartDate(new \DateTime('now'));
  217.                                         $subscription->setExpiryDate($toDay);
  218.                                     }
  219.                                     $toDay $subscription->getExpiryDate();
  220.                                     $toDay date_add($toDay,date_interval_create_from_date_string(strval($infoSanteTransaction->getTypeAbonnement()->getNbrJours()) . " DAYS"));
  221.                                     $subscription->setExpiryDate(date_create(date_format($toDay,"Y-m-d H:i:s")) );
  222.                                     
  223.                                     $entityManager->persist($subscription);
  224.                                    
  225.                                     break;
  226.                                 case "LABBAIK":
  227.                                     $labbaikTransRepo $entityManager->getRepository(LabbaikTransaction::class);
  228.                                     $labbaikSubscriberRepo $entityManager->getRepository(LabbaikSubscriber::class);
  229.                                     $labbaikTransaction $labbaikTransRepo->findOneBy(['sysTransaction' => $transaction]);
  230.                                     $closeStatus $repoClosStatus->findOneBy(["statusCode" => "SUCCESS"]);
  231.                                     $labbaikTransaction->setTransactionStatus($closeStatus);
  232.                                     if(strcmp(strtolower($labbaikTransaction->getTransactionType()) ,"souscription")==or strcmp(strtolower($labbaikTransaction->getTransactionType()) ,"newsouscription")==0){
  233.                                         $textMessageSMS "Merci pour votre nouvelle souscription au service ".$labbaikTransaction->getSubscriptionType()->getLibelle().". Faite vos paiements a tout moment de votre choix en tapant *450*6#";
  234.                                         
  235.                                         //$subscription = $labbaikTransaction->getSubscription();
  236.                                         
  237.                                         //$subscriber = $labbaikSubscriberRepo->findOneBy(['telephoneNumber' => $transaction->getMsisdn()]);
  238.                                         //if($subscription == null){
  239.                                             //$subscriber = new LabbaikSubscriber();
  240.                                             //$subscriber->setTelephoneNumber($transaction->getMsisdn());
  241.                                             //$entityManager->persist($subscriber);
  242.                                             $subscription = new LabbaikSubscription();
  243.                                             $subscription->setSubscriber($labbaikTransaction->getSubscriber());
  244.                                             $subscription->setSubscribtionType($labbaikTransaction->getSubscriptionType());
  245.                                             $subscription->setMsisdn($labbaikTransaction->getMsisdn());
  246.                                             $subscription->setFeeSubscriptionPaid(true);
  247.                                             $subscription->setSubscriptionActivated(false);
  248.                                             $subscription->setAssPolice1Enable(false);
  249.                                             $subscription->setAssPolice2Enable(false);
  250.                                             $subscription->setAssPolice1Number(sprintf("%06d",strval($labbaikTransaction->getId())));
  251.                                             $subscription->setFeeSubscriptionPaid(true);
  252.                                             $subscription->setCreateDate(new \DateTime("Now"));
  253.                                             $subscription->setUpdateTime(new \DateTime("Now"));
  254.                                             $subscription->setMainBalance($labbaikTransaction->getSubscriptionType()->getCotisationAmount());
  255.                                             $entityManager->persist($subscription);
  256.                                         //}
  257.                                         $labbaikTransaction->setPaymentTime(new \DateTime('now'));
  258.                                         $labbaikTransaction->setPaymentValidated(true);
  259.                                         $labbaikTransaction->setAffectedPoliceId(1);
  260.                                         $labbaikTransaction->setBalanceBefore(0);
  261.                                         $labbaikTransaction->setBalanceAfter($subscription->getMainBalance());
  262.                                         $labbaikTransaction->setSubscription($subscription);
  263.                                         $entityManager->persist($labbaikTransaction);
  264.                                     }elseif(strcmp(strtolower($labbaikTransaction->getTransactionType()) ,"paiement")==0){
  265.                                        
  266.                                         //$labbaikSubscriptionRepo = $entityManager->getRepository(LabbaikSubscription::class);
  267.                                         $subscription $labbaikTransaction->getSubscription();
  268.                                         $labbaikTransaction->setAffectedPoliceId(1);
  269.                                         $labbaikTransaction->setBalanceBefore($subscription->getMainBalance());
  270.                                         $labbaikTransaction->setPaymentTime(new \DateTime('now'));
  271.                                         $labbaikTransaction->setPaymentValidated(true);
  272.                                         $subscription->setMainBalance($subscription->getMainBalance() + $labbaikTransaction->getTransactionAmount());
  273.                                         $entityManager->persist($subscription);
  274.                                         
  275.                                         $labbaikTransaction->setBalanceAfter($subscription->getMainBalance());
  276.                                         $entityManager->persist($labbaikTransaction);
  277.                                         $textMessageSMS "Payement de "strval(intval($labbaikTransaction->getTransactionAmount())) ." au service " $labbaikTransaction->getSubscriptionType()->getLibelle() ." effectue avec success. votre nouveau solde est de " strval(intval($subscription->getMainBalance())) . "F" ;
  278.                                     }
  279.                                     $transaction->setIsClosed(true);
  280.                                     //$textMessageSMS = $transaction->getSmsMessage();
  281.                                     //Send admin notification email
  282.                                     if($transaction->getEmailNotif() != null){
  283.                                         SysNotifController::sendEmailGazNotif($transaction->getReservationCode() . "-" $transaction->getMsisdn(), $transaction->getEmailNotif());
  284.                                     }
  285.                                     break;
  286.                                 
  287.                             }
  288.                         }else{
  289.                             $closeStatus $repoClosStatus->findOneBy(["statusCode" => "NOTPAID"]); //TODO: Add service code in condition
  290.                             $transaction->setIsClosed(true);
  291.                             $transaction->setCloseComment("Client payment fail");
  292.                             
  293.                             
  294.                             switch ($transaction->getService()->getCodeService()) {
  295.                                 
  296.                                 case "TTBUS":
  297.                                     $textMessageSMS str_replace("%idResv%"$transaction->getReservationCode() , $transaction->getService()->getTextFailedPayementSMS());
  298.                                     break;
  299.                                 case "RCHGAZ":                                   
  300.                                     $textMessageSMS str_replace("%idResv%"$transaction->getReservationCode() , $transaction->getService()->getTextFailedPayementSMS());
  301.                                     break;
  302.                                 case "SLOYER":
  303.                                     //$textMessageSMS = str_replace("%idResv%", $transaction->getReservationCode() , $transaction->getService()->getTextSuccessPayementSMS());
  304.                                     $textMessageSMS str_replace("%idResv%"$transaction->getReservationCode() , $transaction->getService()->getTextFailedPayementSMS());
  305.                                     break;
  306.                                 case "ESANTE":
  307.                                     $textMessageSMS str_replace("%idResv%"$transaction->getReservationCode() , $transaction->getService()->getTextFailedPayementSMS());
  308.                                     break;
  309.                                 case "LABBAIK":
  310.                                     $textMessageSMS =  $transaction->getService()->getTextFailedPayementSMS();
  311.                                     $labbaikTransRepo $entityManager->getRepository(LabbaikTransaction::class);
  312.                                     $labbaikTransaction $labbaikTransRepo->findOneBy(['sysTransaction' => $transaction]);
  313.                                     $labbaikTransaction->setTransactionStatus($closeStatus);
  314.                                     $entityManager->persist($labbaikTransaction);
  315.                                     //var_dump($textMessageSMS);
  316.                                     break;
  317.                             }
  318.                         }
  319.                         $transaction->setCloseStatus($closeStatus);
  320.                 
  321.                         if(strlen($textMessageSMS) > 0){
  322.                             //Send SMS
  323.                             //Send Message and Record SmsHistoy
  324.                             //SysSMSController::sendSMS($transaction->getMsisdn(),$textMessageSMS);
  325.                             //var_dump($textMessageSMS);
  326.                             SysSMSController::sendSMSWithParm($transaction->getMsisdn(),$textMessageSMS,$transaction->getOperator()->getCodeOperator(), $transaction->getService()->getSmsSenderName() );
  327.                             $sysSmsHistory = new SysSmsHistory();
  328.                             $sysSmsHistory->setMsisdn($transaction->getMsisdn());
  329.                             $sysSmsHistory->setMessageText($textMessageSMS);
  330.                             //$sysSmsHistory->setMessageText($textMessageSMS);
  331.                             $sysSmsHistory->setCreateTime(new \DateTime);
  332.                             $sysSmsHistory->setIsReceived(false);
  333.                             $sysSmsHistory->setTransaction($transaction);
  334.                             $sysSmsHistory->setSmsType('PAYMENT_MSG');
  335.                             $entityManager->persist($sysSmsHistory);
  336.                             //$entityManager->flush();
  337.                         }
  338.                         
  339.                         if(strlen($textMessageSMSGAZADMIN) > 0){
  340.                             //Send SMS
  341.                             //Send Message and Record SmsHistoy
  342.                             SysSMSController::sendSMSWithParm("22995000169",$textMessageSMSGAZADMIN,"MOOVBJ""RESERVLINE" );
  343.                             $sysSmsHistory = new SysSmsHistory();
  344.                             $sysSmsHistory->setMsisdn("22995000169");
  345.                             $sysSmsHistory->setMessageText($textMessageSMSGAZADMIN);
  346.                             $sysSmsHistory->setCreateTime(new \DateTime);
  347.                             $sysSmsHistory->setIsReceived(false);
  348.                             $sysSmsHistory->setTransaction($transaction);
  349.                             $sysSmsHistory->setSmsType('ADMIN');
  350.                             $entityManager->persist($sysSmsHistory);
  351.                             //$entityManager->flush();
  352.                         }
  353.                         //$transaction->setPayementReference($result["isSuccess"]);
  354.                         $entityManager->persist($transaction);
  355.                         $entityManager->flush();
  356.                     }
  357.                 }
  358.             }
  359.         }
  360.         //$this->dispatchMessage(new ServicePayment(56,$this->getDoctrine()));
  361.         $JResponse = new Response();
  362.         $JResponse->headers->set('Content-Type''application/json''charset=utf-8');
  363.         $JResponse->setCharset('UTF-8');
  364.         $JResponse->setContent(json_encode($resultReponse));
  365.         return $JResponse;
  366.     }
  367.     private function ksortRecursive(array $array): array
  368.     {
  369.         ksort($array);
  370.         foreach ($array as &$value) {
  371.             if (is_array($value)) {
  372.                 $value $this->ksortRecursive($value);
  373.             }
  374.         }
  375.         return $array;
  376.     }
  377.     public function payment(int $transctionIdstring $referenceId,ManagerRegistry  $doctrineRes){
  378.         //var_dump("Start paymenet ===>");
  379.         $entityManager $doctrineRes->getManager();
  380.         $repoTrans $doctrineRes->getRepository(SysTransaction::class);
  381.         $transaction $repoTrans->find($transctionId);
  382.         if($transaction->getIsSuccessTransaction() && !$transaction->getIsClosed()){
  383.             //sleep(1);
  384.             //var_dump("2Start paymenet request ===>");
  385.             $operateurCode "";
  386.             $payeReferentId $transaction->getReferenceId() . '+' $transaction->getReservationCode() . '+' strVal(rand(111,999));
  387.             $payementAmount ceil(intval($transaction->getServiceTransactionAmount()));
  388.             
  389.             
  390.             if(strcmp($transaction->getOperator()->getCodeOperator(),"MOOVBJ") == 0){
  391.                 //$operateurCode = "MOOVBENIN";
  392.                 $operateurCode "BJMOOV";
  393.             }    
  394.             if(strcmp($transaction->getOperator()->getCodeOperator(),"MTNBJ") == 0){
  395.                 //$operateurCode = "MTNBENIN";
  396.                 $operateurCode "BJMTN";
  397.             }
  398.             //$url = "https://caurispay.ridcode.com:8184/payement/requestPayement";
  399.             //$url = "https://bridgeapi.caurispay.com/payement/requestPayement";
  400.            
  401.            
  402.            $url "http://liveapi.caurispay.com:10110/v1/userrequest/makepayment";
  403.             $apiKey 'KEY-QV9PD8GYOVYYI94ZSCT3YOU9';
  404.             $apiSecret 'qAAAAABpJ8jWlsaftS5f0A_6MbNHOjGARZ12SaHVzHgsoe4Mk9Wv8rOQi2aS5wVXZ83hRPLDl_cSf_ZmzwPub5FYD9Qe6XqW9NjolHlJLhd8yVBOppHA5B2rHvK_mdZLBcaqHWOJGcuw0_zyGn_iLTZw67IS-bBRLged';
  405.             $clientId 'COM-YWY9Q0BU3';
  406.             $timestamp = (string)time();
  407.             $payload = [
  408.                 "amount" => $payementAmount,
  409.                 "currency" => "XOF",
  410.                 "customerMessage" => $transaction->getService()->getLibelle(),
  411.                 "merchantReference" => $payeReferentId,
  412.                 "feesByPayer" => "no",
  413.                 "operator" => [
  414.                     "countryCodeA2" => "bj",
  415.                     "operatorCode" => $operateurCode,
  416.                     "type" => "MMO"
  417.                 ],
  418.                 "payer" => [
  419.                     "accountNumber" => $transaction->getMsisdn(),
  420.                     "email" => "mailcel@gmail.com",
  421.                     "firstName" => "Prenom",
  422.                     "lastName" => "Nom",
  423.                     "phoneNumber" => $transaction->getMsisdn()
  424.                 ]
  425.             ];
  426.             /**
  427.              * ⚠️ TRI + JSON COMPACT (OBLIGATOIRE)
  428.              */
  429.             $sortedPayload $this->ksortRecursive($payload);
  430.             $body json_encode($sortedPayloadJSON_UNESCAPED_SLASHES);
  431.            
  432.            
  433.             /**
  434.              * SIGNATURE HMAC
  435.              */
  436.             $signature hash_hmac(
  437.                 'sha256',
  438.                 $timestamp $body,
  439.                 $apiSecret
  440.             );
  441.             $headers = [
  442.                 'X-API-KEY' => $apiKey,
  443.                 'X-CLIENT-ID' => $clientId,
  444.                 'X-CLINET-TIMESTEMP' => $timestamp// oui, la faute est voulue
  445.                 'X-CLIENT-SIGNATURE' => $signature,
  446.                 'X-Secure-Version' => 'no',
  447.                 'Content-Type' => 'application/json',
  448.             ];
  449.            
  450.            $client HttpClient::create([
  451.                 'verify_peer' => false,
  452.                 'verify_host' => false,
  453.             ]);
  454.             //var_dump( $url);
  455.             $response $client->request('POST'$url, [
  456.                 'headers' => $headers,
  457.                 'body' => $body,
  458.                 'timeout' => 30,
  459.             ]);
  460.             $statusCode $response->getStatusCode();
  461.             $result['statusCode'] = $statusCode;
  462.             //var_dump("Response code ===>");
  463.             //var_dump($response->getStatusCode());
  464.             //var_dump($response->toArray());
  465.            
  466.             //$result["isSuccess"] = false;
  467.             $result["statusCode"] = $response->getStatusCode();
  468.             if($result["statusCode"] == 200 or $result["statusCode"] ==202 or $result["statusCode"] ==201){
  469.                 $result["requestResponse"] = $response->toArray(false);
  470.                 $result["requestResponse"]["isSuccess"] = true;
  471.                 //if($result["requestResponse"]["isSuccess"]){
  472.                 $repoClosStatus $entityManager->getRepository(SysCloseStatus::class);
  473.                 $closeStatus $repoClosStatus->findOneBy(["statusCode" => "PDPAYE"]); //TODO: Add service code in condition
  474.                 $transaction->setCloseStatus($closeStatus);
  475.                     //$transaction->setClientPayementCanal("CAURISPAY");
  476.                 $transaction->setClientPayementTelephone($transaction->getMsisdn());
  477.                 $transaction->setClientPayementAccount($transaction->getMsisdn());
  478.                 $transaction->setClientPayementStatus($result["requestResponse"]["status"]);
  479.                 $transaction->setClientPayementReference($payeReferentId);
  480.                 $transaction->setClientPayementAmount($payementAmount);
  481.                 $transaction->setAdditionalPayementReference($result["requestResponse"]["precessingReference"]);
  482.                 $transaction->setAdditionalPayementTime(new \DateTime);
  483.                 //$transaction->setPartnerPayementReference($result["requestResponse"]["precessingReference"]);
  484.                 $entityManager->persist($transaction);
  485.                 $entityManager->flush();
  486.                 //}
  487.             }
  488.             //var_dump("End paymenet ===>");
  489.             return $result;
  490.         }
  491.     }
  492.     public function checkPayementStatus(SysTransaction $transaction,ManagerRegistry  $doctrineRes ){
  493.         $entityManager $doctrineRes->getManager();
  494.         $repoTrans $doctrineRes->getRepository(SysTransaction::class);
  495.     }
  496. }