public function getContent()
 {
     $errors = array();
     $success = false;
     $payment_methods = null;
     $payment_methods_settings = null;
     $offline_payment_settings = null;
     $offline_methods_payments = null;
     if (Tools::getValue('login')) {
         $client_id = Tools::getValue('MERCADOPAGO_CLIENT_ID');
         $client_secret = Tools::getValue('MERCADOPAGO_CLIENT_SECRET');
         if (!$this->validateCredential($client_id, $client_secret)) {
             $errors[] = $this->l('Client Id or Client Secret invalid.');
             $success = false;
         } else {
             $this->setDefaultValues($client_id, $client_secret);
             // populate all payments accoring to country
             $mp = new MP($client_id, $client_secret);
             $payment_methods = $mp->getPaymentMethods();
             // load all offline payment method settings
             $offline_methods_payments = $mp->getOfflinePaymentMethods();
             $offline_payment_settings = array();
             foreach ($offline_methods_payments as $offline_payment) {
                 $op_banner_variable = 'MERCADOPAGO_' . strtoupper($offline_payment['id'] . '_BANNER');
                 $op_active_variable = 'MERCADOPAGO_' . strtoupper($offline_payment['id'] . '_ACTIVE');
                 $offline_payment_settings[$offline_payment['id']] = array('name' => $offline_payment['name'], 'banner' => Configuration::get($op_banner_variable), 'active' => Configuration::get($op_active_variable));
             }
         }
     } else {
         if (Tools::getValue('submitmercadopago')) {
             $client_id = Tools::getValue('MERCADOPAGO_CLIENT_ID');
             $client_secret = Tools::getValue('MERCADOPAGO_CLIENT_SECRET');
             $public_key = Tools::getValue('MERCADOPAGO_PUBLIC_KEY');
             $creditcard_active = Tools::getValue('MERCADOPAGO_CREDITCARD_ACTIVE');
             $boleto_active = Tools::getValue('MERCADOPAGO_BOLETO_ACTIVE');
             $standard_active = Tools::getValue('MERCADOPAGO_STANDARD_ACTIVE');
             $new_country = false;
             if (!$this->validateCredential($client_id, $client_secret)) {
                 $errors[] = $this->l('Client Id or Client Secret invalid.');
                 $success = false;
             } else {
                 $previous_country = $this->getCountry(Configuration::get('MERCADOPAGO_CLIENT_ID'), Configuration::get('MERCADOPAGO_CLIENT_SECRET'));
                 $current_country = $this->getCountry($client_id, $client_secret);
                 $new_country = $previous_country == $current_country ? false : true;
                 Configuration::updateValue('MERCADOPAGO_CLIENT_ID', $client_id);
                 Configuration::updateValue('MERCADOPAGO_CLIENT_SECRET', $client_secret);
                 Configuration::updateValue('MERCADOPAGO_COUNTRY', $this->getCountry($client_id, $client_secret));
                 $success = true;
                 if ($creditcard_active == 'true' && !empty($public_key)) {
                     Configuration::updateValue('MERCADOPAGO_PUBLIC_KEY', $public_key);
                 }
                 // populate all payments accoring to country
                 $this->mercadopago = new MP(Configuration::get('MERCADOPAGO_CLIENT_ID'), Configuration::get('MERCADOPAGO_CLIENT_SECRET'));
                 $payment_methods = $this->mercadopago->getPaymentMethods();
             }
             $category = Tools::getValue('MERCADOPAGO_CATEGORY');
             Configuration::updateValue('MERCADOPAGO_CATEGORY', $category);
             $creditcard_banner = Tools::getValue('MERCADOPAGO_CREDITCARD_BANNER');
             Configuration::updateValue('MERCADOPAGO_CREDITCARD_BANNER', $creditcard_banner);
             Configuration::updateValue('MERCADOPAGO_STANDARD_ACTIVE', $standard_active);
             Configuration::updateValue('MERCADOPAGO_BOLETO_ACTIVE', $boleto_active);
             Configuration::updateValue('MERCADOPAGO_CREDITCARD_ACTIVE', $creditcard_active);
             $standard_banner = Tools::getValue('MERCADOPAGO_STANDARD_BANNER');
             Configuration::updateValue('MERCADOPAGO_STANDARD_BANNER', $standard_banner);
             $window_type = Tools::getValue('MERCADOPAGO_WINDOW_TYPE');
             Configuration::updateValue('MERCADOPAGO_WINDOW_TYPE', $window_type);
             $iframe_width = Tools::getValue('MERCADOPAGO_IFRAME_WIDTH');
             Configuration::updateValue('MERCADOPAGO_IFRAME_WIDTH', $iframe_width);
             $iframe_height = Tools::getValue('MERCADOPAGO_IFRAME_HEIGHT');
             Configuration::updateValue('MERCADOPAGO_IFRAME_HEIGHT', $iframe_height);
             $installments = Tools::getValue('MERCADOPAGO_INSTALLMENTS');
             Configuration::updateValue('MERCADOPAGO_INSTALLMENTS', $installments);
             $auto_return = Tools::getValue('MERCADOPAGO_AUTO_RETURN');
             Configuration::updateValue('MERCADOPAGO_AUTO_RETURN', $auto_return);
             $exclude_all = true;
             foreach ($payment_methods as $payment_method) {
                 $pm_variable_name = 'MERCADOPAGO_' . strtoupper($payment_method['id']);
                 $value = Tools::getValue($pm_variable_name);
                 if ($value != 'on') {
                     $exclude_all = false;
                 }
                 // current settings
                 $payment_methods_settings[$payment_method['id']] = Configuration::get($pm_variable_name);
             }
             if (!$exclude_all) {
                 $payment_methods_settings = array();
                 foreach ($payment_methods as $payment_method) {
                     $pm_variable_name = 'MERCADOPAGO_' . strtoupper($payment_method['id']);
                     $value = Tools::getValue($pm_variable_name);
                     //save setting per payment_method
                     Configuration::updateValue($pm_variable_name, $value);
                     $payment_methods_settings[$payment_method['id']] = Configuration::get($pm_variable_name);
                 }
             } else {
                 $errors[] = $this->l('Cannnot exclude all payment methods.');
                 $success = false;
             }
             // if it is new country, reset values
             if ($new_country) {
                 $this->setCustomSettings($client_id, $client_secret, $this->getCountry($client_id, $client_secret));
                 $offline_methods_payments = $this->mercadopago->getOfflinePaymentMethods();
                 $offline_payment_settings = array();
                 foreach ($offline_methods_payments as $offline_payment) {
                     $op_banner_variable = 'MERCADOPAGO_' . strtoupper($offline_payment['id'] . '_BANNER');
                     $op_active_variable = 'MERCADOPAGO_' . strtoupper($offline_payment['id'] . '_ACTIVE');
                     $op_banner = Configuration::get($op_banner_variable);
                     $op_active = Configuration::get($op_banner_variable);
                     $offline_payment_settings[$offline_payment['id']] = array('name' => $offline_payment['name'], 'banner' => Configuration::get($op_banner_variable), 'active' => Configuration::get($op_active_variable));
                 }
             } else {
                 // save offline payment settings
                 $offline_methods_payments = $this->mercadopago->getOfflinePaymentMethods();
                 $offline_payment_settings = array();
                 foreach ($offline_methods_payments as $offline_payment) {
                     $op_banner_variable = 'MERCADOPAGO_' . strtoupper($offline_payment['id'] . '_BANNER');
                     $op_active_variable = 'MERCADOPAGO_' . strtoupper($offline_payment['id'] . '_ACTIVE');
                     $op_banner = Tools::getValue($op_banner_variable);
                     //save setting per payment_method
                     Configuration::updateValue($op_banner_variable, $op_banner);
                     $op_active = Tools::getValue($op_active_variable);
                     //save setting per payment_method
                     Configuration::updateValue($op_active_variable, $op_active);
                     $offline_payment_settings[$offline_payment['id']] = array('name' => $offline_payment['name'], 'banner' => Configuration::get($op_banner_variable), 'active' => Configuration::get($op_active_variable));
                 }
             }
         } else {
             // populate all payments according to country
             if (Configuration::get('MERCADOPAGO_CLIENT_ID') != '' && Configuration::get('MERCADOPAGO_CLIENT_SECRET') != '') {
                 $this->mercadopago = new MP(Configuration::get('MERCADOPAGO_CLIENT_ID'), Configuration::get('MERCADOPAGO_CLIENT_SECRET'));
                 // load payment method settings for standard
                 $payment_methods = $this->mercadopago->getPaymentMethods();
                 $payment_methods_settings = array();
                 foreach ($payment_methods as $payment_method) {
                     $pm_variable_name = 'MERCADOPAGO_' . strtoupper($payment_method['id']);
                     $value = Configuration::get($pm_variable_name);
                     $payment_methods_settings[$payment_method['id']] = Configuration::get($pm_variable_name);
                 }
                 // load all offline payment method settings
                 $offline_methods_payments = $this->mercadopago->getOfflinePaymentMethods();
                 $offline_payment_settings = array();
                 foreach ($offline_methods_payments as $offline_payment) {
                     $op_banner_variable = 'MERCADOPAGO_' . strtoupper($offline_payment['id'] . '_BANNER');
                     $op_active_variable = 'MERCADOPAGO_' . strtoupper($offline_payment['id'] . '_ACTIVE');
                     $offline_payment_settings[$offline_payment['id']] = array('name' => $offline_payment['name'], 'banner' => Configuration::get($op_banner_variable), 'active' => Configuration::get($op_active_variable));
                 }
             }
         }
     }
     $this->context->controller->addCss($this->_path . 'views/css/settings.css', 'all');
     $this->context->controller->addCss($this->_path . 'views/css/bootstrap.css', 'all');
     $this->context->controller->addCss($this->_path . 'views/css/style.css', 'all');
     $settings = array('public_key' => htmlentities(Configuration::get('MERCADOPAGO_PUBLIC_KEY'), ENT_COMPAT, 'UTF-8'), 'client_id' => htmlentities(Configuration::get('MERCADOPAGO_CLIENT_ID'), ENT_COMPAT, 'UTF-8'), 'client_secret' => htmlentities(Configuration::get('MERCADOPAGO_CLIENT_SECRET'), ENT_COMPAT, 'UTF-8'), 'country' => htmlentities(Configuration::get('MERCADOPAGO_COUNTRY'), ENT_COMPAT, 'UTF-8'), 'category' => htmlentities(Configuration::get('MERCADOPAGO_CATEGORY'), ENT_COMPAT, 'UTF-8'), 'creditcard_banner' => htmlentities(Configuration::get('MERCADOPAGO_CREDITCARD_BANNER'), ENT_COMPAT, 'UTF-8'), 'creditcard_active' => htmlentities(Configuration::get('MERCADOPAGO_CREDITCARD_ACTIVE'), ENT_COMPAT, 'UTF-8'), 'boleto_active' => htmlentities(Configuration::get('MERCADOPAGO_BOLETO_ACTIVE'), ENT_COMPAT, 'UTF-8'), 'standard_active' => htmlentities(Configuration::get('MERCADOPAGO_STANDARD_ACTIVE'), ENT_COMPAT, 'UTF-8'), 'standard_banner' => htmlentities(Configuration::get('MERCADOPAGO_STANDARD_BANNER'), ENT_COMPAT, 'UTF-8'), 'window_type' => htmlentities(Configuration::get('MERCADOPAGO_WINDOW_TYPE'), ENT_COMPAT, 'UTF-8'), 'iframe_width' => htmlentities(Configuration::get('MERCADOPAGO_IFRAME_WIDTH'), ENT_COMPAT, 'UTF-8'), 'iframe_height' => htmlentities(Configuration::get('MERCADOPAGO_IFRAME_HEIGHT'), ENT_COMPAT, 'UTF-8'), 'installments' => htmlentities(Configuration::get('MERCADOPAGO_INSTALLMENTS'), ENT_COMPAT, 'UTF-8'), 'auto_return' => htmlentities(Configuration::get('MERCADOPAGO_AUTO_RETURN'), ENT_COMPAT, 'UTF-8'), 'uri' => $_SERVER['REQUEST_URI'], 'payment_methods' => $payment_methods ? $payment_methods : null, 'payment_methods_settings' => $payment_methods_settings ? $payment_methods_settings : null, 'offline_methods_payments' => $offline_methods_payments ? $offline_methods_payments : null, 'offline_payment_settings' => $offline_payment_settings ? $offline_payment_settings : null, 'errors' => $errors, 'success' => $success, 'this_path_ssl' => (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__, 'version' => $this->getPrestashopVersion());
     $this->context->smarty->assign($settings);
     return $this->display(__FILE__, '/views/templates/admin/settings.tpl');
 }