From 4908e1e90a59ef914908176f15ea7e306ab64334 Mon Sep 17 00:00:00 2001 From: Lennard van Gunst Date: Tue, 10 Jun 2014 14:48:47 +0200 Subject: [PATCH] Fix issue when iDEAL bank list is not displayed. --- mollie/controllers/front/payment.php | 10 +- mollie/controllers/front/return.php | 2 +- mollie/controllers/front/webhook.php | 10 +- mollie/mollie.php | 121 +++++++++--------- mollie/translations/fr.php | 8 +- mollie/translations/nl.php | 8 +- mollie/views/templates/hook/mollie_config.tpl | 12 +- .../views/templates/hook/mollie_methods.tpl | 6 +- release.sh | 2 +- tests/unittests/controllers/paymentTest.php | 6 +- tests/unittests/mollieTest.php | 4 +- 11 files changed, 96 insertions(+), 93 deletions(-) diff --git a/mollie/controllers/front/payment.php b/mollie/controllers/front/payment.php index cbbcacbcb..23d6d932e 100644 --- a/mollie/controllers/front/payment.php +++ b/mollie/controllers/front/payment.php @@ -73,7 +73,7 @@ public function initContent() $issuer = !empty($_GET['issuer']) ? $_GET['issuer'] : NULL; // If no issuer was set yet and the issuer list has its own page, show issuer list here - if ($issuer === null && $this->module->getConfigValue('MOLLIE_ISSUERS') === 'own-page') + if ($issuer === null && $this->module->getConfigValue('MOLLIE_ISSUERS') === Mollie::ISSUERS_OWN_PAGE) { $tpl_data = array(); $tpl_data['issuers'] = $this->_getIssuerList($method); @@ -204,7 +204,7 @@ protected function _getIssuerList($method) } catch (Mollie_API_Exception $e) { - if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG')) + if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG') == Mollie::DEBUG_LOG_ERRORS) { Logger::addLog(__METHOD__ . ' said: ' . $e->getMessage(), Mollie::NOTICE); } @@ -223,7 +223,7 @@ protected function _convertCurrencyToEuro($amount) if (!$currency_euro) { // No Euro currency available! - if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG')) + if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG') == Mollie::DEBUG_LOG_ERRORS) { Logger::addLog(__METHOD__ . ' said: In order to use this module, you need to enable Euros as currency.', Mollie::CRASH); } @@ -316,7 +316,7 @@ protected function _createPayment($data) { if ($e->getField() == "webhookUrl") { - if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG')) + if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG') == Mollie::DEBUG_LOG_ERRORS) { Logger::addLog(__METHOD__ . ' said: Could not reach generated webhook url, falling back to profile webhook url.', Mollie::WARNING); } @@ -330,7 +330,7 @@ protected function _createPayment($data) } catch (Mollie_API_Exception $e) { - if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG')) + if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG') == Mollie::DEBUG_LOG_ERRORS) { Logger::addLog(__METHOD__ . ' said: ' . $e->getMessage(), Mollie::CRASH); } diff --git a/mollie/controllers/front/return.php b/mollie/controllers/front/return.php index 31c6d119e..91277ce65 100644 --- a/mollie/controllers/front/return.php +++ b/mollie/controllers/front/return.php @@ -93,7 +93,7 @@ public function initContent() break; default: $data['msg_details'] = $this->module->lang('The transaction has an unexpected status.'); - if (Configuration::get('MOLLIE_DEBUG_LOG')) + if (Configuration::get('MOLLIE_DEBUG_LOG') == Mollie::DEBUG_LOG_ERRORS) { Logger::addLog(__METHOD__ . 'said: The transaction has an unexpected status ('.$data['mollie_info']['bank_status'].')', Mollie::WARNING); } diff --git a/mollie/controllers/front/webhook.php b/mollie/controllers/front/webhook.php index f6d9ce46a..76011a34f 100644 --- a/mollie/controllers/front/webhook.php +++ b/mollie/controllers/front/webhook.php @@ -66,7 +66,7 @@ protected function _executeWebhook() { if (Tools::getValue('testByMollie')) { - if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG')) + if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG') == Mollie::DEBUG_LOG_ERRORS) { Logger::addLog(__METHOD__ . 'said: Mollie webhook tester successfully communicated with the shop.', Mollie::NOTICE); } @@ -77,7 +77,7 @@ protected function _executeWebhook() if (empty($id)) { - if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG')) + if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG') == Mollie::DEBUG_LOG_ERRORS) { Logger::addLog(__METHOD__ . 'said: Received webhook request without proper transaction ID.', Mollie::WARNING); } @@ -93,7 +93,7 @@ protected function _executeWebhook() } catch (Exception $e) { - if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG')) + if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG') == Mollie::DEBUG_LOG_ERRORS) { Logger::addLog(__METHOD__ . 'said: Could not retrieve payment details for id "' . $id . '". Reason: ' . $e->getMessage(), Mollie::WARNING); } @@ -103,7 +103,7 @@ protected function _executeWebhook() // Store status in database if (!$this->_saveOrderStatus($order_id, $status)) { - if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG')) + if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG') == Mollie::DEBUG_LOG_ERRORS) { Logger::addLog(__METHOD__ . 'said: Could not save order status for payment "' . $id . '". Reason: ' . Db::getInstance()->getMsgError(), Mollie::WARNING); } @@ -113,7 +113,7 @@ protected function _executeWebhook() $this->module->setOrderStatus($order_id, $status); // Log successful webhook requests in extended log mode only - if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG') > 1) + if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG') == Mollie::DEBUG_LOG_ALL) { Logger::addLog(__METHOD__ . 'said: Received webhook request for order ' . (int) $order_id . ' / transaction ' . htmlentities($id), Mollie::NOTICE); } diff --git a/mollie/mollie.php b/mollie/mollie.php index 6b2fb4e78..fc24c3edb 100644 --- a/mollie/mollie.php +++ b/mollie/mollie.php @@ -75,6 +75,19 @@ class Mollie extends PaymentModule const NAME = 'mollie'; + CONST LOGOS_BIG = 'big'; + const LOGOS_NORMAL = 'normal'; + const LOGOS_HIDE = 'hide'; + + const ISSUERS_ALWAYS_VISIBLE = 'always-visible'; + const ISSUERS_ON_CLICK = 'on-click'; + const ISSUERS_OWN_PAGE = 'own-page'; + const ISSUERS_PAYMENT_PAGE = 'payment-page'; + + const DEBUG_LOG_NONE = 0; + const DEBUG_LOG_ERRORS = 1; + const DEBUG_LOG_ALL = 2; + public function __construct() { parent::__construct(); @@ -173,7 +186,7 @@ public function install() return FALSE; } if ( - !$this->_initConfig() + !$this->_initConfig() ) { $this->_errors[] = 'Unable to set config values'; @@ -257,7 +270,7 @@ public function reinstall() $this->_unregisterHooks() && $this->_registerHooks() && $this->_initConfig() - ; + ; } @@ -271,7 +284,7 @@ protected function _registerHooks() $this->registerHook('displayAdminOrder') && $this->registerHook('displayHeader') && $this->registerHook('displayBackOfficeHeader') - ; + ; } /** @@ -284,7 +297,7 @@ protected function _unregisterHooks() $this->unregisterHook('displayAdminOrder') && $this->unregisterHook('displayHeader') && $this->unregisterHook('displayBackOfficeHeader') - ; + ; } /** @@ -296,10 +309,10 @@ protected function _initConfig() $this->initConfigValue('MOLLIE_VERSION', $this->version) && $this->initConfigValue('MOLLIE_API_KEY', '') && $this->initConfigValue('MOLLIE_DESCRIPTION', 'Order %') && - $this->initConfigValue('MOLLIE_IMAGES', 'normal') && - $this->initConfigValue('MOLLIE_ISSUERS', 'on-click') && + $this->initConfigValue('MOLLIE_IMAGES', self::LOGOS_NORMAL) && + $this->initConfigValue('MOLLIE_ISSUERS', self::ISSUERS_ON_CLICK) && $this->initConfigValue('MOLLIE_CSS', '') && - $this->initConfigValue('MOLLIE_DEBUG_LOG', 1) && + $this->initConfigValue('MOLLIE_DEBUG_LOG', self::DEBUG_LOG_ERRORS) && $this->initConfigValue('MOLLIE_DISPLAY_ERRORS', FALSE) && $this->initConfigValue('MOLLIE_USE_PROFILE_WEBHOOK', FALSE) && $this->initConfigValue('MOLLIE_STATUS_OPEN', 3) && @@ -312,7 +325,7 @@ protected function _initConfig() $this->initConfigValue('MOLLIE_MAIL_WHEN_CANCELLED', FALSE) && $this->initConfigValue('MOLLIE_MAIL_WHEN_EXPIRED', FALSE) && $this->initConfigValue('MOLLIE_MAIL_WHEN_REFUNDED', TRUE) - ; + ; } /** @@ -334,13 +347,27 @@ public function getContent() $update_message = $this->_getUpdateMessage('https://github.com/mollie/Prestashop'); $result_msg = ''; - $image_options = array($this->l('big'), $this->l('normal'), $this->l('hide')); - $issuer_options = array($this->l('always-visible'), $this->l('on-click'), $this->l('own-page'), $this->l('payment-page')); - $logger_options = array($this->l('Nothing'), $this->l('Errors'), $this->l('Everything')); + + $image_options = array( + self::LOGOS_BIG => $this->l('big'), + self::LOGOS_NORMAL => $this->l('normal'), + self::LOGOS_HIDE => $this->l('hide') + ); + $issuer_options = array( + self::ISSUERS_ALWAYS_VISIBLE => $this->l('Always visible'), + self::ISSUERS_ON_CLICK => $this->l('On click'), + self::ISSUERS_OWN_PAGE => $this->l('Own page'), + self::ISSUERS_PAYMENT_PAGE => $this->l('Payment page') + ); + $logger_options = array( + self::DEBUG_LOG_NONE => $this->l('Nothing'), + self::DEBUG_LOG_ERRORS => $this->l('Errors'), + self::DEBUG_LOG_ALL => $this->l('Everything') + ); if (Tools::isSubmit('Mollie_Config_Save')) { - $result_msg = $this->_getSaveResult($image_options, $issuer_options, $logger_options); + $result_msg = $this->_getSaveResult(array_keys($image_options), array_keys($issuer_options), array_keys($logger_options)); } $data = array( @@ -392,9 +419,9 @@ public function getContent() $val = (int) $val; $data['msg_status_' . $name] = sprintf($msg_status, $this->lang[$name]); $data['desc_status_' . $name] = ucfirst(sprintf($desc_status, - $this->lang[$name], - $db->getValue('SELECT `name` FROM `' . _DB_PREFIX_ . 'order_state_lang` WHERE `id_order_state` = ' . (int) $val . ' AND `id_lang` = ' . (int) $lang) - )); + $this->lang[$name], + $db->getValue('SELECT `name` FROM `' . _DB_PREFIX_ . 'order_state_lang` WHERE `id_order_state` = ' . (int) $val . ' AND `id_lang` = ' . (int) $lang) + )); $data['val_status_' . $name] = $val; $data['msg_mail_' . $name] = sprintf($msg_mail, $this->lang[$name]); $data['desc_mail_' . $name] = sprintf($desc_mail, $this->lang[$name]); @@ -407,8 +434,6 @@ public function getContent() return $this->display(__FILE__, 'mollie_config.tpl'); } - - /** * @param $field * @param $default_value @@ -511,28 +536,9 @@ protected function _getSaveResult($image_options = array(), $issuer_options = ar { $_POST['Mollie_Css'] = ''; } - if (!is_numeric($_POST['Mollie_Logger'])) + if (!in_array($_POST['Mollie_Logger'], $logger_options)) { - if (in_array($_POST['Mollie_Logger'], $logger_options)) - { - $i = 0; - while (($opt = current($logger_options)) !== FALSE) { - if ($opt == $_POST['Mollie_Logger']) { - $_POST['Mollie_Logger'] = key($logger_options); - break; - } - if ($i++ > sizeof($logger_options)) - { - $errors[] = $this->l('Invalid debug log setting.'); - break; - } - next($logger_options); - } - } - else - { - $errors[] = $this->l('Invalid debug log setting.'); - } + $errors[] = $this->l('Invalid debug log setting.'); } if (!isset($_POST['Mollie_Errors'])) { @@ -734,10 +740,10 @@ public function hookDisplayBackOfficeHeader() public function hookDisplayAdminOrder($params) { $mollie_data = Db::getInstance()->getRow(sprintf( - 'SELECT * FROM `%s` WHERE `order_id` = %s;', - _DB_PREFIX_ . 'mollie_payments', - (int) $params['id_order'] - )); + 'SELECT * FROM `%s` WHERE `order_id` = %s;', + _DB_PREFIX_ . 'mollie_payments', + (int) $params['id_order'] + )); // Do not show refund option if it's not a successfully paid Mollie transaction if ($mollie_data === FALSE || $mollie_data['bank_status'] !== Mollie_API_Object_Payment::STATUS_PAID) @@ -772,21 +778,20 @@ public function hookDisplayPayment() if (!Currency::exists('EUR', 0)) { return '

' . - $this->l('Mollie Payment Methods are only available when Euros are activated.') . - '

'; + $this->l('Mollie Payment Methods are only available when Euros are activated.') . + '

'; } $issuer_setting = $this->getConfigValue('MOLLIE_ISSUERS'); - $show_issuers_here = in_array($issuer_setting, array('always-visible', 'on-click')); try { $methods = $this->api->methods->all(); - $issuer_list = in_array($issuer_setting, array('always-visible', 'on-click')) ? $this->_getIssuerList($show_issuers_here) : array(); + $issuer_list = in_array($issuer_setting, array(self::ISSUERS_ALWAYS_VISIBLE, self::ISSUERS_ON_CLICK)) ? $this->_getIssuerList() : array(); } catch (Mollie_API_Exception $e) { $methods = array(); $issuer_list = array(); - if ($this->getConfigValue('MOLLIE_DEBUG_LOG')) + if ($this->getConfigValue('MOLLIE_DEBUG_LOG') == self::DEBUG_LOG_ERRORS) { Logger::addLog(__METHOD__ . ' said: ' . $e->getMessage(), Mollie::ERROR); } @@ -794,22 +799,22 @@ public function hookDisplayPayment() { return '

' . - $e->getMessage() . + $e->getMessage() . '

' - ; + ; } } $this->smarty->assign(array( - 'methods' => $methods, - 'issuers' => $issuer_list, - 'issuer_setting' => $issuer_setting, - 'images' => $this->getConfigValue('MOLLIE_IMAGES'), - 'warning' => $this->warning, - 'msg_pay_with' => $this->lang['Pay with %s'], - 'msg_bankselect' => $this->lang['Select your bank:'], - 'module' => $this, - )); + 'methods' => $methods, + 'issuers' => $issuer_list, + 'issuer_setting' => $issuer_setting, + 'images' => $this->getConfigValue('MOLLIE_IMAGES'), + 'warning' => $this->warning, + 'msg_pay_with' => $this->lang['Pay with %s'], + 'msg_bankselect' => $this->lang['Select your bank:'], + 'module' => $this, + )); return $this->display(__FILE__, 'mollie_methods.tpl'); } diff --git a/mollie/translations/fr.php b/mollie/translations/fr.php index b1ca1dad9..692ccc861 100644 --- a/mollie/translations/fr.php +++ b/mollie/translations/fr.php @@ -42,10 +42,10 @@ $_MODULE['<{mollie}prestashop>mollie_d861877da56b8b4ceb35c8cbfdf65bb4'] = 'large'; $_MODULE['<{mollie}prestashop>mollie_fea087517c26fadd409bd4b9dc642555'] = 'normal'; $_MODULE['<{mollie}prestashop>mollie_a88f05b6c963e145a45b58c47cd42a41'] = 'aucune'; -$_MODULE['<{mollie}prestashop>mollie_1b73bbc1a4953a0cb5c4c1739d368b0a'] = 'toujours-visible'; -$_MODULE['<{mollie}prestashop>mollie_b7b10ab45bb159cbf707d3cf9a119b81'] = 'sur-clic'; -$_MODULE['<{mollie}prestashop>mollie_c0fb21c0519492004d1fad2f0f3f4426'] = 'propre-page'; -$_MODULE['<{mollie}prestashop>mollie_a1ec2845502d15bc956b2d3706035ffc'] = 'page-payement'; +$_MODULE['<{mollie}prestashop>mollie_199451198078814ce456d33991f5282c'] = 'Toujours visible'; +$_MODULE['<{mollie}prestashop>mollie_85a692706bc7597b6e32bc1d354c138f'] = 'Visible après avoir sélectionné le mode de paiement'; +$_MODULE['<{mollie}prestashop>mollie_ea9b19c6f2e9ef60b49778ab9396b293'] = 'Afficher sur une feuille séparée'; +$_MODULE['<{mollie}prestashop>mollie_d35acbb07d2841712a937d5748e9bdc2'] = 'Affichage sur l\'écran de paiement Mollie'; $_MODULE['<{mollie}prestashop>mollie_f80a4ad87fee7c9fdc19b7769495fdb5'] = 'Rien'; $_MODULE['<{mollie}prestashop>mollie_5ef0c737746fae2ca90e66c39333f8f6'] = 'Erreurs'; $_MODULE['<{mollie}prestashop>mollie_709468af25e91284821d1bdbfdded24c'] = 'Tout'; diff --git a/mollie/translations/nl.php b/mollie/translations/nl.php index 532fbcda5..1e16bd91c 100644 --- a/mollie/translations/nl.php +++ b/mollie/translations/nl.php @@ -42,10 +42,10 @@ $_MODULE['<{mollie}prestashop>mollie_d861877da56b8b4ceb35c8cbfdf65bb4'] = 'groot'; $_MODULE['<{mollie}prestashop>mollie_fea087517c26fadd409bd4b9dc642555'] = 'normaal'; $_MODULE['<{mollie}prestashop>mollie_a88f05b6c963e145a45b58c47cd42a41'] = 'geen'; -$_MODULE['<{mollie}prestashop>mollie_1b73bbc1a4953a0cb5c4c1739d368b0a'] = 'altijd-zichtbaar'; -$_MODULE['<{mollie}prestashop>mollie_b7b10ab45bb159cbf707d3cf9a119b81'] = 'na-kik'; -$_MODULE['<{mollie}prestashop>mollie_c0fb21c0519492004d1fad2f0f3f4426'] = 'eigen-pagina'; -$_MODULE['<{mollie}prestashop>mollie_a1ec2845502d15bc956b2d3706035ffc'] = 'betaal-pagina'; +$_MODULE['<{mollie}prestashop>mollie_199451198078814ce456d33991f5282c'] = 'Altijd zichtbaar'; +$_MODULE['<{mollie}prestashop>mollie_85a692706bc7597b6e32bc1d354c138f'] = 'Zichtbaar na klikken betaalmethode'; +$_MODULE['<{mollie}prestashop>mollie_ea9b19c6f2e9ef60b49778ab9396b293'] = 'Tonen op aparte pagina'; +$_MODULE['<{mollie}prestashop>mollie_d35acbb07d2841712a937d5748e9bdc2'] = 'Tonen op Mollie betaalpagina'; $_MODULE['<{mollie}prestashop>mollie_f80a4ad87fee7c9fdc19b7769495fdb5'] = 'Geen'; $_MODULE['<{mollie}prestashop>mollie_5ef0c737746fae2ca90e66c39333f8f6'] = 'Fouten'; $_MODULE['<{mollie}prestashop>mollie_709468af25e91284821d1bdbfdded24c'] = 'Alles'; diff --git a/mollie/views/templates/hook/mollie_config.tpl b/mollie/views/templates/hook/mollie_config.tpl index db08dbc7e..a4edc4cd5 100644 --- a/mollie/views/templates/hook/mollie_config.tpl +++ b/mollie/views/templates/hook/mollie_config.tpl @@ -121,8 +121,8 @@
@@ -134,8 +134,8 @@
@@ -199,8 +199,8 @@
diff --git a/mollie/views/templates/hook/mollie_methods.tpl b/mollie/views/templates/hook/mollie_methods.tpl index 7cebf4400..087e5ed1c 100644 --- a/mollie/views/templates/hook/mollie_methods.tpl +++ b/mollie/views/templates/hook/mollie_methods.tpl @@ -57,16 +57,14 @@
{if isset($issuers[$method->id]) && count($issuers[$method->id])} - + - {*if $issuer_setting === 'on-click'*} - - {*/if*} + {/if}

diff --git a/release.sh b/release.sh index 0f94f6dd1..809f5407f 100755 --- a/release.sh +++ b/release.sh @@ -1,2 +1,2 @@ #!/bin/sh -zip -9 -r release.zip mollie README.mdown -x mollie/*.git* mollie/*.DS_Store \ No newline at end of file +zip -9 -r mollie-prestashop-x.x.x.zip mollie README.mdown -x mollie/*.git* mollie/*.DS_Store \ No newline at end of file diff --git a/tests/unittests/controllers/paymentTest.php b/tests/unittests/controllers/paymentTest.php index 19c33a662..120c2cdc4 100644 --- a/tests/unittests/controllers/paymentTest.php +++ b/tests/unittests/controllers/paymentTest.php @@ -35,12 +35,12 @@ public function setUp() public function testShowModuleList() { - // test if the module list is shown when applicable (config.MOLLIE_ISSUERS == own-page) + // test if the module list is shown when applicable (config.MOLLIE_ISSUERS == Mollie::ISSUERS_OWN_PAGE) // make module list apply $this->mollie->expects($this->atLeastOnce()) ->method('getConfigValue') - ->will($this->returnValue('own-page')); + ->will($this->returnValue(Mollie::ISSUERS_OWN_PAGE)); // needs a method $_GET['method'] = 'ideal'; @@ -66,7 +66,7 @@ public function testSuccessRedirect() // make module list not apply $this->mollie->expects($this->atLeastOnce()) ->method('getConfigValue') - ->will($this->returnValue('payment-page')); + ->will($this->returnValue(Mollie::ISSUERS_PAYMENT_PAGE)); // needs a method $_GET['method'] = 'ideal'; diff --git a/tests/unittests/mollieTest.php b/tests/unittests/mollieTest.php index 2c7124a4e..d0504cdaa 100644 --- a/tests/unittests/mollieTest.php +++ b/tests/unittests/mollieTest.php @@ -65,8 +65,8 @@ public function testSaveConfig() 'Mollie_Config_Save' => TRUE, 'Mollie_Api_Key' => 'test_something', 'Mollie_Description' => 'Order %', - 'Mollie_Images' => 'normal', - 'Mollie_Issuers' => 'on-click', + 'Mollie_Images' => Mollie::LOGOS_NORMAL, + 'Mollie_Issuers' => Mollie::ISSUERS_ON_CLICK, 'Mollie_Logger' => 1, 'Mollie_Errors' => FALSE, 'Mollie_Status_open' => 3,