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; }
/** * @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; }
/** * @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"); } } }