/** * 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; }
/** * This function outputs the payment method title/text and if required, the * input fields. * * @return array Data to present in page */ public function selection() { global $order, $customer_id, $currencies; $co = KiTT::checkoutController($this->_locale, $this->_totalSum); $view = $co->getOption($this->_option); // Update the enabled variable that xtCommerce needs. $this->enabled = $this->_isEnabled($view); if (!$this->enabled) { return; } // Add CSS and Javascript just once. if (!self::$_hasRun) { $templateLoader = KiTT::templateLoader($this->_locale); $cssLoader = $templateLoader->load('css.mustache'); $jsLoader = $templateLoader->load('javascript.mustache'); $merchantID = KlarnaConstant::merchantID($this->_option, $this->_country); $styles = array(EXTERNAL_KITT . "res/v1.1/checkout.css?eid=" . $merchantID, "includes/modules/payment/klarna/checkout/style.css", "includes/external/klarna/template/css/xtcstyle.css"); self::$_hasRun = true; echo $jsLoader->render(array("scripts" => array(EXTERNAL_KITT . "core/v1.0/js/klarna.min.js", EXTERNAL_KITT . "res/v1.1/js/klarna.lib.min.js", EXTERNAL_KITT . "res/v1.1/js/checkout.min.js"))); echo $cssLoader->render(array('styles' => $styles)); } KiTT::configuration()->set('agb_link', KlarnaConstant::agb($this->_option, $this->_country)); $fee = $this->_utils->getInvoiceFee(); if (KlarnaConstant::showPriceTax() === false && MODULE_KLARNA_FEE_TAX_CLASS > 0) { $feeRate = xtc_get_tax_rate(MODULE_KLARNA_FEE_TAX_CLASS); $fee = $fee / ($feeRate / 100 + 1); } $view->setPaymentFee(round($fee, 2)); $view->setPaymentId($this->code); // Have we returned from a failed purchase? if ($this->_utils->getErrorOption() == $this->_option) { $view->setError(html_entity_decode($this->_utils->getError())); $this->_utils->clearErrors(); if ($this->_option == KiTT::PART && array_key_exists('klarna_paymentPlan', $_SESSION)) { $view->selectPClass(intval($_SESSION['klarna_paymentPlan'])); } } $this->_klarna_data = $this->_utils->collectKlarnaData($order); $this->_klarna_data['country'] = $this->_country; if (isset($_SESSION['klarna_data']) || isset(KlarnaUtils::$prefillData)) { $this->_klarna_data = array_merge($this->_klarna_data, $this->_utils->getValuesFromSession()); } $view->prefill($this->_klarna_data); return array('id' => $this->code, 'module' => KITT_String::decode($view->getTitle(), "UTF-8", "ISO-8859-15"), 'module_cost' => $view->getExtra(), 'fields' => array(array('title' => '', 'field' => $view->show()))); }