function generateOrderParams($msc_id, $price, $payment_mode, $msc_option)
 {
     $params = array();
     $params['msc_id'] = $msc_id;
     if ($payment_mode == 'a') {
         $payment = oseMscAddon::getExtInfo($msc_id, 'payment', 'array');
         $payment = $payment[$msc_option];
         if (oseObject::getValue($payment, 'has_trial')) {
             $params['has_trial'] = 1;
             $params['a1'] = $price;
             $params['p1'] = oseObject::getValue($payment, 'p1');
             $params['t1'] = oseObject::getValue($payment, 't1');
             $params['a3'] = oseObject::getValue($payment, 'a3');
             $params['p3'] = oseObject::getValue($payment, 'p3');
             $params['t3'] = oseObject::getValue($payment, 't3');
         } else {
             $params['has_trial'] = 0;
             $params['a3'] = $price;
             $params['p3'] = oseObject::getValue($payment, 'p3');
             $params['t3'] = oseObject::getValue($payment, 't3');
         }
     }
     if ($payment_mode == 'm') {
         $payment = oseMscAddon::getExtInfo($msc_id, 'payment', 'array');
         $payment = $payment[$msc_option];
         $params['recurrence_mode'] = 'period';
         $params['a3'] = $price;
         $params['p3'] = oseObject::getValue($payment, 'p3');
         $params['t3'] = oseObject::getValue($payment, 't3');
         $params['eternal'] = oseObject::getValue($payment, 'eternal');
     }
     $params['msc_option'] = $msc_option;
     return $params;
 }
 function drawSubLeaf($node)
 {
     $item = self::generateSubMsc($node);
     $array = array();
     $payment = oseMscAddon::getExtInfo(oseObject::getValue($node, 'id'), 'payment', 'obj');
     $price = oseObject::getValue($item, 'standard_price') . ' for every ' . oseObject::getValue($item, 'standard_recurrence');
     if ($payment->has_trial) {
         $price .= ' (' . oseObject::getValue($item, 'trial_price') . ' in the first ' . oseObject::getValue($item, 'trial_recurrence') . ')';
     }
     if (strtolower($payment->payment_mode) == 'm') {
         $array['button'] = $this->drawButton($node, 'm', JText::_('Manual Renewal'));
     } elseif (strtolower($payment->payment_mode) == 'a') {
         $array['button'] = $this->drawButton($node, 'a', JText::_('Automatic Renewal'));
     } else {
         $array['button'] = $this->drawButton($node, 'm', JText::_('Manual Renewal'));
         $array['button'] .= $this->drawButton($node, 'a', JText::_('Automatic Renewal'));
     }
     $array['title'] = $this->drawSubTitle('<p>|__' . oseObject::getValue($item, 'title') . "</p>");
     $array['price'] = $this->drawPrice(oseObject::getValue($item, 'price'));
     $array['period'] = $this->drawPeriod(oseObject::getValue($item, 'period'));
     $array = implode("\r\n", $array);
     return $array;
 }
Example #3
0
 function getEmailVariablesReceipt($order_id, $user_id = null)
 {
     $db = oseDB::instance();
     $content = array();
     // get Order Info
     $payment = oseRegistry::call('payment');
     $where = array();
     $where[] = "order_id = {$order_id}";
     $orderInfo = $payment->getOrder($where, 'obj');
     $orderInfoParams = oseJson::decode($orderInfo->params);
     $paymentInfo = oseMscAddon::getExtInfo($orderInfo->entry_id, 'payment', 'obj');
     $member = oseRegistry::call('member');
     $member->instance($orderInfo->user_id);
     $userInfo = $member->getBillingInfo('obj');
     $userInfo->email = $userInfo->user_email;
     $orderInfo->subtotal = $orderInfoParams->subtotal;
     $orderInfo->total = $orderInfoParams->recurrence_times > 1 ? $orderInfoParams->next_total : $orderInfoParams->total;
     $orderInfo->discount = isset($orderInfoParams->discount) ? $orderInfoParams->discount : 0;
     $gw = $payment->getInstance('GateWay');
     $gwInfo = $gw->getGWInfo($orderInfo->payment_method);
     if (!empty($gwInfo)) {
         if ($gwInfo->is_cc) {
             $orderInfo->payment_method = 'Credit Card';
         }
     }
     $orderInfo->itemlist = $this->generateOrderTable($order_id, $orderInfo->user_id);
     if ($orderInfo->payment_mode == 'm') {
         $orderInfo->payment_mode = JText::_('Manual Billing');
         $orderInfo->gross_tax = oseObject::getValue($orderInfoParams, 'gross_tax', '0.00');
         if ($orderInfo->gross_tax > 0) {
             $orderInfo->vat_number = oseObject::getValue($orderInfoParams, 'vat_number');
         }
     } else {
         $orderInfo->payment_mode = JText::_('Automatic Billing');
         $params = oseJson::decode($orderInfo->params);
         $price = null;
         if (oseObject::getValue($orderInfoParams, 'has_trial', 0)) {
             if (oseObject::getValue($orderInfoParams, 'recurrence_times', 0) <= 1) {
                 $orderInfo->gross_tax = oseObject::getValue($orderInfoParams, 'gross_tax', '0.00');
             } else {
                 $orderInfo->gross_tax = oseObject::getValue($orderInfoParams, 'next_gross_tax', '0.00');
             }
         } else {
             if (oseObject::getValue($orderInfoParams, 'recurrence_times', 0) <= 2) {
                 $orderInfo->gross_tax = oseObject::getValue($orderInfoParams, 'gross_tax', '0.00');
             } else {
                 $orderInfo->gross_tax = oseObject::getValue($orderInfoParams, 'next_gross_tax', '0.00');
             }
         }
         $orderInfo->vat_number = oseObject::getValue($orderInfoParams, 'vat_number');
         $orderInfo->recurring_price = $orderInfo->payment_currency . ' ' . $orderInfoParams->next_total;
         $orderInfo->recurring_frequency = $orderInfoParams->p3 . ' ' . $orderInfoParams->t3;
     }
     $query = "SELECT entry_id FROM `#__osemsc_order_item` WHERE `order_id` = " . $order_id;
     $db->setQuery($query);
     $msc_id = $db->loadResult();
     $query = " SELECT *,DATE_SUB(`expired_date`,INTERVAL 1 DAY) AS `real_expired_date` " . " FROM `#__osemsc_member`" . " WHERE member_id = {$orderInfo->user_id} AND msc_id={$msc_id}";
     $db->setQuery($query);
     $memberInfo = oseDB::loadItem('obj');
     $query = "SELECT * FROM `#__osemsc_acl` WHERE `id` = {$msc_id}";
     $db->setQuery($query);
     $mscInfo = oseDB::loadItem('obj');
     $memberInfo->msc_title = $mscInfo->title;
     $memberInfo->msc_des = $mscInfo->description;
     $orderInfo->current_date = oseHTML::getDateTime();
     $globalConfig = oseRegistry::call('msc')->getConfig('global', 'obj');
     if (!empty($globalConfig->DateFormat)) {
         $memberInfo->start_date = date($globalConfig->DateFormat, strtotime($memberInfo->start_date));
         $orderInfo->create_date = date($globalConfig->DateFormat, strtotime($orderInfo->create_date));
         $orderInfo->current_date = date($globalConfig->DateFormat, strtotime($orderInfo->current_date));
     }
     $content['user'] = $userInfo;
     $content['order'] = $orderInfo;
     $content['profile'] = $member->getProfile();
     $content['member'] = $memberInfo;
     return $content;
 }
 function addVmOrder($msc_id, $member_id, $params, $order_number)
 {
     if (empty($member_id)) {
         $result['success'] = false;
         $result['title'] = 'Error';
         $result['content'] = JText::_('Error');
         return $result;
     }
     // Get the IP Address
     if (!empty($_SERVER['REMOTE_ADDR'])) {
         $ip = $_SERVER['REMOTE_ADDR'];
     } else {
         $ip = 'unknown';
     }
     $post = JRequest::get('post');
     $payment_mode = $params['payment_mode'];
     $payment_method = $params['payment_method'];
     //Insert the vm order table(#__vm_orders)
     $order = array();
     //get membership price
     $payment = oseRegistry::call('payment');
     $paymentInfo = oseMscAddon::getExtInfo($msc_id, 'payment', 'obj');
     if ($payment_mode == 'm') {
         $order_subtotal = $paymentInfo->price;
     } else {
         $order_subtotal = empty($paymentInfo->has_trial) ? $paymentInfo->a3 : $paymentInfo->a1;
     }
     $order['order_subtotal'] = $params['payment_price'];
     $order_total = $params['payment_price'];
     $order['order_total'] = $order_total;
     $db = oseDB::instance();
     //$order['order_tax'] = '0.00';
     $query = "SELECT user_info_id FROM `#__vm_user_info` WHERE `user_id` = '" . (int) $member_id . "'  AND (`address_type` = 'BT' OR `address_type` IS NULL)";
     $db->setQuery($query);
     $result = $db->loadResult();
     $hash_secret = "VirtueMartIsCool";
     $user_info_id = empty($result) ? md5(uniqid($hash_secret)) : $result;
     $vendor_id = '1';
     $order['user_id'] = $member_id;
     $order['vendor_id'] = $vendor_id;
     $order['user_info_id'] = $user_info_id;
     $order['order_number'] = $order_number;
     $order['order_currency'] = !empty($payment->currency) ? $payment->currency : "USD";
     $order['order_status'] = 'C';
     $order['cdate'] = time();
     $order['ip_address'] = $ip;
     $keys = array_keys($order);
     $keys = '`' . implode('`,`', $keys) . '`';
     foreach ($order as $key => $value) {
         $order[$key] = $db->Quote($value);
     }
     $values = implode(',', $order);
     $query = "INSERT INTO `#__vm_orders` ({$keys}) VALUES ({$values});";
     $db->setQuery($query);
     if (!oseDB::query()) {
         $result = array();
         $result['success'] = false;
         $result['title'] = 'Error';
         $result['content'] = JText::_('Error');
     }
     //Insert the #__vm_order_history table
     $order_id = $db->insertid();
     $history = array();
     $history['order_id'] = $order_id;
     $history['order_status_code'] = 'C';
     $history['date_added'] = date("Y-m-d G:i:s", time());
     $history['customer_notified'] = '1';
     $keys = array_keys($history);
     $keys = '`' . implode('`,`', $keys) . '`';
     foreach ($history as $key => $value) {
         $history[$key] = $db->Quote($value);
     }
     $values = implode(',', $history);
     $query = "INSERT INTO `#__vm_order_history` ({$keys}) VALUES ({$values});";
     $db->setQuery($query);
     if (!oseDB::query()) {
         $result = array();
         $result['success'] = false;
         $result['title'] = 'Error';
         $result['content'] = JText::_('Error');
     }
     //Insert the Order payment info
     $payment = array();
     $payment['order_id'] = $order_id;
     $payment['payment_method_id'] = $payment_method;
     if ($payment_method == 'authorize') {
     }
     //Insert the User Bill
     $bill = array();
     $query = " SELECT * FROM `#__osemsc_billinginfo`" . " WHERE user_id = {$member_id}";
     $db->setQuery($query);
     $billInfo = oseDB::loadItem();
     if (isset($billInfo)) {
         $bill['company'] = $billInfo['company'];
         $bill['address_1'] = $billInfo['addr1'];
         $bill['address_2'] = $billInfo['addr2'];
         $bill['city'] = $billInfo['city'];
         $bill['state'] = $billInfo['state'];
         $bill['country'] = $billInfo['country'];
         //get vm country code
         $query = " SELECT country_3_code FROM `#__vm_country` WHERE `country_2_code` = '{$bill['country']}' ";
         $db->setQuery($query);
         $country_code = $db->loadResult();
         $bill['country'] = empty($country_code) ? $bill['country'] : $country_code;
         //get vm state code
         $query = " SELECT state_2_code FROM `#__vm_state` WHERE `state_name` = '{$bill['state']}' ";
         $db->setQuery($query);
         $state_code = $db->loadResult();
         $bill['state'] = empty($state_code) ? $bill['state'] : $state_code;
         $bill['zip'] = $billInfo['postcode'];
         $bill['phone_1'] = $billInfo['telephone'];
     }
     $query = " SELECT * FROM `#__osemsc_userinfo_view`" . " WHERE user_id = {$member_id}";
     $db->setQuery($query);
     $userInfo = oseDB::loadItem();
     $bill['order_id'] = $order_id;
     $bill['user_id'] = $member_id;
     $bill['address_type'] = 'BT';
     $bill['address_type_name'] = '-default-';
     $bill['last_name'] = $userInfo['lastname'];
     $bill['first_name'] = $userInfo['firstname'];
     $bill['user_email'] = $userInfo['email'];
     $keys = array_keys($bill);
     $keys = '`' . implode('`,`', $keys) . '`';
     foreach ($bill as $key => $value) {
         $bill[$key] = $db->Quote($value);
     }
     $values = implode(',', $bill);
     $query = "INSERT INTO `#__vm_order_user_info` ({$keys}) VALUES ({$values});";
     $db->setQuery($query);
     if (!oseDB::query()) {
         $result = array();
         $result['success'] = false;
         $result['title'] = 'Error';
         $result['content'] = JText::_('Error');
     }
     //Insert the itme table(#__vm_order_item)
     $item = array();
     $item['order_id'] = $order_id;
     $item['user_info_id'] = $user_info_id;
     $item['vendor_id'] = $vendor_id;
     //get the product info
     $vm = oseMscAddon::getExtInfo($msc_id, 'vm', 'obj');
     $query = " SELECT * FROM `#__vm_product` WHERE `product_id` = '{$vm->product_id}' ";
     $db->setQuery($query);
     $product = $db->loadObject();
     $item['product_id'] = $vm->product_id;
     $item['order_item_sku'] = $product->product_sku;
     $item['order_item_name'] = $product->product_name;
     $item['product_quantity'] = '1';
     $item['product_item_price'] = $order_subtotal;
     $item['product_final_price'] = $order_total;
     $item['order_item_currency'] = !empty($payment->currency) ? $payment->currency : "USD";
     $item['order_status'] = 'C';
     $item['cdate'] = time();
     $keys = array_keys($item);
     $keys = '`' . implode('`,`', $keys) . '`';
     foreach ($item as $key => $value) {
         $item[$key] = $db->Quote($value);
     }
     $values = implode(',', $item);
     $query = "INSERT INTO `#__vm_order_item` ({$keys}) VALUES ({$values});";
     $db->setQuery($query);
     if (!oseDB::query()) {
         $result = array();
         $result['success'] = false;
         $result['title'] = 'Error';
         $result['content'] = JText::_('Error');
     }
     $result = array();
     $result['success'] = true;
     $result['title'] = 'Done';
     $result['content'] = JText::_('Done');
     return $result;
 }
Example #5
0
	function generateOrder($member_id, $payment_method, $orderPaymentInfo) {
		return oseRegistry::call('msc')->runAddonAction('register.payment.save', array('member_id' => $member_id, 'payment_method' => $payment_method), true, false);
		$result = array();
		if (empty($member_id)) {
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText::_('Error');
			return $result;
		}
		$paymentOrder = oseRegistry::call('payment')->getInstance('Order');
		$params = array();
		$items = $orderPaymentInfo['items'];
		unset($orderPaymentInfo['items']);
		$order_number = $paymentOrder->generateOrderNumber($member_id);
		$orderPaymentInfo['order_number'] = $order_number;
		$orderPaymentInfo['entry_type'] = 'msc_list';
		$orderPaymentInfo['create_date'] = oseHTML::getDateTime();//date("Y-m-d H:i:s");
		$orderPaymentInfo['payment_serial_number'] = substr($orderPaymentInfo['order_number'], 0, 20);
		$orderPaymentInfo['payment_method'] = 'system';
		$orderPaymentInfo['payment_from'] = 'system_admin';
		$orderPaymentInfo['payment_mode'] = 'm';
		oseObject::setParams($orderPaymentInfo, array('time_stamp' => uniqid("{$member_id}_", true)));
		// Extra Order Params Updating Function
		$list = oseMscAddon::getAddonList('register_order', true, 1, 'obj');
		foreach ($list as $addon) {
			$action_name = 'register_order.' . $addon->name . '.add';
			//echo $action_name;
			$params = oseMscAddon::runAction($action_name, $orderPaymentInfo['params'], true, false);
		}
		// generate Order
		$updated = $paymentOrder->generateOrder('', $member_id, $orderPaymentInfo);
		if (!$updated) {
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText::_('Error');
			return $result;
		}
		// generate orer item
		// in the backend, only manual payment
		$order_id = $result['order_id'] = $updated;
		$payment_mode = 'm';
		foreach ($items as $item) {
			$itemParams = array();
			$entry_type = oseObject::getValue($item, 'entry_type');
			switch ($entry_type) {
			case ('license'):
				$license_id = oseObject::getValue($item, 'entry_id');
				$license = oseRegistry::call('lic')->getInstance(0);
				$licenseInfo = $license->getKeyInfo($license_id, 'obj');
				$licenseInfoParams = oseJson::decode($licenseInfo->params);
				$msc_id = $licenseInfoParams->msc_id;
				break;
			case ('msc'):
				$msc_id = oseObject::getValue($item, 'entry_id');
				break;
			}
			$msc_option = oseObject::getValue($item, 'msc_option');
			if (oseObject::getValue($item, 'eternal')) {
				$itemParams['payment_mode'] = 'm';
			} else {
				$itemParams['payment_mode'] = 'm';
			}
			$price = oseObject::getValue($item, 'a3');
			if ($payment_mode == 'a') {
				if (oseObject::getValue($item, 'has_trial')) {
					$price = oseObject::getValue($item, 'a1');
				}
			}
			$itemParams['entry_type'] = oseObject::getValue($item, 'entry_type');
			$itemParams['payment_price'] = 0;//oseObject::getValue($item,'first_raw_price');
			$itemParams['payment_currency'] = $orderPaymentInfo['payment_currency'];
			$itemParams['create_date'] = oseHTML::getDateTime();//date("Y-m-d H:i:s");
			$price_params = $paymentOrder->generateOrderParams($msc_id, $price, $payment_mode, $msc_option);
			$price_params['start_date'] = oseObject::getValue($item, 'start_date', null);
			$price_params['expired_date'] = oseObject::getValue($item, 'expired_date', null);
			$itemParams['params'] = oseJSON::encode($price_params);
			$paymentInfos = oseMscAddon::getExtInfo($msc_id, 'payment', 'obj');
			$paymentInfo = oseObject::getValue($paymentInfos, $msc_option);
			$updated = $paymentOrder->generateOrderItem($order_id, oseObject::getValue($item, 'entry_id'), $itemParams);
		}
		if ($updated) {
			$result['success'] = true;
			$result['title'] = JText::_('Done');
			$result['content'] = JText::_('Done');
		} else {
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText::_('Order Generate Error');
		}
		return $result;
	}
	private static function saveOS( $params )
	{
		$result = array();

    	$post = JRequest::get('post');

    	$member_id = $params['member_id'];
		$payment_method = $params['payment_method'];
		//oseExit($params);
    	JRequest::setVar('member_id',$member_id);

    	if(empty($member_id))
    	{
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText :: _('Error');

			return $result;
    	}

    	$params = array();

    	$paymentCart = oseMscPublic::getCart();
		$subtotal = $paymentCart->getSubtotal();

		$items = $paymentCart->get('items');

		$osePaymentCurrency = $paymentCart->get('currency');

		$payment = oseRegistry::call('payment');

		$keys = array_keys($items);
    	$payment_mode = $paymentCart->getParams('payment_mode');

		$order_number = $payment->generateOrderNumber( $member_id );

		$params['entry_type'] = 'msc_list';
		$params['payment_price'] = $subtotal;
		$params['payment_currency'] = $osePaymentCurrency;
        $params['order_number'] = $order_number;
        $params['create_date'] = oseHTML::getDateTime();//date("Y-m-d H:i:s");
		$params['payment_serial_number'] = substr($order_number,0,20);
		$params['payment_method'] = $payment_method;
		$params['payment_mode'] = $payment_mode;

		//$paymentOrder->__construct('#__osemsc_order_item');

		$params['params'] = array();
		foreach($items as $item)
		{
			$entry_type = oseObject::getValue($item,'entry_type');

			switch($entry_type)
			{
				case('license'):
					$license_id = oseObject::getValue($item,'entry_id');

					$license = oseRegistry::call('lic')->getInstance(0);
					$licenseInfo = $license->getKeyInfo($license_id,'obj');
					//oseExit($item);
					$licenseInfoParams = oseJson::decode($licenseInfo->params);

					$msc_id = $licenseInfoParams->msc_id;
				break;

				case('msc'):
					$msc_id = oseObject::getValue($item,'entry_id');
				break;
			}
			$msc_option = oseObject::getValue($item,'msc_option');

			$paymentInfos = oseRegistry::call('msc')->getExtInfo($msc_id,'payment','obj');
			$paymentInfo = oseObject::getValue($paymentInfos,$msc_option);

			$price = $paymentInfo->a3;
			if($payment_mode == 'a')
			{
				if($paymentInfo->has_trial)
				{
					$price = $paymentInfo->a1;
				}
			}

			$price = $payment->pricing($price,$msc_id,$osePaymentCurrency);

			$params['params'] = $payment->generateOrderParams($msc_id,$price,$payment_mode,$msc_option);
		}

		//oseExit($params['params']);
		$params['params']['total'] = $paymentCart->get('total');
		$params['params']['discount'] = $paymentCart->get('discount');
		$params['params']['subtotal'] = $subtotal;
		$params['params']['next_subtotal'] = $paymentCart->get('next_subtotal');
    	$params['params'] = oseJSON::encode($params['params']);

		//$config = oseRegistry::call('msc')->getConfig('payment','obj');
        //$params['payment_from'] = $config->payment_system;


		$paymentOrder = $payment->getInstance('Order');
		$updated = $paymentOrder->generateOrder('', $member_id, $params);

		if($updated)
		{
			$order_id = $updated;

			JRequest::setVar('order_id',$order_id);
		}
		else
		{
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText :: _('Error');

			return $result;
		}

		//$paymentOrder->__construct('#__osemsc_order_item');
		foreach($items as $item)
		{
			$itemParams = array();

			$entry_type = oseObject::getValue($item,'entry_type');

			switch($entry_type)
			{
				case('license'):
					$license_id = oseObject::getValue($item,'entry_id');

					$license = oseRegistry::call('lic')->getInstance(0);
					$licenseInfo = $license->getKeyInfo($license_id,'obj');
					//oseExit($item);
					$licenseInfoParams = oseJson::decode($licenseInfo->params);

					$msc_id = $licenseInfoParams->msc_id;
				break;

				case('msc'):
					$msc_id = oseObject::getValue($item,'entry_id');
				break;
			}
			$msc_option = oseObject::getValue($item,'msc_option');

			$paymentInfos = oseRegistry::call('msc')->getExtInfo($msc_id,'payment','obj');
			$paymentInfo = oseObject::getValue($paymentInfos,$msc_option);

			$price = $paymentInfo->a3;
			if($payment_mode == 'a')
			{
				if($paymentInfo->has_trial)
				{
					$price = $paymentInfo->a1;
				}
			}

			$price = $payment->pricing($price,$msc_id,$osePaymentCurrency);

			$itemParams['entry_type'] = oseObject::getValue($item,'entry_type');
			$itemParams['payment_price'] = oseObject::getValue($item,'first_raw_price');
			$itemParams['payment_currency'] = $osePaymentCurrency;
	        $itemParams['create_date'] = oseHTML::getDateTime();//date("Y-m-d H:i:s");

	        $price_params = $payment->generateOrderParams($msc_id,$price,$payment_mode,$msc_option);
	        //$itemParams['msc_id'] = $msc_id;
	        $itemParams['params'] = oseJSON::encode($price_params);

	        $paymentInfos = oseMscAddon::getExtInfo($msc_id,'payment','obj');
	        $paymentInfo = oseObject::getValue($paymentInfos,$msc_option);

	        if ( $paymentInfo->payment_mode == $payment_mode || $paymentInfo->payment_mode == 'b')
			{
				$itemParams['payment_mode'] = $payment_mode;
			}
			else
			{
				$itemParams['payment_mode'] = $paymentInfo->payment_mode;
			}

			$updated = $paymentOrder->generateOrderItem($order_id,oseObject::getValue($item,'entry_id'), $itemParams);
		}
		//$paymentOrder->__construct('#__osemsc_order');

		if($updated)
		{
			/*
			$vmorder=self::AddVmOrder($msc_id,$params,$order_number,$paymentInfo);
			if(!$vmorder['success'])
			{
				return $vmorder;
			}
			*/
			$result['success'] = true;
			$result['title'] = JText :: _('Done');
			$result['content'] = JText :: _('Done');
		}
		else
		{
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText :: _('Order Generate Error');
		}

		return $result;
	}
	private static function saveOS($params) {
		$result = array();
		$member_id = $params['member_id'];
		$payment_method = $params['payment_method'];
		JRequest::setVar('member_id', $member_id);
		if (empty($member_id)) {
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText::_('Error1');
			return $result;
		}
		$params = array();
		$paymentCart = $cart = oseRegistry::call('payment')->getInstance('Cart');
		$paymentCart->refreshCartItems($paymentCart->get('items'), $paymentCart->get('currency'));
		$osePaymentCurrency = $paymentCart->get('currency');
		$payment_mode = $paymentCart->getParams('payment_mode');
		$subtotal = $paymentCart->getSubtotal();
		if (empty($payment_mode)) {
			$payment_mode = oseMscPublic::savePaymentMode();
		}
		$items = $paymentCart->get('items');
		$oneItem = $items[0];
		$payment = oseRegistry::call('payment');
		$keys = array_keys($items);
		$order_number = $payment->generateOrderNumber($member_id);
		$params['entry_type'] = 'msc_list';
		$params['payment_price'] = $paymentCart->get('total');
		$params['payment_currency'] = $osePaymentCurrency;
		$params['order_number'] = $order_number;
		$params['create_date'] = oseHTML::getDateTime();
		$params['payment_serial_number'] = substr($order_number, 0, 20);
		$params['payment_method'] = $payment_method;
		$params['payment_mode'] = $payment_mode;
		$params['payment_from'] = 'system_reg';
		$params['params'] = array();
		$params['params']['start_date'] = oseObject::getValue($oneItem, 'start_date', null);
		$params['params']['expired_date'] = oseObject::getValue($oneItem, 'expired_date', null);
		$params['params']['total'] = $paymentCart->get('total');
		$params['params']['next_total'] = $paymentCart->get('next_total');
		$params['params']['discount'] = $paymentCart->get('discount');
		$params['params']['subtotal'] = $subtotal;
		$params['params']['coupon_user_id'] = $paymentCart->getParams('coupon_user_id');
		$params['params']['gross_tax'] = $paymentCart->getTaxParams('amount');
		$params['params']['next_gross_tax'] = $paymentCart->getTaxParams('next_amount');
		$params['params']['vat_number'] = $paymentCart->getTaxParams('vat_number');
		$params['params']['timestamp'] = uniqid("{$member_id}_", true);
		$params['params']['returnUrl'] = $paymentCart->getParams('returnUrl');
		if ($payment_mode == 'a') {
			$params['params']['has_trial'] = oseObject::getValue($oneItem, 'has_trial', 0);
		} else {
			$params['params']['has_trial'] = 0;
		}
		$sisow_issuerid = JRequest::getVar('sisow_issuerid');
		if ($sisow_issuerid) {
			$params['params']['sisow_issuerid'] = $sisow_issuerid;
		}
		$sisow_payment = JRequest::getVar('sisow_payment');
		if ($sisow_payment) {
			$params['params']['sisow_payment'] = $sisow_payment;
		}
		$params['params']['a1'] = $paymentCart->get('total');
		$params['params']['p1'] = oseObject::getValue($oneItem, 'p1', 0);
		$params['params']['t1'] = oseObject::getValue($oneItem, 't1');
		$params['params']['a3'] = $paymentCart->get('next_total');
		$params['params']['p3'] = oseObject::getValue($oneItem, 'p3', 0);
		$params['params']['t3'] = oseObject::getValue($oneItem, 't3');
		$params['params'] = oseJSON::encode($params['params']);
		$list = oseMscAddon::getAddonList('register_order', false, 1, 'obj');
		foreach ($list as $addon) {
			$action_name = 'register_order.' . $addon->name . '.add';
			$params = oseMscAddon::runAction($action_name, $params);
		}
		$paymentOrder = $payment->getInstance('Order');
		$updated = $paymentOrder->generateOrder('', $member_id, $params);
		if ($updated) {
			$order_id = $updated;
			$result['order_id'] = $order_id;
			JRequest::setVar('order_id', $order_id);
		} else {
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText::_('Error2');
			return $result;
		}
		foreach ($items as $item) {
			$itemParams = array();
			$entry_type = oseObject::getValue($item, 'entry_type');
			switch ($entry_type) {
			case ('license'):
				$license_id = oseObject::getValue($item, 'entry_id');
				$license = oseRegistry::call('lic')->getInstance(0);
				$licenseInfo = $license->getKeyInfo($license_id, 'obj');
				$licenseInfoParams = oseJson::decode($licenseInfo->params);
				$msc_id = $licenseInfoParams->msc_id;
				break;
			case ('msc'):
				$msc_id = oseObject::getValue($item, 'entry_id');
				break;
			}
			$msc_option = oseObject::getValue($item, 'msc_option');
			if (oseObject::getValue($item, 'eternal')) {
				$itemParams['payment_mode'] = 'm';
			} else {
				$itemParams['payment_mode'] = $payment_mode;
			}
			$price = oseObject::getValue($item, 'a3');
			if ($payment_mode == 'a') {
				if (oseObject::getValue($item, 'has_trial')) {
					$price = oseObject::getValue($item, 'a1');
				}
			}
			$itemParams['entry_type'] = oseObject::getValue($item, 'entry_type');
			$itemParams['payment_price'] = oseObject::getValue($item, 'first_raw_price');
			$itemParams['payment_currency'] = $osePaymentCurrency;
			$itemParams['create_date'] = oseHTML::getDateTime();
			$price_params = $payment->generateOrderParams($msc_id, $price, $payment_mode, $msc_option);
			$price_params['start_date'] = oseObject::getValue($item, 'start_date', null);
			$price_params['expired_date'] = oseObject::getValue($item, 'expired_date', null);
			$price_params['recurrence_mode'] = oseObject::getValue($item, 'recurrence_mode', 'period');
			$itemParams['params'] = oseJSON::encode($price_params);
			$paymentInfos = oseMscAddon::getExtInfo($msc_id, 'payment', 'obj');
			$paymentInfo = oseObject::getValue($paymentInfos, $msc_option);
			$updated = $paymentOrder->generateOrderItem($order_id, oseObject::getValue($item, 'entry_id'), $itemParams);
		}
		if ($updated) {
			$result['success'] = true;
			$result['title'] = JText::_('Done');
			$result['content'] = JText::_('Done');
		} else {
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText::_('Order Generate Error');
		}
		$emailConfig = oseMscConfig::getConfig('email', 'obj');
		if (!empty($emailConfig->order_notification)) {
			$db = oseDB::instance();
			$where = array();
			$where[] = '`order_id` = ' . $db->Quote($order_id);
			$orderInfo = $paymentOrder->getOrder($where, 'obj');
			$memEmail = oseRegistry::call('member')->getInstance('Email');
			$receipt = $memEmail->getOrderNotification($orderInfo);//print_r($receipt);exit;
			$memEmail->sendToAdminGroup($receipt, $emailConfig->admin_group);
		}
		return $result;
	}
	private static function saveOS( $params )
	{
		$result = array();

    	//$post = JRequest::get('post');

    	$member_id = $params['member_id'];
		$payment_method = $params['payment_method'];


		//oseExit($params);
    	JRequest::setVar('member_id',$member_id);

    	if(empty($member_id))
    	{
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText :: _('Error1');

			return $result;
    	}

    	$params = array();

    	//$paymentCart = oseMscPublic::getCart();
    	$paymentCart = $cart = oseRegistry::call('payment')->getInstance('Cart');
    	$paymentCart->refreshCartItems($paymentCart->get('items'),$paymentCart->get('currency'));

		$osePaymentCurrency = $paymentCart->get('currency');
		$payment_mode = $paymentCart->getParams('payment_mode');
		$subtotal = $paymentCart->getSubtotal();

		if(empty($payment_mode))
    	{
    		$payment_mode = oseMscPublic::savePaymentMode();
    	}

		$items = $paymentCart->get('items');

		$oneItem = $items[0];

		$payment = oseRegistry::call('payment');

		$keys = array_keys($items);
    	//$payment_mode = $paymentCart->getParams('payment_mode');

		$order_number = $payment->generateOrderNumber( $member_id );

		$params['entry_type'] = 'msc_list';
		$params['payment_price'] = $paymentCart->get('total');
		$params['payment_currency'] = $osePaymentCurrency;
        $params['order_number'] = $order_number;
        $params['create_date'] = oseHTML::getDateTime();//date("Y-m-d H:i:s");
		$params['payment_serial_number'] = substr($order_number,0,20);
		$params['payment_method'] = $payment_method;
		$params['payment_mode'] = $payment_mode;
		$params['payment_from'] = 'system_reg';

		$params['params'] = array();
		$params['params']['start_date'] = oseObject::getValue($oneItem,'start_date',null);
		$params['params']['expired_date'] = oseObject::getValue($oneItem,'expired_date',null);
		$params['params']['total'] = $paymentCart->get('total');
		if($paymentCart->getParams('coupon_range2') == 'all')
		{
			$params['params']['next_total'] = $params['params']['total'];
		}
		else
		{
			$params['params']['next_total'] = $paymentCart->get('next_total');
			//
		}
		
		//$params['params']['next_total'] = $params['params']['total'];//$paymentCart->get('next_total');
		$params['params']['discount'] = $paymentCart->get('discount');
		$params['params']['subtotal'] = $subtotal;
		$params['params']['coupon_user_id'] = $paymentCart->getParams('coupon_user_id');
		$params['params']['gross_tax'] = $paymentCart->getTaxParams('amount');
		$params['params']['next_gross_tax'] = $paymentCart->getTaxParams('next_amount');
		$params['params']['vat_number'] = $paymentCart->getTaxParams('vat_number');
		$params['params']['timestamp'] = uniqid("{$member_id}_",true);
		$params['params']['returnUrl'] = $paymentCart->getParams('returnUrl');
		if($payment_mode == 'a')
		{
			$params['params']['has_trial'] = oseObject::getValue($oneItem,'has_trial',0);
		}
		else
		{
			$params['params']['has_trial'] = 0;
		}

		$params['params']['a1'] = $paymentCart->get('total');
		$params['params']['p1'] = oseObject::getValue($oneItem,'p1',0);
		$params['params']['t1'] = oseObject::getValue($oneItem,'t1');
		$params['params']['a3'] = $paymentCart->get('next_total');
		$params['params']['p3'] = oseObject::getValue($oneItem,'p3',0);
		$params['params']['t3'] = oseObject::getValue($oneItem,'t3');
    	$params['params'] = oseJSON::encode($params['params']);

		$list = oseMscAddon :: getAddonList('register_order', false, 1, 'obj');
    	foreach($list as $addon) {
			$action_name= 'register_order.'.$addon->name.'.add';
			//echo $action_name;
			$params = oseMscAddon :: runAction($action_name, $params);
		}

		$paymentOrder = $payment->getInstance('Order');
		$updated = $paymentOrder->generateOrder('', $member_id, $params);

		if($updated)
		{
			$order_id = $updated;
			$result['order_id'] = $order_id;
			JRequest::setVar('order_id',$order_id);
		}
		else
		{
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText :: _('Error2');

			return $result;
		}

		//$paymentOrder->__construct('#__osemsc_order_item');
		foreach($items as $item)
		{
			$itemParams = array();

			$entry_type = oseObject::getValue($item,'entry_type');

			switch($entry_type)
			{
				case('license'):
					$license_id = oseObject::getValue($item,'entry_id');

					$license = oseRegistry::call('lic')->getInstance(0);
					$licenseInfo = $license->getKeyInfo($license_id,'obj');
					//oseExit($item);
					$licenseInfoParams = oseJson::decode($licenseInfo->params);

					$msc_id = $licenseInfoParams->msc_id;
				break;

				case('msc'):
					$msc_id = oseObject::getValue($item,'entry_id');
				break;
			}
			$msc_option = oseObject::getValue($item,'msc_option');

			//$paymentInfos = oseRegistry::call('msc')->getExtInfo($msc_id,'payment','obj');
			//$paymentInfo = oseObject::getValue($paymentInfos,$msc_option);

			if ( oseObject::getValue($item,'eternal'))
	        {
	        	$itemParams['payment_mode'] = 'm';
	        }
	        else
	        {
	        	$itemParams['payment_mode'] = $payment_mode;
	        }

			$price = oseObject::getValue($item,'a3');
			if($payment_mode == 'a')
			{
				if(oseObject::getValue($item,'has_trial'))
				{
					$price = oseObject::getValue($item,'a1');
				}
			}

			//$price = $payment->pricing($price,$msc_id,$osePaymentCurrency);

			$itemParams['entry_type'] = oseObject::getValue($item,'entry_type');
			$itemParams['payment_price'] = oseObject::getValue($item,'first_raw_price');
			$itemParams['payment_currency'] = $osePaymentCurrency;
	        $itemParams['create_date'] = oseHTML::getDateTime();//date("Y-m-d H:i:s");

	        $price_params = $payment->generateOrderParams($msc_id,$price,$payment_mode,$msc_option);
	        $price_params['start_date'] = oseObject::getValue($item,'start_date',null);
			$price_params['expired_date'] = oseObject::getValue($item,'expired_date',null);
			$price_params['recurrence_mode'] = oseObject::getValue($item,'recurrence_mode','period');
	        $itemParams['params'] = oseJSON::encode($price_params);

	        $paymentInfos = oseMscAddon::getExtInfo($msc_id,'payment','obj');
	        $paymentInfo = oseObject::getValue($paymentInfos,$msc_option);

			$updated = $paymentOrder->generateOrderItem($order_id,oseObject::getValue($item,'entry_id'), $itemParams);
		}
		//$paymentOrder->__construct('#__osemsc_order');

		if($updated)
		{
			/*
			$vmorder=self::AddVmOrder($msc_id,$params,$order_number,$paymentInfo);
			if(!$vmorder['success'])
			{
				return $vmorder;
			}
			*/
			$result['success'] = true;
			$result['title'] = JText :: _('Done');
			$result['content'] = JText :: _('Done');
		}
		else
		{
			$result['success'] = false;
			$result['title'] = 'Error';
			$result['content'] = JText :: _('Order Generate Error');
		}

		return $result;

	}
Example #9
0
 public function joinMsc($msc_id)
 {
     $db = oseDB::instance();
     $query = " SELECT COUNT(*) FROM `#__osemsc_member`" . " WHERE msc_id !={$msc_id} AND member_id = {$this->member_id}" . " AND status = 1";
     $db->setQuery($query);
     $hasMsc = $db->loadResult();
     if ($hasMsc > 0) {
         //return false;
     }
     $query = " SELECT * FROM `#__osemsc_member`" . " WHERE msc_id = {$msc_id} AND member_id = {$this->member_id}";
     $db->setQuery($query);
     $item = oseDB::loadItem('obj');
     if (!empty($item)) {
         $query = " UPDATE `#__osemsc_member`" . " SET `status` = 1, `notified` = '0', `notified2` = '0', `notified3` = '0' " . " WHERE msc_id = {$msc_id} AND member_id = {$this->member_id}";
         $db->setQuery($query);
         if (!$db->query()) {
             return false;
         }
         return $msc_id;
     } else {
         $exts = oseMscAddon::getExtInfo($msc_id, 'payment');
         foreach ($exts as $ext) {
             $eternal = $db->Quote(oseObject::getValue($ext, 'eternal'));
             break;
         }
         $eternal = empty($eternal) ? 0 : $eternal;
         $query = " INSERT INTO `#__osemsc_member` ( msc_id, member_id, eternal ) VALUES " . " ( {$msc_id},{$this->member_id}," . (int) $eternal . " ) ";
         $db->setQuery($query);
         if (!$db->query()) {
             return false;
         }
         return $db->insertid();
     }
 }
Example #10
0
 function getExtInfo($msc_id, $xtype, $type = 'array')
 {
     switch ($xtype) {
         case 'paymentAdv':
         case 'payment':
             $info = oseMscAddon::getExtInfoItem($msc_id, $xtype, 'obj');
             if (empty($info)) {
                 return array();
             } else {
                 $isArray = $type == 'array' ? true : false;
                 $items = oseJson::decode($info->params, $isArray);
                 if (empty($items)) {
                     $items = array();
                 }
                 return $items;
             }
             break;
         default:
             $info = oseMscAddon::getExtInfo($msc_id, $xtype, $type);
             return $info;
             break;
     }
 }