Beispiel #1
0
 /**
  * Fetches the PClasses from backend.<br>
  * Removes the cached/stored pclasses and updates.<br>
  * You are only allowed to call this once, or once per update of PClasses in KO.<br>
  *
  * <b>Note</b>:<br>
  * If all parameters are omitted or null, all PClasses (for all countries) will be fetched.<br>
  * If language and/or currency is null, then they will be set to mirror the specified country.<br/>
  * Short codes like DE, SV or EUR can also be used instead of the constants.<br/>
  *
  * @param  string|int  $country   {@link KlarnaCountry Country} constant, or two letter code.
  * @param  mixed       $language  {@link KlarnaLanguage Language} constant, or two letter code.
  * @param  mixed       $currency  {@link KlarnaCurrency Currency} constant, or three letter code.
  * @throws KlarnaException
  * @return void
  */
 public function fetchPClasses($country = null, $language = null, $currency = null)
 {
     $countries = array();
     if ($country === null && $language === null && $currency === null) {
         $countries = array(array('country' => KlarnaCountry::DE, 'language' => KlarnaLanguage::DE, 'currency' => KlarnaCurrency::EUR), array('country' => KlarnaCountry::DK, 'language' => KlarnaLanguage::DA, 'currency' => KlarnaCurrency::DKK), array('country' => KlarnaCountry::FI, 'language' => KlarnaLanguage::FI, 'currency' => KlarnaCurrency::EUR), array('country' => KlarnaCountry::NL, 'language' => KlarnaLanguage::NL, 'currency' => KlarnaCurrency::EUR), array('country' => KlarnaCountry::NO, 'language' => KlarnaLanguage::NB, 'currency' => KlarnaCurrency::NOK), array('country' => KlarnaCountry::SE, 'language' => KlarnaLanguage::SV, 'currency' => KlarnaCurrency::SEK));
     } else {
         if (!is_numeric($country) && (strlen($country) == 2 || strlen($country) == 3)) {
             $country = self::getCountryForCode($country);
         }
         $this->checkCountry($country, __METHOD__);
         if ($currency === null) {
             $currency = $this->getCurrencyForCountry($country);
         } else {
             if (!is_numeric($currency) && strlen($currency) == 3) {
                 $currency = self::getCurrencyForCode($currency);
             }
         }
         $this->checkCurrency($currency, __METHOD__);
         if ($language === null) {
             $language = $this->getLanguageForCountry($country);
         } else {
             if (!is_numeric($language) && strlen($language) == 2) {
                 $language = self::getLanguageForCode($language);
             }
         }
         $this->checkLanguage($language, __METHOD__);
         $countries = array(array('country' => $country, 'language' => $language, 'currency' => $currency));
     }
     try {
         if ($this->config instanceof ArrayAccess) {
             $pclasses = $this->getPCStorage();
             try {
                 //Attempt to load previously stored, so they aren't accidentially removed.
                 $pclasses->load($this->pcURI);
             } catch (Exception $e) {
                 //Silently fail
             } catch (KlarnaException $e) {
                 //Silently fail
             }
             foreach ($countries as $item) {
                 $digestSecret = self::digest($this->colon($this->eid, $item['currency'], $this->secret));
                 $paramList = array($this->eid, $item['currency'], $digestSecret, $item['country'], $item['language']);
                 self::printDebug('get_pclasses array', $paramList);
                 $result = $this->xmlrpc_call('get_pclasses', $paramList);
                 self::printDebug('get_pclasses result', $result);
                 foreach ($result as &$pclass) {
                     //numeric htmlentities
                     $pclass[1] = Klarna::num_htmlentities($pclass[1]);
                     //Below values are in "cents", fix them.
                     $pclass[3] /= 100;
                     //divide start fee with 100
                     $pclass[4] /= 100;
                     //divide invoice fee with 100
                     $pclass[5] /= 100;
                     //divide interest rate with 100
                     $pclass[6] /= 100;
                     //divide min amount with 100
                     if ($pclass[9] != '-') {
                         $pclass[9] = strtotime($pclass[9]);
                         //unix timestamp instead of yyyy-mm-dd
                     }
                     array_unshift($pclass, $this->eid);
                     //Associate the PClass with this estore.
                     $pclasses->addPClass(new KlarnaPClass($pclass));
                 }
             }
             $pclasses->save($this->pcURI);
             $this->pclasses = $pclasses;
         } else {
             throw new Exception('Klarna instance not fully configured!', 50001);
         }
     } catch (Exception $e) {
         $this->pclasses = null;
         throw new KlarnaException('Error in ' . __METHOD__ . ': ' . $e->getMessage(), $e->getCode());
     }
 }
 public function getAddress()
 {
     $aSessionCalls = array();
     // Check the session for calls
     if (array_key_exists('klarna_address', $_SESSION)) {
         $sSessionCalls = base64_decode($_SESSION['klarna_address']);
         $aSessionCalls = unserialize($sSessionCalls);
     }
     $sPNO = JRequest::getWord('socialNumber');
     //JRequest::getWord('pno');
     $sCountry = strtolower(JRequest::getWord('country'));
     if (array_key_exists($sPNO, $aSessionCalls)) {
         $addrs = $aSessionCalls[$sPNO];
     } else {
         $addrs = $this->api->getAddresses($sPNO, NULL, KlarnaFlags::GA_GIVEN);
         $aSessionCalls[$sPNO] = $addrs;
         $_SESSION['klarna_address'] = base64_encode(serialize($aSessionCalls));
     }
     $sString = "<?xml version='1.0'" . "?" . ">\n";
     //eval breaks at question-mark gt
     $sString .= "<getAddress>\n";
     //This example only works for GA_GIVEN.
     foreach ($addrs as $index => $addr) {
         if ($addr->isCompany) {
             $implode = array('companyName' => $addr->getCompanyName(), 'street' => $addr->getStreet(), 'zip' => $addr->getZipCode(), 'city' => $addr->getCity(), 'countryCode' => $addr->getCountryCode());
         } else {
             $implode = array('first_name' => $addr->getFirstName(), 'last_name' => $addr->getLastName(), 'street' => $addr->getStreet(), 'zip' => $addr->getZipCode(), 'city' => $addr->getCity(), 'countryCode' => $addr->getCountryCode());
         }
         $sString .= "<address>\n";
         foreach ($implode as $key => $val) {
             $sString .= "<" . $key . ">" . Klarna::num_htmlentities($val) . "</" . $key . ">\n";
         }
         $sString .= "</address>\n";
     }
     $sString .= "</getAddress>";
     return array('type' => 'text/xml', 'value' => $sString);
 }
Beispiel #3
0
 /**
  * Fetch pclasses
  *
  * @param PCStorage $storage  PClass Storage
  * @param int       $country  KlarnaCountry constant
  * @param int       $language KlarnaLanguage constant
  * @param int       $currency KlarnaCurrency constant
  *
  * @return void
  */
 private function _fetchPClasses($storage, $country, $language, $currency)
 {
     $digestSecret = self::digest($this->_eid . ":" . $currency . ":" . $this->_secret);
     $paramList = array($this->_eid, $currency, $digestSecret, $country, $language);
     self::printDebug('get_pclasses array', $paramList);
     $result = $this->xmlrpc_call('get_pclasses', $paramList);
     self::printDebug('get_pclasses result', $result);
     foreach ($result as &$pclass) {
         //numeric htmlentities
         $pclass[1] = Klarna::num_htmlentities($pclass[1]);
         //Below values are in "cents", fix them.
         $pclass[3] /= 100;
         //divide start fee with 100
         $pclass[4] /= 100;
         //divide invoice fee with 100
         $pclass[5] /= 100;
         //divide interest rate with 100
         $pclass[6] /= 100;
         //divide min amount with 100
         if ($pclass[9] != '-') {
             //unix timestamp instead of yyyy-mm-dd
             $pclass[9] = strtotime($pclass[9]);
         }
         //Associate the PClass with this estore.
         array_unshift($pclass, $this->_eid);
         $storage->addPClass(new KlarnaPClass($pclass));
     }
 }