Skip to content

Commit

Permalink
Fix issue when iDEAL bank list is not displayed.
Browse files Browse the repository at this point in the history
  • Loading branch information
lvgunst committed Jun 10, 2014
1 parent 6cf599a commit 4908e1e
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 93 deletions.
10 changes: 5 additions & 5 deletions mollie/controllers/front/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion mollie/controllers/front/return.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions mollie/controllers/front/webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
121 changes: 63 additions & 58 deletions mollie/mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -173,7 +186,7 @@ public function install()
return FALSE;
}
if (
!$this->_initConfig()
!$this->_initConfig()
)
{
$this->_errors[] = 'Unable to set config values';
Expand Down Expand Up @@ -257,7 +270,7 @@ public function reinstall()
$this->_unregisterHooks() &&
$this->_registerHooks() &&
$this->_initConfig()
;
;
}


Expand All @@ -271,7 +284,7 @@ protected function _registerHooks()
$this->registerHook('displayAdminOrder') &&
$this->registerHook('displayHeader') &&
$this->registerHook('displayBackOfficeHeader')
;
;
}

/**
Expand All @@ -284,7 +297,7 @@ protected function _unregisterHooks()
$this->unregisterHook('displayAdminOrder') &&
$this->unregisterHook('displayHeader') &&
$this->unregisterHook('displayBackOfficeHeader')
;
;
}

/**
Expand All @@ -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) &&
Expand All @@ -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)
;
;
}

/**
Expand All @@ -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(
Expand Down Expand Up @@ -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]);
Expand All @@ -407,8 +434,6 @@ public function getContent()
return $this->display(__FILE__, 'mollie_config.tpl');
}



/**
* @param $field
* @param $default_value
Expand Down Expand Up @@ -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']))
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -772,44 +778,43 @@ public function hookDisplayPayment()
if (!Currency::exists('EUR', 0))
{
return '<p class="payment_module" style="color:red;">' .
$this->l('Mollie Payment Methods are only available when Euros are activated.') .
'</p>';
$this->l('Mollie Payment Methods are only available when Euros are activated.') .
'</p>';
}

$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);
}
if ($this->getConfigValue('MOLLIE_DISPLAY_ERRORS'))
{
return
'<p class="payment_module" style="color:red;">' .
$e->getMessage() .
$e->getMessage() .
'</p>'
;
;
}
}

$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');
}
Expand Down
8 changes: 4 additions & 4 deletions mollie/translations/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions mollie/translations/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading

0 comments on commit 4908e1e

Please sign in to comment.