示例#1
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;
 }
示例#2
0
	/**
	 * Save updated order data to the method specific table
	 *
	 * @param array $order Form data
	 * @return mixed, True on success, false on failures (the rest of the save-process will be
	 * skipped!), or null when this method is not actived.

	 */
	public function plgVmOnUpdateOrderPayment (&$order, $old_order_status) {

		if (!$this->selectedThisByMethodId ($order->virtuemart_paymentmethod_id)) {
			return NULL; // Another method was selected, do nothing
		}

		if (!($method = $this->getVmPluginMethod ($order->virtuemart_paymentmethod_id))) {
			return NULL; // Another method was selected, do nothing
		}
		if (!($payments = $this->_getKlarnaInternalData ($order->virtuemart_order_id))) {
			vmError (JText::sprintf ('VMPAYMENT_KLARNA_ERROR_NO_DATA', $order->virtuemart_order_id));
			return NULL;
		}

		if (!($invNo = $this->_getKlarnaInvoiceNo ($payments))) {
			return NULL;
		}
		// to activate the order
		if ($order->order_status == $method->status_shipped) {
			$country = $this->getCountryCodeByOrderId ($order->virtuemart_order_id);
			$klarna_vm = new Klarna_virtuemart();
			$cData = KlarnaHandler::countryData ($method, $country);
			/*
		   * The activateInvoice function is used to activate a passive invoice.
		   * Please note that this function call cannot activate an invoice created in test mode.
		   * It is however possible to manually activate that type of invoices.
		   */
			$force_emailInvoice = FALSE;
			$klarna_vm->config ($cData['eid'], $cData['secret'], $cData['country_code'], NULL, $cData['currency_code'], KlarnaHandler::getKlarnaMode ($method, $cData['country_code_3']));

			try {
				//You can specify a new pclass ID if the customer wanted to change it before you activate.

				 $klarna_vm->activateInvoice ($invNo);
				$invoice_url=$this->getInvoice($invNo, $invoice_url);

				//The url points to a PDF file for the invoice.
				//Invoice activated, proceed accordingly.
			}
			catch (Exception $e) {
				$log = $e->getMessage () . " (#" . $e->getCode () . ")";
				if ($e->getCode () != 8111) { // (invoice_not_passive_or_frozen)
					$this->_updateKlarnaInternalData ($order, $log);
					VmError ($e->getMessage () . " (#" . $e->getCode () . ")");
					return FALSE;
				} else {
					$force_emailInvoice = TRUE;
				}
			}

			$emailInvoice = $this->emailInvoice ($method, $klarna_vm, $invNo, $force_emailInvoice);
			$dbValues['order_number'] = $order->order_number;
			$dbValues['virtuemart_order_id'] = $order->virtuemart_order_id;
			$dbValues['virtuemart_paymentmethod_id'] = $order->virtuemart_paymentmethod_id;
			$dbValues['klarna_invoice_no'] = $invNo;
			$dbValues['klarna_log'] = Jtext::sprintf ('VMPAYMENT_KLARNA_ACTIVATE_INVOICE', $invNo);
			if ($emailInvoice) {
				$dbValues['klarna_log'] .= "<br />" . Jtext::sprintf ('VMPAYMENT_KLARNA_EMAIL_INVOICE', $invNo);
			} else {
				$dbValues['klarna_log'] .= "<br />" . Jtext::_ ('VMPAYMENT_KLARNA_EMAIL_INVOICE_NOT_SENT');
			}
			$dbValues['klarna_eid'] = $cData['eid'];
			//$dbValues['klarna_status_code'] = KLARNA_INVOICE_ACTIVE; // Invoice is active
			//$dbValues['klarna_status_text'] = '';
			$dbValues['klarna_pdf_invoice'] = $invoice_url;

			$this->storePSPluginInternalData ($dbValues);
			return TRUE;
		}
		return NULL;
	}
 /**
  * @static
  * @param $method
  * @return array
  */
 public static function fetchAllPClasses($method)
 {
     $message = '';
     $success = '';
     $results = array();
     $countries = self::getKlarnaCountries();
     $pc_type = KlarnaHandler::getKlarna_pc_type();
     if (empty($pc_type)) {
         return FALSE;
     } else {
         // delete the file directly
         if (file_exists($pc_type)) {
             unlink($pc_type);
         }
     }
     foreach ($countries as $country) {
         $active_country = "klarna_active_" . $country;
         if ($method->{$active_country}) {
             // country is CODE 3==> converting to 2 letter country
             //$country = self::convertCountryCode($method, $country);
             $lang = self::getLanguageForCountry($method, $country);
             $flagImg = JURI::root(TRUE) . '/administrator/components/com_virtuemart/assets/images/flag/' . strtolower($lang) . '.png';
             $flag = "<img src='" . $flagImg . "' />";
             try {
                 $settings = self::getCountryData($method, $country);
                 $klarna = new Klarna_virtuemart();
                 $klarna->config($settings['eid'], $settings['secret'], $settings['country'], $settings['language'], $settings['currency'], KlarnaHandler::getKlarnaMode($method, $settings['country_code_3']), VMKLARNA_PC_TYPE, $pc_type, TRUE);
                 $klarna->fetchPClasses($country);
                 $success .= shopFunctions::getCountryByID($settings['virtuemart_country_id']);
             } catch (Exception $e) {
                 $message .= $flag . " " . shopFunctions::getCountryByID($settings['virtuemart_country_id']) . ": " . $e->getMessage() . ' Error Code #' . $e->getCode() . '</span></br>';
             }
         }
     }
     $results['msg'] = $message;
     $results['notice'] = $success;
     return $results;
     //echo $notice;
 }
示例#4
0
 public static function fetchPClasses($method)
 {
     $message = '';
     $success = '';
     $results = array();
     $countries = self::getKlarnaCountries();
     foreach ($countries as $country) {
         $active_country = "klarna_active_" . $country;
         if ($method->{$active_country}) {
             // country is CODE 3==> converting to 2 letter country
             //$country = self::convertCountryCode($method, $country);
             $lang = self::getLanguageForCountry($method, $country);
             $flagImg = JURI::root(true) . '/administrator/components/com_virtuemart/assets/images/flag/' . strtolower($lang) . '.png';
             $flag = "<img src='" . $flagImg . "' />";
             try {
                 $settings = self::getCountryData($method, $country);
                 $klarna = new Klarna_virtuemart();
                 $klarna->config($settings['eid'], $settings['secret'], $settings['country'], $settings['language'], $settings['currency'], KlarnaHandler::getKlarnaMode($method), VMKLARNA_PC_TYPE, KlarnaHandler::getKlarna_pc_type(), true);
                 // fetch pclass from file
                 $klarna->fetchPClasses($country);
                 $success .= '<span style="padding: 5px;">' . $flag . " " . shopFunctions::getCountryByID($settings['virtuemart_country_id']) . '</span>';
             } catch (Exception $e) {
                 $message .= '<br><span style="font-size: 15px;">' . $flag . " " . shopFunctions::getCountryByID($settings['virtuemart_country_id']) . ": " . $e->getMessage() . ' Error Code #' . $e->getCode() . '</span></br>';
             }
         }
     }
     $results['msg'] = $message;
     $results['notice'] = 'PClasses fetched for : ' . $success;
     return $results;
     //echo $notice;
 }