iKhokha integration complete
This commit is contained in:
60
test_payment.php
Normal file
60
test_payment.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
$endpoint = "https://api.ikhokha.com/public-api/v1/api/payment";
|
||||
$appID = "IKFLESZTKFM4HWWS76131L8HK9BYF96P";
|
||||
$appSecret = "gfoQTvXRXuzq6ArPHUS2CBFxtHtH1bxM";
|
||||
$requestBody = [
|
||||
"entityID" => "4",
|
||||
"externalEntityID" => "4",
|
||||
"amount" => 1000,
|
||||
"currency" => "ZAR",
|
||||
"requesterUrl" => "https://beta.4wdcsa.co.za/requester",
|
||||
"description" => "Test Description 1",
|
||||
"paymentReference" => "4",
|
||||
"mode" => "sandbox",
|
||||
"externalTransactionID" => "5",
|
||||
"urls" => [
|
||||
"callbackUrl" => "https://beta.4wdcsa.co.za/callback",
|
||||
"successPageUrl" => "https://beta.4wdcsa.co.za/success",
|
||||
"failurePageUrl" => "https://beta.4wdcsa.co.za/failure",
|
||||
"cancelUrl" => "https://beta.4wdcsa.co.za/cancel"
|
||||
]
|
||||
];
|
||||
function escapeString($str) {
|
||||
$escaped = preg_replace(['/[\\"\'\"]/u', '/\x00/'], ['\\\\$0', '\\0'], (string)$str);
|
||||
$cleaned = str_replace('\/', '/', $escaped);
|
||||
return $cleaned;
|
||||
}
|
||||
function createPayloadToSign($urlPath, $body) {
|
||||
$parsedUrl = parse_url($urlPath);
|
||||
$basePath = $parsedUrl['path'];
|
||||
if (!$basePath) {
|
||||
throw new Exception("No path present in the URL");
|
||||
}
|
||||
$payload = $basePath . $body;
|
||||
$escapedPayloadString = escapeString($payload);
|
||||
return $escapedPayloadString;
|
||||
}
|
||||
function generateSignature($payloadToSign, $secret) {
|
||||
return hash_hmac('sha256', $payloadToSign, $secret);
|
||||
}
|
||||
$stringifiedBody = json_encode($requestBody);
|
||||
$payloadToSign = createPayloadToSign($endpoint, $stringifiedBody);
|
||||
$ikSign = generateSignature($payloadToSign, $appSecret);
|
||||
// Initialize cURL session
|
||||
$ch = curl_init($endpoint);
|
||||
// Set cURL options
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $stringifiedBody);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/json",
|
||||
"IK-APPID: $appID",
|
||||
"IK-SIGN: $ikSign"
|
||||
]);
|
||||
// Execute cURL session
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
// Decode and output the response
|
||||
$responseData = json_decode($response, true);
|
||||
echo print_r($responseData, true);
|
||||
?>
|
||||
Reference in New Issue
Block a user