示例#1
0
	function cancelOrder()
	{
		$result = array();
		$result['success']= false;
		$result['title']= 'Error';
		$result['content']= 'Error';

		$db = oseDB::instance();

		$msc= oseRegistry :: call('msc');
		$member = oseRegistry::call('member');
		$email = oseRegistry::call('member')->getInstance('Email');
		$payment= oseRegistry :: call('payment');
		$paymentOrder= $payment->getInstance('Order');

		$my = JFactory::getUser();
		$user_id = $my->id;
		$member->instance($user_id);

		$order_id = JRequest::getInt('order_id',0);

		$member->instance($user_id);
		$memberships = $member->getMemberOwnedMscInfo(false,1,'obj');

		$query = " SELECT * FROM `#__osemsc_order`"
				." WHERE `user_id` = '{$user_id}' AND `order_status` = 'confirmed' AND `payment_mode`='a'"
				;

		$db->setQuery($query);
		$list = oseDB::loadList('obj');
		$order_ids = array();
		foreach($list as $oItem)
		{
			//$memParams = oseJson::decode($membership->params);
			$order_ids[$oItem->order_id] = $oItem->order_id;
		}

		if( !in_array( $order_id,$order_ids ) )
		{
			$result['success']= false;
			$result['title']= 'Error';
			$result['content']= JText :: _('Error No this authority: ').$order_id;
		}

		$where= array();
		$where[]= "`order_id` = ".$db->Quote($order_id);
		$order = $payment->getOrder($where, 'obj');

		//$result['success']= true;
		$result['payment_mode']= $order->payment_mode;
		$result['payment_method'] = $order->payment_method;

		//$msc_id = $order->entry_id;

		switch($order->payment_method)
		{
			case('paypal_cc') :
				if($order->payment_mode == 'a') {

					$config= oseMscConfig :: getConfig('payment', 'obj');

					$updated = $paymentOrder->PaypalAPIDeleteProfile($order->payment_serial_number, substr($order->order_number, 0, 20), $user_id);

					if ($updated['success']==true)
					{
						$email->sendCancelOrderEmail(array('orderInfo'=>$order));
						$result['success']= true;
						$result['title']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY_TITLE');
						$result['content']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY');
					}
					else
					{
						$result['success']= false;
						$result['title']= 'Error';
						$result['content']= JText :: _('ERROR_CANCELLING_SUB_PLAN').' '.urldecode($order->payment_serial_number). "<br />".JText::_(' Error response from server: '). urldecode($updated['text']);
					}
				}
			break;

			case('paypal') :
				if($order->payment_mode == 'a') {

					$config= oseMscConfig :: getConfig('payment', 'obj');

					if($config->paypal_mode == 'paypal_express')
					{
						$test_mode= $config->paypal_testmode;
						$paypal_email = $config->paypal_email;
						if($test_mode == true)
						{
							$url= "https://www.sandbox.paypal.com/cgi-bin/webscr";
						} else {
							$url= "https://www.paypal.com/cgi-bin/webscr";
						}
						$url = $url.'?cmd=_subscr-find&alias='.$paypal_email;

						$result['success']= true;
						$result['payment_method'] = 'paypal';
						$result['paypal']= 'ipn';
						$result['url']= $url;
						return $result;
					}
					else
					{
						//$result['payment_method'] = 'paypal_pro';
						$updated= $paymentOrder->PaypalAPIDeleteProfile($order->payment_serial_number, substr($order->order_number, 0, 20), $user_id);
						if ($updated['success']==true)
						{
							$paymentOrder->updateOrder($order->order_id,'cancelled');
							$email->sendCancelOrderEmail(array('orderInfo'=>$order));
							$result['success']= true;
							$result['title']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY_TITLE');
							$result['content']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY');
						}
						else
						{
							$result['success']= false;
							$result['title']= 'Error';
							$result['content']= JText :: _('ERROR_CANCELLING_SUB_PLAN').' '.urldecode($order->payment_serial_number). "<br />".JText::_(' Error response from server: '). urldecode($updated['text']);
						}

					}
				}
				break;

			case('authorize') :
				if($order->payment_mode == 'a') {
					$updated= $paymentOrder->AuthorizeARBDeleteProfile($order->payment_serial_number, substr($order->order_number, 0, 20), $user_id);
					if ($updated['success']==true)
					{
						$email->sendCancelOrderEmail(array('orderInfo'=>$order));

						$result['success']= true;
						$result['title']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY_TITLE');
						$result['content']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY');
					}
					else
					{
						$result['success']= false;
						$result['title']= 'Error';

						if (strpos($order->payment_serial_number, "_")>0)
						{
							$tmpUID = explode("_", $order->payment_serial_number);
							if ($tmpUID[0] == $order->user_id)
							{
								$result['content']= JText :: _('CREDIT_CARD_EXPIRE_BEFORE_SUB_ENDS');
							}
							else
							{
								$result['content']= JText :: _('ERROR_CANCELLING_SUB_PLAN').' '.urldecode($order->payment_serial_number);
							}
						}
						else
						{
							$result['content']= $updated['text'];
						}
					}
				}
				break;

			case('eway'):
				if($order->payment_mode == 'a') {
					$updated= $paymentOrder->eWayDeleteProfile($order);
					if ($updated['success']==true)
					{
						$email->sendCancelOrderEmail(array('orderInfo'=>$order));

						$result['success']= true;
						$result['title']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY_TITLE');
						$result['content']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY');
					}
					else
					{
						$result['success']= false;
						$result['title']= 'Error';
						$result['content']= $updated['text'];//JText :: _('Error cancelling subscription plan! Please contact the web administrator and quote this profile ID: ').urldecode($order->payment_serial_number);
					}
				}
				break;

			case('beanstream') :
				if($order->payment_mode == 'a') {
					$updated= $paymentOrder->BeanStreamDeleteProfile($order);
					if ($updated['success']==true)
					{
						$email->sendCancelOrderEmail(array('orderInfo'=>$order));

						$result['success']= true;
						$result['title']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY_TITLE');
						$result['content']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY');
					}
					else
					{
						$result['success']= false;
						$result['title']= 'Error';
						$result['content']= $updated['text'];//JText :: _('Error cancelling subscription plan! Please contact the web administrator and quote this profile ID: ').urldecode($order->payment_serial_number);
					}
				}
				break;
			case('epay') :
				if($order->payment_mode == 'a') {
					require_once(OSEMSC_B_PATH.DS.'libraries'.DS.'epaysoap.php');
					$epay = new EpaySoap();
					$config = oseMscConfig::getConfig('payment','obj');
					$merchantnumber = $config->epay_merchantnumber;
					$subscriptionid = $order->payment_serial_number;
					$updated= $epay->deleteSubscription($merchantnumber, $subscriptionid);
					if($updated['deletesubscriptionResult'] == true && $result['epayresponse'] == '-1')

					//$updated= $paymentOrder->BeanStreamDeleteProfile($order);
					//if ($updated['success']==true)
					{
						$email->sendCancelOrderEmail(array('orderInfo'=>$order));

						$result['success']= true;
						$result['title']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY_TITLE');
						$result['content']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY');
					}
					else
					{
						$result['success']= false;
						$result['title']= 'Error';
						$result['content']= $updated['text'];//JText :: _('Error cancelling subscription plan! Please contact the web administrator and quote this profile ID: ').urldecode($order->payment_serial_number);
					}
				}
				break;
				
			case('2co') :
				if($order->payment_mode == 'a') {	
					$updated= $paymentOrder->twoCheckoutDeleteProfile($order);
					if ($updated['success']==true)
					{
						$email->sendCancelOrderEmail(array('orderInfo'=>$order));

						$result['success']= true;
						$result['title']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY_TITLE');
						$result['content']= JText :: _('SUB_PLAN_CANCEL_SUCCESSFULLY');
					}
					else
					{
						$result['success']= false;
						$result['title']= 'Error';
						$result['content']= $updated['text'];//JText :: _('Error cancelling subscription plan! Please contact the web administrator and quote this profile ID: ').urldecode($order->payment_serial_number);
					}
				}
			break;	
			default :
				$orderItems = $paymentOrder->getOrderItems($order->order_id,'obj');
				foreach($orderItems as $key=>$orderItem)
				{
					if($orderItem->entry_type == 'msc')
					{
						$msc_id = $orderItem->entry_id;

						$params= oseRegistry :: call('member')->getAddonParams($msc_id, $user_id, $order_id);
						$updated= $msc->runAddonAction('member.msc.cancelMsc', $params);
						if(!$updated['success']) {
							return $updated;
						}
					}
				}

				break;
		}

		if ($result['success']==true)
		{
			$orderItems = $paymentOrder->getOrderItems($order->order_id,'obj');
			foreach($orderItems as $key=>$orderItem)
			{
				if($orderItem->entry_type == 'msc')
				{
					$msc_id = $orderItem->entry_id;

					$arr = array('allow_work'=>true,'msc_id'=>$msc_id,'member_id'=>$user_id,'master'=>true);
					oseMscAddon::runAction('join.history.manualCancelOrder', $arr);
				}
			}

	    	$paymentOrder->updateOrder($order_id, 'cancelled', $params= array('payment_mode'=>'a'));
	    	//$paymentOrder->updateMembership($msc_id, $user_id, $order_id, 'm');
		}
		return $result;
	}
        $pageURL .= "s";
    }
    $pageURL .= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
        $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
    } else {
        $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
    }
    $replace = "&mode=" . $_GET['mode'];
    $pageURL = str_replace($replace, "", $pageURL);
    return $pageURL;
}
//Get the class
require_once "epaysoap.php";
//Access the webservice
$epay = new EpaySoap();
//Get action
if (isset($_GET['mode'])) {
    $mode = $_GET['mode'];
    //Select mode
    switch ($mode) {
        case 1:
            //Capture
            $return = $epay->capture($merchantnumber, $_GET['tid'], $_GET['amount']);
            break;
        case 2:
            //Credit
            $return = $epay->credit($merchantnumber, $_GET['tid'], $_GET['amount']);
            break;
        case 3:
            //Delete