/**
  * @return null
  * @throws KlarnaApiException
  */
 public function languagepack()
 {
     $sSubAction = vRequest::getWord('subAction');
     if (!isset($this->template['name']) || $this->template['name'] == '') {
         $this->template['name'] = "default";
     }
     if ($sSubAction == "klarna_box") {
         $sNewISO = vRequest::getWord('newIso');
         $sCountry = vRequest::getWord('country');
         $iSum = vRequest::getFloat('sum', 0);
         $iInvoiceFee = vRequest::getFloat('fee', 0);
         $iFlag = vRequest::getInt('flag');
         $sType = vRequest::getWord('type');
         $aParams = vRequest::getVar('params');
         $aValues = vRequest::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 = vRequest::getWord('newIso');
             $sFetch = "";
         } else {
             throw new KlarnaApiException("Invalid sub-action");
         }
     }
 }
 function plgVmOnSelfCallBE($type, $name, &$render)
 {
     if ($name != $this->_name || $type != 'vmpayment') {
         return FALSE;
     }
     $virtuemart_paymentmethod_id = vRequest::getInt('virtuemart_paymentmethod_id');
     //Load the method
     if (!($this->_currentMethod = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) {
         return NULL;
         // Another method was selected, do nothing
     }
     $amount = vRequest::getFloat('amount');
     $actions = array('rebatePayment', 'settlePayment');
     $action = vRequest::getCmd('action');
     if (!in_array($action, $actions)) {
         vmError('VMPAYMENT_REALEX_HPP_API_UPDATEPAYMENT_UNKNOWN_ACTION');
         return NULL;
     }
     $virtuemart_order_id = vRequest::getInt('virtuemart_order_id');
     if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) {
         return null;
     }
     $orderModel = VmModel::getModel('orders');
     $orderData = $orderModel->getOrder(vRequest::getInt('virtuemart_order_id'));
     $requestSent = false;
     $order_history_comment = '';
     $realexInterface = $this->_loadRealexInterface();
     $canDo = true;
     if ($action == 'settlePayment') {
         $requestSent = true;
         $order_history_comment = vmText::_('VMPAYMENT_REALEX_HPP_API_UPDATE_STATUS_CAPTURE');
         $realexInterface->setOrder($orderData);
         $realexInterface->setPaymentCurrency();
         $realexInterface->setTotalInPaymentCurrency($amount);
         $realexInterface->loadCustomerData();
         $response = $realexInterface->settleTransaction($payments);
     } elseif ($action == 'rebatePayment') {
         $requestSent = true;
         $response = $this->doRebate($realexInterface, $orderData, $payments, $amount);
     }
     if ($requestSent) {
         if ($response) {
             $db_values = $this->_storeRealexInternalData($response, $this->_currentMethod->virtuemart_paymentmethod_id, $orderData['details']['BT']->virtuemart_order_id, $orderData['details']['BT']->order_number, $realexInterface->request_type);
             $xml_response = simplexml_load_string($response);
             $success = $realexInterface->isResponseSuccess($xml_response);
             if (!$success) {
                 $error = $xml_response->message . " (" . (string) $xml_response->result . ")";
                 $realexInterface->displayError($error);
             } else {
                 $order_history = array();
                 $order_history['comments'] = $order_history_comment;
                 $order_history['customer_notified'] = false;
                 $order_history['order_status'] = $orderData['details']['BT']->order_status;
                 $modelOrder = VmModel::getModel('orders');
                 $modelOrder->updateStatusForOneOrder($orderData['details']['BT']->virtuemart_order_id, $order_history, false);
             }
         } else {
             vmError('VMPAYMENT_REALEX_HPP_API_NO_RESPONSE');
         }
     }
     $app = JFactory::getApplication();
     $link = 'index.php?option=com_virtuemart&view=orders&task=edit&virtuemart_order_id=' . $virtuemart_order_id;
     $app->redirect(JRoute::_($link, FALSE));
 }
Exemple #3
0
	function plgVmOnSelfCallBE ($type, $name, &$render) {
		if ($name != $this->_name || $type != 'vmpayment') {
			return FALSE;
		}
		$action = vRequest::getCmd('action');
		$virtuemart_paymentmethod_id = vRequest::getInt('virtuemart_paymentmethod_id');
		//Load the method
		if (!($this->_currentMethod = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) {
			return NULL; // Another method was selected, do nothing
		}
		$virtuemart_order_id = vRequest::getInt('virtuemart_order_id');
		if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) {
			return null;
		}
		$orderModel = VmModel::getModel('orders');
		$order = $orderModel->getOrder($virtuemart_order_id);
		$this->_order_number = $this->getUniqueReferenceId($order['details']['BT']->order_number);
		$this->_amount = vRequest::getFloat('amount');

		switch ($action) {
			case 'refundPayment':
				if ($this->canDoRefund($payments, $order)) {
					$this->refundPayment($payments, $order);
				}
				break;
			case 'capturePayment':

				if ($authorizationId = $this->canDoCapture($payments, $order)) {
					// may be we did a new authorization in case of partial capture
					$this->capturePayment($payments, $order);
				}
				break;
			case 'newAuthorization':

				if ($this->canDoAuthorization($payments, $order)) {
					$this->getAuthorization($this->getOffAmazonPaymentsService_Client(), NULL, $order, false);
				}
				break;
			default:
				vmError('VMPAYMENT_AMAZON_UPDATEPAYMENT_UNKNOWN_ACTION');
		}
		$app = JFactory::getApplication();
		$link = 'index.php?option=com_virtuemart&view=orders&task=edit&virtuemart_order_id=' . $virtuemart_order_id;

		$app->redirect(JRoute::_($link, FALSE));

	}