/**
  * Perform a checkOrder
  *
  * @param int    $id          order id
  * @param string $paymentCode payment option code
  *
  * @return void
  */
 public function checkOrder($id, $paymentCode)
 {
     global $xtPrice;
     $orderId = mysqli_real_escape_string(xtc_db_connect(), $_GET['oID']);
     $comments = $this->_getComments($orderId);
     // Don't update orderstatus if it is already updated to approved once.
     foreach ($comments as $comment) {
         if (strstr($comment, $this->_assembleOrderComment(self::APPROVED))) {
             $this->_showError("Klarna Status already updated and approved.");
             return;
         }
     }
     $ref = $this->_getRefNumber($orderId);
     if ($ref === null) {
         $this->_showError("No matching reference found for order id {$orderId}.");
         return;
     }
     KlarnaUtils::configureKiTT(KlarnaConstant::getKiTTOption($paymentCode));
     KlarnaUtils::configureKlarna(KlarnaConstant::getKiTTOption($paymentCode));
     $statusName = null;
     try {
         $statusName = $this->_getStatus(KiTT::api($this->_getOrderCountry()), $ref);
     } catch (Exception $e) {
         $this->_showError($e->getMessage() . " Is {$paymentCode} configured?");
     }
     if ($statusName === null) {
         return;
     }
     $newComment = $this->_assembleOrderComment($statusName);
     echo "<br /> {$newComment} <br />";
     $order_status_id = $this->_getPaymentStatusID($paymentCode, $statusName);
     $sql_data_arr = array('orders_id' => $orderId, 'orders_status_id' => $order_status_id, 'comments' => $newComment, 'customer_notified' => 0, 'date_added' => date("Y-m-d H:i:s"));
     $this->_klarnaDB->perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_arr);
     xtc_db_query("UPDATE " . TABLE_ORDERS . " SET orders_status='" . $order_status_id . "' WHERE orders_id='" . $orderId . "'");
 }
 /**
  * Show the ppBox for given price.
  *
  * @param float $price price
  * @param int   $page  KlarnaFlags page flag
  *
  * @return void
  */
 public function showPPBox($price, $page = KlarnaFlags::PRODUCT_PAGE)
 {
     if (!$this->_enabled) {
         return;
     }
     if (!KiTT_CountryLogic::isBelowLimit($this->_country, $price)) {
         return;
     }
     $templateLoader = KiTT::templateLoader($this->_locale);
     $cssLoader = $templateLoader->load('css.mustache');
     $jsLoader = $templateLoader->load('javascript.mustache');
     $merchantID = KlarnaConstant::merchantID(KiTT::PART, $this->_country);
     $styles = array("includes/external/klarna/template/css/oscstyle.css", "includes/modules/payment/klarna/productprice/style.css", EXTERNAL_KITT . "pp/v1.0/pp.css?eid=" . $merchantID);
     if (KlarnaConstant::isLegacyShop()) {
         $styles[] = "includes/external/klarna/template/css/klarna22rc2a.css";
     }
     $html = $cssLoader->render(array('styles' => $styles));
     $html .= $jsLoader->render(array("scripts" => array(EXTERNAL_KITT . "core/v1.0/js/klarna.min.js", EXTERNAL_KITT . "res/v1.0/js/klarna.lib.min.js", EXTERNAL_KITT . "pp/v1.0/js/productprice.min.js")));
     $html .= "<div style='clear: both;'></div>";
     $html .= KiTT::partPaymentBox($this->_locale, $price, $page)->show();
     return $html;
 }
 /**
  * Prepare to fetch pclasses by building an array of eid and secrets
  *
  * @param string $option 'part' or 'spec'
  *
  * @return array
  */
 public function prepareFetch($option)
 {
     $countries = "";
     // Fethcing the pclasses
     if ($option == 'part') {
         $countries = explode(",", strtolower(MODULE_PAYMENT_KLARNA_PARTPAYMENT_ACTIVATED_COUNTRIES));
     } else {
         if ($option == 'spec') {
             $countries = explode(",", strtolower(MODULE_PAYMENT_KLARNA_SPECCAMP_ACTIVATED_COUNTRIES));
         } else {
             return;
         }
     }
     // Set the array
     $eid_array = array();
     foreach ($countries as $country) {
         $eid_array[$country]['eid'] = KlarnaConstant::merchantID($option, $country);
         $eid_array[$country]['secret'] = KlarnaConstant::secret($option, $country);
     }
     return $eid_array;
 }
 /**
  * Calculate the invoice fee and add the invoice fee tax to the order total
  * if it has one.
  *
  * @return float
  */
 public function calculateInvoiceFee()
 {
     global $order;
     $payment = $_SESSION['payment'];
     $customer_zone_id = $_SESSION['customer_zone_id'];
     $customer_country_id = $_SESSION['customer_country_id'];
     $currency = $_SESSION['currency'];
     if ($payment !== "klarna_invoice") {
         return 0;
     }
     $fee = $this->_utils->getInvoiceFee();
     if ($fee === 0 || MODULE_KLARNA_FEE_TAX_CLASS <= 0) {
         return $fee;
     }
     $showTax = KlarnaConstant::showPriceTax();
     $feeTax = 0;
     $rate = xtc_get_tax_rate(MODULE_KLARNA_FEE_TAX_CLASS);
     $feeExclTax = $fee / ($rate / 100 + 1);
     $feeTax = $fee - $feeExclTax;
     $tax_desc_prefix = "";
     if ($showTax === true) {
         $tax_desc_prefix = TAX_ADD_TAX;
     } else {
         if (KlarnaConstant::addTaxOT() === true) {
             $tax_desc_prefix = TAX_NO_TAX;
         }
     }
     $tax_desc = xtc_get_tax_description(MODULE_KLARNA_FEE_TAX_CLASS, $customer_country_id, $customer_zone_id);
     $order->info['tax_groups'][$tax_desc_prefix . $tax_desc] += $feeTax;
     $order->info['tax'] += $feeTax;
     return $showTax === true ? $fee : $feeExclTax;
 }
 /**
  * Check if the instanced payment module should be shown.
  *
  * @param KiTT_Payment_Option $view KiTT Payment Option instance
  *
  * @return boolean
  */
 private function _isEnabled($view)
 {
     return KlarnaConstant::isActivated($this->_option, $this->_country) && KlarnaConstant::isEnabled($this->_option, $this->_country) && $view->isAvailable();
 }