/** * Update orderstatuses in the database * * @param int $customer The order status id to show the customer * @param int $admin The order status id to show in the administration page * * @return void */ public function updateOrderDatabase($customer, $admin) { global $insert_id; $orderid = mysqli_real_escape_string(xtc_db_connect(), $insert_id); $refno = mysqli_real_escape_string(xtc_db_connect(), $_SESSION['klarna_refno']); $sql_data_arr = array('orders_id' => $orderid, 'orders_status_id' => $customer, 'comments' => "Accepted by Klarna. Reference #: {$refno}", 'customer_notified' => 1, 'date_added' => date("Y-m-d H:i:s")); xtc_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_arr); $has_ordernum_table = xtc_db_fetch_array(xtc_db_query("SELECT COUNT(*) " . "FROM information_schema.tables " . "WHERE table_schema = '" . DB_DATABASE . "' " . "AND table_name = 'klarna_ordernum';")); $has_ordernum_table = $has_ordernum_table['COUNT(*)']; if ($has_ordernum_table > 0) { xtc_db_query("INSERT INTO `klarna_ordernum` (orders_id, klarna_ref) " . "VALUES ({$orderid}, {$refno})"); } // Set pending status and hide it from customer. $status = $_SESSION['klarna_orderstatus']; if (isset($status)) { $orderStatusQuery = $this->_klarnaDB->query("SELECT orders_status_id FROM " . TABLE_ORDERS_STATUS . " WHERE orders_status_name = '{$status}'"); $orderStatusID = $orderStatusQuery->getArray(); $sql_data_arr = array('orders_id' => $orderid, 'orders_status_id' => $orderStatusID['orders_status_id'], 'comments' => "Klarna Orderstatus: {$status}", 'customer_notified' => 0, 'date_added' => date("Y-m-d H:i:s")); xtc_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_arr); xtc_db_query("UPDATE " . TABLE_ORDERS . " SET orders_status='" . $orderStatusID['orders_status_id'] . "' WHERE orders_id='" . $orderid . "'"); } try { $this->_klarna->setEstoreInfo(KiTT_String::encode($orderid)); $this->_klarna->update($_SESSION['klarna_refno']); } catch (Exception $e) { Klarna::printDebug(__METHOD__, "{$e->getMessage()} #({$e->getCode()})"); } //Delete Session with user details unset($_SESSION['klarna_data']); unset($_SESSION['klarna_refno']); unset($_SESSION['klarna_orderstatus']); }
/** * Installation function * * @return void */ function install() { $this->_klarnaDB->query("INSERT INTO " . TABLE_CONFIGURATION . " (sort_order, configuration_key, configuration_value, " . "configuration_group_id, set_function, " . "date_added) " . "VALUES ('0', 'MODULE_KLARNA_FEE_STATUS', 'true', '6', 'xtc_cfg_select_option(array(\\'true\\', \\'false\\'), ', now())"); $this->_klarnaDB->query("INSERT INTO " . TABLE_CONFIGURATION . " (sort_order, configuration_key, configuration_value, " . "configuration_group_id, set_function, date_added) " . "VALUES ('1', 'MODULE_KLARNA_FEE_MODE', 'fixed', '6', " . "'xtc_cfg_select_option(array(\\'fixed\\', \\'price\\'), ', now())"); foreach (KiTT_CountryLogic::supportedCountries() as $country) { $flag = "<span class=\\'klarna_flag_" . strtolower($country) . "\\'></span>"; $this->_klarnaDB->query("INSERT INTO " . TABLE_CONFIGURATION . " (sort_order, configuration_key, configuration_value, configuration_group_id, date_added) " . "VALUES ('2', 'MODULE_KLARNA_FEE_FIXED_{$country}', '20', '6', now())"); $this->_klarnaDB->query("INSERT INTO " . TABLE_CONFIGURATION . " (sort_order, " . "configuration_key, configuration_value, configuration_group_id, date_added) " . "VALUES ('3', 'MODULE_KLARNA_FEE_TABLE_{$country}', '200:20,500:10,10000:5', '6', now())"); } $this->_klarnaDB->query("INSERT INTO " . TABLE_CONFIGURATION . " (sort_order, " . "configuration_key, configuration_value, configuration_group_id, use_function, " . "set_function, date_added) " . "VALUES ('4', 'MODULE_KLARNA_FEE_TAX_CLASS', '0', '6', 'xtc_get_tax_class_title', 'xtc_cfg_pull_down_tax_classes(', now())"); $this->_klarnaDB->query("INSERT INTO " . TABLE_CONFIGURATION . " (sort_order, " . "configuration_key, configuration_value, configuration_group_id, date_added) " . "VALUES ('5', 'MODULE_KLARNA_FEE_SORT_ORDER', '46', '6', now())"); }
/** * Check if module is enabled * * @return int 1 if enabled */ public function check() { $key = ''; if ($this->_isInvoice()) { $key = 'MODULE_PAYMENT_KLARNA_INVOICE_STATUS'; } else { if ($this->_isPart()) { $key = 'MODULE_PAYMENT_KLARNA_PARTPAYMENT_STATUS'; } else { if ($this->_isSpec()) { $key = 'MODULE_PAYMENT_KLARNA_SPECCAMP_STATUS'; } } } if (!isset($this->_check)) { $this->_check = $this->_klarnaDB->query("SELECT configuration_value FROM " . TABLE_CONFIGURATION . " WHERE configuration_key = " . "'{$key}'")->count(); } return $this->_check; }