1010class OmnipayController extends Controller
1111{
1212 private $ orderModel ;
13+ private $ request ;
1314
14- public function __construct (Order $ orderPro ){
15+ public function __construct (Order $ orderPro, Request $ request ){
1516 $ this ->orderModel = $ orderPro ;
17+ $ this ->request = $ request ;
1618 }
1719 public function pay ($ gatewayNmae )
1820 {
@@ -25,8 +27,8 @@ public function pay($gatewayNmae)
2527 // ];
2628 // $order = $this->orderModel->create($createOrder);//订单写入数据库
2729
28- $ order_id = '20170929090814572607 ' ;
29- $ order = $ this ->orderModel ->where ( ' order_id ' , $ order_id )-> first ( );
30+ $ orderId = '20170929090814572608 ' ;
31+ $ order = $ this ->orderModel ->getOrder ( $ orderId );
3032 $ gateway = resolve ('omnipay ' )->gateway ($ gatewayNmae );
3133 switch ($ gatewayNmae ) {
3234 case 'alipay ' :
@@ -96,41 +98,64 @@ protected function unionpay($gateway,$order)
9698 /**
9799 * [callback 回调处理]
98100 * @param [type] $gatewayNmae [description]
99- * @param Request $request [description]
100101 * @return function [description]
101102 */
102- public function callback ($ gatewayNmae, Request $ request )
103+ public function callback ($ gatewayNmae )
103104 {
104- $ this ->completePurchase ($ gatewayNmae, $ request );
105+ dd ( $ this ->completePurchase ($ gatewayNmae) );
105106 }
106107 /**
107108 * [notify 异步通知处理]
108109 * @param [type] $gatewayNmae [description]
109- * @param Request $request [description]
110110 * @return [type] [description]
111111 */
112- public function notify ($ gatewayNmae, Request $ request )
112+ public function notify ($ gatewayNmae )
113113 {
114- $ this ->completePurchase ($ gatewayNmae, $ request );
114+ $ this ->completePurchase ($ gatewayNmae );
115115 }
116- protected function completePurchase ($ gatewayNmae , $ request )
116+ /**
117+ * [completePurchase 处理支付返回数据]
118+ * @param [type] $gatewayNmae [description]
119+ * @return [type] [description]
120+ */
121+ protected function completePurchase ($ gatewayNmae )
117122 {
118123 $ gateway = resolve ('omnipay ' )->gateway ($ gatewayNmae );
119- switch ($ gatewayNmae ) {
120- case 'alipay ' :
121- $ options = [
122- 'params ' => $ request ->all ()
123- ];
124- break ;
125- default :
126- $ options = [
127- 'request_params ' => $ request ->all ()
128- ];
129- break ;
130- }
124+ $ options = [
125+ 'params ' => $ this ->request ->all (),
126+ 'request_params ' => $ this ->request ->all ()
127+ ];
131128 $ response = $ gateway ->completePurchase ($ options )->send ();
132- dd ($ response );
133- $ response =get_class_methods ($ response );
134- dd ($ response );
129+ if ($ response ->isPaid ()||$ response ->isSuccessful ()) {
130+ $ data = $ response ->getData ();
131+ switch ($ gatewayNmae ) {
132+ case 'alipay ' :
133+ $ order = [
134+ 'order_id ' => $ data ['out_trade_no ' ],
135+ 'fee ' => $ data ['total_amount ' ],
136+ 'query_id ' => $ data ['trade_no ' ],
137+ ];
138+ break ;
139+ case 'wechat ' :
140+ $ order = [
141+ 'order_id ' => $ data ['out_trade_no ' ],
142+ 'fee ' => $ data ['total_amount ' ],
143+ 'query_id ' => $ data ['trade_no ' ],
144+ ];
145+ break ;
146+ case 'unionpay ' :
147+ $ order = [
148+ 'order_id ' => $ data ['orderId ' ],
149+ 'fee ' => $ data ['txnAmt ' ]*0.01 ,
150+ 'query_id ' => $ data ['queryId ' ],
151+ ];
152+ break ;
153+ }
154+ $ order ['gateway ' ] = $ gatewayNmae ;
155+ $ order ['status ' ] = 'paid ' ;
156+ return $ this ->orderModel ->paySuccess ($ order );
157+ }else {
158+ return false ;
159+ }
135160 }
136161}
0 commit comments