<?php
namespace App\Controller;
namespace App\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Annotation\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Service;
use App\Service\Api\ApiClient;
use App\Service\Operation\Payment;
class AppController extends AbstractController
{
public function __construct()
{
}
/**
* @Route("/", name="home")
*/
public function home()
{
dd("home");
}
/**
* @Route("/v1_0/payment", name="payment")
*/
public function payment(Request $request)
{
$ip = $request->getClientIp();
$idClient = "ycb-d5d2e5";
$secretKey = "test_d4fe5et45e2df45e-5";
//
$referer1 = $request->headers->get('referer');
$referer2 = $request->server->get('HTTP_REFERER');
$amount = "";
// dd($request->headers->get("Autorization"));
if (preg_match("/^(Bearer)[ ]*[a-zA-Z0-9_-]*:[a-zA-Z0-9_-]*$/",$request->headers->get("Authorization")) != 1) {
return new JsonResponse(
[
'success' => false,
'message' => "credentials is wrong",
],
200
);
}
$credentials = explode(":", trim(str_replace("Bearer", "", $request->headers->get("Authorization"))));
$idClient = $credentials[0];
$secretKey = $credentials[1];
return new JsonResponse(
[
'success' => false,
'message' => "client : $idClient, key: $secretKey",
],
420
);
if ($request->isMethod('POST')) {
if (null != $request->get("amount")) {
$amount = "amount_currency = " . $request->get("amount")["currency"] . "; amount_value = " . $request->get("amount")["value"];
}
return new JsonResponse(
[
'success' => true,
'response' => "payment_create",
"params" => json_encode($request->getContent()),
"amount" => $amount,
"ip" => $ip,
'referer' => $referer1."-".$referer2,
]
);
} else if ($request->isMethod('PUT')) {
return new JsonResponse(
[
'success' => true,
'response' => "payment_update",
"amount" => $amount,
"ip" => $ip,
'referer' => $referer1."-".$referer2,
]
);
} else if ($request->isMethod('GET')) {
return new JsonResponse(
[
"success" => true,
"message" => "",
"payment" => [
"item" => [
"id" => "1235",
"mode" => "test",
"typePayment" => "Moov FLOOZ",
"description" => "Paiement",
"amount" => "4500",
"currency" => "XOF",
"redirectUrl" => "http://www.nakod.net/success",
"cancelUrl" => "http://www.nakod.net/failure",
"idOrder" => "x27x58",
"idCustomer" => "12355",
"country" => "Bénin",
"status" => "PENDING",
"created" => "2020-12-18 12:12:00",
"paid" => "",
"canceled" => "",
"expired" => ""
]
],
],
200
);
} else if ($request->isMethod('DELETE')) {
return new JsonResponse(
[
'success' => true,
'response' => "payment_delete",
"params" => json_encode($request->query->all()),
"amount" => $amount,
"ip" => $ip,
'referer' => $referer1."-".$referer2,
]
);
}
return new JsonResponse(
[
'success' => false,
'message' => "payment",
"ip" => $ip,
'referer' => $referer1."-".$referer2,
],
400
);
}
/**
* @Route("/v1_0/payment/list", name="payment_list")
*/
public function listPayment(Request $request)
{
if ($request->isMethod('GET')) {
return new JsonResponse(
[
"payment" => [
"collection" => [
[
"id" => "1235",
"mode" => "test",
"typePayment" => "Moov FLOOZ",
"description" => "Paiement",
"amount" => "4500",
"currency" => "XOF",
"redirectUrl" => "http://www.nakod.net/success",
"cancelUrl" => "http://www.nakod.net/failure",
"idOrder" => "x27x58",
"idCustomer" => "12355",
"country" => "Bénin",
"status" => "PENDING",
"created" => "2020-12-18 12:12:00",
"paid" => "",
"canceled" => "",
"expired" => ""
],
[
"id" => "1236",
"mode" => "test",
"typePayment" => "Moov FLOOZ",
"description" => "Paiement",
"amount" => "4500",
"currency" => "XOF",
"redirectUrl" => "http://www.nakod.net/success",
"cancelUrl" => "http://www.nakod.net/failure",
"idOrder" => "x27x61",
"idCustomer" => "12355",
"country" => "Bénin",
"status" => "PENDING",
"created" => "2020-12-18 12:12:00",
"paid" => "",
"canceled" => "",
"expired" => ""
],
[
"id" => "1237",
"mode" => "test",
"typePayment" => "Mtn",
"description" => "Paiement",
"amount" => "4500",
"currency" => "XOF",
"redirectUrl" => "http://www.nakod.net/success",
"cancelUrl" => "http://www.nakod.net/failure",
"idOrder" => "x27x63",
"idCustomer" => "12355",
"country" => "Bénin",
"status" => "PENDING",
"created" => "2020-12-18 12:12:00",
"paid" => "",
"canceled" => "",
"expired" => ""
],
[
"id" => "1238",
"mode" => "test",
"typePayment" => "Moov FLOOZ",
"description" => "Paiement",
"amount" => "4500",
"currency" => "XOF",
"redirectUrl" => "http://www.nakod.net/success",
"cancelUrl" => "http://www.nakod.net/failure",
"idOrder" => "x27x67",
"idCustomer" => "12355",
"country" => "Bénin",
"status" => "PENDING",
"created" => "2020-12-18 12:12:00",
"paid" => "",
"canceled" => "",
"expired" => ""
],
[
"id" => "1239",
"mode" => "test",
"typePayment" => "Mtn",
"description" => "Paiement",
"amount" => "4500",
"currency" => "XOF",
"redirectUrl" => "http://www.nakod.net/success",
"cancelUrl" => "http://www.nakod.net/failure",
"idOrder" => "x27x69",
"idCustomer" => "12355",
"country" => "Bénin",
"status" => "PENDING",
"created" => "2020-12-18 12:12:00",
"paid" => "",
"canceled" => "",
"expired" => ""
],
]
]
],
200
);
}
return new JsonResponse(
[
'success' => false,
'message' => "response",
],
400
);
}
}