/** * Initializes the Klarna object accordingly to the set config object. * * @throws KlarnaException * @return void */ protected function init() { $this->hasFields('eid', 'secret', 'mode', 'pcStorage', 'pcURI'); if (!is_int($this->config['eid'])) { $this->config['eid'] = intval($this->config['eid']); } if ($this->config['eid'] <= 0) { throw new Klarna_ConfigFieldMissingException('eid'); } if (!is_string($this->config['secret'])) { $this->config['secret'] = strval($this->config['secret']); } if (strlen($this->config['secret']) == 0) { throw new Klarna_ConfigFieldMissingException('secret'); } //Set the shop id and secret. $this->_eid = $this->config['eid']; $this->_secret = $this->config['secret']; //Set the country specific attributes. try { $this->hasFields('country', 'language', 'currency'); //If hasFields doesn't throw exception we can set them all. $this->setCountry($this->config['country']); $this->setLanguage($this->config['language']); $this->setCurrency($this->config['currency']); } catch (Exception $e) { //fields missing for country, language or currency $this->_country = $this->_language = $this->_currency = null; } //Set addr and port according to mode. $this->mode = (int) $this->config['mode']; $this->_url = array(); // If a custom url has been added to the config, use that as xmlrpc // recipient. if (isset($this->config['url'])) { $this->_url = parse_url($this->config['url']); if ($this->_url === false) { $message = "Configuration value 'url' could not be parsed. " . "(Was: '{$this->config['url']}')"; Klarna::printDebug(__METHOD__, $message); throw new InvalidArgumentException($message); } } else { $this->_url['scheme'] = 'https'; if ($this->mode === self::LIVE) { $this->_url['host'] = self::$_live_addr; } else { $this->_url['host'] = self::$_beta_addr; } if (isset($this->config['ssl']) && (bool) $this->config['ssl'] === false) { $this->_url['scheme'] = 'http'; } } // If no port has been specified, deduce from url scheme if (!array_key_exists('port', $this->_url)) { if ($this->_url['scheme'] === 'https') { $this->_url['port'] = 443; } else { $this->_url['port'] = 80; } } try { $this->hasFields('candice'); self::$_candice = (bool) $this->config['candice']; } catch (Exception $e) { //No 'candice' field ignore it... } try { $this->hasFields('xmlrpcDebug'); Klarna::$xmlrpcDebug = $this->config['xmlrpcDebug']; } catch (Exception $e) { //No 'xmlrpcDebug' field ignore it... } try { $this->hasFields('debug'); Klarna::$debug = $this->config['debug']; } catch (Exception $e) { //No 'debug' field ignore it... } $this->pcStorage = $this->config['pcStorage']; $this->pcURI = $this->config['pcURI']; // Default path to '/' if not set. if (!array_key_exists('path', $this->_url)) { $this->_url['path'] = '/'; } $this->xmlrpc = new xmlrpc_client($this->_url['path'], $this->_url['host'], $this->_url['port'], $this->_url['scheme']); $this->xmlrpc->request_charset_encoding = 'ISO-8859-1'; }
/** * Initializes the Klarna object accordingly to the set config object. * * @throws KlarnaException * @return void */ protected function init() { $this->hasFields('eid', 'secret', 'mode', 'pcStorage', 'pcURI'); if (!is_int($this->config['eid'])) { $this->config['eid'] = intval($this->config['eid']); } if ($this->config['eid'] <= 0) { throw new Klarna_ConfigFieldMissingException('eid'); } if (!is_string($this->config['secret'])) { $this->config['secret'] = strval($this->config['secret']); } if (strlen($this->config['secret']) == 0) { throw new Klarna_ConfigFieldMissingException('secret'); } //Set the shop id and secret. $this->_eid = $this->config['eid']; $this->_secret = $this->config['secret']; //Set the country specific attributes. try { $this->hasFields('country', 'language', 'currency'); //If hasFields doesn't throw exception we can set them all. $this->setCountry($this->config['country']); $this->setLanguage($this->config['language']); $this->setCurrency($this->config['currency']); } catch (Exception $e) { //fields missing for country, language or currency $this->_country = $this->_language = $this->_currency = null; } //Set addr and port according to mode. $this->mode = (int) $this->config['mode']; if ($this->mode === self::LIVE) { $this->addr = self::$_live_addr; $this->ssl = true; } else { $this->addr = self::$_beta_addr; $this->ssl = true; } try { $this->hasFields('ssl'); $this->ssl = (bool) $this->config['ssl']; } catch (Exception $e) { //No 'ssl' field ignore it... } if ($this->ssl) { $this->port = 443; } else { $this->port = 80; } try { $this->hasFields('candice'); self::$_candice = (bool) $this->config['candice']; } catch (Exception $e) { //No 'candice' field ignore it... } try { $this->hasFields('xmlrpcDebug'); Klarna::$xmlrpcDebug = $this->config['xmlrpcDebug']; } catch (Exception $e) { //No 'xmlrpcDebug' field ignore it... } try { $this->hasFields('debug'); Klarna::$debug = $this->config['debug']; } catch (Exception $e) { //No 'debug' field ignore it... } $this->pcStorage = $this->config['pcStorage']; $this->pcURI = $this->config['pcURI']; $this->xmlrpc = new xmlrpc_client('/', $this->addr, $this->port, $this->ssl ? 'https' : 'http'); $this->xmlrpc->request_charset_encoding = 'ISO-8859-1'; }