2 Commits
3.1 ... master

Author SHA1 Message Date
12f9d4fa18 Update src/mollie/callback.php 2025-06-21 16:30:35 +02:00
60b8d2b62c Update src/mollie/mollie.php 2025-06-21 16:26:28 +02:00
2 changed files with 84 additions and 89 deletions

View File

@@ -1,97 +1,92 @@
<?php <?php
/** use Illuminate\Database\Capsule\Manager as Capsule;
* use Mollie\Api\MollieApiClient;
* Setting requirements and includes
*
*/
require_once __DIR__ . '/../../../init.php'; require_once __DIR__ . '/../../../init.php';
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
$whmcs->load_function('gateway'); $whmcs->load_function('gateway');
$whmcs->load_function('invoice'); $whmcs->load_function('invoice');
/** if ($_SERVER['REQUEST_METHOD'] !== 'POST' || empty($_POST['id'])) {
* logTransaction('mollieunknown', $_POST, 'Callback - Failure 0 (Arg mismatch)');
* Check parameters http_response_code(500);
* exit('Arg mismatch');
*/ }
if (isset($_POST['id'])) {
// Get transaction // Find transaction by Mollie payment ID
$transactionQuery = select_query('gateway_mollie', '', array('paymentid' => $_POST['id']), null, null, 1); $transaction = Capsule::table('gateway_mollie')
->where('paymentid', $_POST['id'])
->first();
if (mysql_num_rows($transactionQuery) != 1) { if (!$transaction) {
logTransaction('mollieunknown', $_POST, 'Callback - Failure 2 (Transaction not found)'); logTransaction('mollieunknown', $_POST, 'Callback - Failure 2 (Transaction not found)');
http_response_code(500);
header('HTTP/1.1 500 Transaction not found'); exit('Transaction not found');
exit();
} }
$transaction = mysql_fetch_assoc($transactionQuery); $transaction = (array) $transaction;
$method = $transaction['method'] ?: 'checkout';
$method = $transaction['method'];
if (empty($method)) {
$method = 'checkout';
}
// Load gateway configuration
$_GATEWAY = getGatewayVariables('mollie' . $method . '_devapp'); $_GATEWAY = getGatewayVariables('mollie' . $method . '_devapp');
if ($transaction['status'] != 'open') { if ($transaction['status'] !== 'open') {
logTransaction($_GATEWAY['paymentmethod'], array_merge($transaction, $_POST), 'Callback - Failure 3 (Transaction not open)'); logTransaction($_GATEWAY['paymentmethod'], array_merge($transaction, $_POST), 'Callback - Failure 3 (Transaction not open)');
http_response_code(500);
header('HTTP/1.1 500 Transaction not open'); exit('Transaction not open');
exit();
} }
// Get user and transaction currencies // Load currencies
$userCurrency = getCurrency($transaction['userid']); $userCurrency = getCurrency($transaction['userid']);
$transactionCurrency = select_query('tblcurrencies', '', array('id' => $transaction['currencyid'])); $transactionCurrency = Capsule::table('tblcurrencies')
$transactionCurrency = mysql_fetch_assoc($transactionCurrency); ->where('id', $transaction['currencyid'])
->first();
// Check payment $transactionCurrency = (array) $transactionCurrency;
$mollie = new \Mollie\Api\MollieApiClient();
// Init Mollie
$mollie = new MollieApiClient();
$mollie->setApiKey($_GATEWAY['key']); $mollie->setApiKey($_GATEWAY['key']);
try {
$payment = $mollie->payments->get($_POST['id']); $payment = $mollie->payments->get($_POST['id']);
} catch (Exception $e) {
logTransaction($_GATEWAY['paymentmethod'], $_POST, 'Callback - Failure 4 (API Error): ' . $e->getMessage());
http_response_code(500);
exit('Mollie API error');
}
// Handle payment status
if ($payment->isPaid()) { if ($payment->isPaid()) {
// Currency conversion if needed
// Add conversion, when there is need to. WHMCS only supports currencies per user. WHY?!
if ($transactionCurrency['id'] != $userCurrency['id']) { if ($transactionCurrency['id'] != $userCurrency['id']) {
$transaction['amount'] = convertCurrency($transaction['amount'], $transaction['currencyid'], $userCurrency['id']); $transaction['amount'] = convertCurrency($transaction['amount'], $transaction['currencyid'], $userCurrency['id']);
} }
// Check invoice
$invoiceid = checkCbInvoiceID($transaction['invoiceid'], $_GATEWAY['paymentmethod']); $invoiceid = checkCbInvoiceID($transaction['invoiceid'], $_GATEWAY['paymentmethod']);
checkCbTransID($transaction['paymentid']); checkCbTransID($transaction['paymentid']);
// Add invoice
addInvoicePayment($invoiceid, $transaction['paymentid'], $transaction['amount'], '', $_GATEWAY['paymentmethod']); 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'])); Capsule::table('gateway_mollie')
->where('id', $transaction['id'])
->update(['status' => 'paid', 'updated' => date('Y-m-d H:i:s')]);
logTransaction($_GATEWAY['paymentmethod'], array_merge($transaction, $_POST), 'Callback - Successful (Paid)'); logTransaction($_GATEWAY['paymentmethod'], array_merge($transaction, $_POST), 'Callback - Successful (Paid)');
http_response_code(200);
exit('OK');
header('HTTP/1.1 200 OK'); } elseif (!$payment->isOpen()) {
exit(); Capsule::table('gateway_mollie')
} else if ($payment->isOpen() == FALSE) { ->where('id', $transaction['id'])
update_query('gateway_mollie', array('status' => 'closed', 'updated' => date('Y-m-d H:i:s', time())), array('id' => $transaction['id'])); ->update(['status' => 'closed', 'updated' => date('Y-m-d H:i:s')]);
logTransaction($_GATEWAY['paymentmethod'], array_merge($transaction, $_POST), 'Callback - Successful (Closed)'); logTransaction($_GATEWAY['paymentmethod'], array_merge($transaction, $_POST), 'Callback - Successful (Closed)');
http_response_code(200);
exit('Closed');
header('HTTP/1.1 200 OK');
exit();
} else { } else {
logTransaction($_GATEWAY['paymentmethod'], array_merge($transaction, $_POST), 'Callback - Failure 1 (Payment not open or paid)'); logTransaction($_GATEWAY['paymentmethod'], array_merge($transaction, $_POST), 'Callback - Failure 1 (Payment not open or paid)');
http_response_code(500);
header('HTTP/1.1 500 Payment not open or paid'); exit('Payment not open or paid');
exit();
}
} else {
logTransaction('mollieunknown', $_POST, 'Callback - Failure 0 (Arg mismatch)');
header('HTTP/1.1 500 Arg mismatch');
exit();
} }

View File

@@ -41,7 +41,7 @@ function mollie_link($params, $method = Mollie_API_Object_Method::IDEAL)
$tableCheckQuery = full_query('SHOW TABLES LIKE \'gateway_mollie\''); $tableCheckQuery = full_query('SHOW TABLES LIKE \'gateway_mollie\'');
if (mysql_num_rows($tableCheckQuery) != 1) { if (mysql_num_rows($tableCheckQuery) != 1) {
full_query('CREATE TABLE IF NOT EXISTS `gateway_mollie` (`id` int(11) NOT NULL AUTO_INCREMENT, `paymentid` varchar(15), `amount` double NOT NULL, `currencyid` int(11) NOT NULL, `ip` varchar(50) NOT NULL, `userid` int(11) NOT NULL, `invoiceid` int(11) NOT NULL, `status` ENUM(\'open\',\'paid\',\'closed\') NOT NULL DEFAULT \'open\', `method` VARCHAR(25) NOT NULL, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `paymentid` (`paymentid`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;'); full_query('CREATE TABLE IF NOT EXISTS `gateway_mollie` (`id` int(11) NOT NULL AUTO_INCREMENT, `paymentid` varchar(40), `amount` double NOT NULL, `currencyid` int(11) NOT NULL, `ip` varchar(50) NOT NULL, `userid` int(11) NOT NULL, `invoiceid` int(11) NOT NULL, `status` ENUM(\'open\',\'paid\',\'closed\') NOT NULL DEFAULT \'open\', `method` VARCHAR(25) NOT NULL, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `paymentid` (`paymentid`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;');
} }
$mollie = new \Mollie\Api\MollieApiClient(); $mollie = new \Mollie\Api\MollieApiClient();