Ejemplo n.º 1
0
function upgrade_module_0_9_7($module)
{
    // Add test status && add hook
    Configuration::deleteByName('PAYPLUG_ORDER_STATE_REFUND');
    Payplug::updateConfiguration('PAYPLUG_SANDBOX', '0');
    $install = new InstallPayplug();
    $install->createOrderState();
    $module->registerHook('header');
    $install->installPayplugLock();
    return true;
    // Return true if success.
}
Ejemplo n.º 2
0
 public function getContent()
 {
     // if ps version is not available
     if (version_compare(_PS_VERSION_, '1.4', '<')) {
         return;
     }
     // Link base
     if (version_compare(_PS_VERSION_, '1.5', '>')) {
         $this->_link = 'index.php?controller=' . Tools::getValue('controller');
     } else {
         $this->_link = 'index.php?tab=' . Tools::getValue('tab');
     }
     $this->_link .= '&configure=' . $this->name . '&token=' . Tools::getValue('token') . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
     $display_form = true;
     // Check extensions
     $curl_exists = extension_loaded('curl');
     $openssl_exists = extension_loaded('openssl');
     $errors = array();
     // Add msg if extension not exists
     if (!$curl_exists || !$openssl_exists) {
         // cURL not found
         if (!$curl_exists) {
             $errors[] = sprintf($this->l('Connection error: %s library is missing. Please ask your hosting provider to install the %s library on your server, and try configuring the PayPlug module on Prestashop again.'), 'cURL', 'cURL');
         }
         // OpenSSL not found
         if (!$openssl_exists) {
             $errors[] = sprintf($this->l('Connection error: %s library is missing. Please ask your hosting provider to install the %s library on your server, and try configuring the PayPlug module on Prestashop again.'), 'OpenSSL', 'OpenSSL');
         }
     }
     // Check if form was sent
     if (Tools::getValue('payplug_email') && Tools::getValue('payplug_password')) {
         $this->assignForVersion('email', Tools::getValue('payplug_email'));
         // if extensions exist
         if ($curl_exists && $openssl_exists) {
             $sandbox_button = Tools::isSubmit('sandboxButton');
             // Get url to curl
             $url = $sandbox_button ? Payplug::URL_TEST_AUTOCONFIG : Payplug::URL_AUTOCONFIG;
             $curl_version = curl_version();
             $process = curl_init($url);
             curl_setopt($process, CURLOPT_USERPWD, Tools::getValue('payplug_email') . ':' . Tools::getValue('payplug_password'));
             curl_setopt($process, CURLOPT_RETURNTRANSFER, true);
             // CURL const are in uppercase
             curl_setopt($process, CURLOPT_SSL_VERIFYPEER, true);
             # >= 7.26 to 7.28.1 add a notice message for value 1 will be remove
             curl_setopt($process, CURLOPT_SSL_VERIFYHOST, version_compare($curl_version['version'], '7.21', '<') ? true : 2);
             curl_setopt($process, CURLOPT_CAINFO, realpath(dirname(__FILE__) . '/cacert.pem'));
             //work only wiht cURL 7.10+
             $answer = curl_exec($process);
             $error_curl = curl_errno($process);
             curl_close($process);
             // if no error
             if ($error_curl == 0) {
                 $json_answer = Tools::jsonDecode($answer);
                 // if account is just in test mod
                 if ($json_answer->status == 403) {
                     $errors[] = sprintf($this->l('To set up the module in LIVE mode, you first need %s to request your account to be activated %s.'), '<a href="http://support.payplug.fr/customer/portal/articles/1438899-comment-activer-mon-compte-">', '</a>');
                 } else {
                     if ($json_answer->status == 200) {
                         $payplug_install = new InstallPayplug();
                         if (!is_array($json_answer->currencies)) {
                             $currencies = implode(Tools::jsonDecode($json_answer->currencies), ';');
                         } else {
                             $currencies = $json_answer->currencies[0];
                         }
                         $private_key = $json_answer->yourPrivateKey;
                         $public_key = $json_answer->payplugPublicKey;
                         // explode for validator
                         $payplug_install->updateConfig($private_key, $public_key, $json_answer->url, $json_answer->amount_min, $json_answer->amount_max, $currencies, (string) (int) $sandbox_button);
                         $display_form = false;
                         // redirect for update message
                         Tools::redirectAdmin($this->_link . '&conf=4');
                     } else {
                         $errors[] = $this->l('Your email or password is incorrect.');
                     }
                 }
             } else {
                 $errors[] = $error_curl;
             }
         }
     } else {
         if (Tools::getIsset('debug_mode')) {
             self::updateConfiguration('PAYPLUG_DEBUG', !self::getConfiguration('PAYPLUG_DEBUG'));
             Tools::redirectAdmin($this->_link . '&conf=4');
         }
     }
     if (Configuration::get('PAYPLUG_MODULE_KEY') != '' && Configuration::get('PAYPLUG_MODULE_PUBLIC_KEY') != '' && Configuration::get('PAYPLUG_MODULE_URL') != '' && Configuration::get('PAYPLUG_MODULE_MIN_AMOUNT') != '' && Configuration::get('PAYPLUG_MODULE_MAX_AMOUNT') != '' && Configuration::get('PAYPLUG_MODULE_CURRENCIES') != '') {
         $this->assignForVersion(array('moduleInstalled' => true, 'minAmount' => Configuration::get('PAYPLUG_MODULE_MIN_AMOUNT'), 'maxAmount' => Configuration::get('PAYPLUG_MODULE_MAX_AMOUNT'), 'currencies' => Configuration::get('PAYPLUG_MODULE_CURRENCIES'), 'sandboxMode' => Payplug::getConfiguration('PAYPLUG_SANDBOX'), 'debugMode' => Payplug::getConfiguration('PAYPLUG_DEBUG')));
     }
     // Assign datas
     $datas = array('this_path' => $this->_path, 'displayForm' => $display_form, 'errors' => $errors, 'this_link' => $this->_link);
     $this->assignForVersion($datas);
     return $this->display(__FILE__, './views/templates/admin/admin.tpl');
 }