/** * Parse a valid Klarna country to uppercase iso alpha code * * @param string|int $country KlarnaCountry * * @return string|null */ public static function parseCountry($country) { if (is_numeric($country)) { $country = KlarnaCountry::getCode($country); if ($country !== null) { return strtoupper($country); } } if (KlarnaCountry::fromCode($country) !== null) { return strtoupper($country); } return null; }
/** * The constructor * * @param string|int $country alpha-2 country code or KlarnaCountry constant. * * @return void */ public function __construct($country = null) { if ($country === null) { $country = self::getCountryByID(STORE_COUNTRY); } else { if (is_numeric($country)) { $country = KlarnaCountry::getCode($country); } else { $country = strtolower($country); } } $this->_country = $country; $this->_klarnaDB = new XtcKlarnaDB(); }
/** * Returns the country as a two letter representation. * * @throws KlarnaException * @return string E.g. 'de', 'dk', ... */ public function getCountryCode() { return KlarnaCountry::getCode($this->country); }
/** * @param $product * @return array|null */ private function getViewData($product) { if (!class_exists('KlarnaAPI')) { require JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarnaapi.php'; } if (!class_exists('VirtueMartModelCurrency')) { require VMPATH_ADMIN . DS . 'models' . DS . 'currency.php'; } $price = $product->prices['salesPrice']; $country = $this->cData['country']; $lang = $this->cData['language_code']; $types = array(KlarnaPClass::CAMPAIGN, KlarnaPClass::ACCOUNT, KlarnaPClass::FIXED); try { $kCheckout = new KlarnaAPI($country, $lang, 'part', $price, KlarnaFlags::PRODUCT_PAGE, $this->klarna_virtuemart, $types, $this->path); } catch (Exception $e) { VmDebug('getViewData', 'Error in ' . __METHOD__ . ': ' . $e->getMessage(), $e->getCode()); VmError($e->getMessage(), 'getViewData' . 'Error in ' . __METHOD__ . ': ' . $e->getMessage(), $e->getCode()); return NULL; } $kCheckout->setCurrency($this->cData['currency']); // TODO : Not top to get setup values here! $this->settings = $kCheckout->getSetupValues(); if ($price > 0 && count($kCheckout->aPClasses) > 0) { $currencydisplay = CurrencyDisplay::getInstance(); $sMonthDefault = NULL; $sTableHtml = ""; $monthTable = array(); // either in vendor's currency, or shipTo Currency $countryCurrencyId = $this->cData['virtuemart_currency_id']; $currency = CurrencyDisplay::getInstance($countryCurrencyId); $fromCurrency = $currency->getCurrencyForDisplay(); //$paymentCurrency = CurrencyDisplay::getInstance($this->cart->paymentCurrency); //$totalInPaymentCurrency = $paymentCurrency->priceDisplay( $this->cart->cartPrices['billTotal'],$this->cart->paymentCurrency) ; //$currencyDisplay = CurrencyDisplay::getInstance($this->cart->pricesCurrency); $i = 0; foreach ($kCheckout->aPClasses as $pclass) { if ($sMonthDefault === NULL || $pclass['monthlyCost'] < $sMonthDefault) { $sMonthDefault = $currency->priceDisplay($pclass['monthlyCost'], $countryCurrencyId); } if ($pclass['pclass']->getType() == KlarnaPClass::ACCOUNT) { $pp_title = tsmText::_('VMPAYMENT_KLARNA_PPBOX_ACCOUNT'); } else { $pp_title = $pclass['pclass']->getMonths() . " " . tsmText::_('VMPAYMENT_KLARNA_PPBOX_TH_MONTH'); } $pp_price = $currency->priceDisplay($pclass['monthlyCost'], $countryCurrencyId); $monthTable[$i] = array('pp_title' => html_entity_decode($pp_title), 'pp_price' => $pp_price, 'country' => $country); $i++; } $cd = CurrencyDisplay::getInstance($fromCurrency); $aInputValues = array(); $aInputValues['defaultMonth'] = $sMonthDefault; $aInputValues['monthTable'] = $monthTable; $aInputValues['eid'] = $this->cData['eid']; $aInputValues['country'] = KlarnaCountry::getCode($country); if ($country == KlarnaCountry::DE) { $aInputValues['asterisk'] = '*'; } else { $aInputValues['asterisk'] = ''; } return $aInputValues; } return NULL; }
/** * Constructor * * @param mixed $country country * @param mixed $language language */ public function __construct($country, $language) { $countryCode = KlarnaCountry::getCode($country); parent::__construct("Mismatching country/language for '{$countryCode}'! " . "[country: {$country} language: {$language}]", 50024); }
/** * Rounds a value depending on the specified country. * * @param int|float $value The value to be rounded. * @param int $country KlarnaCountry constant. * * @return float|int */ public static function pRound($value, $country) { $multiply = 1; //Round to closest integer $country = KlarnaCountry::getCode($country); switch ($country) { case "FI": case "DE": case "NL": case "AT": $multiply = 10; //Round to closest decimal break; } return floor($value * $multiply + 0.5) / $multiply; }
/** * Returns the country code for the set country constant. * * @param int {@link KlarnaCountry Country} constant. * @return string Two letter code, e.g. "se", "no", etc. */ public function getCountryCode($country = null) { $country = $country === null ? $this->country : $country; $code = KlarnaCountry::getCode($country); return $code === null ? '' : $code; }
/** * Returns the PNO/SSN encoding constant for currently set country. * * <b>Note</b>:<br> * Country, language and currency needs to match! * * @throws KlarnaException * @return int {@link KlarnaEncoding} constant. */ public function getPNOEncoding() { $this->_checkLocale(); $country = KlarnaCountry::getCode($this->_country); return KlarnaEncoding::get($country); }
/** * Constructor * * @param mixed $country country */ public function __construct($country) { $countryCode = KlarnaCountry::getCode($country); if ($countryCode === null) { $countryCode = $country; } parent::__construct("Unknown/unsupported country! ({$countryCode})! ", 50025); }
/** * Attempt to locate where a user is from based on currency, * language and address. * * @param string $currency iso-4217 currency code * @param string $language iso-639-1 language code * @param KlarnaAddr $address Customers KlarnaAddr object * @param string $ipAddress Customer IPAddress for eventual geoIP lookup * * @return Country iso-3166-alpha-2 code if a match is found, null * otherwise. */ public function locate($currency = null, $language = null, $address = null, $ipAddress = null) { // Polish input to be the expected uppercase and lowercase if ($currency !== null) { $currency = strtoupper($currency); } if ($language !== null) { $language = strtolower($language); } // If the currency is not in the list of supported currencies, exit if ($this->_lookup->getCountries($currency) === null) { return null; } // If we do have an address, check if it is valid to sell to. If it is, // return it, otherwise exit if ($address !== null) { $country = strtoupper(KlarnaCountry::getCode($address->getCountry())); return $this->_getValid($country, $currency); } // Get all possible valid candidates based on currency and language. $candidates = $this->_getCandidates($currency, $language); // If there is only one valid candidate, return it if (count($candidates) === 1) { return $candidates[0]; } // Check if the default store is a valid candidate, and if it is, // return it. $default = $this->_getDefaultCountry(); if ($default !== null && in_array($default, $candidates)) { return $default; } // No match has been found, exit. return null; }
private function getViewData($product) { if (!class_exists('KlarnaAPI')) { require JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarnaapi.php'; } if (!class_exists('VirtueMartModelCurrency')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'currency.php'; } $price = $product->prices['salesPrice']; $country = $this->cData['country']; $lang = $this->cData['language_code']; $types = array(KlarnaPClass::CAMPAIGN, KlarnaPClass::ACCOUNT, KlarnaPClass::FIXED); $kCheckout = new KlarnaAPI($country, $lang, 'part', $price, KlarnaFlags::PRODUCT_PAGE, $this->klarna, $types, $this->path); $kCheckout->setCurrency($this->cData['currency']); // TODO : Not top to get setup values here! $this->settings = $kCheckout->getSetupValues(); if ($price > 0 && count($kCheckout->aPClasses) > 0) { $currencydisplay = CurrencyDisplay::getInstance(); $sMonthDefault = NULL; $sTableHtml = ""; // either in vendor's currency, or shipTo Currency $countryCurrencyId = ShopFunctions::getCurrencyIDByName($this->cData['currency_code']); $currency = CurrencyDisplay::getInstance($countryCurrencyId); $fromCurrency = $currency->getCurrencyForDisplay(); //$paymentCurrency = CurrencyDisplay::getInstance($this->cart->paymentCurrency); //$totalInPaymentCurrency = $paymentCurrency->priceDisplay( $this->cart->pricesUnformatted['billTotal'],$this->cart->paymentCurrency) ; //$currencyDisplay = CurrencyDisplay::getInstance($this->cart->pricesCurrency); $i = 0; foreach ($kCheckout->aPClasses as $pclass) { if ($sMonthDefault === NULL || $pclass['monthlyCost'] < $sMonthDefault) { $sMonthDefault = $currency->priceDisplay($pclass['monthlyCost'], $countryCurrencyId); } if ($pclass['pclass']->getType() == KlarnaPClass::ACCOUNT) { $pp_title = JText::_('VMPAYMENT_KLARNA_PPBOX_ACCOUNT'); } else { $pp_title = $pclass['pclass']->getMonths() . " " . JText::_('VMPAYMENT_KLARNA_PPBOX_TH_MONTH'); } $pp_price = $currency->priceDisplay($pclass['monthlyCost'], $countryCurrencyId); $monthTable[$i] = array('pp_title' => html_entity_decode($pp_title), 'pp_price' => $pp_price, 'country' => $country); $i++; } $cd = CurrencyDisplay::getInstance($fromCurrency); $aInputValues = array(); $aInputValues['defaultMonth'] = $sMonthDefault; $aInputValues['monthTable'] = $monthTable; $aInputValues['eid'] = $this->cData['eid']; $aInputValues['country'] = KlarnaCountry::getCode($country); if ($country == KlarnaCountry::DE) { $aInputValues['asterisk'] = '*'; } else { $aInputValues['asterisk'] = ''; } //$aInputValues['nlBanner'] = (($country == KlarnaCountry::NL) ? '<div class="nlBanner"><img src="' . VMKLARNAPLUGINWEBASSETS . '/images/account/' . $notice . '" /></div>' : ""); return $aInputValues; // return $kCheckout->retrieveHTML($aInputValues, null, JPATH_VMKLARNAPLUGIN . '/klarna/tmpl/productprice_layout.html'); } return NULL; }
/** * Returns the country code for the set country constant. * * @param int $country {@link KlarnaCountry Country} constant. * * @return string Two letter code, e.g. "se", "no", etc. */ public function getCountryCode($country = null) { if ($country === null) { $country = $this->_country; } $code = KlarnaCountry::getCode($country); return (string) $code; }