/**
  * Match an address from the checkout with an address from getAddress, and
  * return the matching address.
  *
  * @param array  &$errors reference to errors array
  * @param string $option  payment method
  *
  * @return object KlarnaAddr object
  */
 public function getMatchingAddress(&$errors, $option)
 {
     $addrs = array();
     $pno = $_POST["klarna_{$option}_pno"];
     $_SESSION['klarna_data']['pno'] = $pno;
     $_SESSION['klarna_data']['phone'] = $_POST["klarna_{$option}_phone_number"];
     $address = new KlarnaAddr();
     $KITTaddr = new KiTT_Addresses(KiTT::api('SE'));
     try {
         $address = $KITTaddr->getMatchingAddress($pno, $_POST["klarna_{$option}_address_key"]);
         $address->setTelno($_POST["klarna_{$option}_phone_number"]);
         $address->setCellno($_POST["klarna_{$option}_phone_number"]);
         $address->setEmail($_POST["klarna_email"]);
     } catch (Exception $e) {
         Klarna::printDebug('Error in __METHOD__', $e->getMessage());
         $errors[] = "error_no_address";
     }
     return $address;
 }
 /**
  * The constructor
  *
  * @param int|string $country country
  *
  * @return void
  */
 public function __construct($country = null)
 {
     global $currency;
     $this->_country = KlarnaUtils::deduceCountry('part');
     $this->_language = KlarnaUtils::getLanguageCode();
     $this->_currency = $currency;
     if ($country === null && $this->_country == null) {
         $this->_country = strtoupper($_SESSION['language_code']);
     }
     if ($this->_country === null) {
         Klarna::printDebug(__METHOD__, array('currency' => $this->_currency, 'language' => $this->_language));
         $this->_enabled = false;
         return;
     }
     $this->_utils = new KlarnaUtils($this->_country);
     $this->_enabled = KlarnaConstant::isEnabled('part', $this->_country);
     if ($this->_enabled === true && !KlarnaConstant::isActivated('part', $this->_country)) {
         $this->_enabled = false;
     }
     $this->_locale = KiTT::locale($this->_country, $this->_language, $this->_currency);
 }
Пример #3
0
 /**
  * @param null $a_sHTMLFile
  * @param null $aTemplateData
  * @return string
  * @deprecated
  */
 public function loadTemplate($a_sHTMLFile = NULL, $aTemplateData = NULL)
 {
     $sFilename = '';
     /**
      * @todo Check for file and trow error if missing
      */
     if ($a_sHTMLFile != NULL) {
         $sFilename = $a_sHTMLFile;
     } else {
         if ($this->sType != "spec") {
             $sFilename = ($this->sPath != NULL ? $this->sPath : "") . "/klarna/tmpl/" . $this->sType . "_" . strtolower($this->sCountryCode) . ".html";
         } else {
             $this->aSetupSettings['conditionsLink'] = $aTemplateData['conditions'];
             $sFilename = ($this->sPath != NULL ? $this->sPath : "") . '/klarna/tmpl/' . $this->sType . "_" . strtolower($this->sCountryCode) . ".html";
         }
     }
     Klarna::printDebug(__METHOD__ . 'loading template', $sFilename);
     return file_get_contents($sFilename);
 }
 /**
  * Update orderstatuses in the database
  *
  * @param int $customer The order status id to show the customer
  * @param int $admin    The order status id to show in the administration page
  *
  * @return void
  */
 public function updateOrderDatabase($customer, $admin)
 {
     global $insert_id;
     $orderid = mysqli_real_escape_string(xtc_db_connect(), $insert_id);
     $refno = mysqli_real_escape_string(xtc_db_connect(), $_SESSION['klarna_refno']);
     $sql_data_arr = array('orders_id' => $orderid, 'orders_status_id' => $customer, 'comments' => "Accepted by Klarna. Reference #: {$refno}", 'customer_notified' => 1, 'date_added' => date("Y-m-d H:i:s"));
     xtc_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_arr);
     $has_ordernum_table = xtc_db_fetch_array(xtc_db_query("SELECT COUNT(*) " . "FROM information_schema.tables " . "WHERE table_schema = '" . DB_DATABASE . "' " . "AND table_name = 'klarna_ordernum';"));
     $has_ordernum_table = $has_ordernum_table['COUNT(*)'];
     if ($has_ordernum_table > 0) {
         xtc_db_query("INSERT INTO `klarna_ordernum` (orders_id, klarna_ref) " . "VALUES ({$orderid}, {$refno})");
     }
     // Set pending status and hide it from customer.
     $status = $_SESSION['klarna_orderstatus'];
     if (isset($status)) {
         $orderStatusQuery = $this->_klarnaDB->query("SELECT orders_status_id FROM " . TABLE_ORDERS_STATUS . " WHERE orders_status_name = '{$status}'");
         $orderStatusID = $orderStatusQuery->getArray();
         $sql_data_arr = array('orders_id' => $orderid, 'orders_status_id' => $orderStatusID['orders_status_id'], 'comments' => "Klarna Orderstatus: {$status}", 'customer_notified' => 0, 'date_added' => date("Y-m-d H:i:s"));
         xtc_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_arr);
         xtc_db_query("UPDATE " . TABLE_ORDERS . " SET orders_status='" . $orderStatusID['orders_status_id'] . "' WHERE orders_id='" . $orderid . "'");
     }
     try {
         $this->_klarna->setEstoreInfo(KiTT_String::encode($orderid));
         $this->_klarna->update($_SESSION['klarna_refno']);
     } catch (Exception $e) {
         Klarna::printDebug(__METHOD__, "{$e->getMessage()} #({$e->getCode()})");
     }
     //Delete Session with user details
     unset($_SESSION['klarna_data']);
     unset($_SESSION['klarna_refno']);
     unset($_SESSION['klarna_orderstatus']);
 }
Пример #5
0
 /**
  * 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';
 }