Example #1
0
 /**
  * 服务器端 POST形式响应
  */
 public function respond_post()
 {
     $_POST['code'] = $_POST['code'] ? $_POST['code'] : $_GET['code'];
     if ($_POST['code']) {
         $payment = $this->get_by_code($_POST['code']);
         if (!$payment) {
             error_log(date('m-d H:i:s', SYS_TIME) . '| POST: payment is null |' . "\r\n", 3, CACHE_PATH . 'pay_error_log.php');
         }
         $cfg = unserialize_config($payment['config']);
         $pay_name = ucwords($payment['pay_code']);
         pc_base::load_app_class('pay_factory', '', 0);
         $payment_handler = new pay_factory($pay_name, $cfg);
         $return_data = $payment_handler->notify();
         if ($return_data) {
             if ($return_data['order_status'] == 0) {
                 $this->update_member_amount_by_sn($return_data['order_id']);
             }
             $this->update_recode_status_by_sn($return_data['order_id'], $return_data['order_status']);
             $result = TRUE;
         } else {
             $result = FALSE;
         }
         $payment_handler->response($result);
     }
 }
 /**
  * --------------------------------------------------------------
  * 服务器端get响应
  * --------------------------------------------------------------
  * 返回成功提示,5秒后跳转到指定页面
  */
 public function respondGet($code = '')
 {
     if (empty($code)) {
         return false;
     }
     \Omnipay::setGateway($code);
     $resquest = \Omnipay::completePurchase(['request_params' => \Input::all()]);
     $response = $resquest->send();
     if ($response->isSuccessful()) {
         //TODO
         //验证成功
         //更新账户余额
         //更新订单状态
     } else {
     }
     if ($code) {
         $payment = $this->get_by_code($_GET['code']);
         if (!$payment) {
             showmessage(L('payment_failed'));
         }
         $cfg = unserialize_config($payment['config']);
         $pay_name = ucwords($payment['pay_code']);
         pc_base::load_app_class('pay_factory', '', 0);
         $payment_handler = new pay_factory($pay_name, $cfg);
         $return_data = $payment_handler->receive();
         if ($return_data) {
             if ($return_data['order_status'] == 0) {
                 $this->update_member_amount_by_sn($return_data['order_id']);
             }
             $this->update_recode_status_by_sn($return_data['order_id'], $return_data['order_status']);
             //支付成功
             //showmessage(L('pay_success'),APP_PATH.'index.php?m=pay&c=deposit');
         } else {
             //支付失败
             //showmessage(L('pay_failed'),APP_PATH.'index.php?m=pay&c=deposit');
         }
     } else {
         //支付成功
     }
 }
Example #3
0
	public function pay_recharge() {
		if(isset($_POST['dosubmit'])) {
			$code = isset($_POST['code']) && trim($_POST['code']) ? trim($_POST['code']) : showmessage(L('input_code'), HTTP_REFERER);
			if ($_SESSION['code'] != strtolower($code)) {
					showmessage(L('code_error'), HTTP_REFERER);
			}
			$pay_id = $_POST['pay_type'];
			if(!$pay_id) showmessage(L('illegal_pay_method'));
			$payment = $this->handle->get_payment($pay_id);
			$cfg = unserialize_config($payment['config']);
			$pay_name = ucwords($payment['pay_code']);
			if(!param::get_cookie('trade_sn')) {showmessage(L('illegal_creat_sn'));}
			
			$trade_sn	= param::get_cookie('trade_sn');
			$usernote = $_POST['info']['usernote'] ? $_POST['info']['name'].'['.$trade_sn.']'.'-'.new_html_special_chars(trim($_POST['info']['usernote'])) : $_POST['info']['name'].'['.$trade_sn.']';
			
			$surplus = array(
					'userid'      => $this->_userid,
					'username'    => $this->_username,
					'money'       => trim(floatval($_POST['info']['price'])),
					'quantity'    => $_POST['quantity'] ? trim(intval($_POST['quantity'])) : 1,
					'telephone'   => trim($_POST['info']['telephone']),
					'contactname' => $_POST['info']['name'] ? trim($_POST['info']['name']).L('recharge') : $this->_username.L('recharge'),
					'email'       => trim($_POST['info']['email']),
					'addtime'	  => SYS_TIME,
					'ip'	  => ip(),
					'pay_type'	  => 'recharge',
					'pay_id'     => $payment['pay_id'],		
					'payment'     => trim($payment['pay_name']),
					'ispay'		  => '1',
					'usernote'    => $usernote,
					'trade_sn'	  => $trade_sn,
			);
			
			$recordid = $this->handle->set_record($surplus);
			
			$factory_info = $this->handle->get_record($recordid);
			if(!$factory_info) showmessage(L('order_closed_or_finish'));
			$pay_fee = pay_fee($factory_info['money'],$payment['pay_fee'],$payment['pay_method']);
			$logistics_fee = $factory_info['logistics_fee'];
			$discount = $factory_info['discount'];
			
			// calculate amount
			$factory_info['price'] = $factory_info['money'] + $pay_fee + $logistics_fee + $discount;
			
			// add order info
			$order_info['id']	= $factory_info['trade_sn'];
			$order_info['quantity']	= $factory_info['quantity'];
			$order_info['buyer_email']	= $factory_info['email'];
			$order_info['order_time']	= $factory_info['addtime'];
			
			//add product info
			$product_info['name'] = $factory_info['contactname'];
			$product_info['body'] = $factory_info['usernote'];
			$product_info['price'] = $factory_info['price'];
			
			//add set_customerinfo
			$customerinfo['telephone'] = $factory_info['telephone'];
			if($payment['is_online'] === '1') {
				pc_base::load_app_class('pay_factory','',0);
				$payment_handler = new pay_factory($pay_name, $cfg);
				$payment_handler->set_productinfo($product_info)->set_orderinfo($order_info)->set_customerinfo($customer_info);
				$code = $payment_handler->get_code('value="'.L('confirm_pay').'" class="button"');	
			} else {
				$this->account_db->update(array('status'=>'waitting','pay_type'=>'offline'),array('id'=>$recordid));
				$code = '<div class="point">'.L('pay_tip').'</div>';
			}
		}
		include template('pay', 'payment_cofirm');		
	}