コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * Build the cart to be used for the purchase.
  *
  * @param string $estoreUser  estoreUser identifier
  * @param object $order       osCommerce order object
  * @param string $option      invoice, part or spec
  * @param string $code        payment code
  * @param int    $paymentPlan pclass id
  *
  * @return void
  */
 public function buildCart($estoreUser, $order, $option, $code, $paymentPlan)
 {
     if ($option == KiTT::PART) {
         $artno = MODULE_PAYMENT_KLARNA_PARTPAYMENT_ARTNO;
     } else {
         if ($option == KiTT::SPEC) {
             $artno = MODULE_PAYMENT_KLARNA_SPECCAMP_ARTNO;
         } else {
             $artno = MODULE_PAYMENT_KLARNA_INVOICE_ARTNO;
         }
     }
     $flags = KlarnaFlags::INC_VAT;
     if (KlarnaConstant::showPriceTax() === false) {
         $flags = KlarnaFlags::NO_FLAG;
     }
     // Add all the articles to the goodslist
     foreach ($order->products as $product) {
         $attributes = "";
         if (isset($product['attributes'])) {
             foreach ($product['attributes'] as $attr) {
                 $attributes = $attributes . ", " . $attr['option'] . ": " . $attr['value'];
             }
         }
         $artnumber = $product[$artno];
         if ($artno == 'id' || $artno == '') {
             $artnumber = xtc_get_prid($product['id']);
         }
         $this->_klarna->addArticle(KiTT_String::encode($product['qty']), KiTT_String::encode($artnumber), KiTT_String::encode(strip_tags($product['name'] . $attributes)), KiTT_String::encode($product['price']), KiTT_String::encode(number_format($product['tax'], 2)), 0, $flags);
     }
     // Then the extra charges like shipping and invoicefee and
     // discount.
     $klarna_ot = $_SESSION['klarna_ot'];
     $extra = $klarna_ot['code_entries'];
     // If someone tries to set a pclass value to -1 using firebug, force
     // an invoice fee on them.
     if ($paymentPlan < 0) {
         $code = "klarna";
     }
     // Go over all the order total modules that are active for this order
     // and add them.
     foreach ($klarna_ot as $key => $item) {
         $flags = KlarnaFlags::INC_VAT;
         if (KlarnaConstant::showPriceTax() === false) {
             $flags = KlarnaFlags::NO_FLAG;
         }
         if ($key === "ot_shipping") {
             $flags |= KlarnaFlags::IS_SHIPMENT;
         } else {
             if ($key === "ot_klarna_fee") {
                 $flags |= KlarnaFlags::IS_HANDLING;
             } else {
                 if ($key === "ot_coupon" || $key === "ot_discount" || $key === "ot_gv") {
                     if ($item["value"] > 0) {
                         $item["value"] *= -1;
                     }
                 }
             }
         }
         $title = rtrim($item["title"], ':');
         $this->_klarna->addArticle(1, "", html_entity_decode($title, ENT_COMPAT, KiTT_String::$klarnaEncoding), $item["value"], $item["rate"], 0, $flags);
     }
 }
コード例 #3
0
 /**
  * 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())));
 }