-
Notifications
You must be signed in to change notification settings - Fork 0
/
callback.php
70 lines (56 loc) · 1.6 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
<?php
require __DIR__ . '/config.php';
function wh_log($log_msg)
{
$log_filename = "log";
if (!file_exists($log_filename))
{
mkdir($log_filename, 0777, true);
}
$log_file_data = $log_filename.'/log_' . date('d-M-Y') . '.log';
file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND);
}
function verifyCallbackData($post)
{
$secretKey = API_KEY;
if (!isset($post['verify_hash'])) {
return false;
}
$verifyHash = $post['verify_hash'];
unset($post['verify_hash']);
ksort($post);
if (isset($post['expire_utc'])){
$post['expire_utc'] = (string)$post['expire_utc'];
}
if (isset($post['tx_urls'])){
$post['tx_urls'] = html_entity_decode($post['tx_urls']);
}
$postString = serialize($post);
$checkKey = hash_hmac('sha1', $postString, $secretKey);
if ($checkKey != $verifyHash) {
return false;
}
return true;
}
function callback()
{
if (verifyCallbackData($_POST)) {
$order_id = $_POST['order_number'];
switch ($_POST['status']) {
case 'new':
$order_status = 'pending';
case 'completed':
case 'mismatch':
$order_status = 'completed';
break;
case 'expired':
case 'cancelled':
$order_status = 'cancelled';
break;
}
wh_log("Successfully received an callback for order# $order_id . Order status changed to $order_status");
} else {
wh_log('Plisio response looks suspicious. Skip updating order.');
}
}
callback();