AAAAklarna/helpers/define.php 0000666 00000003775 15137314773 0011454 0 ustar 00 set_language($HTTP_GET_VARS['language']); } else { $lng->get_browser_language(); } $language = $lng->language['directory']; $languages_id = $lng->language['id']; $product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$mProductId . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'"); $aProduct_info = tep_db_fetch_array($product_info_query); $sArtNo = (MODULE_PAYMENT_KLARNA_ARTNO == 'id' || MODULE_PAYMENT_KLARNA_ARTNO == '' ? $aProduct_info['id'] : $aProduct_info['name']); $iTax = tep_get_tax_rate($aProduct_info['products_tax_class_id']); if(DISPLAY_PRICE_WITH_TAX == 'true') { $iPrice_with_tax = $currencies->get_value($currency) * $aProduct_info['products_price']; } else { $iPrice_with_tax = $currencies->get_value($currency) * $aProduct_info['products_price'] * (($iTax/100)+1); } // Add goods $this->oKlarna->addArticle( 1, //Quantity $sArtNo, //Article number $aProduct_info['products_name'], //Article name/title $iPrice_with_tax, // Price $iTax, //25% VAT 0, // Discount KlarnaFlags::INC_VAT // Flag incl. excl vat ); $this->iSum += $iPrice_with_tax; } /** * When a purchase is made, the script returns an redirect-URL or a message. When the URL is returned, the user is re-directed to this page. * This could be an URL to a downloadable file (WARNING! SHOULD ALWAYS BE A DYNAMIC URL!), or a link to a "Thank you"/confirmation page (Comon for donation purposes) * * @param mixed $mProductId The product identified. Either int or string. Adapted according shop functionality * @return mixed Either NULL or FALSE if no URL is available, or STRING with full URL when URL is available. */ protected function fetchRedirectUrl ($mProductId) { return "http://www.klarna.com"; } /** * When a purchase is made (approved as well) it might needs to be added to the merchants order system. In this function you can define how the order of a product should be handled. * * @param mixed $mProductId The product identified. Either int or string. Adapted according shop functionality * @param integer $iKlarnaReference The reference returned by Klarna * @param string $sTelNo The telephone number used to make a purchase * @return void */ protected function processOrder ($mProductId, $iKlarnaReference, $iTelNo) { // Here you should implement the functionality of how the product is managed. } } klarna/helpers/klarnaapi.php 0000666 00000066627 15137314773 0012171 0 ustar 00 sPath = $sPath; if ($a_sLangISO == NULL) { $aLangArray = array( "swe" => "sv", "deu" => "de", "dnk" => "da", "nld" => "nl", "nor" => "nb", "fin" => "fi", "en" => "en"); $a_sLangISO = @$aLangArray[strtolower ($a_sCountry)]; } // Set the klarna object $this->oKlarna = &$a_oKlarna; // Validate the submitted values $this->setCountry ($a_sCountry); $this->setLanguage ($a_sLangISO); $this->validateType ($a_sType); /* // Set the default input names $this->aInputParameters['street'] = "street"; $this->aInputParameters['homenumber'] = "homenumber"; $this->aInputParameters['paymentPlan'] = "paymentPlan"; $this->aInputParameters['gender'] = "gender"; $this->aInputParameters['male'] = "male"; $this->aInputParameters['female'] = "female"; $this->aInputParameters['birth_day'] = "birth_day"; $this->aInputParameters['birth_month'] = "birth_month"; $this->aInputParameters['birth_year'] = "birth_year"; $this->aInputParameters['bd_jan'] = "1"; $this->aInputParameters['bd_feb'] = "2"; $this->aInputParameters['bd_mar'] = "3"; $this->aInputParameters['bd_apr'] = "4"; $this->aInputParameters['bd_may'] = "5"; $this->aInputParameters['bd_jun'] = "6"; $this->aInputParameters['bd_jul'] = "7"; $this->aInputParameters['bd_aug'] = "8"; $this->aInputParameters['bd_sep'] = "9"; $this->aInputParameters['bd_oct'] = "10"; $this->aInputParameters['bd_nov'] = "11"; $this->aInputParameters['bd_dec'] = "12"; $this->aInputParameters['socialNumber'] = "socialNumber"; $this->aInputParameters['phoneNumber'] = "phoneNumber"; $this->aInputParameters['year_salary'] = "year_salary"; $this->aInputParameters['house_extension'] = "house_extension"; $this->aInputParameters['shipmentAddressInput'] = "shipment_address"; $this->aInputParameters['emailAddress'] = "emailAddress"; $this->aInputParameters['invoiceType'] = "invoiceType"; $this->aInputParameters['reference'] = "reference"; $this->aInputParameters['companyName'] = "companyName"; $this->aInputParameters['firstName'] = "firstName"; $this->aInputParameters['lastName'] = "lastName"; $this->aInputParameters['invoice_type'] = "invoice_type"; $this->aInputParameters['consent'] = "consent"; $this->aInputParameters['city'] = "city"; $this->aInputParameters['zipcode'] = "zipcode"; // Set the default setup values $this->aSetupSettings['langISO'] = $this->sLangISO; $this->aSetupSettings['countryCode'] = $this->sCountryCode; $this->aSetupSettings['sum'] = $a_iSum; $this->aSetupSettings['flag'] = $a_iFlag; $this->aSetupSettings['payment_id'] = "payment"; $this->aSetupSettings['invoice_name'] = 'klarna_invoice'; $this->aSetupSettings['part_name'] = 'klarna_partPayment'; $this->aSetupSettings['spec_name'] = 'klarna_SpecCamp'; */ // $this->aSetupSettings['web_root'] = "/"; //$this->setPaths(); //$this->country=$this->getCountry(); //?????? // Fetch PClasses in case type is invoice if (($this->sType == 'part' || $this->sType == 'spec') && $this->oKlarna != NULL) { $this->fetchPClasses ($a_iSum, $a_iFlag, $aTypes); } } // public function setPaths() { // $this->aSetupSettings['path_css'] = $this->aSetupSettings['web_root'].VMKLARNAPLUGINWEBROOT. '/klarna/assets/css/'; // $this->aSetupSettings['path_js'] = $this->aSetupSettings['web_root'] .VMKLARNAPLUGINWEBROOT. '/klarna/assets/js/'; // $this->aSetupSettings['path_img'] = $this->aSetupSettings['web_root'] .VMKLARNAPLUGINWEBROOT. '/klarna/assets/images/'; // } /** * Add/Overwrite extra setup values. * * @param string $sName The name of the value * @param string $sValue The value * @return void * @deprecated */ public function addSetupValue ($sName, $sValue) { $this->aSetupSettings[$sName] = $sValue; } /** * Add multiple setup values at once * * @param array $aSetupValues The setup values as array. Key is name, value is value. * @return void * * @deprecated */ public function addMultipleSetupValues ($aSetupValues) { foreach ($aSetupValues as $sName => $sValue) { $this->aSetupSettings[$sName] = $sValue; } } public function getSetupValues () { return $this->aSetupSettings; } /** * Add/Overwrite input values. * * @param string $sName The name of the value * @param string $sValue The value * @return void * @deprecated */ public function addInputValue ($sName, $sValue) { $this->aInputValue[$sName] = $sValue; } /** * Add multiple input values at once * * @param array $aSetupValues The setup values as array. Key is name, value is value. * @return void */ public function addMultipleInputValues ($aInputValues) { foreach ($aInputValues as $sName => $sValue) { $this->aInputValue[$sName] = $sValue; } } /* * * @deprecated */ public function getInputValues () { return $this->aInputValues; } /* * @deprecated * */ public function setInvoiceFee ($fee) { if ($this->sType != 'invoice') { throw new KlarnaApiException("Invoice fee only supported when payment type is invoice"); } $this->aSetupSettings['fee'] = round (floatval ($fee), 1); } /** * Retrieve the finished HTML * * @param array $a_aParams The input field names. Only submitted for those that should be different from default values * @param string $a_sHTMLFile (Optional) The file to import. If not submitted, which HTML file will be decides by the class * @return string * @deprecated */ public function retrieveHTML ($a_aParams = NULL, $a_aValues = NULL, $a_sHTMLFile = NULL, $aTemplateData = NULL) { if ($a_aValues != NULL) { $this->aInputValues = array_merge ( $this->aInputValues, $a_aValues); } if ($a_aParams != NULL) { $this->aInputParameters = array_merge ( $this->aInputParameters, $a_aParams); } // print_r($this->aInputValues); // Backwards compability // using input values for red baloon is DEPRECATED if (array_key_exists ('red_baloon_content', $this->aInputValues)) { $this->aSetupSettings['red_baloon_content'] = $this->aInputValues['red_baloon_content']; } if (array_key_exists ('red_baloon_paymentBox', $this->aInputValues)) { $this->aSetupSettings['red_baloon_paymentBox'] = $this->aInputValues['red_baloon_paymentBox']; } if (is_array ($this->aPClasses)) { foreach ($this->aPClasses as $pclass) { if ($pclass['default'] === TRUE) { $this->aInputValues['paymentPlan'] = $pclass['pclass']->getId (); break; } } } $sTemplate = $this->loadTemplate ($a_sHTMLFile, $aTemplateData); Klarna::printDebug (__METHOD__ . ' setup settings', $this->aSetupSettings); Klarna::printDebug (__METHOD__ . ' input values', $this->aInputValues); return $this->translateInputFields ($sTemplate); } /** * @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); } /** * Fetch the PClasses from file * * @param integer $iSum The sum of the objects to be bought * @param integer $iFlag The KlarnaFlag to be used. Either Checkout or ProductPage flag. * @return void */ public function fetchPClasses ($iSum, $iFlag, $aTypes = NULL) { if ($this->oKlarna == NULL) { throw new KlarnaApiException("No klarna class is set.", "1000"); } $aPClasses = array(); $default = NULL; foreach ($this->oKlarna->getPClasses () as $pclass) { if ($aTypes == NULL || in_array ($pclass->getType (), $aTypes)) { $sType = $pclass->getType (); if ($sType != KlarnaPClass::SPECIAL) { if ($iSum < $pclass->getMinAmount ()) { continue; } if ($pclass->getType () == KlarnaPClass::FIXED) { if ($iFlag == KlarnaFlags::PRODUCT_PAGE) { continue; } $iMonthlyCost = -1; } else { $lowest_payment = KlarnaCalc::get_lowest_payment_for_account ($pclass->getCountry ()); $iMonthlyCost = KlarnaCalc::calc_monthly_cost ($iSum, $pclass, $iFlag); if ($iMonthlyCost < 0.01) { continue; } if ($iFlag == KlarnaFlags::CHECKOUT_PAGE && $pclass->getType () == KlarnaPClass::ACCOUNT && $iMonthlyCost < $lowest_payment) { $iMonthlyCost = $lowest_payment; } if ($pclass->getType () == KlarnaPClass::CAMPAIGN && $iMonthlyCost < $lowest_payment) { continue; } } } else { $iMonthlyCost = -1; } if ($this->sType == 'part') { if ($sType == KlarnaPClass::ACCOUNT) { $default = $pclass; } else { if ($sType == KlarnaPClass::CAMPAIGN) { if ($default === NULL || $default->getType () != KlarnaPClass::ACCOUNT) { $default = $pclass; } } else { if ($sType == KlarnaPClass::FIXED) { if ($default === NULL) { $default = $pclass; } } else { continue; } } } } else { if ($this->sType == 'spec') { if ($sType != KlarnaPClass::SPECIAL) { continue; } $default = $pclass; } } $aPClasses[$pclass->getId ()]['pclass'] = $pclass; $aPClasses[$pclass->getId ()]['monthlyCost'] = $iMonthlyCost; $aPClasses[$pclass->getId ()]['default'] = FALSE; } } if ($default !== NULL) { $aPClasses[$default->getId ()]['default'] = TRUE; } $this->aPClasses = $aPClasses; } /** * Checks whether the country code is accepted by the API * * @throws KlarnaApiException * @param string $sCountryCode The country code ISO-2 * @return boolean */ private function validateCountry ($sCountryCode) { if (in_array (strtolower ($sCountryCode), array("nl", "se", "de", "dk", "no", "fi"))) { $this->sCountryCode = strtolower ($sCountryCode); switch ($this->sCountryCode) { case "nl": $this->iKlarnaCountry = KlarnaCountry::NL; $this->iKlarnaCurrency = KlarnaCurrency::EUR; break; case "se": $this->iKlarnaCountry = KlarnaCountry::SE; $this->iKlarnaCurrency = KlarnaCurrency::SEK; break; case "de": $this->iKlarnaCountry = KlarnaCountry::DE; $this->iKlarnaCurrency = KlarnaCurrency::EUR; break; case "dk": $this->iKlarnaCountry = KlarnaCountry::DK; $this->iKlarnaCurrency = KlarnaCurrency::DKK; break; case "no": $this->iKlarnaCountry = KlarnaCountry::NO; $this->iKlarnaCurrency = KlarnaCurrency::NOK; break; case "fi": $this->iKlarnaCountry = KlarnaCountry::FI; $this->iKlarnaCurrency = KlarnaCurrency::EUR; break; default: break; } return TRUE; } else { throw new KlarnaApiException('Error in ' . __METHOD__ . ': Invalid country code submitted!'); } } /** * Checks whether the country code is accepted by the API * * @throws KlarnaApiException * @param string $sType The type. Either "part", "spec" or "invoice" * @return boolean */ private function validateType ($sType) { if (in_array (strtolower ($sType), array("part", "invoice", "spec"))) { $this->sType = strtolower ($sType); return TRUE; } else { throw new KlarnaApiException('Error in ' . __METHOD__ . ': Invalid type submitted!'); } } /** * Sets the active country from a ISO country string * or a KlarnaCountry constant */ public function setCountry ($country) { if (!is_numeric ($country)) { $country = KlarnaCountry::fromCode ($country); } else { $country = intval ($country); } if ($this->oKlarna == NULL) { throw new KlarnaApiException('Error in ' . __METHOD__ . ': Klarna instance not set'); } $this->iKlarnaCountry = $country; $this->iKlarnaCurrency = $this->oKlarna->getCurrencyForCountry ($country); $this->sCountryCode = $this->oKlarna->getCountryCode ($country); } public function getCountry () { return $this->iKlarnaCountry; } /** * Sets the active country from a ISO country string * or a KlarnaLanguage constant */ public function setLanguage ($language) { if (!is_numeric ($language)) { $language = Klarna::getLanguageForCode ($language); } else { $language = intval ($language); } $this->iKlarnaLanguage = $language; if ($this->oKlarna == NULL) { throw new KlarnaApiException('Error in ' . __METHOD__ . ': Klarna instance not set'); } $this->sLangISO = $this->oKlarna->getLanguageCode ($language); } public function getLanguage () { return $this->iKlarnaLanguage; } /** * Checks whether the country code is accepted by the API * * @throws KlarnaApiException * @param string $a_sLangISO The language in ISO-2 format * @return boolean * @deprecated */ private function validateLangISO ($a_sLangISO) { if (in_array (strtolower ($a_sLangISO), array("sv", "da", "en", "de", "nl", "nb", "fi"))) { $this->sLangISO = strtolower ($a_sLangISO); switch ($this->sLangISO) { case "sv": $this->iKlarnaLanguage = KlarnaLanguage::SV; break; case "da": $this->iKlarnaLanguage = KlarnaLanguage::DA; break; case "de": $this->iKlarnaLanguage = KlarnaLanguage::DE; break; case "nl": $this->iKlarnaLanguage = KlarnaLanguage::NL; break; case "nb": $this->iKlarnaLanguage = KlarnaLanguage::NB; break; case "fi": $this->iKlarnaLanguage = KlarnaLanguage::FI; break; default: break; } return TRUE; } else { throw new KlarnaApiException('Error in ' . __METHOD__ . ': Invalid language (' . $a_sLangISO . ') ISO submitted!'); } } /** * Translating the fetched HTML agains dynamic values set in this class * * @param string $sHtml The HTML to translate * @return string */ private function translateInputFields ($sHtml) { $sHtml = preg_replace_callback ("@{{(.*?)}}@", array($this, 'changeText'), $sHtml); return $sHtml; } /** * Changing the text from a HTML {{VALUE}} to the actual value decided by the array * * @param array $aText The result from the match in function translateInputFields * @return mixed * @deprecated */ private function changeText ($aText) { // Split them $aExplode = explode (".", $aText[1]); $sType = $aExplode[0]; $sName = @$aExplode[1]; if ($sType == "input") { if (array_key_exists ($sName, $this->aInputParameters)) { return $this->aInputParameters[$sName]; } else { throw new KlarnaApiException('Error in ' . __METHOD__ . ': Invalid inputfield value (' . $sName . ') found in HTML code!'); } } else { if ($sType == "lang") { return JText::_ ('VMPAYMENT_KLARNA_' . strtoupper ($sName)); //$this->fetchFromLanguagePack($sName); } else { if ($sType == "setup") { if ($sName == "pclasses") { return $this->renderPClasses (); } if ($sName == 'threatmetrix') { if (!array_key_exists ('threatmetrix', $this->aSetupSettings)) { $this->aSetupSettings['threatmetrix'] = $this->oKlarna-> checkoutHTML (); } return @$this->aSetupSettings['threatmetrix']; } if ($sName == 'additional_information') { $key = @$this->aSetupSettings['additional_information']; $key = 'VMPAYMENT_KLARNA_' . strtoupper ($key); $lang = JFactory::getLanguage (); if ($lang->hasKey ($key)) { $frmt = @JText::_ ($key); //$this->fetchFromLanguagePack($key); return @$this->translateInputFields ($frmt); } else { return ''; } } return @$this->aSetupSettings[$sName]; } else { if ($sType == "value") { return (@$this->aInputValues[$sName]); } else { throw new KlarnaApiException('Error in ' . __METHOD__ . ': Invalid field name (' . $sType . ') found in HTML code!'); } } } } } /** * Redender the PClasses to HTML * * @deprecated * * @return string */ public function renderPClasses () { $sString = ''; foreach ($this->aPClasses as $sPClassId => $aPClassData) { $value = $this->getPresentableValuta ($aPClassData['monthlyCost']); $pm = JText::_ ('VMPAYMENT_KLARNA_PER_MONTH'); $sString .= '
' :
'') .
'
' :
'');
$pClasses[$i]['string'] = $sString;
$pClasses[$i]['classId'] = $sPClassId;
$i++;
}
return $pClasses;
}
/**
* Redender the PClasses to HTML
*
* @return string
*/
public function renderPClass ($pid) {
$sString = "";
foreach ($this->aPClasses as $sPClassId => $aPClassData) {
if ($aPClassData['pclass']->getId () == $pid) {
$value = $this->getPresentableValuta ($aPClassData['monthlyCost']);
$pm = JText::_ ('VMPAYMENT_KLARNA_PER_MONTH');
$sString .= $aPClassData['pclass']->getDescription () . ($aPClassData['monthlyCost'] > 0 ? " - $value $pm" : '');
return $sString;
}
}
return $sString;
}
/**
* Make the sum shown presentable
*
* @param integer $iSum The sum to present
* @return string
*/
/* private */
function getPresentableValuta ($iSum) {
$sBefore = "";
$sAfter = "";
switch (strtolower($this->sCountryCode)) {
case 'se':
$sAfter = " kr";
break;
case 'no':
$sAfter = " NOK";
break;
case 'dk':
$sAfter = " DKK";
break;
case 'fi';
$sBefore = "EUR";
break;
case 'de';
case 'nl';
$sBefore = "€";
break;
}
return $sBefore . $iSum . $sAfter;
}
public function setCurrency ($currency) {
if (!is_numeric ($currency)) {
$currency = KlarnaCurrency::fromCode ($currency);
}
else {
$currency = intval ($currency);
}
switch ($currency) {
case KlarnaCurrency::SEK:
case KlarnaCurrency::NOK:
case KlarnaCurrency::DKK:
$this->addSetupValue ('currency_suffix', ' kr');
$this->addSetupValue ('currency_prefix', '');
break;
case KlarnaCurrency::EUR:
$this->addSetupValue ('currency_prefix', '€');
$this->addSetupValue ('currency_suffix', '');
break;
default:
$this->addSetupValue ('currency_suffix', '');
$this->addSetupValue ('currency_prefix', '');
break;
}
}
/**
* 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);
}
/**
* Returns the country code for the set country constant.
*
* @return string
*/
public function getISOCode ($sCode = NULL) {
switch (strtolower ($sCode)) {
case "se":
case "sv":
return "sv";
case "no":
case "nb":
return "nb";
case "dk":
case "da":
return "da";
case "fi":
return "fi";
case "de":
return "de";
case "nl":
return "nl";
case "us":
case "uk":
case "en":
default:
return "en";
}
}
public function displayError ($message, $field = NULL) {
// Append message
if (array_key_exists ('red_baloon_content', $this->aSetupSettings)) {
$this->aSetupSettings['red_baloon_content'] =
$this->aSetupSettings['red_baloon_content'] .
'[Error: {$this->code}]: {$this->message}
\n"; } } klarna/helpers/klarna_payments.php 0000666 00000027712 15137314773 0013407 0 ustar 00 shipTo = $shipTo; $this->country = $cData['country_code']; $this->country_code_3 = $cData['country_code_3']; $this->currency = $cData['currency_code']; $this->virtuemart_currency_id = $cData['virtuemart_currency_id']; //$this->currency = $vendor_currency; // Get EID and Secret $this->eid = $cData['eid']; $this->secret = $cData['secret']; $this->lang = $cData['language_code']; // Is Invoice enabled? $this->enabled = TRUE; // Set modes $this->mode = $cData['mode']; $this->ssl = KlarnaHandler::getKlarnaSSL ($this->mode); $this->web_root = JURI::base (); try { $this->klarna = new Klarna_virtuemart(); $this->klarna->config ($this->eid, $this->secret, $this->country, $this->lang, $this->currency, $this->mode, VMKLARNA_PC_TYPE, KlarnaHandler::getKlarna_pc_type (), $this->ssl); } catch (Exception $e) { VmError ('klarna_payments', $e); unset($this->klarna); } } /** * Attempt to fill in some of what we've already filled in if we * come back after failing a purchase. */ private function setPreviouslyFilledIn ($klarna_data) { if (($this->country == "nl" ) && isset($klarna_data['pno'])) { $pno = $klarna_data['pno']; $this->klarna_bday['year'] = substr ($pno, 4, 4); $this->klarna_bday['month'] = substr ($pno, 2, 2); $this->klarna_bday['day'] = substr ($pno, 0, 2); } elseif ( $this->country == "de") { $pno = $klarna_data['pno']; $this->klarna_bday['year'] = $klarna_data['birth_year']; $this->klarna_bday['month'] = $klarna_data['birth_month']; $this->klarna_bday['day'] = $klarna_data['birth_day']; } else { $this->socialNumber=$klarna_data['socialNumber']; } $this->klarna_street = ((isset($klarna_data['street']) && !isset($this->klarna_street)) ? $klarna_data['street'] : $this->klarna_street); $this->klarna_houseNr = ((isset($klarna_data['house_no']) && !isset($this->klarna_houseNr)) ? $klarna_data['house_no'] : $this->klarna_houseNr); $this->klarna_houseExt = ((isset($klarna_data['house_ext']) && !isset($this->klarna_houseExt)) ? $klarna_data['house_ext'] : $this->klarna_houseExt); $this->klarna_gender = ((isset($klarna_data['gender']) && !isset($this->klarna_gender)) ? $klarna_data['gender'] : $this->klarna_gender); $this->klarna_year_salary = ((isset($klarna_data['year_salary']) && !isset($this->klarna_year_salary)) ? $klarna_data['year_salary'] : $this->klarna_year_salary); } /** * Build the Payment params */ public function get_payment_params ($method, $payment_type, $cart = NULL, $country_currency_code = '', $vendor_currency='') { if (!class_exists ('CurrencyDisplay')) { require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php'); } if (!class_exists ('KlarnaAPI')) { require (JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarnaapi.php'); } $payment_params = array(); $invoice_fee = 0; if (!isset($this->klarna) || !($this->klarna instanceof Klarna_virtuemart)) { return NULL; } $payment_params['payment_currency_info'] = ""; if ($cart->pricesCurrency != $this->virtuemart_currency_id) { $payment_params['payment_currency_info'] = JText::_ ('VMPAYMENT_KLARNA_PAYMENT_CURRENCY_INFO'); } if ($payment_type == 'invoice') { KlarnaHandler::getInvoiceFeeInclTax ($method, $this->country_code_3, $cart->pricesCurrency, $this->virtuemart_currency_id, $display_invoice_fee, $invoice_fee); $billTotalInCountryCurrency = 0; $aTypes = NULL; $payment_params['pClasses'] = NULL; } else { $display_fee = 0; $billTotalInCountryCurrency = 0; if (isset($cart->pricesUnformatted['billTotal'])) { $billTotalInCountryCurrency = KlarnaHandler::convertPrice ($cart->pricesUnformatted['billTotal'], $vendor_currency, $country_currency_code, $cart->pricesCurrency); } if ($billTotalInCountryCurrency <= 0) { return NULL; } //$aTypes = array(KlarnaPClass::ACCOUNT, KlarnaPClass::CAMPAIGN, KlarnaPClass::FIXED); $aTypes = array(KlarnaPClass::ACCOUNT, KlarnaPClass::CAMPAIGN); } $payment_params['sType'] = $payment_type; $kCheckout = new KlarnaAPI($this->country, $this->lang, $payment_type, $billTotalInCountryCurrency, KlarnaFlags::CHECKOUT_PAGE, $this->klarna, $aTypes, JPATH_VMKLARNAPLUGIN); if ($payment_type == 'invoice') { if ($invoice_fee) { $payment_params['module'] = JText::sprintf ('VMPAYMENT_KLARNA_INVOICE_TITLE', $display_invoice_fee); } else { $payment_params['module'] = JText::_ ('VMPAYMENT_KLARNA_INVOICE_TITLE_NO_PRICE'); } $payment_params['pClasses'] = NULL; $payment_params['id'] = 'klarna_invoice'; } elseif ($payment_type == 'part') { KlarnaHandler::getCheapestPclass ($kCheckout, $cheapest, $minimum); if ($billTotalInCountryCurrency < $minimum) { return NULL; } if (!class_exists ('VirtueMartModelCurrency')) { require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'currency.php'); } // Cheapest is in the Klarna country currency, convert it to the current currency display //$currencyDisplay = CurrencyDisplay::getInstance( ); //$countryCurrencyId = $this->virtuemart_currency_id; //$sFee = $currencyDisplay->priceDisplay($cheapest, 0, 1,false); $sFee = $kCheckout->getPresentableValuta ($cheapest); $payment_params['module'] = JText::sprintf ('VMPAYMENT_KLARNA_PARTPAY_TITLE', $sFee); $payment_params['pClasses'] = $kCheckout->getPClassesInfo (); $payment_params['id'] = 'klarna_partPayment'; } else { $pclasses = $kCheckout->aPClasses; if (empty($pclasses)) { return NULL; } $payment_params['module'] = JText::_ ('VMPAYMENT_KLARNA_SPEC_TITLE'); $payment_params['pClasses'] = $kCheckout->getPClassesInfo (); $payment_params['id'] = 'klarna_SpecCamp'; } $payment_params['payment_link'] = "https://online.klarna.com/villkor.yaws?eid=" . $this->eid . "&charge=" . $invoice_fee; if (strtolower ($this->country) == 'de') { $vendor_id = 1; $payment_params['agb_link'] = JRoute::_ ('index.php?option=com_virtuemart&view=vendor&layout=tos&virtuemart_vendor_id=' . $vendor_id); } //$lang = KlarnaHandler::getLanguageForCountry($method, $this->country); $symbol = KlarnaHandler::getCurrencySymbolForCountry ($method, $this->country); if (KlarnaHandler::getKlarnaError ($klarnaError, $klarnaOption)) { if ($klarnaOption == 'klarna_' . $payment_type) { $payment_params['red_baloon_content'] = $klarnaError; $payment_params['red_baloon_paymentBox'] = 'klarna_box_' . $klarnaOption; //KlarnaHandler::clearKlarnaError (); } } // Something went wrong, refill what we can. $session = JFactory::getSession (); $sessionKlarna = $session->get ('Klarna', 0, 'vm'); if (!empty($sessionKlarna)) { $sessionKlarnaData = unserialize ($sessionKlarna); if (isset($sessionKlarnaData->KLARNA_DATA)) { $klarnaData = $sessionKlarnaData->KLARNA_DATA; $this->setPreviouslyFilledIn ($klarnaData); } } $payment_params['paymentPlan'] = ''; if (is_array ($kCheckout->aPClasses)) { foreach ($kCheckout->aPClasses as $pclass) { if ($pclass['default'] === TRUE) { $payment_params['paymentPlan'] = $pclass['pclass']->getId (); break; } } } if ($payment_type != "spec") { //$payment_params['conditionsLink'] = $aTemplateData['conditions']; } $payment_params['fields'] = $this->shipTo; $payment_params['payment_id'] = 'virtuemart_paymentmethod_id'; $payment_params['checkout'] = $this->klarna->checkoutHTML (); $payment_params['eid'] = $this->eid; $payment_params['year_salary'] = $this->klarna_year_salary; $payment_params['agreement_link'] = $this->payment_charge_link; $payment_params['sum'] = $invoice_fee; $payment_params['fee'] = $invoice_fee; $payment_params['invoice_fee'] = $invoice_fee; $payment_params['langISO'] = $this->lang; $payment_params['countryCode'] = $this->country; $payment_params['flag'] = KlarnaFlags::CHECKOUT_PAGE; $payment_params['payment_id'] = "payment"; $payment_params['invoice_name'] = 'klarna_invoice'; $payment_params['part_name'] = 'klarna_partPayment'; $payment_params['spec_name'] = 'klarna_SpecCamp'; $payment_params['fields']['socialNumber'] = isset($this->socialNumber)?$this->socialNumber:""; return $payment_params; } /** * Build the Payment params */ public function getCheapestMonthlyCost ($cart = NULL, $cData) { if (!class_exists ('CurrencyDisplay')) { require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php'); } if (!class_exists ('KlarnaAPI')) { require (JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarnaapi.php'); } if (!isset($this->klarna) || !($this->klarna instanceof Klarna_virtuemart)) { return NULL; } $display_fee = 0; $billTotalInCountryCurrency = 0; if (isset($cart->pricesUnformatted['billTotal'])) { $billTotalInCountryCurrency = KlarnaHandler::convertPrice ($cart->pricesUnformatted['billTotal'], $cData['vendor_currency'], $cData['virtuemart_currency_id'], $cart->pricesCurrency); } if ($billTotalInCountryCurrency <= 0) { return NULL; } $aTypes = array(KlarnaPClass::ACCOUNT, KlarnaPClass::CAMPAIGN); $kCheckout = new KlarnaAPI($this->country, $this->lang, 'part', $billTotalInCountryCurrency, KlarnaFlags::CHECKOUT_PAGE, $this->klarna, $aTypes, JPATH_VMKLARNAPLUGIN); KlarnaHandler::getCheapestPclass ($kCheckout, $cheapest, $minimum); vmdebug('getCheapestMonthlyCost',$cart->pricesUnformatted['billTotal'], $billTotalInCountryCurrency , $cheapest,$minimum); if ($billTotalInCountryCurrency < $minimum) { return NULL; } if (!class_exists ('VirtueMartModelCurrency')) { require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'currency.php'); } $sFee = $kCheckout->getPresentableValuta ($cheapest); return $sFee; } /** * @return string */ public function getTermsLink () { return 'https://static.klarna.com/external/html/' . KLARNA_SPECIAL_CAMPAIGN . '_' . strtolower ($this->country) . '.html'; } /** * @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); } } klarna/helpers/index.html 0000666 00000000057 15137314773 0011474 0 ustar 00