Esempio n. 1
0
                        if (version_compare(_PS_VERSION_, '1.5', '>') && version_compare(_PS_VERSION_, '1.5.2', '<')) {
                            $order_id = Order::getOrderByCartId($cart->id);
                            $order = new Order($order_id);
                            $order_payment = end($order->getOrderPayments());
                            $order_payment->transaction_id = $extra_vars['transaction_id'];
                            $order_payment->update();
                        }
                    }
                    PayplugLock::deleteLock($cart->id);
                }
                Configuration::updateValue('PAYPLUG_CONFIGURATION_OK', true);
            } else {
                echo 'Error : missing or wrong parameters.';
                header($_SERVER['SERVER_PROTOCOL'] . ' 400 Missing or wrong parameters for address', true, 400);
                die;
            }
        } else {
            echo 'Error : missing or wrong parameters.';
            header($_SERVER['SERVER_PROTOCOL'] . ' 400 Missing or wrong parameters for cart', true, 400);
            die;
        }
    } else {
        echo 'Error : missing or wrong parameters.';
        header($_SERVER['SERVER_PROTOCOL'] . ' 400 Missing or wrong parameters', true, 400);
        die;
    }
}
/** Restore display errors configuration */
if (Payplug::getConfiguration('PAYPLUG_DEBUG')) {
    @ini_set('display_errors', $display_errors);
}
Esempio 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');
 }
Esempio n. 3
0
 /**
  * Create order
  * @param  string  $key  OS Key
  * @param  boolean $test if os test
  */
 private function createOrderStateSpecifc($key, $test = false)
 {
     // Logo source
     $source = dirname(__FILE__) . '/logo.gif';
     // If is an OS test
     if ($test == true) {
         $key .= '_test';
     }
     // Configuration key
     $key_config = 'PAYPLUG_ORDER_STATE_' . Tools::strtoupper($key);
     // If configuration not exists
     if (!($os = Payplug::getConfiguration($key_config))) {
         // New state
         $order_state = new OrderState();
         // Init state
         $this->initOrderState($order_state, Tools::strtolower($key));
         // Add state
         if ($order_state->add()) {
             // Change
             $destination = _PS_IMG_DIR_ . 'os/' . (int) $order_state->id . '.gif';
             copy($source, $destination);
         }
         // Update configuration
         Payplug::updateConfiguration($key_config, (int) $order_state->id);
     } else {
         // Get status
         $order_state = new OrderState($os);
         // Init status
         $this->initOrderState($order_state, Tools::strtolower($key));
         // Update status
         $order_state->update();
     }
 }