Пример #1
0
 private function getViewData($product)
 {
     if (!class_exists('KlarnaAPI')) {
         require JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarnaapi.php';
     }
     if (!class_exists('VirtueMartModelCurrency')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'currency.php';
     }
     $price = $product->prices['salesPrice'];
     $country = $this->cData['country'];
     $lang = $this->cData['language_code'];
     $types = array(KlarnaPClass::CAMPAIGN, KlarnaPClass::ACCOUNT, KlarnaPClass::FIXED);
     $kCheckout = new KlarnaAPI($country, $lang, 'part', $price, KlarnaFlags::PRODUCT_PAGE, $this->klarna, $types, $this->path);
     $kCheckout->setCurrency($this->cData['currency']);
     // TODO : Not top to get setup  values here!
     $this->settings = $kCheckout->getSetupValues();
     if ($price > 0 && count($kCheckout->aPClasses) > 0) {
         $currencydisplay = CurrencyDisplay::getInstance();
         $sMonthDefault = NULL;
         $sTableHtml = "";
         // either in vendor's currency, or shipTo Currency
         $countryCurrencyId = ShopFunctions::getCurrencyIDByName($this->cData['currency_code']);
         $currency = CurrencyDisplay::getInstance($countryCurrencyId);
         $fromCurrency = $currency->getCurrencyForDisplay();
         //$paymentCurrency = CurrencyDisplay::getInstance($this->cart->paymentCurrency);
         //$totalInPaymentCurrency = $paymentCurrency->priceDisplay( $this->cart->pricesUnformatted['billTotal'],$this->cart->paymentCurrency) ;
         //$currencyDisplay = CurrencyDisplay::getInstance($this->cart->pricesCurrency);
         $i = 0;
         foreach ($kCheckout->aPClasses as $pclass) {
             if ($sMonthDefault === NULL || $pclass['monthlyCost'] < $sMonthDefault) {
                 $sMonthDefault = $currency->priceDisplay($pclass['monthlyCost'], $countryCurrencyId);
             }
             if ($pclass['pclass']->getType() == KlarnaPClass::ACCOUNT) {
                 $pp_title = JText::_('VMPAYMENT_KLARNA_PPBOX_ACCOUNT');
             } else {
                 $pp_title = $pclass['pclass']->getMonths() . " " . JText::_('VMPAYMENT_KLARNA_PPBOX_TH_MONTH');
             }
             $pp_price = $currency->priceDisplay($pclass['monthlyCost'], $countryCurrencyId);
             $monthTable[$i] = array('pp_title' => html_entity_decode($pp_title), 'pp_price' => $pp_price, 'country' => $country);
             $i++;
         }
         $cd = CurrencyDisplay::getInstance($fromCurrency);
         $aInputValues = array();
         $aInputValues['defaultMonth'] = $sMonthDefault;
         $aInputValues['monthTable'] = $monthTable;
         $aInputValues['eid'] = $this->cData['eid'];
         $aInputValues['country'] = KlarnaCountry::getCode($country);
         if ($country == KlarnaCountry::DE) {
             $aInputValues['asterisk'] = '*';
         } else {
             $aInputValues['asterisk'] = '';
         }
         //$aInputValues['nlBanner'] = (($country == KlarnaCountry::NL) ? '<div class="nlBanner"><img src="' . VMKLARNAPLUGINWEBASSETS . '/images/account/' . $notice . '" /></div>' : "");
         return $aInputValues;
         // return $kCheckout->retrieveHTML($aInputValues, null, JPATH_VMKLARNAPLUGIN . '/klarna/tmpl/productprice_layout.html');
     }
     return NULL;
 }
Пример #2
0
 /**
  * @param $pid
  * @param $totalSum
  * @return string
  */
 function displayPclass($pid, $totalSum)
 {
     if (!class_exists('KlarnaAPI')) {
         require JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarnaapi.php';
     }
     $kCheckout = new KlarnaAPI($this->country, $this->lang, 'part', $totalSum, KlarnaFlags::CHECKOUT_PAGE, $this->klarna, array(KlarnaPClass::ACCOUNT, KlarnaPClass::CAMPAIGN, KlarnaPClass::FIXED), JPATH_VMKLARNAPLUGIN);
     return $kCheckout->renderPClass($pid);
 }
 /**
  * @param $product
  * @return array|null
  */
 private function getViewData($product)
 {
     if (!class_exists('KlarnaAPI')) {
         require JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarnaapi.php';
     }
     if (!class_exists('VirtueMartModelCurrency')) {
         require VMPATH_ADMIN . DS . 'models' . DS . 'currency.php';
     }
     $price = $product->prices['salesPrice'];
     $country = $this->cData['country'];
     $lang = $this->cData['language_code'];
     $types = array(KlarnaPClass::CAMPAIGN, KlarnaPClass::ACCOUNT, KlarnaPClass::FIXED);
     try {
         $kCheckout = new KlarnaAPI($country, $lang, 'part', $price, KlarnaFlags::PRODUCT_PAGE, $this->klarna_virtuemart, $types, $this->path);
     } catch (Exception $e) {
         VmDebug('getViewData', 'Error in ' . __METHOD__ . ': ' . $e->getMessage(), $e->getCode());
         VmError($e->getMessage(), 'getViewData' . 'Error in ' . __METHOD__ . ': ' . $e->getMessage(), $e->getCode());
         return NULL;
     }
     $kCheckout->setCurrency($this->cData['currency']);
     // TODO : Not top to get setup  values here!
     $this->settings = $kCheckout->getSetupValues();
     if ($price > 0 && count($kCheckout->aPClasses) > 0) {
         $currencydisplay = CurrencyDisplay::getInstance();
         $sMonthDefault = NULL;
         $sTableHtml = "";
         $monthTable = array();
         // either in vendor's currency, or shipTo Currency
         $countryCurrencyId = $this->cData['virtuemart_currency_id'];
         $currency = CurrencyDisplay::getInstance($countryCurrencyId);
         $fromCurrency = $currency->getCurrencyForDisplay();
         //$paymentCurrency = CurrencyDisplay::getInstance($this->cart->paymentCurrency);
         //$totalInPaymentCurrency = $paymentCurrency->priceDisplay( $this->cart->cartPrices['billTotal'],$this->cart->paymentCurrency) ;
         //$currencyDisplay = CurrencyDisplay::getInstance($this->cart->pricesCurrency);
         $i = 0;
         foreach ($kCheckout->aPClasses as $pclass) {
             if ($sMonthDefault === NULL || $pclass['monthlyCost'] < $sMonthDefault) {
                 $sMonthDefault = $currency->priceDisplay($pclass['monthlyCost'], $countryCurrencyId);
             }
             if ($pclass['pclass']->getType() == KlarnaPClass::ACCOUNT) {
                 $pp_title = tsmText::_('VMPAYMENT_KLARNA_PPBOX_ACCOUNT');
             } else {
                 $pp_title = $pclass['pclass']->getMonths() . " " . tsmText::_('VMPAYMENT_KLARNA_PPBOX_TH_MONTH');
             }
             $pp_price = $currency->priceDisplay($pclass['monthlyCost'], $countryCurrencyId);
             $monthTable[$i] = array('pp_title' => html_entity_decode($pp_title), 'pp_price' => $pp_price, 'country' => $country);
             $i++;
         }
         $cd = CurrencyDisplay::getInstance($fromCurrency);
         $aInputValues = array();
         $aInputValues['defaultMonth'] = $sMonthDefault;
         $aInputValues['monthTable'] = $monthTable;
         $aInputValues['eid'] = $this->cData['eid'];
         $aInputValues['country'] = KlarnaCountry::getCode($country);
         if ($country == KlarnaCountry::DE) {
             $aInputValues['asterisk'] = '*';
         } else {
             $aInputValues['asterisk'] = '';
         }
         return $aInputValues;
     }
     return NULL;
 }
Пример #4
0
 /**
  * Fetch data from the language pack
  *
  * @param    string    $sText    The text to fech
  * @return    string
  */
 public function fetchFromLanguagePack($sText)
 {
     if ($this != null && $this->sLangISO != null) {
         $sISO = strtolower($this->sLangISO);
     } else {
         $sISO = KlarnaAPI::getISOCode();
     }
     $oXml = simplexml_load_file($this->sPath . '/klarna_files/klarna_language.xml');
     $aResult = (array) @$oXml->xpath("//string[@id='{$sText}']/{$sISO}");
     $aResult = (array) @$aResult[0];
     return @$aResult[0];
 }
Пример #5
0
 /**
  * Fetch data from the language pack
  *
  * @param    string    $sText    The text to fech
  * @param null         $sISO
  * @param null         $sPath
  * @return    string
  * @deprecated
  */
 public function fetchFromLanguagePack($sText, $sISO = NULL, $sPath = NULL)
 {
     if ($sISO == NULL) {
         if ($this != NULL && $this->sLangISO != NULL) {
             $sISO = strtolower($this->sLangISO);
         } else {
             $sISO = KlarnaAPI::getISOCode();
         }
     } else {
         $sISO = KlarnaAPI::getISOCode($sISO);
     }
     if ($this->sPath != NULL) {
         $sPath = $this->sPath;
     }
     if ($this->languagePack == NULL) {
         $this->languagePack = new KlarnaLanguagePack(JPATH_VMKLARNAPLUGIN . '/klarna/language/klarna_language.xml');
     }
     return $this->languagePack->fetch($sText, $sISO);
 }
Пример #6
0
 /**
  * @return null
  * @throws KlarnaApiException
  */
 public function languagepack()
 {
     $sSubAction = JRequest::getWord('subAction');
     if (!isset($this->template['name']) || $this->template['name'] == '') {
         $this->template['name'] = "default";
     }
     if ($sSubAction == "klarna_box") {
         $sNewISO = JRequest::getWord('newIso');
         $sCountry = JRequest::getWord('country');
         $iSum = JRequest::getFloat('sum', 0);
         $iInvoiceFee = JRequest::getFloat('fee', 0);
         $iFlag = JRequest::getInt('flag');
         $sType = JRequest::getWord('type');
         $aParams = JRequest::getVar('params');
         $aValues = JRequest::getVar('values');
         // foreach($aValues as $key => $value) {
         // $aValues[$key] = utf8_encode($value);
         // }
         // foreach($aParams as $key => $value) {
         // $aParams[$key] = utf8_decode($value);
         // }
         if ($sType != "part" && $sType != "invoice" && $sType != "spec") {
             throw new KlarnaApiException("Invalid parameters");
         }
         $this->api->setCountry($sCountry);
         if ($sType == 'spec') {
             $types = array(KlarnaPClass::SPECIAL);
         } else {
             $types = array(KlarnaPClass::CAMPAIGN, KlarnaPClass::ACCOUNT, KlarnaPClass::FIXED);
         }
         $oApi = new KlarnaAPI($sCountry, $sNewISO, $sType, $iSum, $iFlag, $this->api, $types, VMKLARNAPLUGINWEBROOT);
         // $oApi->addSetupValue ('web_root', $this->webroot);
         // $oApi->setPaths ();
         $oApi->addSetupValue('eid', $this->eid);
         if ($sType == 'invoice') {
             $oApi->setInvoiceFee($iInvoiceFee);
         }
         $oApi->setCurrency($this->api->getCurrency());
         if (count($this->coSetup) > 0) {
             $oApi->addMultipleSetupValues($this->coSetup);
         }
         return $oApi->retrieveLayout($aParams, $aValues);
         // if ($sType == 'spec') {
         // return $oApi->retrieveHTML($aParams, $aValues, null, $this->template);
         // } else {
         // return $oApi->retrieveHTML ($aParams, $aValues);
         // }
     } else {
         if ($sSubAction == 'jsLanguagePack') {
             $sNewISO = JRequest::getWord('newIso');
             $sFetch = "";
         } else {
             throw new KlarnaApiException("Invalid sub-action");
         }
     }
 }
Пример #7
0
 public function __construct($a_sCountry, $a_sLangISO, $a_sType, $a_iSum, $a_iFlag, &$a_oKlarna = null, $aTypes = null, $sPath = null)
 {
     parent::__construct($a_sCountry, $a_sLangISO, $a_sType, $a_iSum, $a_iFlag, $a_oKlarna, $aTypes, $sPath);
 }