-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcoingate_callback.php
More file actions
49 lines (40 loc) · 1.75 KB
/
coingate_callback.php
File metadata and controls
49 lines (40 loc) · 1.75 KB
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
<?php
require('includes/application_top.php');
require_once(dirname(__FILE__) . "/includes/modules/payment/CoinGate/init.php");
require_once(dirname(__FILE__) . "/includes/modules/payment/CoinGate/version.php");
$token = MODULE_PAYMENT_COINGATE_CALLBACK_SECRET;
if ($token == '' || $_GET['token'] != $token)
throw new Exception('Token: ' . $_GET['token'] . ' do not match');
global $db;
$order_id = $_REQUEST['order_id'];
$order = tep_db_query("select orders_id from " . TABLE_ORDERS . " where orders_id = '" . intval($order_id) . "' limit 1");
if (tep_db_num_rows($order) <= 0)
throw new Exception('Order #' . $order_id . ' does not exists');
$coingate_order = \CoinGate\Merchant\Order::findOrFail($_REQUEST['id'], array(), array(
'app_id' => MODULE_PAYMENT_COINGATE_APP_ID,
'api_key' => MODULE_PAYMENT_COINGATE_API_KEY,
'api_secret' => MODULE_PAYMENT_COINGATE_API_SECRET,
'environment' => MODULE_PAYMENT_COINGATE_TEST == "True" ? 'sandbox' : 'live',
'user_agent' => 'CoinGate - osCommerce Extension v' . COINGATE_OSCOMMERCE_EXTENSION_VERSION));
switch ($coingate_order->status) {
case 'paid':
$cg_order_status = MODULE_PAYMENT_COINGATE_PAID_STATUS_ID;
break;
case 'canceled':
$cg_order_status = MODULE_PAYMENT_COINGATE_CANCELED_STATUS_ID;
break;
case 'expired':
$cg_order_status = MODULE_PAYMENT_COINGATE_EXPIRED_STATUS_ID;
break;
case 'invalid':
$cg_order_status = MODULE_PAYMENT_COINGATE_INVALID_STATUS_ID;
break;
case 'refunded':
$cg_order_status = MODULE_PAYMENT_COINGATE_REFUNDED_STATUS_ID;
break;
default:
$cg_order_status = NULL;
}
if ($cg_order_status)
tep_db_query("update ". TABLE_ORDERS. " set orders_status = " . $cg_order_status . " where orders_id = ". intval($coingate_order->order_id));
echo 'OK';