name = 'santandercredit'; $this->tab = 'payments_gateways'; $this->version = '1.9.24'; //remember to change MODULE_NUMBER_PREFIX $this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_); $this->author = 'Santander Consumer Bank'; $this->bootstrap = true; parent::__construct(); $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('Santander - System ratalny'); $this->description = $this->l('Santander - Zakupy na raty w internecie'); if (array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] == "on") { $this->ssl = true; } } /** * Odczyt z ostatniego rekordu tabeli scb_espl_phist lub 0 */ public static function getEhpDbVersion() { $dbVer = 0; $tableExists = 0; $apos = '\''; $pfx = Db::getInstance()->getPrefix(); $queryTableExists = 'SHOW TABLES LIKE ' . $apos . $pfx . 'scb_espl_phist' . $apos; Db::getInstance()->execute($queryTableExists); $tableExists = Db::getInstance()->numRows(); if ($tableExists > 0) { $queryMax = ' (SELECT MAX(id) from ' . _DB_PREFIX_ . 'scb_ehp_phist' . ') '; $queryDbVer = 'SELECT db_ver FROM ' . _DB_PREFIX_ . 'scb_ehp_phist where id = ' . $queryMax; $dbVer = Db::getInstance()->getValue($queryDbVer); } return $dbVer; } public function install() { // $dbVer = $this->getEhpDbVersion(); include_once 'sql/installDB.php'; //nowe statusy foreach (EHP_APP_STATES as $key => $value) { if (!$this->createOrderState($key, $value, $this->getStatusColor($key))) { return false; } } return parent::install() && $this->createOrUpdateParam('SANTANDERCREDIT_SHOP_ID', $this->shopTestId) && $this->createOrUpdateParam('SANTANDERCREDIT_BLOCK', 'left') && $this->createOrUpdateParam('SANTANDERCREDIT_BLOCK_TITLE', 'eRaty Santander Consumer Bank') && $this->createOrUpdateParam('SANTANDERCREDIT_SYMULATOR', 'true') && $this->createOrUpdateParam('SANTANDERCREDIT_URL_SYMULATOR', 'https://wniosek.eraty.pl/symulator/oblicz/') && $this->createOrUpdateParam('SANTANDERCREDIT_URL_WNIOSEK', 'https://wniosek.eraty.pl/formularz/') && $this->createOrUpdateParam('SANTANDERCREDIT_QTY_SELECTOR', '#quantity_wanted') && $this->createOrUpdateParam('SANTANDERCREDIT_PRICE_SELECTOR', 'div.current-price > span[itemprop="price"],div.current-price > span.current-price-value') && $this->createOrUpdateParam('SANTANDERCREDIT_SECUREPOST', 'true') && $this->createOrUpdateParam('SANTANDERCREDIT_QTY_QUERY', "$('#quantity_wanted').val();") && $this->createOrUpdateParam('SANTANDERCREDIT_PRICE_QUERY', "$('div.current-price > span[itemprop=\"price\"],div.current-price > span.current-price-value').attr(\"content\");") && $this->createOrUpdateParam('SANTANDERCREDIT_SIM_DATA_FORM', null) && $this->createOrUpdateParam('SANTANDERCREDIT_USE_ORDER_STATE', 'SCB_EHP_ST_PAYMENT_DECLARED') && $this->createOrUpdateParam('SANTANDERCREDIT_PSH_LOGIN', '') && $this->createOrUpdateParam('SANTANDERCREDIT_PSH_PASS', '') && $this->createOrUpdateParam('SANTANDERCREDIT_SVC_LOCATION', 'https://api.santanderconsumer.pl/ProposalServiceHybrid') && $this->createOrUpdateParam('SANTANDERCREDIT_CRT_FILE', 'newfile.crt.pem') && $this->registerHook('paymentOptions') && // $this->registerHook('displayPaymentReturn') && $this->registerHook('displayOrderConfirmation') && $this->registerHook('displayProductAdditionalInfo') && $this->registerHook('displayHeader') && $this->registerHook('displayBackOfficeHeader') && $this->registerHook('displayAdminOrder') && $this->registerHook('displayOrderDetail') && $this->registerHook('actionGetAdminOrderButtons'); } function createOrUpdateParam($pName, $pValue) { $result = true; if (empty(Configuration::get($pName))) { $result = Configuration::updateValue($pName, $pValue); } return $result; } public function uninstall() { include(dirname(__FILE__) . '/sql/uninstall.php'); return parent::uninstall(); } private function scbQueryDecode($query) { // $query = base64_decode($query); $query = str_replace('_nawiasL_', '(', $query); $query = str_replace('_nawiasP_', ')', $query); return $query; } public function getContent() { $output = null; if (Tools::isSubmit('submit' . $this->name)) { $scbShopID = strval(Tools::getValue('SANTANDERCREDIT_SHOP_ID')); if (!$scbShopID || empty($scbShopID) || !Validate::isGenericName($scbShopID)) $output .= $this->displayError($this->l('Nieprawidłowy numer Sklepu')); else { Configuration::updateValue('SANTANDERCREDIT_SHOP_ID', '1234'); Configuration::updateValue('SANTANDERCREDIT_SHOP_ID', trim(Tools::getValue('SANTANDERCREDIT_SHOP_ID'))); Configuration::updateValue('SANTANDERCREDIT_SYMULATOR', strval(Tools::getValue('SANTANDERCREDIT_SYMULATOR'))); Configuration::updateValue('SANTANDERCREDIT_SECUREPOST', strval(Tools::getValue('SANTANDERCREDIT_SECUREPOST'))); Configuration::updateValue('SANTANDERCREDIT_URL_SYMULATOR', Tools::getValue('SANTANDERCREDIT_URL_SYMULATOR')); Configuration::updateValue('SANTANDERCREDIT_URL_WNIOSEK', Tools::getValue('SANTANDERCREDIT_URL_WNIOSEK')); // Configuration::updateValue('SANTANDERCREDIT_QTY_QUERY', Tools::getValue('SANTANDERCREDIT_QTY_QUERY')); Configuration::updateValue('SANTANDERCREDIT_QTY_QUERY', $this->scbQueryDecode(Tools::getValue('SANTANDERCREDIT_QTY_QUERY'))); // Configuration::updateValue('SANTANDERCREDIT_PRICE_QUERY', Tools::getValue('SANTANDERCREDIT_PRICE_QUERY')); Configuration::updateValue('SANTANDERCREDIT_PRICE_QUERY', $this->scbQueryDecode(Tools::getValue('SANTANDERCREDIT_PRICE_QUERY'))); Configuration::updateValue('SANTANDERCREDIT_SIM_DATA_FORM', strval(Tools::getValue('SANTANDERCREDIT_SIM_DATA_FORM'))); Configuration::updateValue('SANTANDERCREDIT_PSH_LOGIN', Tools::getValue('SANTANDERCREDIT_PSH_LOGIN')); Configuration::updateValue('SANTANDERCREDIT_PSH_PASS', Tools::getValue('SANTANDERCREDIT_PSH_PASS')); Configuration::updateValue('SANTANDERCREDIT_SVC_LOCATION', Tools::getValue('SANTANDERCREDIT_SVC_LOCATION')); Configuration::updateValue('SANTANDERCREDIT_CRT_FILE', Tools::getValue('SANTANDERCREDIT_CRT_FILE')); $output .= $this->displayConfirmation($this->l('Zmiany zostały zapisane')); } } // $this->context->smarty->assign(array_merge($definedurls, $otherValues, $apiValues)); // $output = $this->context->smarty->fetch($this->local_path . 'views/templates/admin/configure.tpl'); $proto = 'http://'; if ($this->ssl) { $proto = 'https://'; } $defaultUrls = EHP_DEF_URLS; $defaultQueries = EHP_DEF_QUERIES; $ehpCurrentValues = [ 'EHP_CURRENT_URL_SYMULATOR' => Configuration::get('SANTANDERCREDIT_URL_SYMULATOR'), 'EHP_CURRENT_URL_WNIOSEK' => Configuration::get('SANTANDERCREDIT_URL_WNIOSEK'), 'EHP_CURRENT_SVC_LOCATION' => Configuration::get('SANTANDERCREDIT_SVC_LOCATION'), 'EHP_CURRENT_QTY_QUERY' => str_replace('<', '<', str_replace('>', '>', str_replace('"', '"', str_replace("'", "'", Configuration::get('SANTANDERCREDIT_QTY_QUERY'))))), 'EHP_CURRENT_PRICE_QUERY' => str_replace('<', '<', str_replace('>', '>', str_replace('"', '"', str_replace("'", "'", Configuration::get('SANTANDERCREDIT_PRICE_QUERY'))))) ]; $otherCfgVars = [ 'OrderMapCmd' => $proto . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/' . $this->name . '/sql/repair_oa_mapping.php' , 'scbEhpDocUrl' => $proto . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/' . $this->name . '/doc/scb_ehp_payment_UserDoc.pdf' , 'scbEhpSlsDocUrl' => $proto . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/' . $this->name . '/doc/scb_ehp_payment_SalesmanDoc.pdf' , 'scbEhpAdmDocUrl' => $proto . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/' . $this->name . '/doc/scb_ehp_payment_AdminDoc.pdf' , 'pshIsActiveCommand' => $proto . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/' . $this->name . '/services/ProposalService/custom/IsActiveRequest.php' , 'pshLoginChckCommand' => $proto . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/' . $this->name . '/services/ProposalService/custom/FreeAppStateRequest.php' ]; $qFunctions = [ 'quantityFn' => $this->quantityFnJs(), 'priceFn' => $this->priceFnJs() ]; $this->context->smarty->assign(array_merge($otherCfgVars, $defaultUrls, $defaultQueries, $ehpCurrentValues, $qFunctions)); // $output = $output . $this->display(__FILE__, 'infos.tpl'); $output = $output . $this->context->smarty->fetch($this->local_path . 'views/templates/hook/infos.tpl'); $output = $output . $this->displayForm() . $this->context->smarty->fetch($this->local_path . 'views/templates/hook/infos2.tpl'); return $output; } public function displayForm() { $proto = 'http://'; if ($this->ssl) { $proto = 'https://'; } $crtFile = Configuration::get('SANTANDERCREDIT_CRT_FILE');; // Get default language $default_lang = (int) Configuration::get('PS_LANG_DEFAULT'); $defaultUrls = array( array( 'id_option' => 1, // The value of the 'value' attribute of the