-
Notifications
You must be signed in to change notification settings - Fork 3
/
requestTransaction.php
60 lines (45 loc) · 2.21 KB
/
requestTransaction.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
52
53
54
55
56
57
58
59
60
<?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";
$paymentAmount = $result->{'paymentAmount'};
$merchantOrderId = time();
$signature = md5($merchantCode . $merchantOrderId . $paymentAmount . $merchantKey);
$itemsParam = array(
'merchantCode' => $merchantCode,
'merchantKey' => $merchantKey,
'merchantOrderId' => $merchantOrderId,
'signature' => $signature
);
class emp{}
$params = array_merge((array)$result,$itemsParam);
$params_string = json_encode($params);
$url = 'https://sandbox.duitku.com/webapi/api/merchant/v2/inquiry'; // Sandbox
//$url = 'https://passport.duitku.com/webapi/api/merchant/v2/inquiry'; // Production
$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{
$response = new emp();
$response->statusMessage = "Server Error . $httpCode ";
$response->error = $httpCode;
die(json_encode($response));
}
?>