/**
  * 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();
 }
 /**
  * {@inheritDoc}
  */
 protected function populateConfig(ArrayObject $config)
 {
     if (!class_exists('KlarnaCurrency')) {
         throw new \LogicException('You must install "fp/klarna-invoice" library.');
     }
     $config->defaults(array('payum.factory_name' => 'klarna_invoice', 'payum.factory_title' => 'Klarna Invoice', 'sandbox' => true, 'pClassStorage' => 'json', 'pClassStoragePath' => './pclasses.json', 'xmlRpcVerifyHost' => 2, 'xmlRpcVerifyPeer' => true, 'payum.action.capture' => new CaptureAction(), 'payum.action.authorize' => new AuthorizeAction(), 'payum.action.status' => new StatusAction(), 'payum.action.sync' => new SyncAction(), 'payum.action.refund' => new RefundAction(), 'payum.action.api.activate' => new ActivateAction(), 'payum.action.api.activate_reservation' => new ActivateReservationAction(), 'payum.action.api.cancel_reservation' => new CancelReservationAction(), 'payum.action.api.check_order_status' => new CheckOrderStatusAction(), 'payum.action.api.get_addresses' => new GetAddressesAction(), 'payum.action.api.populate_klarna_from_details' => new PopulateKlarnaFromDetailsAction(), 'payum.action.api.credit_invoice' => new CreditInvoiceAction(), 'payum.action.api.credit_part' => new CreditPartAction(), 'payum.action.api.reserve_amount' => new ReserveAmountAction(), 'payum.action.api.return_amount' => new ReturnAmountAction(), 'payum.action.api.email_invoice' => new EmailInvoiceAction(), 'payum.action.api.send_invoice' => new SendInvoiceAction(), 'payum.action.api.update' => new UpdateAction()));
     if (false == $config['payum.api']) {
         $config['payum.default_options'] = array('eid' => '', 'secret' => '', 'country' => '', 'language' => '', 'currency' => '', 'sandbox' => true);
         $config->defaults($config['payum.default_options']);
         $config['payum.required_options'] = array('eid', 'secret', 'country', 'language', 'currency');
         $config->defaults(array('sandbox' => true));
         $config['payum.api'] = function (ArrayObject $config) {
             $config->validateNotEmpty($config['payum.required_options']);
             $config['mode'] = $config['sandbox'] ? \Klarna::BETA : \Klarna::LIVE;
             if (null === ($country = \KlarnaCountry::fromCode($config['country']))) {
                 throw new LogicException(sprintf('Given %s country code is not valid. Klarna cannot recognize it.', $config['country']));
             }
             if (null === ($language = \KlarnaLanguage::fromCode($config['language']))) {
                 throw new LogicException(sprintf('Given %s language code is not valid. Klarna cannot recognize it.', $config['language']));
             }
             if (null === ($currency = \KlarnaCurrency::fromCode($config['currency']))) {
                 throw new LogicException(sprintf('Given %s currency code is not valid. Klarna cannot recognize it.', $config['currency']));
             }
             $klarnaConfig = new Config();
             $klarnaConfig->eid = $config['eid'];
             $klarnaConfig->secret = $config['secret'];
             $klarnaConfig->mode = $config['mode'];
             $klarnaConfig->country = $country;
             $klarnaConfig->language = $language;
             $klarnaConfig->currency = $currency;
             $klarnaConfig->pClassStorage = $config['pClassStorage'];
             $klarnaConfig->pClassStoragePath = $config['pClassStoragePath'];
             $klarnaConfig->xmlRpcVerifyHost = $config['xmlRpcVerifyHost'];
             $klarnaConfig->xmlRpcVerifyHost = $config['xmlRpcVerifyHost'];
             return $klarnaConfig;
         };
     }
 }
 /**
  * Sets the country, use either a two letter representation or the integer
  * constant.
  *
  * @param int $country {@link KlarnaCountry}
  *
  * @throws KlarnaException
  * @return void
  */
 public function setCountry($country)
 {
     if ($country === null) {
         throw new Klarna_ArgumentNotSetException('Country');
     }
     if (is_numeric($country)) {
         if (!is_int($country)) {
             $country = intval($country);
         }
         $this->country = $country;
         return;
     }
     if (strlen($country) == 2 || strlen($country) == 3) {
         $this->setCountry(KlarnaCountry::fromCode($country));
         return;
     }
     throw new KlarnaException("Failed to set country! ({$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;
 }
Esempio n. 5
0
 /**
  * Converts a KlarnaCountry constant to the respective country code.
  *
  * @param int  $val    KlarnaCountry constant
  * @param bool $alpha3 Whether to return a ISO-3166-1 alpha-3 code
  *
  * @return string|null
  */
 public static function getCode($val, $alpha3 = false)
 {
     if (self::$_countryFlip === array()) {
         self::$_countryFlip = array_flip(self::$_countries);
     }
     if (!array_key_exists($val, self::$_countryFlip)) {
         return null;
     }
     $result = self::$_countryFlip[$val];
     if ($alpha3) {
         return self::$_tlcMap[$result];
     }
     return $result;
 }
Esempio n. 6
0
 /**
  * Sets the active country from a ISO country string
  * or a KlarnaCountry constant
  */
 public function setCountry($country)
 {
     if (!is_numeric($country)) {
         $country = KlarnaCountry::fromCode($country);
     } else {
         $country = intval($country);
     }
     if ($this->oKlarna == NULL) {
         throw new KlarnaApiException('Error in ' . __METHOD__ . ': Klarna instance not set');
     }
     $this->iKlarnaCountry = $country;
     $this->iKlarnaCurrency = $this->oKlarna->getCurrencyForCountry($country);
     $this->sCountryCode = $this->oKlarna->getCountryCode($country);
 }
Esempio n. 7
0
 /**
  * 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;
 }
Esempio n. 9
0
 /**
  * get the country of the locale
  *
  * @return int country constant
  */
 public function getCountry()
 {
     return KlarnaCountry::fromCode($this->_country);
 }
Esempio n. 10
0
 /**
  * Returns the {@link KlarnaCountry country} constant from the country code.
  *
  * @param  string  $code  Two letter code, e.g. "se", "no", etc.
  * @throws KlarnaException
  * @return int  {@link KlarnaCountry Country} constant.
  */
 public static function getCountryForCode($code)
 {
     $country = KlarnaCountry::fromCode($code);
     if ($country === null) {
         throw new KlarnaException('Error in ' . __METHOD__ . ': Unknown country! ("' . $code . '")', 50002);
     }
     return $country;
 }
Esempio n. 11
0
 /**
  * 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);
 }
Esempio n. 12
0
 /**
  * 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;
 }
Esempio n. 15
0
 /**
  * Returns the {@link KlarnaCurrency currency} constant for the specified
  * or set country.
  *
  * @param int $country {@link KlarnaCountry country} constant.
  *
  * @return int|false {@link KlarnaCurrency currency} constant.
  */
 public function getCurrencyForCountry($country = null)
 {
     if ($country === null) {
         $country = $this->_country;
     }
     return KlarnaCountry::getCurrency($country);
 }