-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkTransaction.php
51 lines (40 loc) · 1.94 KB
/
checkTransaction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
$json = file_get_contents('php://input');
$result = json_decode($json);
// Set your merchant code (Note: Server key for sandbox and production mode are different)
$merchantCode = "YOUR MERCHANT CODE";
// Set your merchant key (Note: Server key for sandbox and production mode are different)
$merchantKey = "YOUR MERCHANT KEY";
$reference = $result->{'reference'};
$signature = md5($merchantCode . $reference . $merchantKey);
$itemsParam = array(
'merchantCode' => $merchantCode,
'signature' => $signature
);
class emp{}
$params = array_merge((array)$result,$itemsParam);
$params_string = json_encode($params);
//if sandbox
$url = 'http://sandbox.duitku.com/webapi/api/merchant/transactionStatus';
//if production
//$url = 'https://passport.duitku.com/webapi/api/merchant/transactionStatus';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $params_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($params_string))
);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
//execute post
$request = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($httpCode == 200)
{
echo $request;
}
else
echo $httpCode;
?>