/**
  * 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 . "'");
 }
 /**
  * Create the instance of this payment method translator
  *
  * @param string $lang language iso code
  */
 public function __construct($lang)
 {
     if ($lang === null) {
         $lang = 'en';
     }
     KlarnaUtils::configureKITT();
     $this->_translator = KiTT::translator(KiTT::locale(null, $lang));
 }
 /**
  * Load the json and store it's values
  *
  * @return void
  */
 protected function loadDefinitions()
 {
     $path = KiTT::configuration()->get('paths/input');
     $fileContent = $this->_vfs->file_get_contents($path);
     $temp = json_decode($fileContent, true);
     $this->fields = $temp['fields'];
     $this->countries = $temp['country_fields'];
 }
 /**
  * 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();
 }
 /**
  * Show information
  *
  * @return void
  */
 function process()
 {
     global $order;
     $od_amount = $this->calculateInvoiceFee();
     //Disable module when $od_amount is <= 0
     if ($od_amount <= 0) {
         $this->enabled = false;
         return;
     }
     $formatter = new XtcFormatter();
     $this->output[] = array('title' => $this->title . ':', 'text' => KITT_String::decode($formatter->formatPrice($od_amount, KiTT::locale($this->_country)), "UTF-8", "ISO-8859-15"), 'value' => $od_amount);
     $order->info['total'] += $od_amount;
 }
 /**
  * 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;
 }
 /**
  * Check if pclasses for given option exists and show warning if it doesn't
  *
  * @param string $option 'part' or 'spec'
  *
  * @return void
  */
 public function checkForPClasses($option)
 {
     $sql = "";
     $module = "";
     if ($option == KiTT::PART) {
         $module = 'Part Payment Module';
         $sql = "type <> 2";
     } else {
         if (KiTT::SPEC) {
             $module = 'Special Campaigns Module';
             $sql = "type = 2";
         } else {
             return;
         }
     }
     if (KlarnaConstant::isEnabled($option, $this->_country)) {
         // instantiate MySQLStorage to ensure the table exists
         $pcURI = KlarnaConstant::pcURI();
         $pcstorage = new MySQLStorage();
         $pcstorage->load($pcURI);
         $count = $this->_klarnaDB->query("SELECT COUNT(type) as num FROM klarna_pclasses WHERE {$sql}")->getArray();
         if ($count['num'] == 0 && !isset($_GET['get_pclasses']) && headers_sent()) {
             $templateLoader = KiTT::templateLoader(KiTT::Locale($this->_country));
             $no_pclasses = $templateLoader->load('no_pclasses.mustache');
             echo $no_pclasses->render(array('module' => $module));
         }
     }
 }
 /**
  * Show the ppBox for given price.
  *
  * @param float $price price
  * @param int   $page  KlarnaFlags page flag
  *
  * @return void
  */
 public function showPPBox($price, $page = KlarnaFlags::PRODUCT_PAGE)
 {
     if (!$this->_enabled) {
         return;
     }
     if (!KiTT_CountryLogic::isBelowLimit($this->_country, $price)) {
         return;
     }
     $templateLoader = KiTT::templateLoader($this->_locale);
     $cssLoader = $templateLoader->load('css.mustache');
     $jsLoader = $templateLoader->load('javascript.mustache');
     $merchantID = KlarnaConstant::merchantID(KiTT::PART, $this->_country);
     $styles = array("includes/external/klarna/template/css/oscstyle.css", "includes/modules/payment/klarna/productprice/style.css", EXTERNAL_KITT . "pp/v1.0/pp.css?eid=" . $merchantID);
     if (KlarnaConstant::isLegacyShop()) {
         $styles[] = "includes/external/klarna/template/css/klarna22rc2a.css";
     }
     $html = $cssLoader->render(array('styles' => $styles));
     $html .= $jsLoader->render(array("scripts" => array(EXTERNAL_KITT . "core/v1.0/js/klarna.min.js", EXTERNAL_KITT . "res/v1.0/js/klarna.lib.min.js", EXTERNAL_KITT . "pp/v1.0/js/productprice.min.js")));
     $html .= "<div style='clear: both;'></div>";
     $html .= KiTT::partPaymentBox($this->_locale, $price, $page)->show();
     return $html;
 }
Example #9
0
 /**
  *  Gets a Lookup object.
  *
  * Requires configuration to be made with a lookup path to a json containing
  * a lookup table.
  *
  * @return KiTT_Lookup
  */
 public static function lookup()
 {
     if (self::$_lookup === null) {
         self::$_lookup = new KiTT_Lookup(self::configuration(), self::vfs());
     }
     return self::$_lookup;
 }
 /**
  * Build and return the title for the admin backend.
  *
  * @return string
  */
 private function _title()
 {
     $tulip = '<span class="klarna_icon"> </span>';
     if ($this->_isInvoice()) {
         return $tulip . KiTT::translator($this->_locale)->translate('MODULE_INVOICE_TEXT_TITLE');
     }
     if ($this->_isPart()) {
         return $tulip . KiTT::translator($this->_locale)->translate('MODULE_PARTPAY_TEXT_TITLE');
     }
     if ($this->_isSpec()) {
         return $tulip . KiTT::translator($this->_locale)->translate('MODULE_SPEC_TEXT_TITLE');
     }
 }