0% found this document useful (0 votes)
66 views

Sample Code For Hashing and Json Call

The document provides sample code for hashing and making a JSON API call in PHP. The hashing section shows how to collect data values, implode them into a string, and hash it with HMAC and a secret key. The JSON call section shows initializing a cURL request to make a POST call to a payments API, with the request body containing order details and a hashed value, and echoing the response.

Uploaded by

郑浩威
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Sample Code For Hashing and Json Call

The document provides sample code for hashing and making a JSON API call in PHP. The hashing section shows how to collect data values, implode them into a string, and hash it with HMAC and a secret key. The JSON call section shows initializing a cURL request to make a POST call to a payments API, with the request body containing order details and a hashed value, and echoing the response.

Uploaded by

郑浩威
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

SAMPLE CODE FOR HASHING AND JSON CALL

Hashing :
$string = collect([
$data['cust_code'], $data['merchant_outlet_id'], $data['terminal_id'],
$data['merchant_return_url'], $data['description'], $data['currency'],
$data['amount'],
$data['order_id'], $data['user_fullname']
])->implode('');

return strtoupper(hash_hmac($algorithm, $string, $data['secret_key']));

JSON CALL :
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://devapiportal.oisbizcraft.com/api/payments',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"cust_code": "001003",
"merchant_outlet_id": "01",
"terminal_id": "001",
"merchant_return_url": "https:\\/\\/example.com\\/ois_bizcraft\\/checkout\\/return\\/order_id\\/15322\\/",
"description": "Order:#1-000015134;Tax:SGD28.04;IP:1.54.162.156",
"currency": "SGD",
"amount": 7041,
"order_id": "1-000015163",
"user_fullname": "Test Tester",
"hash": "B04A25F15351E083CS48FCF7F251BD3C985041FB3",
"origin_call": "custom",
"merchant_failed_return_url": "https:\\/\\/example.com\\/ois_bizcraft\\/checkout\\/return\\/order_id\\/15322\\/"
}',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/json'
),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

You might also like