Skip to content

Commit 02e3923

Browse files
authored
Merge pull request #202 from mollie/9.2.6
9.2.6
2 parents 15c500e + 7bb3d1e commit 02e3923

File tree

10 files changed

+117
-87
lines changed

10 files changed

+117
-87
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
# Changelog #
44

5+
#### Changes in release 9.2.6
6+
+ Redirected to success page after 'Open' payment status
7+
+ Made mollie_order_id primary in mollie_payments table
8+
+ Added date_modified field in mollie_payments table
9+
+ Call cleanup function on more occasions
10+
+ Added settings update to make sure module keeps working when an update introduces new settings
11+
512
#### Changes in release 9.2.5
613
+ Bugfix URL creation
714
+ Added option to force currency for payment

admin/controller/payment/mollie/base.php

Lines changed: 73 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,22 @@ public function cleanUp() {
272272
$catalogControllerDir = DIR_CATALOG . 'controller/';
273273
$catalogModelDir = DIR_CATALOG . 'model/';
274274

275+
$files = array();
276+
275277
foreach (DEPRECATED_METHODS as $method) {
276-
if (file_exists($adminControllerDir . 'extension/payment/mollie_' . $method . '.php')) {
277-
unlink($adminControllerDir . 'extension/payment/mollie_' . $method . '.php');
278+
$files = array(
279+
$adminControllerDir . 'extension/payment/mollie_' . $method . '.php',
280+
$catalogControllerDir . 'extension/payment/mollie_' . $method . '.php',
281+
$catalogModelDir . 'extension/payment/mollie_' . $method . '.php',
282+
$adminControllerDir . 'payment/mollie_' . $method . '.php',
283+
$catalogControllerDir . 'payment/mollie_' . $method . '.php',
284+
$catalogModelDir . 'payment/mollie_' . $method . '.php'
285+
);
286+
287+
foreach ($files as $file) {
288+
if (file_exists($file)) {
289+
unlink($file);
290+
}
278291
}
279292

280293
$languageFiles = glob($adminLanguageDir . '*/extension/payment/mollie_' . $method . '.php');
@@ -284,67 +297,51 @@ public function cleanUp() {
284297
}
285298
}
286299

287-
if (file_exists($catalogControllerDir . 'extension/payment/mollie_' . $method . '.php')) {
288-
unlink($catalogControllerDir . 'extension/payment/mollie_' . $method . '.php');
289-
}
290-
291-
if (file_exists($catalogModelDir . 'extension/payment/mollie_' . $method . '.php')) {
292-
unlink($catalogModelDir . 'extension/payment/mollie_' . $method . '.php');
293-
}
294-
295-
if (file_exists($adminControllerDir . 'payment/mollie_' . $method . '.php')) {
296-
unlink($adminControllerDir . 'payment/mollie_' . $method . '.php');
297-
}
298-
299300
$languageFiles = glob($adminLanguageDir . '*/payment/mollie_' . $method . '.php');
300301
foreach ($languageFiles as $file) {
301302
if (file_exists($file)) {
302303
unlink($file);
303304
}
304305
}
305-
306-
if (file_exists($catalogControllerDir . 'payment/mollie_' . $method . '.php')) {
307-
unlink($catalogControllerDir . 'payment/mollie_' . $method . '.php');
308-
}
309-
310-
if (file_exists($catalogModelDir . 'payment/mollie_' . $method . '.php')) {
311-
unlink($catalogModelDir . 'payment/mollie_' . $method . '.php');
312-
}
313306
}
314307

315308
if (MollieHelper::isOpenCart3x()) {
316-
if(file_exists($adminThemeDir . 'extension/payment/mollie(max_1.5.6.4).tpl')) {
317-
unlink($adminThemeDir . 'extension/payment/mollie(max_1.5.6.4).tpl');
318-
unlink($adminThemeDir . 'payment/mollie(max_1.5.6.4).tpl');
319-
unlink($catalogThemeDir . 'extension/payment/mollie_return.tpl');
320-
unlink($catalogThemeDir . 'payment/mollie_return.tpl');
321-
unlink($catalogThemeDir . 'extension/payment/mollie_checkout_form.tpl');
322-
unlink($catalogThemeDir . 'payment/mollie_checkout_form.tpl');
323-
}
324-
//Remove twig file from old version
325-
if(file_exists($adminThemeDir . 'extension/payment/mollie.twig')) {
326-
unlink($adminThemeDir . 'extension/payment/mollie.twig');
327-
}
328-
if(file_exists($adminThemeDir . 'payment/mollie.twig')) {
329-
unlink($adminThemeDir . 'payment/mollie.twig');
330-
}
309+
$files = array(
310+
$adminThemeDir . 'extension/payment/mollie(max_1.5.6.4).tpl',
311+
$adminThemeDir . 'payment/mollie(max_1.5.6.4).tpl',
312+
$catalogThemeDir . 'extension/payment/mollie_return.tpl',
313+
$catalogThemeDir . 'payment/mollie_return.tpl',
314+
$catalogThemeDir . 'extension/payment/mollie_checkout_form.tpl',
315+
$catalogThemeDir . 'payment/mollie_checkout_form.tpl',
316+
$adminThemeDir . 'extension/payment/mollie.twig', //Remove twig file from old version
317+
$adminThemeDir . 'payment/mollie.twig' //Remove twig file from old version
318+
);
319+
331320
} elseif (MollieHelper::isOpenCart2x()) {
332-
if(file_exists($adminThemeDir . 'extension/payment/mollie(max_1.5.6.4).tpl')) {
333-
unlink($adminThemeDir . 'extension/payment/mollie(max_1.5.6.4).tpl');
334-
unlink($adminThemeDir . 'payment/mollie(max_1.5.6.4).tpl');
335-
unlink($catalogThemeDir . 'extension/payment/mollie_return.twig');
336-
unlink($catalogThemeDir . 'payment/mollie_return.twig');
337-
unlink($catalogThemeDir . 'extension/payment/mollie_checkout_form.twig');
338-
unlink($catalogThemeDir . 'payment/mollie_checkout_form.twig');
339-
}
321+
$files = array(
322+
$adminThemeDir . 'extension/payment/mollie(max_1.5.6.4).tpl',
323+
$adminThemeDir . 'payment/mollie(max_1.5.6.4).tpl',
324+
$catalogThemeDir . 'extension/payment/mollie_return.twig',
325+
$catalogThemeDir . 'payment/mollie_return.twig',
326+
$catalogThemeDir . 'extension/payment/mollie_checkout_form.twig',
327+
$catalogThemeDir . 'payment/mollie_checkout_form.twig'
328+
);
329+
340330
} else {
341-
if(file_exists($adminThemeDir . 'extension/payment/mollie.tpl')) {
342-
unlink($adminThemeDir . 'extension/payment/mollie.tpl');
343-
unlink($adminThemeDir . 'payment/mollie.tpl');
344-
unlink($catalogThemeDir . 'extension/payment/mollie_return.twig');
345-
unlink($catalogThemeDir . 'payment/mollie_return.twig');
346-
unlink($catalogThemeDir . 'extension/payment/mollie_checkout_form.twig');
347-
unlink($catalogThemeDir . 'payment/mollie_checkout_form.twig');
331+
$files = array(
332+
$adminThemeDir . 'extension/payment/mollie.tpl',
333+
$adminThemeDir . 'payment/mollie.tpl',
334+
$catalogThemeDir . 'extension/payment/mollie_return.twig',
335+
$catalogThemeDir . 'payment/mollie_return.twig',
336+
$catalogThemeDir . 'extension/payment/mollie_checkout_form.twig',
337+
$catalogThemeDir . 'payment/mollie_checkout_form.twig'
338+
);
339+
340+
}
341+
342+
foreach ($files as $file) {
343+
if (file_exists($file)) {
344+
unlink($file);
348345
}
349346
}
350347

@@ -374,6 +371,24 @@ public function delTree($dir) {
374371
return rmdir($dir);
375372
}
376373

374+
/**
375+
* Insert variables that are added in later versions.
376+
*/
377+
public function updateSettings() {
378+
$code = MollieHelper::getModuleCode();
379+
$stores = Util::info()->stores();
380+
$vars = array(
381+
'default_currency' => 'DEF' // variable => default value
382+
);
383+
foreach($stores as $store) {
384+
foreach($vars as $var=>$val) {
385+
if (null == Util::config($store['store_id'])->get($code . '_' . $var, true)) {
386+
Util::config($store['store_id'])->setValue($code, $code . '_' . $var, $val);
387+
}
388+
}
389+
}
390+
}
391+
377392
/**
378393
* Trigger installation of all Mollie modules.
379394
*/
@@ -431,41 +446,21 @@ public function clearData() {
431446
public function index () {
432447
// Double-check if clean-up has been done - For upgrades
433448
if (empty($this->config->get('mollie_payment_version')) || $this->config->get('mollie_payment_version') < MOLLIE_VERSION) {
434-
$this->cleanUp();
435449
Util::config(0)->set('mollie_payment', 'mollie_payment_version', MOLLIE_VERSION);
436450
}
437451

438-
$adminThemeDir = DIR_APPLICATION . 'view/template/';
439-
if (MollieHelper::isOpenCart3x() || MollieHelper::isOpenCart2x()) {
440-
if(file_exists($adminThemeDir . 'extension/payment/mollie(max_1.5.6.4).tpl') || file_exists($adminThemeDir . 'extension/payment/mollie.twig') || file_exists($adminThemeDir . 'payment/mollie.twig')) {
441-
$this->cleanUp();
442-
}
443-
} else {
444-
if(file_exists($adminThemeDir . 'extension/payment/mollie.tpl')) {
445-
$this->cleanUp();
446-
}
447-
}
448-
449-
$adminControllerDir = DIR_APPLICATION . 'controller/';
450-
foreach (DEPRECATED_METHODS as $method) {
451-
if (file_exists($adminControllerDir . 'extension/payment/mollie_' . $method . '.php') || file_exists($adminControllerDir . 'payment/mollie_' . $method . '.php')) {
452-
$this->cleanUp();
453-
}
454-
}
455-
456-
$catalogControllerDir = DIR_CATALOG . 'controller/';
457-
458-
// Remove un-used files from version 8.x
459-
if (file_exists($adminControllerDir . 'extension/payment/mollie') || file_exists($catalogControllerDir . 'extension/payment/mollie') || file_exists($catalogControllerDir . 'extension/payment/mollie-api-client')) {
460-
$this->cleanUp();
461-
}
452+
// Run cleanup
453+
$this->cleanUp();
462454

463455
//Also delete data related to deprecated modules from settings
464456
$this->clearData();
465457

466458
// Run database patch
467459
$this->patch();
468460

461+
// Update settings with newly added variables
462+
$this->updateSettings();
463+
469464
//Load language data
470465
$data = array("version" => MOLLIE_RELEASE);
471466
Util::load()->language("payment/mollie", $data);
@@ -633,7 +628,7 @@ public function index () {
633628
$code . "_ideal_shipping_status_id" => 3,
634629
$code . "_create_shipment_status_id" => 3,
635630
$code . "_ideal_refund_status_id" => 11,
636-
$code . "_create_shipment" => 1,
631+
$code . "_create_shipment" => 3,
637632
$code . "_refresh_token" => '',
638633
$code . "_payment_screen_language" => 'en-gb',
639634
$code . "_default_currency" => 'DEF',

admin/patch/mollie/0_createMolliePaymentsTable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
return function () {
55
Util::patch()->table("mollie_payments")
6-
->addField("order_id", "INT(11) NOT NULL", "primary")
6+
->addField("order_id", "INT(11) NOT NULL")
77
->addField("method", "VARCHAR(32) NOT NULL")
8-
->addField("mollie_order_id", "VARCHAR(32) NOT NULL")
8+
->addField("mollie_order_id", "VARCHAR(32) NOT NULL", "primary")
99
->addField("transaction_id", "VARCHAR(32)")
1010
->addField("bank_account", "VARCHAR(15)")
1111
->addField("bank_status", "VARCHAR(20)")
1212
->addField("refund_id", "VARCHAR(32)")
13-
->addUnique("mollie_order_id")
13+
->addUnique("mollie_order_id")
1414
->create();
1515
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return function () {
4+
$query = $this->db->query("SHOW INDEX FROM `" .DB_PREFIX. "mollie_payments` where Key_name = 'PRIMARY'");
5+
if($query->num_rows > 0 && $query->row['Column_name'] != 'mollie_order_id') {
6+
$this->db->query("ALTER TABLE `" .DB_PREFIX. "mollie_payments` DROP PRIMARY KEY, ADD PRIMARY KEY (mollie_order_id)");
7+
}
8+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
use comercia\Util;
3+
4+
return function () {
5+
Util::patch()->table("mollie_payments")
6+
->addField("date_modified", "DATETIME NOT NULL")
7+
->update();
8+
};

catalog/controller/payment/mollie/base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ public function callback()
11911191
} else if(!empty($orderDetails->_embedded->payments)) {
11921192

11931193
$payment = $orderDetails->_embedded->payments[0];
1194-
if (($payment->status == 'paid') && !in_array($paid_status_id, $orderStatuses)) {
1194+
if (($payment->status == 'paid' || $payment->status == 'open') && !in_array($paid_status_id, $orderStatuses)) {
11951195
$this->addOrderHistory($order, $paid_status_id, $this->language->get("response_success"), true);
11961196
$order['order_status_id'] = $paid_status_id;
11971197
}

catalog/controller/payment/mollie/helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class MollieHelper
77
{
8-
const PLUGIN_VERSION = "9.2.5";
8+
const PLUGIN_VERSION = "9.2.6";
99
const OUTH_URL = 'https://api.mollie.com/oauth2';
1010

1111
// All available modules. These should correspond to the Mollie_API_Object_Method constants.

catalog/model/payment/mollie/base.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function setPayment($order_id, $mollie_order_id, $method)
205205
{
206206
$bank_account = isset($this->session->data['mollie_issuer']) ? $this->session->data['mollie_issuer'] : NULL;
207207
if (!empty($order_id) && !empty($mollie_order_id) && !empty($method)) {
208-
$this->db->query("INSERT INTO `" . DB_PREFIX . "mollie_payments` SET `order_id` = '" . (int)$order_id . "', `mollie_order_id` = '" . $this->db->escape($mollie_order_id) . "', `method` = '" . $this->db->escape($method) . "', `bank_account` = '" . $this->db->escape($bank_account) . "' ON DUPLICATE KEY UPDATE `order_id` = '" . (int)$order_id . "'");
208+
$this->db->query("INSERT INTO `" . DB_PREFIX . "mollie_payments` SET `order_id` = '" . (int)$order_id . "', `mollie_order_id` = '" . $this->db->escape($mollie_order_id) . "', `method` = '" . $this->db->escape($method) . "', `bank_account` = '" . $this->db->escape($bank_account) . "', `date_modified` = NOW() ON DUPLICATE KEY UPDATE `order_id` = '" . (int)$order_id . "'");
209209

210210
if ($this->db->countAffected() > 0) {
211211
return TRUE;
@@ -227,7 +227,7 @@ public function setPayment($order_id, $mollie_order_id, $method)
227227
public function updatePayment($order_id, $mollie_order_id, $data, $consumer = NULL)
228228
{
229229
if (!empty($order_id) && !empty($mollie_order_id)) {
230-
$this->db->query("UPDATE `" . DB_PREFIX . "mollie_payments` SET `transaction_id` = '" . $this->db->escape($data['payment_id']) . "', `bank_status` = '" . $this->db->escape($data['status']) . "' WHERE `order_id` = '" . (int)$order_id . "' AND `mollie_order_id` = '" . $this->db->escape($mollie_order_id) . "'");
230+
$this->db->query("UPDATE `" . DB_PREFIX . "mollie_payments` SET `transaction_id` = '" . $this->db->escape($data['payment_id']) . "', `bank_status` = '" . $this->db->escape($data['status']) . "', `date_modified` = NOW() WHERE `order_id` = '" . (int)$order_id . "' AND `mollie_order_id` = '" . $this->db->escape($mollie_order_id) . "'");
231231

232232
return $this->db->countAffected() > 0;
233233
}

system/comercia/config.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ class Config
66
var $model;
77
var $store_id;
88
var $data = [];
9+
var $db;
910

1011
function __construct($store_id = 0)
1112
{
1213
$this->model = Util::load()->model("setting/setting");
1314
$this->store_id = $store_id;
15+
$this->db = Util::registry()->get("db");
1416
$data = Util::db()->query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = " . $store_id . "");
1517
foreach ($data as $value) {
1618
if (!$value['serialized']) {
@@ -58,6 +60,16 @@ function set($code, $key, $value = false)
5860
$this->data[$key] = $val;
5961
}
6062
}
63+
64+
function setValue($code, $key, $value = '')
65+
{
66+
if (!is_array($value)) {
67+
$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$this->store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape($value) . "'");
68+
} else {
69+
$this->db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$this->store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape(json_encode($value, true)) . "', serialized = '1'");
70+
}
71+
$this->data[$key] = $value;
72+
}
6173
}
6274

6375
?>

tests/unittests/catalog/model/ModelPaymentMollieIdealTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testSetPaymentNothingAffected()
6464
$this->model->db->expects($this->once())
6565
->method("query")
6666

67-
->with("INSERT INTO `prefix_mollie_payments` SET `order_id` = '1337', `mollie_order_id` = '1bba1d8fdbd8103b46151634bdbe0a60', `method` = 'idl', `bank_account` = '' ON DUPLICATE KEY UPDATE `order_id` = '1337'");
67+
->with("INSERT INTO `prefix_mollie_payments` SET `order_id` = '1337', `mollie_order_id` = '1bba1d8fdbd8103b46151634bdbe0a60', `method` = 'idl', `bank_account` = '', `date_modified` = NOW() ON DUPLICATE KEY UPDATE `order_id` = '1337'");
6868

6969
$this->model->db->expects($this->once())
7070
->method("countAffected")
@@ -77,7 +77,7 @@ public function testSetPaymentPaymentSet()
7777
{
7878
$this->model->db->expects($this->once())
7979
->method("query")
80-
->with("INSERT INTO `prefix_mollie_payments` SET `order_id` = '1337', `mollie_order_id` = '1bba1d8fdbd8103b46151634bdbe0a60', `method` = 'idl', `bank_account` = '' ON DUPLICATE KEY UPDATE `order_id` = '1337'");
80+
->with("INSERT INTO `prefix_mollie_payments` SET `order_id` = '1337', `mollie_order_id` = '1bba1d8fdbd8103b46151634bdbe0a60', `method` = 'idl', `bank_account` = '', `date_modified` = NOW() ON DUPLICATE KEY UPDATE `order_id` = '1337'");
8181

8282
$this->model->db->expects($this->once())
8383
->method("countAffected")

0 commit comments

Comments
 (0)