-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcallback.php
97 lines (71 loc) · 3.21 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
*
* Setting requirements and includes
*
*/
require_once __DIR__ . '/../../../init.php';
require_once __DIR__ . '/vendor/autoload.php';
$whmcs->load_function('gateway');
$whmcs->load_function('invoice');
/**
*
* Check parameters
*
*/
if (isset($_POST['id'])) {
// Get transaction
$transactionQuery = select_query('gateway_mollie', '', array('paymentid' => $_POST['id']), null, null, 1);
if (mysql_num_rows($transactionQuery) != 1) {
logTransaction('mollieunknown', $_POST, 'Callback - Failure 2 (Transaction not found)');
header('HTTP/1.1 500 Transaction not found');
exit();
}
$transaction = mysql_fetch_assoc($transactionQuery);
$method = $transaction['method'];
if (empty($method)) {
$method = 'checkout';
}
$_GATEWAY = getGatewayVariables('mollie' . $method . '_devapp');
if ($transaction['status'] != 'open') {
logTransaction($_GATEWAY['paymentmethod'], array_merge($transaction, $_POST), 'Callback - Failure 3 (Transaction not open)');
header('HTTP/1.1 500 Transaction not open');
exit();
}
// Get user and transaction currencies
$userCurrency = getCurrency($transaction['userid']);
$transactionCurrency = select_query('tblcurrencies', '', array('id' => $transaction['currencyid']));
$transactionCurrency = mysql_fetch_assoc($transactionCurrency);
// Check payment
$mollie = new \Mollie\Api\MollieApiClient();
$mollie->setApiKey($_GATEWAY['key']);
$payment = $mollie->payments->get($_POST['id']);
if ($payment->isPaid()) {
// Add conversion, when there is need to. WHMCS only supports currencies per user. WHY?!
if ($transactionCurrency['id'] != $userCurrency['id']) {
$transaction['amount'] = convertCurrency($transaction['amount'], $transaction['currencyid'], $userCurrency['id']);
}
// Check invoice
$invoiceid = checkCbInvoiceID($transaction['invoiceid'], $_GATEWAY['paymentmethod']);
checkCbTransID($transaction['paymentid']);
// Add invoice
addInvoicePayment($invoiceid, $transaction['paymentid'], $transaction['amount'], '', $_GATEWAY['paymentmethod']);
update_query('gateway_mollie', array('status' => 'paid', 'updated' => date('Y-m-d H:i:s', time())), array('id' => $transaction['id']));
logTransaction($_GATEWAY['paymentmethod'], array_merge($transaction, $_POST), 'Callback - Successful (Paid)');
header('HTTP/1.1 200 OK');
exit();
} else if ($payment->isOpen() == FALSE) {
update_query('gateway_mollie', array('status' => 'closed', 'updated' => date('Y-m-d H:i:s', time())), array('id' => $transaction['id']));
logTransaction($_GATEWAY['paymentmethod'], array_merge($transaction, $_POST), 'Callback - Successful (Closed)');
header('HTTP/1.1 200 OK');
exit();
} else {
logTransaction($_GATEWAY['paymentmethod'], array_merge($transaction, $_POST), 'Callback - Failure 1 (Payment not open or paid)');
header('HTTP/1.1 500 Payment not open or paid');
exit();
}
} else {
logTransaction('mollieunknown', $_POST, 'Callback - Failure 0 (Arg mismatch)');
header('HTTP/1.1 500 Arg mismatch');
exit();
}