Reformatted code and added support for all payment methods

This commit adds the following payment methods:
- EPS
- Giftcards
- Giropay
- ING Home'Pay
- KBC/CBC

I've also ran a reformatter to clean up the code and added composer
instead of git modules. The latter enables us to keep up-to-date
with the last Mollie library in a more modern manner.
This commit is contained in:
Wouter van Os
2018-09-12 20:29:20 +02:00
parent 7bd9cb9340
commit 27d3ae1745
23 changed files with 661 additions and 129 deletions

View File

@@ -1,21 +1,21 @@
<?php
/**
*
* Setting requirements and includes
* Setting requirements and includes
*
*/
require_once __DIR__ . '/../../../init.php';
require_once __DIR__ . '/vendor/Mollie/src/Mollie/API/Autoloader.php';
require_once __DIR__ . '/vendor/autoload.php';
$whmcs->load_function('gateway');
$whmcs->load_function('invoice');
/**
*
* Check parameters
* Check parameters
*
*/
if(isset($_POST['id'])) {
if (isset($_POST['id'])) {
// Get transaction
$transactionQuery = select_query('gateway_mollie', '', array('paymentid' => $_POST['id']), null, null, 1);
@@ -31,9 +31,6 @@ if(isset($_POST['id'])) {
$method = $transaction['method'];
if ($method === Mollie_API_Object_Method::MISTERCASH) {
$method = 'bancontact';
}
$_GATEWAY = getGatewayVariables('mollie' . $method . '_devapp');
@@ -50,12 +47,12 @@ if(isset($_POST['id'])) {
$transactionCurrency = mysql_fetch_assoc($transactionCurrency);
// Check payment
$mollie = new Mollie_API_Client;
$mollie = new \Mollie\Api\MollieApiClient();
$mollie->setApiKey($_GATEWAY['key']);
$payment = $mollie->payments->get($_POST['id']);
$payment = $mollie->payments->get($_POST['id']);
if($payment->isPaid()) {
if ($payment->isPaid()) {
// Add conversion, when there is need to. WHMCS only supports currencies per user. WHY?!
if ($transactionCurrency['id'] != $userCurrency['id']) {
@@ -89,7 +86,7 @@ if(isset($_POST['id'])) {
header('HTTP/1.1 500 Payment not open or paid');
exit();
}
}else{
} else {
logTransaction('mollieunknown', $_POST, 'Callback - Failure 0 (Arg mismatch)');
header('HTTP/1.1 500 Arg mismatch');

View File

@@ -13,7 +13,12 @@ $_GATEWAYLANG['payWithBelfius'] = 'Betaal met Belfius';
$_GATEWAYLANG['payWithBitcoin'] = 'Betaal met Bitcoin';
$_GATEWAYLANG['payWithCreditcard'] = 'Betaal met Creditcard';
$_GATEWAYLANG['payWithIdeal'] = 'Betaal met iDeal';
$_GATEWAYLANG['payWithMistercash'] = 'Betaal met Bancontact';
$_GATEWAYLANG['payWithBancontact'] = 'Betaal met Bancontact';
$_GATEWAYLANG['payWithPaypal'] = 'Betaal met PayPal';
$_GATEWAYLANG['payWithPaysafecard'] = 'Betaal met Paysafecard';
$_GATEWAYLANG['payWithSofort'] = 'Betaal met Sofort Banking';
$_GATEWAYLANG['payWithEps'] = 'Betaal met EPS';
$_GATEWAYLANG['payWithGiftcard'] = 'Betaal met een cadeaukaart';
$_GATEWAYLANG['payWithGiropay'] = 'Betaal met Giropay';
$_GATEWAYLANG['payWithInghomepay'] = 'Betaal met ING Home\'Pay';
$_GATEWAYLANG['payWithKbc'] = 'Betaal met KBC/CBC-betaalknop';

View File

@@ -14,7 +14,12 @@ $_GATEWAYLANG['payWithBelfius'] = 'Pay with Belfius';
$_GATEWAYLANG['payWithBitcoin'] = 'Pay with Bitcoin';
$_GATEWAYLANG['payWithCreditcard'] = 'Pay with Credit Card';
$_GATEWAYLANG['payWithIdeal'] = 'Pay with iDeal';
$_GATEWAYLANG['payWithMistercash'] = 'Pay with Bancontact';
$_GATEWAYLANG['payWithBancontact'] = 'Pay with Bancontact';
$_GATEWAYLANG['payWithPaypal'] = 'Pay with PayPal';
$_GATEWAYLANG['payWithPaysafecard'] = 'Pay with Paysafecard';
$_GATEWAYLANG['payWithSofort'] = 'Pay with Sofort Banking';
$_GATEWAYLANG['payWithEps'] = 'Pay with EPS';
$_GATEWAYLANG['payWithGiftcard'] = 'Pay with a gift card';
$_GATEWAYLANG['payWithGiropay'] = 'Pay with Giropay';
$_GATEWAYLANG['payWithInghomepay'] = 'Pay with ING Home\'Pay';
$_GATEWAYLANG['payWithKbc'] = 'Pay with KBC/CBC Payment Button';

View File

@@ -1,28 +1,30 @@
<?php
require_once __DIR__ . '/vendor/Mollie/src/Mollie/API/Autoloader.php';
require_once __DIR__ . '/vendor/autoload.php';
function mollie_config() {
function mollie_config()
{
return array(
'key' => array(
'FriendlyName' => 'API key',
'Type' => 'text',
'Size' => '35',
'Description' => 'Your channel\'s API key.'
'Description' => 'Your channels API key.'
)
);
}
function mollie_link($params, $method = Mollie_API_Object_Method::IDEAL) {
function mollie_link($params, $method = Mollie_API_Object_Method::IDEAL)
{
global $whmcs;
/**
*
* Setting requirements and includes
* Setting requirements and includes
*
*/
if(substr($params['returnurl'], 0, 1) == '/')
$params['returnurl'] = $params['systemurl'].$params['returnurl'];
if (substr($params['returnurl'], 0, 1) == '/')
$params['returnurl'] = $params['systemurl'] . $params['returnurl'];
if (empty($params['language']))
$params['language'] = ((isset($_SESSION['language'])) ? $_SESSION['language'] : $whmcs->get_config('Language'));
@@ -42,12 +44,12 @@ function mollie_link($params, $method = Mollie_API_Object_Method::IDEAL) {
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;');
}
$mollie = new Mollie_API_Client;
$mollie = new \Mollie\Api\MollieApiClient();
$mollie->setApiKey($params['key']);
/**
*
* Check if good state to open transaction.
* Check if good state to open transaction.
*
*/
if (isset($_GET['check_payment']) && ctype_digit($_GET['check_payment'])) {
@@ -84,7 +86,10 @@ function mollie_link($params, $method = Mollie_API_Object_Method::IDEAL) {
));
$payment = $mollie->payments->create(array(
'amount' => $params['amount'],
'amount' => [
'value' => $params['amount'],
'currency' => $params['currency'],
],
'method' => $method,
'description' => $params['description'],
'redirectUrl' => $params['returnurl'] . '&check_payment=' . $transactionId,
@@ -97,19 +102,19 @@ function mollie_link($params, $method = Mollie_API_Object_Method::IDEAL) {
update_query('gateway_mollie', array('paymentid' => $payment->id), array('id' => $transactionId));
header('Location: ' . $payment->getPaymentUrl());
header('Location: ' . $payment->getCheckoutUrl());
exit();
} else {
$return = '<form action="" method="POST">';
if ($method == Mollie_API_Object_Method::IDEAL) {
if ($method == \Mollie\Api\Types\PaymentMethod::IDEAL) {
$issuers = $mollie->issuers->all();
$return .= '<label for="issuer">' . $_GATEWAYLANG['selectBank'] . ':</label> ';
$return .= '<select name="issuer">';
foreach ($issuers as $issuer) {
if ($issuer->method == Mollie_API_Object_Method::IDEAL) {
if ($issuer->method == \Mollie\Api\Types\PaymentMethod::IDEAL) {
$return .= '<option value=' . htmlspecialchars($issuer->id) . '>' . htmlspecialchars($issuer->name) . '</option>';
}
}