/** * Initializes the Klarna object accordingly to the set config object. * * @ignore Do not show this in PHPDoc. * @throws KlarnaException|Exception * @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 Exception("Config field 'eid' is not valid!", 50001); } if (!is_string($this->config['secret'])) { $this->config['secret'] = strval($this->config['secret']); } if (strlen($this->config['secret']) == 0) { throw new Exception("Config field 'secret' not set!", 50001); } //Set the shop id and secret. $this->eid = $this->config['eid']; $this->secret = $this->config['secret']; if (!is_numeric($this->config['country']) && strlen($this->config['country']) == 2) { $this->setCountry($this->config['country']); } else { //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'; }