/**
  * Display the part payment box
  *
  * @return string rendered html
  */
 public function show()
 {
     if (count($this->pclasses->pclasses) == 0) {
         return '';
     }
     if (array_key_exists('HTTP_USER_AGENT', $_SERVER) && (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE 7.0") || strstr($_SERVER['HTTP_USER_AGENT'], "MSIE 6.0"))) {
         return '';
     }
     $this->country = strtolower($this->locale->getCountryCode());
     $this->asterisk = '';
     if (KiTT_CountryLogic::needAsterisk($this->country)) {
         $this->asterisk = '*';
     }
     return parent::show();
 }
 /**
  * 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;
 }
 /**
  * Get the formatted street required for a Klarna Addr
  *
  * @param string $street  The street to split
  * @param mixed  $country The country to split for
  *
  * @return array
  */
 public static function splitStreet($street, $country)
 {
     $country = KiTT_Locale::parseCountry($country);
     $split = KiTT_CountryLogic::getSplit($country);
     $elements = self::splitAddress($street);
     $result = array('street' => $elements[0]);
     if (in_array('house_extension', $split)) {
         $result['house_extension'] = $elements[2];
     } else {
         $elements[1] .= ' ' . $elements[2];
     }
     if (in_array('house_number', $split)) {
         $result['house_number'] = $elements[1];
     } else {
         $result['street'] .= ' ' . $elements[1];
     }
     return array_map('trim', $result);
 }
 /**
  * Handle the $_POST variable and return a KlarnaAddr object
  *
  * @param string $option payment option, invoice, part or spec
  *
  * @return KlarnaAddr address object
  */
 public function handlePost($option)
 {
     $addrHandler = new KlarnaAddressXtc();
     $errors = array();
     $lang = self::getLanguageCode();
     $address = new KlarnaAddr();
     if (strtolower($this->_country) == 'se') {
         try {
             $address = $addrHandler->getMatchingAddress($errors, $option);
         } catch (Exception $e) {
             $this->setError(htmlentities($e->getMessage()) . " (#" . $e->getCode() . ")", $option);
             xtc_redirect($this->errorLink(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
         }
     }
     if (strtolower($this->_country) != "se") {
         try {
             $aKlarnaAddress = $addrHandler->addressArrayFromPost($option);
             $address = $addrHandler->buildKlarnaAddressFromArray($aKlarnaAddress, $this->_country);
         } catch (Exception $e) {
             $this->setError(htmlentities($e->getMessage()) . " (#" . $e->getCode() . ")", $option);
             xtc_redirect($this->errorLink(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
         }
         $_SESSION['klarna_data'] = $aKlarnaAddress;
         if (KiTT_CountryLogic::needConsent($this->_country) && $_POST["klarna_{$option}_consent"] != 'consent') {
             $errors[] = "no_consent";
         }
         if (KiTT_CountryLogic::needDateOfBirth($this->_country)) {
             $_SESSION['klarna_data']["pno"] = $_POST["klarna_{$option}_birth_day"] . $_POST["klarna_{$option}_birth_month"] . $_POST["klarna_{$option}_birth_year"];
             $_SESSION['klarna_data']['gender'] = $_POST["klarna_{$option}_gender"];
         }
     }
     if (!empty($errors)) {
         foreach ($errors as $err) {
             $translated[] = $this->translate($err, $lang);
         }
         $this->setError(htmlentities(implode(',', $translated), ENT_COMPAT, 'UTF-8'), $option);
         xtc_redirect($this->errorLink(FILENAME_CHECKOUT_PAYMENT, "", "SSL"));
     }
     return $address;
 }
 /**
  * Constants
  *
  * @return array     constants configured
  */
 function keys()
 {
     $keys = array('MODULE_KLARNA_FEE_STATUS', 'MODULE_KLARNA_FEE_MODE');
     foreach (KiTT_CountryLogic::supportedCountries() as $country) {
         $keys[] = "MODULE_KLARNA_FEE_FIXED_{$country}";
         $keys[] = "MODULE_KLARNA_FEE_TABLE_{$country}";
     }
     $keys[] = 'MODULE_KLARNA_FEE_TAX_CLASS';
     $keys[] = 'MODULE_KLARNA_FEE_SORT_ORDER';
     return $keys;
 }
 /**
  * Country specific fields that don't fit in the array above
  *
  * @return void
  */
 private function _countryFields()
 {
     foreach (KiTT_CountryLogic::supportedCountries() as $country) {
         $flag = "<span class='klarna_flag_" . strtolower($country) . "'></span> ";
         define("{$this->_code}EID_{$country}_TITLE", "{$flag}{$country} " . $this->_translator->translate('KLARNA_ADMIN_MERCHANT_ID_TITLE'));
         define("{$this->_code}EID_{$country}_DESC", $this->_translator->translate('KLARNA_ADMIN_MERCHANT_ID_DESC'));
         define("{$this->_code}SECRET_{$country}_TITLE", "{$flag}{$country} " . $this->_translator->translate('KLARNA_ADMIN_SECRET_TITLE'));
         define("{$this->_code}SECRET_{$country}_DESC", $this->_translator->translate('KLARNA_ADMIN_SECRET_DESC'));
         if (KiTT_CountryLogic::needAGB($country)) {
             define("{$this->_code}AGB_LINK_{$country}_TITLE", "{$flag}{$country} " . $this->_translator->translate('KLARNA_ADMIN_TAC_TITLE'));
             define("{$this->_code}AGB_LINK_{$country}_DESC", $this->_translator->translate('KLARNA_ADMIN_TAC_DESC'));
         }
     }
 }
 /**
  * Assert that the payment option is available
  *
  * @return bool
  */
 public function isAvailable()
 {
     $country = $this->locale->getCountryCode();
     $countryCurrency = $this->lookup->getCurrency($country);
     if ($this->locale->getCurrencyCode() !== $countryCurrency) {
         return false;
     }
     if (!$this->config->has("sales_countries/{$country}")) {
         return false;
     }
     if (!KiTT_CountryLogic::isBelowLimit($country, $this->getTotalSum())) {
         return false;
     }
     if ($this->paymentCode === KiTT::PART || $this->paymentCode === KiTT::SPEC) {
         return count($this->pclasses->pclasses) > 0;
     }
     return true;
 }
 /**
  * Get the configuration array to be inserted into the database.
  *
  * @return array configuration array for specified payment option
  */
 private function _getConfigArray()
 {
     $configs = array(array('configuration_key' => "{$this->_module}STATUS", 'configuration_value' => 'true', 'configuration_group_id' => '6', 'sort_order' => '0', 'set_function' => 'xtc_cfg_select_option(array(\'true\', \'false\'), '), array('configuration_key' => "{$this->_module}LATESTVERSION", 'configuration_value' => 'true', 'configuration_group_id' => '6', 'sort_order' => '0', 'set_function' => 'xtc_cfg_select_option(array(\'true\', \'false\'), '), array('configuration_key' => "{$this->_module}ZONE", 'configuration_value' => '0', 'configuration_group_id' => '6', 'sort_order' => '2', 'use_function' => 'xtc_get_zone_class_title', 'set_function' => 'xtc_cfg_pull_down_zone_classes('), array('configuration_key' => "{$this->_module}ARTNO", 'configuration_value' => 'id', 'configuration_group_id' => '6', 'sort_order' => '8', 'set_function' => 'xtc_cfg_select_option(array(\'id\', \'model\'), '), array('configuration_key' => "{$this->_module}SORT_ORDER", 'configuration_value' => '0', 'configuration_group_id' => '6', 'sort_order' => '20'), array('configuration_key' => "{$this->_module}ORDER_STATUS_ID", 'configuration_value' => '0', 'configuration_group_id' => '6', 'sort_order' => '20', 'set_function' => 'xtc_cfg_pull_down_order_statuses(', 'use_function' => 'xtc_get_order_status_name'), array('configuration_key' => "{$this->_module}ORDER_STATUS_PENDING_ID", 'configuration_value' => $this->_newId, 'configuration_group_id' => '6', 'sort_order' => '11', 'set_function' => 'xtc_cfg_pull_down_order_statuses(', 'use_function' => 'xtc_get_order_status_name'), array('configuration_key' => "{$this->_module}LIVEMODE", 'configuration_value' => 'true', 'configuration_group_id' => '6', 'sort_order' => '21', 'set_function' => 'xtc_cfg_select_option(array(\'true\', \'false\'), '), array('configuration_key' => "{$this->_module}ALLOWED", 'configuration_value' => implode(',', KiTT_CountryLogic::supportedCountries()), 'configuration_group_id' => '6', 'sort_order' => '14'));
     foreach (KiTT_CountryLogic::supportedCountries() as $country) {
         $flags = "<span class='klarna_flag_" . strtolower($country) . "'></span>";
         $configs[] = array('configuration_key' => "{$this->_module}SECRET_{$country}", 'configuration_group_id' => '6', 'sort_order' => '3');
         $configs[] = array('configuration_key' => "{$this->_module}EID_{$country}", 'configuration_value' => '0', 'configuration_group_id' => '6', 'sort_order' => '1');
         if (KiTT_CountryLogic::needAGB($country)) {
             $configs[] = array('configuration_key' => "{$this->_module}AGB_LINK_{$country}", 'configuration_value' => 'http://', 'configuration_group_id' => '', 'sort_order' => '');
         }
     }
     return $configs;
 }
 /**
  * This function implements any checks of any conditions after payment
  * method has been selected.
  *
  * @return void
  */
 public function preConfirmationCheck()
 {
     global $order;
     $addressHandler = new KlarnaAddressXtc();
     $this->_utils->cleanPost();
     $this->_addrs = $this->_utils->handlePost($this->_option);
     if ($this->_isPart() || $this->_isSpec()) {
         $this->_paymentPlan = $_SESSION['klarna_paymentPlan'] = (int) $_POST["klarna_{$this->_option}_paymentPlan"];
     } else {
         $this->_paymentPlan = -1;
     }
     $order->delivery = array_merge($order->delivery, $addressHandler->klarnaAddrToXtcAddr($this->_addrs));
     if (KiTT_CountryLogic::shippingSameAsBilling($this->_country)) {
         $order->billing = $order->delivery;
     }
     $_SESSION['klarna_data']['serial_addr'] = serialize($this->_addrs);
 }
 /**
  * Is company allowed?
  *
  * @return true if companies are allowed to use this payment option.
  */
 private function _companyAllowed()
 {
     return KiTT_CountryLogic::isCompanyAllowed($this->_locale->getCountryCode()) && $this->_paymentCode === 'invoice';
 }