10
10
class OmnipayController extends Controller
11
11
{
12
12
private $ orderModel ;
13
+ private $ request ;
13
14
14
- public function __construct (Order $ orderPro ){
15
+ public function __construct (Order $ orderPro, Request $ request ){
15
16
$ this ->orderModel = $ orderPro ;
17
+ $ this ->request = $ request ;
16
18
}
17
19
public function pay ($ gatewayNmae )
18
20
{
@@ -25,8 +27,8 @@ public function pay($gatewayNmae)
25
27
// ];
26
28
// $order = $this->orderModel->create($createOrder);//订单写入数据库
27
29
28
- $ order_id = '20170929090814572607 ' ;
29
- $ order = $ this ->orderModel ->where ( ' order_id ' , $ order_id )-> first ( );
30
+ $ orderId = '20170929090814572608 ' ;
31
+ $ order = $ this ->orderModel ->getOrder ( $ orderId );
30
32
$ gateway = resolve ('omnipay ' )->gateway ($ gatewayNmae );
31
33
switch ($ gatewayNmae ) {
32
34
case 'alipay ' :
@@ -96,41 +98,64 @@ protected function unionpay($gateway,$order)
96
98
/**
97
99
* [callback 回调处理]
98
100
* @param [type] $gatewayNmae [description]
99
- * @param Request $request [description]
100
101
* @return function [description]
101
102
*/
102
- public function callback ($ gatewayNmae, Request $ request )
103
+ public function callback ($ gatewayNmae )
103
104
{
104
- $ this ->completePurchase ($ gatewayNmae, $ request );
105
+ dd ( $ this ->completePurchase ($ gatewayNmae) );
105
106
}
106
107
/**
107
108
* [notify 异步通知处理]
108
109
* @param [type] $gatewayNmae [description]
109
- * @param Request $request [description]
110
110
* @return [type] [description]
111
111
*/
112
- public function notify ($ gatewayNmae, Request $ request )
112
+ public function notify ($ gatewayNmae )
113
113
{
114
- $ this ->completePurchase ($ gatewayNmae, $ request );
114
+ $ this ->completePurchase ($ gatewayNmae );
115
115
}
116
- protected function completePurchase ($ gatewayNmae , $ request )
116
+ /**
117
+ * [completePurchase 处理支付返回数据]
118
+ * @param [type] $gatewayNmae [description]
119
+ * @return [type] [description]
120
+ */
121
+ protected function completePurchase ($ gatewayNmae )
117
122
{
118
123
$ 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
+ ];
131
128
$ 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
+ }
135
160
}
136
161
}
0 commit comments