src/Controller/AppController.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. namespace App\Controller;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\Routing\Annotation\Method;
  6. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Contracts\Translation\TranslatorInterface;
  12. use App\Service;
  13. use App\Service\Api\ApiClient;
  14. use App\Service\Operation\Payment;
  15. class AppController extends AbstractController
  16. {
  17.     public function __construct()
  18.     {
  19.     }
  20.     /**
  21.      * @Route("/", name="home")
  22.      */
  23.     public function home()
  24.     {
  25.        dd("home");
  26.     }
  27.     /**
  28.      * @Route("/v1_0/payment", name="payment")
  29.      */
  30.     public function payment(Request $request)
  31.     {
  32.         $ip $request->getClientIp();
  33.         $idClient "ycb-d5d2e5";
  34.         $secretKey "test_d4fe5et45e2df45e-5";
  35.         //
  36.         $referer1 $request->headers->get('referer');
  37.         $referer2 $request->server->get('HTTP_REFERER');
  38.         $amount "";
  39.         // dd($request->headers->get("Autorization"));  
  40.         if (preg_match("/^(Bearer)[ ]*[a-zA-Z0-9_-]*:[a-zA-Z0-9_-]*$/",$request->headers->get("Authorization")) != 1)  {
  41.             return new JsonResponse(
  42.                 [
  43.                     'success' => false,
  44.                     'message' => "credentials is wrong",
  45.                 ],
  46.                 200
  47.             );
  48.         }
  49.         $credentials explode(":"trim(str_replace("Bearer"""$request->headers->get("Authorization"))));
  50.         $idClient $credentials[0];
  51.         $secretKey $credentials[1];
  52.         return new JsonResponse(
  53.             [
  54.                 'success' => false,
  55.                 'message' => "client : $idClient, key: $secretKey",
  56.             ],
  57.             420
  58.         );
  59.         if ($request->isMethod('POST')) {
  60.             if (null != $request->get("amount")) {
  61.                 $amount "amount_currency = " $request->get("amount")["currency"] . "; amount_value = " $request->get("amount")["value"];
  62.             }
  63.             return new JsonResponse(
  64.                 [
  65.                     'success' => true,
  66.                     'response' => "payment_create",
  67.                     "params" => json_encode($request->getContent()),
  68.                     "amount" => $amount,
  69.                     "ip" => $ip,
  70.                     'referer' => $referer1."-".$referer2,
  71.                 ]
  72.             );
  73.         } else if ($request->isMethod('PUT')) {
  74.             return new JsonResponse(
  75.                 [
  76.                     'success' => true,
  77.                     'response' => "payment_update",
  78.                     "amount" => $amount,
  79.                     "ip" => $ip,
  80.                     'referer' => $referer1."-".$referer2,
  81.                 ]
  82.             );
  83.         } else if ($request->isMethod('GET')) {
  84.             return new JsonResponse(
  85.                 [
  86.                     "success" => true,
  87.                     "message" => "",
  88.                     "payment" => [
  89.                         "item" => [
  90.                             "id" => "1235",
  91.                             "mode" => "test",
  92.                             "typePayment" => "Moov FLOOZ",
  93.                             "description" => "Paiement",
  94.                             "amount" => "4500",
  95.                             "currency" => "XOF",
  96.                             "redirectUrl" => "http://www.nakod.net/success",
  97.                             "cancelUrl" => "http://www.nakod.net/failure",
  98.                             "idOrder" => "x27x58",
  99.                             "idCustomer" => "12355",
  100.                             "country" => "Bénin",
  101.                             "status" => "PENDING",
  102.                             "created" => "2020-12-18 12:12:00",
  103.                             "paid" => "",
  104.                             "canceled" => "",
  105.                             "expired" => ""
  106.                         ]
  107.                     ],
  108.                 ],
  109.                 200
  110.             );
  111.         } else if ($request->isMethod('DELETE')) {
  112.             return new JsonResponse(
  113.                 [
  114.                     'success' => true,
  115.                     'response' => "payment_delete",
  116.                     "params" => json_encode($request->query->all()),
  117.                     "amount" => $amount,
  118.                     "ip" => $ip,
  119.                     'referer' => $referer1."-".$referer2,
  120.                 ]
  121.             );
  122.         }
  123.        return new JsonResponse(
  124.             [
  125.                 'success' => false,
  126.                 'message' => "payment",
  127.                 "ip" => $ip,
  128.                 'referer' => $referer1."-".$referer2,
  129.             ],
  130.             400
  131.         );
  132.     }
  133.     /**
  134.      * @Route("/v1_0/payment/list", name="payment_list")
  135.      */
  136.     public function listPayment(Request $request)
  137.     {
  138.         if ($request->isMethod('GET')) {
  139.             return new JsonResponse(
  140.                 [
  141.                     "payment" => [
  142.                         "collection" => [
  143.                             [
  144.                                 "id" => "1235",
  145.                                 "mode" => "test",
  146.                                 "typePayment" => "Moov FLOOZ",
  147.                                 "description" => "Paiement",
  148.                                 "amount" => "4500",
  149.                                 "currency" => "XOF",
  150.                                 "redirectUrl" => "http://www.nakod.net/success",
  151.                                 "cancelUrl" => "http://www.nakod.net/failure",
  152.                                 "idOrder" => "x27x58",
  153.                                 "idCustomer" => "12355",
  154.                                 "country" => "Bénin",
  155.                                 "status" => "PENDING",
  156.                                 "created" => "2020-12-18 12:12:00",
  157.                                 "paid" => "",
  158.                                 "canceled" => "",
  159.                                 "expired" => ""
  160.                             ],
  161.                             [
  162.                                 "id" => "1236",
  163.                                 "mode" => "test",
  164.                                 "typePayment" => "Moov FLOOZ",
  165.                                 "description" => "Paiement",
  166.                                 "amount" => "4500",
  167.                                 "currency" => "XOF",
  168.                                 "redirectUrl" => "http://www.nakod.net/success",
  169.                                 "cancelUrl" => "http://www.nakod.net/failure",
  170.                                 "idOrder" => "x27x61",
  171.                                 "idCustomer" => "12355",
  172.                                 "country" => "Bénin",
  173.                                 "status" => "PENDING",
  174.                                 "created" => "2020-12-18 12:12:00",
  175.                                 "paid" => "",
  176.                                 "canceled" => "",
  177.                                 "expired" => ""
  178.                             ],
  179.                             [
  180.                                 "id" => "1237",
  181.                                 "mode" => "test",
  182.                                 "typePayment" => "Mtn",
  183.                                 "description" => "Paiement",
  184.                                 "amount" => "4500",
  185.                                 "currency" => "XOF",
  186.                                 "redirectUrl" => "http://www.nakod.net/success",
  187.                                 "cancelUrl" => "http://www.nakod.net/failure",
  188.                                 "idOrder" => "x27x63",
  189.                                 "idCustomer" => "12355",
  190.                                 "country" => "Bénin",
  191.                                 "status" => "PENDING",
  192.                                 "created" => "2020-12-18 12:12:00",
  193.                                 "paid" => "",
  194.                                 "canceled" => "",
  195.                                 "expired" => ""
  196.                             ],
  197.                             [
  198.                                 "id" => "1238",
  199.                                 "mode" => "test",
  200.                                 "typePayment" => "Moov FLOOZ",
  201.                                 "description" => "Paiement",
  202.                                 "amount" => "4500",
  203.                                 "currency" => "XOF",
  204.                                 "redirectUrl" => "http://www.nakod.net/success",
  205.                                 "cancelUrl" => "http://www.nakod.net/failure",
  206.                                 "idOrder" => "x27x67",
  207.                                 "idCustomer" => "12355",
  208.                                 "country" => "Bénin",
  209.                                 "status" => "PENDING",
  210.                                 "created" => "2020-12-18 12:12:00",
  211.                                 "paid" => "",
  212.                                 "canceled" => "",
  213.                                 "expired" => ""
  214.                             ],
  215.                             [
  216.                                 "id" => "1239",
  217.                                 "mode" => "test",
  218.                                 "typePayment" => "Mtn",
  219.                                 "description" => "Paiement",
  220.                                 "amount" => "4500",
  221.                                 "currency" => "XOF",
  222.                                 "redirectUrl" => "http://www.nakod.net/success",
  223.                                 "cancelUrl" => "http://www.nakod.net/failure",
  224.                                 "idOrder" => "x27x69",
  225.                                 "idCustomer" => "12355",
  226.                                 "country" => "Bénin",
  227.                                 "status" => "PENDING",
  228.                                 "created" => "2020-12-18 12:12:00",
  229.                                 "paid" => "",
  230.                                 "canceled" => "",
  231.                                 "expired" => ""
  232.                             ],
  233.                         ]
  234.                     ]
  235.                 ],
  236.                 200
  237.             );
  238.         }
  239.        return new JsonResponse(
  240.             [
  241.                 'success' => false,
  242.                 'message' => "response",
  243.             ],
  244.             400
  245.         );
  246.     }   
  247. }