/
tinklit_cron.php
70 lines (50 loc) · 2.8 KB
/
tinklit_cron.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
include_once('includes/application_top.php');
require_once 'tinklit/tinklit_lib.php';
$tinkl_info_sql = "SELECT configuration_value
FROM ".TABLE_CONFIGURATION."
WHERE configuration_key = 'MODULE_PAYMENT_TINKLIT_CLIENTID'";
$tinkl_info = $db->execute($tinkl_info_sql);
$clientid = $tinkl_info->fields['configuration_value'];
$tinkl_info_sql = "SELECT configuration_value
FROM ".TABLE_CONFIGURATION."
WHERE configuration_key = 'MODULE_PAYMENT_TINKLIT_TOKEN'";
$tinkl_info = $db->execute($tinkl_info_sql);
$tokenid = $tinkl_info->fields['configuration_value'];
$tinkl_orders_sql = "SELECT guid, order_id FROM ".TABLE_TINKLIT."
WHERE status = 'pending'
AND time_created BETWEEN '".date('Y-m-d h:i:s', (date('U')-15*60))."' AND '".date('Y-m-d h:i:s')."'";
//echo $tinkl_orders_sql; exit();
$tinkl_orders = $db->execute($tinkl_orders_sql);
while (!$tinkl_orders->EOF) {
$guid = $tinkl_orders->fields['guid'];
$options = array('guid' => $tinkl_info->fields['guid']);
$post = json_encode($options);
// create invoice
//$invoice = tinklitCurl('https://api-staging.tinkl.it/v1/invoices', MODULE_PAYMENT_TINKLIT_CLIENTID, MODULE_PAYMENT_TINKLIT_TOKEN, $post);
$invoice = tinklitCurl('https://api.tinkl.it/invoices/'.$guid, $clientid, $tokenid);
echo $guid;
echo '<pre>'; print_r($invoice); echo '</pre>'; //exit();
if ($invoice['status'] == 'payed') {
$get_status_sql = "SELECT orders_status FROM ".TABLE_ORDERS."
WHERE orders_id = '".$tinkl_orders->fields['order_id']."'";
$get_status = $db->execute($get_status_sql);
if ($get_status->fields['orders_status'] != '2') {
$db->Execute("update " . TABLE_ORDERS . "
set orders_status = '2', last_modified = now()
where orders_id = '" . $tinkl_orders->fields['order_id'] . "'");
$db->Execute("insert into " . TABLE_ORDERS_STATUS_HISTORY . "
(orders_id, orders_status_id, date_added, customer_notified, comments)
values ('" . $tinkl_orders->fields['order_id'] . "',
'2',
now(),
'0',
'Order successfully payed')");
$db->Execute("update " . TABLE_TINKLIT . "
set status = 'payed'
where order_id = '" . $tinkl_orders->fields['order_id'] . "'");
}
}
$tinkl_orders->MoveNext();
}
?>