/**
  * @param $product
  * @return bool
  */
 private function showPP($product)
 {
     if (!isset($this->klarna_virtuemart) || !$this->klarna_virtuemart instanceof Klarna_virtuemart) {
         return FALSE;
     }
     if (!VMKLARNA_SHOW_PRODUCTPRICE) {
         return FALSE;
     }
     // the price is in the vendor currency
     // convert price in NLD currency= euro
     $price = KlarnaHandler::convertPrice($product->prices['salesPrice'], $product->product_currency, 'EUR');
     if (strtolower($this->cData['country_code']) == 'nl' && $price > 250) {
         vmDebug('showPP', 'dont show price for NL', $this->cData['country_code'], $price);
         return FALSE;
     }
     if ($price <= $this->cData['min_amount'] and !empty($this->cData['min_amount'])) {
         return FALSE;
     }
     return TRUE;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 function displayKlarnaLogos($method, $virtuemart_country_id, $shipTo, $total)
 {
     $session = JFactory::getSession();
     $sessionKlarna = $session->get('Klarna', 0, 'vm');
     if (empty($sessionKlarna)) {
         return '';
     }
     $sessionKlarnaData = unserialize($sessionKlarna);
     $address['virtuemart_country_id'] = $virtuemart_country_id;
     $cData = KlarnaHandler::getcData($method, $address);
     $country2 = strtolower(shopFunctions::getCountryByID($virtuemart_country_id, 'country_2_code'));
     switch ($sessionKlarnaData->klarna_option) {
         case 'invoice':
             $image = '/klarna_invoice_' . $country2 . '.png';
             $klarna_invoice_fee = KlarnaHandler::getInvoiceFeeInclTax($method, $cData['country_code_3']);
             $currency = CurrencyDisplay::getInstance();
             $display_fee = $currency->priceDisplay($klarna_invoice_fee);
             $text = JText::sprintf('VMPAYMENT_KLARNA_INVOICE_TITLE_NO_PRICE', $display_fee);
             break;
         case 'partpayment':
         case 'part':
             $image = '/klarna_part_' . $country2 . '.png';
             $address['virtuemart_country_id'] = $virtuemart_country_id;
             $pclasses = KlarnaHandler::getPClasses(NULL, $country2, KlarnaHandler::getKlarnaMode($method), $cData);
             if (!class_exists('Klarna_payments')) {
                 require JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarna_payments.php';
             }
             if (!class_exists('KlarnaVm2API')) {
                 require JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarna_vm2api.php';
             }
             $payments = new klarna_payments($cData, $shipTo);
             //vmdebug('displaylogos',$cart_prices);
             $totalInPaymentCurrency = KlarnaHandler::convertPrice($total, $cData['currency_code']);
             $text = $payments->displayPclass($sessionKlarnaData->KLARNA_DATA['pclass'], $totalInPaymentCurrency);
             // .' '.$total;
             break;
         case 'speccamp':
             $image = 'klarna_logo.png';
             $text = JText::_('VMPAYMENT_KLARNA_SPEC_TITLE');
             break;
         default:
             $image = '';
             $text = '';
             break;
     }
     $html = $this->renderByLayout('payment_cart', array('logo' => $image, 'description' => $text));
     return $html;
 }
Exemplo n.º 4
0
 function checkPartpriceCondition($cData, $cart)
 {
     //  Since 12/09/12: merchants can sell goods with Klarna Invoice up to thousands of euros.
     // convert price in euro
     //$euro_currency_id = ShopFunctions::getCurrencyByName( 'EUR');
     $amount = KlarnaHandler::convertPrice($cart->cartPrices['billTotal'], $cart->pricesCurrency, 'EUR', $cart->pricesCurrency);
     if ($amount <= $cData['min_amount'] and !empty($cData['min_amount'])) {
         return FALSE;
     }
     return true;
 }
Exemplo n.º 5
0
	/**
	 * @param $method
	 * @param $virtuemart_country_id
	 * @param $shipTo
	 * @param $total
	 * @return string
	 */
	protected function renderKlarnaPluginName ($method, $virtuemart_country_id, $shipTo, $total, $cartPricesCurrency) {

		$session = JFactory::getSession ();
		$sessionKlarna = $session->get ('Klarna', 0, 'vm');
		if (empty($sessionKlarna)) {
			return '';
		}
		$sessionKlarnaData = unserialize ($sessionKlarna);
		$address['virtuemart_country_id'] = $virtuemart_country_id;
		$cData = KlarnaHandler::getcData ($method, $address);
		$country2 = strtolower (shopFunctions::getCountryByID ($virtuemart_country_id, 'country_2_code'));
		$text = "";
		if (isset($sessionKlarnaData->klarna_option)) {
			switch ($sessionKlarnaData->klarna_option) {
				case 'invoice':
					$sType='invoice';
					$image = '/klarna_invoice_' . $country2 . '.png';
					//$logo = VMKLARNAPLUGINWEBASSETS . '/images/' . 'logo/klarna_' . $sType . '_' . $code2 . '.png';
					$image ="https://cdn.klarna.com/public/images/".strtoupper($country2)."/badges/v1/". $sType ."/".$country2."_". $sType ."_badge_std_blue.png?height=55&eid=".$cData['eid'];
					$display_invoice_fee = NULL;
					$invoice_fee = 0;
					KlarnaHandler::getInvoiceFeeInclTax ($method, $cData['country_code_3'], $cartPricesCurrency, $cData['virtuemart_currency_id'], $display_invoice_fee, $invoice_fee);
					$text = JText::sprintf ('VMPAYMENT_KLARNA_INVOICE_TITLE_NO_PRICE', $display_invoice_fee);
					break;
				case 'partpayment':
				case 'part':
					$sType='account';
					//$image = '/klarna_part_' . $country2 . '.png';
					$image ="https://cdn.klarna.com/public/images/".strtoupper($country2)."/badges/v1/". $sType ."/".$country2."_". $sType ."_badge_std_blue.png?height=55&eid=".$cData['eid'];

					$address['virtuemart_country_id'] = $virtuemart_country_id;
					//$pclasses                         = KlarnaHandler::getPClasses(NULL,   KlarnaHandler::getKlarnaMode($method), $cData);
					if (!class_exists ('Klarna_payments')) {
						require (JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarna_payments.php');
					}

					$payments = new klarna_payments($cData, $shipTo);
					//vmdebug('displaylogos',$cart_prices);
					$totalInPaymentCurrency = KlarnaHandler::convertPrice ($total, $cData['vendor_currency'], $cData['virtuemart_currency_id']);
					vmdebug ('totalInPaymentCurrency', $totalInPaymentCurrency);
					if (isset($sessionKlarnaData->KLARNA_DATA)) {
						$text = $payments->displayPclass ($sessionKlarnaData->KLARNA_DATA['pclass'], $totalInPaymentCurrency); // .' '.$total;
					}
					break;
				case 'speccamp':
					$image = 'klarna_logo.png';
					$text = JText::_ ('VMPAYMENT_KLARNA_SPEC_TITLE');
					break;
				default:
					$image = '';
					$text = '';
					break;
			}

			$plugin_name = $this->_psType . '_name';
			$plugin_desc = $this->_psType . '_desc';
			$payment_description = '';
			if (!empty($method->$plugin_desc)) {
				$payment_description = $method->$plugin_desc;
			}
			$payment_name = $method->$plugin_name;

			$html = $this->renderByLayout ('payment_cart', array(
				'logo'                => $image,
				'text'                => $text,
				'payment_description' => $payment_description,
				'payment_name'        => $payment_name
			));
			return $html;
		}
	}
Exemplo n.º 6
0
 function checkPartNLpriceCondition($cart)
 {
     //  Since 12/09/12: merchants can sell goods with Klarna Invoice up to thousands of euros.
     // convert price in euro
     //$euro_currency_id = ShopFunctions::getCurrencyByName( 'EUR');
     $price = KlarnaHandler::convertPrice($cart->pricesUnformatted['billTotal'], $cart->pricesCurrency, 'EUR', $cart->pricesCurrency);
     return self::checkNLpriceCondition($price);
 }
 /**
  * Build the Payment params
  */
 public function get_payment_params($method, $payment_type, $cart = NULL, $country_currency_code = '')
 {
     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'], $cart->pricesCurrency, $country_currency_code);
         }
         if ($billTotalInCountryCurrency <= 0) {
             return NULL;
         }
         $aTypes = array(KlarnaPClass::ACCOUNT, KlarnaPClass::CAMPAIGN, KlarnaPClass::FIXED);
     }
     $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') {
         $pclasses = $kCheckout->aPClasses;
         if (empty($pclasses)) {
             return NULL;
         }
         $cheapest = 0;
         $minimum = '';
         foreach ($pclasses as $pclass) {
             if ($cheapest == 0 || $pclass['monthlyCost'] < $cheapest) {
                 $cheapest = $pclass['monthlyCost'];
             }
             if ($pclass['pclass']->getMinAmount() < $minimum || $minimum === '') {
                 $minimum = $pclass['pclass']->getMinAmount();
             }
         }
         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';
     return $payment_params;
 }
Exemplo n.º 8
0
 /**
  * Build the PartPayment module.
  */
 public function partPay($cart)
 {
     // If module isn't enabled, don't do anything.
     $this->code = "klarna_partPayment";
     if (!isset($this->klarna) || !$this->klarna instanceof Klarna_virtuemart) {
         return NULL;
     }
     /* Should contain the shipment Fee */
     $billTotal = KlarnaHandler::convertPrice($cart->pricesUnformatted['billTotal'], $this->virtuemart_currency_id);
     if ($billTotal <= 0) {
         return NULL;
     }
     $this->paymeny_charge_link = "https://online.klarna.com/villkor.yaws?eid=" . $this->eid . "&charge=0";
     //$lang = KlarnaHandler::getLanguageForCountry($method, $this->country);
     $kCheckout = new KlarnaVm2API($this->country, $this->lang, 'part', $billTotal, KlarnaFlags::CHECKOUT_PAGE, $this->klarna, array(KlarnaPClass::ACCOUNT, KlarnaPClass::CAMPAIGN, KlarnaPClass::FIXED), JPATH_VMKLARNAPLUGIN);
     $kCheckout->addSetupValue('payment_id', 'virtuemart_paymentmethod_id');
     $kCheckout->addSetupValue('eid', $this->eid);
     if (strtolower($this->country) == 'de') {
         $vendor_id = 1;
         $link = JRoute::_('index.php?option=com_virtuemart&view=vendor&layout=tos&virtuemart_vendor_id=' . $vendor_id);
         $kCheckout->addSetupValue('agb_link', $link);
     }
     $kCheckout->addMultipleSetupValues(array("web_root" => $this->web_root, "path_js" => $this->web_root . VMKLARNAPLUGINWEBROOT . "/klarna/assets/js/", "path_img" => $this->web_root . VMKLARNAPLUGINWEBROOT . '/klarna/assets/images/', "path_css" => $this->web_root . VMKLARNAPLUGINWEBROOT . '/klarna/assets/css/'));
     if ($billTotal > 0) {
         $pclasses = $kCheckout->aPClasses;
         if (empty($pclasses)) {
             $this->enabled = false;
         }
         $cheapest = 0;
         $minimum = '';
         foreach ($pclasses as $pclass) {
             if ($cheapest == 0 || $pclass['monthlyCost'] < $cheapest) {
                 $cheapest = $pclass['monthlyCost'];
             }
             if ($pclass['pclass']->getMinAmount() < $minimum || $minimum === '') {
                 $minimum = $pclass['pclass']->getMinAmount();
             }
         }
         if ($billTotal < $minimum) {
             $this->enabled = false;
         }
         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);
         $title = JText::sprintf('VMPAYMENT_KLARNA_PARTPAY_TITLE', $sFee);
     } else {
         $title = JText::_('VMPAYMENT_KLARNA_PARTPAY_TITLE_NOSUM');
     }
     if (KlarnaHandler::getKlarnaError($klarnaError, $klarnaOption)) {
         $kCheckout->addSetupValue('red_baloon_content', $klarnaError);
         $kCheckout->addSetupValue('red_baloon_paymentBox', 'klarna_box_' . $klarnaOption);
         KlarnaHandler::clearKlarnaError();
     }
     // Something went wrong, refill what we can.
     if (isset($_SESSION['KLARNA_DATA'])) {
         $this->setPreviouslyFilledIn($_SESSION['KLARNA_DATA']);
     }
     $aParams = $this->getParams();
     $aValues = $this->getValues();
     return array('id' => 'klarna_partPayment', 'module' => $title, 'fields' => $kCheckout->retrieveLayout($aParams, $aValues), 'pClasses' => $kCheckout->getPClassesInfo());
 }