src/Controller/PaymentController.php line 54

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Payment;
  4. use App\Form\PaymentType;
  5. use App\Repository\PaymentRepository;
  6. use App\Repository\ApplicationRepository;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. /**
  13.  * @Route("/payment")
  14.  */
  15. class PaymentController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/", name="app_payment_index", methods={"GET"})
  19.      */
  20.     public function index(PaymentRepository $paymentRepository): Response
  21.     {
  22.         return $this->render('payment/index.html.twig', [
  23.             'payments' => $paymentRepository->findAll(),
  24.         ]);
  25.     }
  26.     /**
  27.      * @Route("/new", name="app_payment_new", methods={"GET", "POST"})
  28.      */
  29.     public function new(Request $requestPaymentRepository $paymentRepository): Response
  30.     {
  31.         $payment = new Payment();
  32.         $form $this->createForm(PaymentType::class, $payment);
  33.         $form->handleRequest($request);
  34.         if ($form->isSubmitted() && $form->isValid()) {
  35.             $paymentRepository->add($paymenttrue);
  36.             return $this->redirectToRoute('app_payment_index', [], Response::HTTP_SEE_OTHER);
  37.         }
  38.         return $this->renderForm('payment/new.html.twig', [
  39.             'payment' => $payment,
  40.             'form' => $form,
  41.         ]);
  42.     }
  43.     /**
  44.      * @Route("/{id}", name="app_payment_show", methods={"GET"})
  45.      */
  46.     public function show(Payment $payment): Response
  47.     {
  48.         return $this->render('payment/show.html.twig', [
  49.             'payment' => $payment,
  50.         ]);
  51.     }
  52.     /**
  53.      * @Route("/{id}/edit", name="app_payment_edit", methods={"GET", "POST"})
  54.      */
  55.     public function edit(Request $requestPayment $paymentPaymentRepository $paymentRepository): Response
  56.     {
  57.         $form $this->createForm(PaymentType::class, $payment);
  58.         $form->handleRequest($request);
  59.         if ($form->isSubmitted() && $form->isValid()) {
  60.             $paymentRepository->add($paymenttrue);
  61.             return $this->redirectToRoute('app_payment_index', [], Response::HTTP_SEE_OTHER);
  62.         }
  63.         return $this->renderForm('payment/edit.html.twig', [
  64.             'payment' => $payment,
  65.             'form' => $form,
  66.         ]);
  67.     }
  68.     /**
  69.      * @Route("/{id}", name="app_payment_delete", methods={"POST"})
  70.      */
  71.     public function delete(Request $requestPayment $paymentPaymentRepository $paymentRepository): Response
  72.     {
  73.         if ($this->isCsrfTokenValid('delete'.$payment->getId(), $request->request->get('_token'))) {
  74.             $paymentRepository->remove($paymenttrue);
  75.         }
  76.         return $this->redirectToRoute('app_payment_index', [], Response::HTTP_SEE_OTHER);
  77.     }
  78.     /** 
  79.      * Creates a new payment entity.
  80.      *
  81.      * @Route("/cash/out/user", name="payment_cash_out")     * 
  82.      *
  83.      */
  84.     public function cashOutAction(Request $requestPaymentRepository $paymentRepositoryApplicationRepository $applicationRepository)
  85.     {
  86.         $applicationKey $request->get('applicationKey');
  87.         $amount $request->get('amount');
  88.         $reason $request->get('reason');
  89.         $number $request->get('number');
  90.         $operator $request->get('operator');// useless
  91.         if(!empty($applicationKey) && !empty($amount) && !empty($reason)  && !empty($number) && !empty($operator))
  92.         {                
  93.             $app $applicationRepository->FindOneBy(['applicationPass'=>$applicationKey]);
  94.             if(!empty($app) )
  95.             {
  96.                 if($app->getCashOutCumul() < 10000){
  97.                     $ret $this->CashInPay($amount$number$reason);
  98.                     $payment = new Payment();
  99.                     $payment->setOperator($operator);
  100.                     $payment->setAmount($amount);
  101.                     $payment->setNumber($number);
  102.                     $payment->setReason($reason);
  103.                     $payment->setOperationType("CASHIN");
  104.                     $payment->setApiResponse($ret);
  105.                     $payment->setComment($ret['data']['txnmessage']);                        
  106.                     $app->setCashOutCumul($app->getCashOutCumul() + $amount);
  107.                     $paymentRepository->add($paymenttrue);
  108.                     $applicationRepository->add($apptrue);
  109.                     $return = array(
  110.                         'Etat' =>'SUCCESS'
  111.                         'Message' =>"Dépôt effectué avec succès !!!",
  112.                         'detail'=>$ret
  113.                     );  
  114.                 }else
  115.                 {
  116.                     $return = array(
  117.                         'Etat' =>'FAILED'
  118.                         'Message' =>"Le montant maximal de vos opérations est atteint.",
  119.                     );  
  120.                 
  121.                 }                    
  122.             }else
  123.             {
  124.                 $return = array(
  125.                     'Etat' =>'FAILED'
  126.                     'Message' =>"N'êtes pas autorisé à effectuer cette opération"
  127.                     'applicationKey' =>$applicationKey,
  128.                 );  
  129.             }
  130.             
  131.         }else
  132.         {
  133.             $return = array(
  134.                 'Etat' =>'FAILED' 
  135.                 'Message' =>'Paramètres manquants'
  136.             );
  137.         }
  138.     
  139.         $retour = new JsonResponse($return);
  140.         return $retour;       
  141.     }
  142.     
  143.     /** 
  144.      * Creates a new payment entity.
  145.      *
  146.      * @Route("/get/orange/user/name", name="payment_get_user_name")     * 
  147.      *
  148.      */
  149.     public function getUserNameAction(Request $requestApplicationRepository $applicationRepository)
  150.     {
  151.         $applicationKey $request->get('applicationKey');
  152.         $number $request->get('number');
  153.         if(!empty($applicationKey) && !empty($number))
  154.         {                
  155.             $app $applicationRepository->FindOneBy(['applicationPass'=>$applicationKey]);
  156.             if(!empty($app) )
  157.             {
  158.                 $curl curl_init();
  159.                 curl_setopt_array($curl, array(
  160.                 CURLOPT_URL => 'https://api.wantacm.cesd-sa.com/api/v1.1/TestRefit/OmUserInfo?_phonenumber='.$number,
  161.                 CURLOPT_RETURNTRANSFER => true,
  162.                 CURLOPT_ENCODING => '',
  163.                 CURLOPT_MAXREDIRS => 10,
  164.                 CURLOPT_TIMEOUT => 0,
  165.                 CURLOPT_FOLLOWLOCATION => true,
  166.                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  167.                 CURLOPT_CUSTOMREQUEST => 'GET',
  168.                 ));
  169.                 $response curl_exec($curl);
  170.                 $response json_decode($response,true);
  171.                 curl_close($curl);
  172.                 if($response["status"]=="SUCCES"){
  173.                     $return = array(
  174.                         'Etat' =>'SUCCESS'
  175.                         'Message' =>"Vérification de nom effectué avec succès !!!",
  176.                         'Nom'=>$response['data']
  177.                     );  
  178.                 }else{
  179.                     $return = array(
  180.                         'Etat' =>'FAILED',
  181.                         'Message' =>"Vérification de nom effectué avec ECHEC !!!",
  182.                         'Nom'=>"Nom indisponible"
  183.                     );
  184.                 }
  185.             }else
  186.             {
  187.                 $return = array(
  188.                     'Etat' =>'FAILED',
  189.                     'Message' =>"N'êtes pas autorisé à effectuer cette opération",
  190.                     'applicationKey' =>$applicationKey,
  191.                 );
  192.             }            
  193.         }else
  194.         {
  195.             $return = array(
  196.                 'Etat' =>'FAILED' 
  197.                 'Message' =>'Paramètres manquants'
  198.             );  
  199.         }
  200.     
  201.         $retour = new JsonResponse($return);
  202.         return $retour;       
  203.     }
  204.     
  205.     function getAccessToken()
  206.     {     
  207.         $curl curl_init();
  208.         curl_setopt_array($curl, array(
  209.         CURLOPT_URL => 'https://api-s1.orange.cm/token',
  210.         CURLOPT_RETURNTRANSFER => true,
  211.         CURLOPT_ENCODING => '',
  212.         CURLOPT_MAXREDIRS => 10,
  213.         CURLOPT_TIMEOUT => 0,
  214.         CURLOPT_FOLLOWLOCATION => true,
  215.         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  216.         CURLOPT_CUSTOMREQUEST => 'POST',
  217.         CURLOPT_POSTFIELDS => 'grant_type=client_credentials',
  218.         CURLOPT_HTTPHEADER => array(
  219.             'Authorization: Basic aGtBcnl1V2ZNSXE3OXFiSjMydUQ2R2Z1YlJrYTpLT1Bfekdpa0lNQWRxWFI0WkJkajhSSjBnWWth',
  220.             'Content-Type: application/x-www-form-urlencoded'
  221.         ),
  222.         ));
  223.         $response curl_exec($curl);
  224.         $response json_decode($response,true);
  225.         curl_close($curl);
  226.         $response $response["access_token"];
  227.         return $response;
  228.     }
  229.     function InitTransaction(){
  230.         $accessToken $this->getAccessToken();
  231.         $curl curl_init();
  232.         curl_setopt_array($curl, array(
  233.         CURLOPT_URL => 'https://api-s1.orange.cm/omcoreapis/1.0.2/cashin/init',
  234.         CURLOPT_RETURNTRANSFER => true,
  235.         CURLOPT_ENCODING => '',
  236.         CURLOPT_MAXREDIRS => 10,
  237.         CURLOPT_TIMEOUT => 0,
  238.         CURLOPT_FOLLOWLOCATION => true,
  239.         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  240.         CURLOPT_CUSTOMREQUEST => 'POST',
  241.         CURLOPT_HTTPHEADER => array(
  242.             'X-AUTH-TOKEN: QU1MQVBST0Q6QU1MQVBST0QyMDIw',
  243.             'Content-Type: application/json',
  244.             'Authorization: Bearer '.$accessToken
  245.         ),
  246.         ));
  247.         $response curl_exec($curl);
  248.         $response json_decode($response,true);
  249.         curl_close($curl);
  250.         
  251.         $return = array(
  252.             'access_token' =>$accessToken 
  253.             'pay_token' =>$response["data"]["payToken"],
  254.         );
  255.         
  256.         return $return;
  257.     }
  258.     function CashInPay($amount$number$reason){
  259.       
  260.         $initAndPayToken $this->InitTransaction();
  261.         $curl curl_init();
  262.         curl_setopt_array($curl, array(
  263.         CURLOPT_URL => 'https://api-s1.orange.cm/omcoreapis/1.0.2/cashin/pay',
  264.         CURLOPT_RETURNTRANSFER => true,
  265.         CURLOPT_ENCODING => '',
  266.         CURLOPT_MAXREDIRS => 10,
  267.         CURLOPT_TIMEOUT => 0,
  268.         CURLOPT_FOLLOWLOCATION => true,
  269.         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  270.         CURLOPT_CUSTOMREQUEST => 'POST',
  271.         CURLOPT_POSTFIELDS =>'{
  272.         "subscriberMsisdn": "'.$number.'",
  273.         "channelUserMsisdn": "691128951",
  274.         "amount":  "'.$amount.'",
  275.         "description": "test",
  276.         "orderId": "'.$reason.'",
  277.         "pin": "2562",
  278.         "payToken": "'.$initAndPayToken['pay_token'].'",
  279.         "notifUrl": "https://webhook.site/7ad03c61-5fe1-4436-92e3-61563016efb2"
  280.         }',
  281.         CURLOPT_HTTPHEADER => array(
  282.                 'X-AUTH-TOKEN: QU1MQVBST0Q6QU1MQVBST0QyMDIw',
  283.                 'Content-Type: application/json',
  284.                 'Authorization: Bearer '.$initAndPayToken['access_token']
  285.             ),
  286.         ));
  287.         $response curl_exec($curl);
  288.         $response json_decode($response,true);
  289.         curl_close($curl);
  290.         return $response;
  291.     }
  292.     function checkStatus($reference$token){
  293.         
  294.         $curl curl_init();
  295.         curl_setopt_array($curl, array(
  296.         CURLOPT_URL => 'https://api-s1.orange.cm/omcoreapis/1.0.2/cashin/paymentstatus/CI2405107ED3DB2096DD671F3A20',
  297.         CURLOPT_RETURNTRANSFER => true,
  298.         CURLOPT_ENCODING => '',
  299.         CURLOPT_MAXREDIRS => 10,
  300.         CURLOPT_TIMEOUT => 0,
  301.         CURLOPT_FOLLOWLOCATION => true,
  302.         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  303.         CURLOPT_CUSTOMREQUEST => 'GET',
  304.         CURLOPT_HTTPHEADER => array(
  305.             'X-AUTH-TOKEN: QU1MQVBST0Q6QU1MQVBST0QyMDIw',
  306.             'Content-Type: application/json',
  307.             'Authorization: Bearer 5610615e-64aa-3d6f-aaeb-b7390d995770'
  308.         ),
  309.         ));
  310.         $response curl_exec($curl);
  311.         $response json_decode($response,true);
  312.         curl_close($curl);
  313.         return $response;
  314.     }
  315. }