-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallback.php
72 lines (54 loc) · 2.12 KB
/
callback.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
61
62
63
64
65
66
67
68
69
70
71
72
<?php
$application->connectDb();
$application->initSession();
$application->initPlugins();
ob_start();
try {
$source = file_get_contents('php://input');
$requestBody = json_decode($source, true);
$headers = getallheaders();
print_r($requestBody);
print_r($headers);
$order = \Sale\Order::getById( $requestBody['transaction']['orderId'] );
$gateway = $order->getPaymentGateway();
if($requestBody['event'] == 'payment'){
$hash = hash_hmac ( "sha256" , implode('|',[
$requestBody['transaction']['amount'],
$gateway->params['MerchantId'],
$requestBody['transaction']['orderId'],
$requestBody['transaction']['status']['value'],
$requestBody['transaction']['status']['date'],
]), $gateway->params['secretKey']);
if ($hash != $headers['X-Api-Signature-Sha256']) {
throw new \Exception('X-Api-Signature check failed');
}
$gateway->saveTransaction($requestBody['transaction']['id'], $requestBody);
if ($requestBody['transaction']['status']['value'] == 'SUCCESS') {
$order->paymentSuccess();
$gateway->sendReceiptSell();
}
header("HTTP/1.1 200 OK");
print 'OK';
}
if(isset($requestBody['refund']) && !empty($requestBody['refund'])){
$hash = hash_hmac ( "sha256" , implode('|',[
$requestBody['refund']['amount'],
$gateway->params['MerchantId'],
'refund'.$requestBody['refund']['id'],
$requestBody['refund']['status']['value'],
$requestBody['refund']['status']['date'],
]), $gateway->params['secretKey']);
if ($hash != $headers['X-Api-Signature-Sha256']) {
throw new \Exception('X-Api-Signature check failed');
}
header("HTTP/1.1 200 OK");
print 'OK';
}
}
catch (\Exception $e) {
header( "HTTP/1.1 500 ".trim(preg_replace('/\s+/', ' ', $e->getMessage())) );
print $e->getMessage();
}
/*$data = ob_get_contents();
ob_end_flush();
file_put_contents(__DIR__.'/log'.time().'.txt', $data);*/