/**
  * Perform a checkOrder
  *
  * @param int    $id          order id
  * @param string $paymentCode payment option code
  *
  * @return void
  */
 public function checkOrder($id, $paymentCode)
 {
     global $xtPrice;
     $orderId = mysqli_real_escape_string(xtc_db_connect(), $_GET['oID']);
     $comments = $this->_getComments($orderId);
     // Don't update orderstatus if it is already updated to approved once.
     foreach ($comments as $comment) {
         if (strstr($comment, $this->_assembleOrderComment(self::APPROVED))) {
             $this->_showError("Klarna Status already updated and approved.");
             return;
         }
     }
     $ref = $this->_getRefNumber($orderId);
     if ($ref === null) {
         $this->_showError("No matching reference found for order id {$orderId}.");
         return;
     }
     KlarnaUtils::configureKiTT(KlarnaConstant::getKiTTOption($paymentCode));
     KlarnaUtils::configureKlarna(KlarnaConstant::getKiTTOption($paymentCode));
     $statusName = null;
     try {
         $statusName = $this->_getStatus(KiTT::api($this->_getOrderCountry()), $ref);
     } catch (Exception $e) {
         $this->_showError($e->getMessage() . " Is {$paymentCode} configured?");
     }
     if ($statusName === null) {
         return;
     }
     $newComment = $this->_assembleOrderComment($statusName);
     echo "<br /> {$newComment} <br />";
     $order_status_id = $this->_getPaymentStatusID($paymentCode, $statusName);
     $sql_data_arr = array('orders_id' => $orderId, 'orders_status_id' => $order_status_id, 'comments' => $newComment, 'customer_notified' => 0, 'date_added' => date("Y-m-d H:i:s"));
     $this->_klarnaDB->perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_arr);
     xtc_db_query("UPDATE " . TABLE_ORDERS . " SET orders_status='" . $order_status_id . "' WHERE orders_id='" . $orderId . "'");
 }
 /**
  * Constructor.
  * Takes information from GET and sends it to KlarnaAjax and
  * the Dispatcher.
  */
 public function __construct()
 {
     $country = $_GET['country'];
     $option = str_replace('klarna_box_', '', $_GET['type']);
     if ($option == 'special') {
         $option = 'spec';
     }
     KlarnaUtils::configureKiTT($option);
     KlarnaUtils::configureKlarna($option);
     $dispatcher = KiTT::ajaxDispatcher(new KiTT_Addresses(KiTT::api($country)), null);
     $dispatcher->dispatch();
 }
 /**
  * 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;
 }
 /**
  * Show the PClasses
  *
  * @param array  $eid_array array of eids and secrets
  * @param string $option    payment option
  *
  * @return void
  */
 public function showPClasses($eid_array, $option)
 {
     self::configureKlarna($option);
     if ($_GET['get_pclasses'] == true) {
         $pcstorage = new MySQLStorage();
         $pcstorage->clear(KlarnaConstant::pcURI());
     }
     $data = array();
     $country_data = array();
     foreach (KlarnaConstant::getActivated($option) as $country) {
         $country = strtolower($country);
         try {
             if ($_GET['get_pclasses'] == true) {
                 KiTT::api($country)->fetchPClasses();
             }
             foreach (KiTT::api($country)->getPClasses() as $pclass) {
                 $country_data['country'][] = array('country' => $country, 'id' => $pclass->getId(), 'months' => $pclass->getMonths(), 'interestrate' => $pclass->getInterestRate(), 'invoicefee' => $pclass->getInvoiceFee(), 'startfee' => $pclass->getStartFee(), 'minamount' => $pclass->getMinAmount(), 'description' => $pclass->getDescription());
             }
         } catch (Exception $e) {
             $data['error']['country'][] = array('country' => $country, 'message' => $e->getMessage(), 'code' => $e->getCode());
         }
     }
     $data['success'] = $country_data;
     $templateLoader = KiTT::templateLoader(KiTT::Locale($this->_country));
     $fetch = $templateLoader->load('fetched_pclasses.mustache');
     echo $fetch->render($data);
 }
 /**
  * Implements any checks or processing on the order information before
  * proceeding to payment confirmation.
  *
  * @return array
  */
 public function confirmation()
 {
     $logo_base = KlarnaUtils::getStaticPath() . 'logo/';
     $country = strtolower($this->_locale->getCountryCode());
     $url_base = "<a href='http://www.klarna.com' target='_blank'>";
     $desc = '';
     if ($this->_isInvoice()) {
         $type = 'invoice';
     }
     if ($this->_isPart()) {
         $type = 'account';
     }
     if ($this->_isSpec()) {
         $type = 'special';
         $desc = '<br>' . KiTT::api($country)->getPClass($_POST['klarna_spec_paymentPlan'])->getDescription();
     }
     $css = "<link href='" . KlarnaUtils::getStaticPath() . "images.css' type='text/css' rel='stylesheet'/>";
     $logo = "<span class='klarna_logo_{$type}_{$country}'></span>";
     $title = "{$css}<br />{$url_base}{$logo}</a>{$desc}";
     return array('title' => $title);
 }