|
7 | 7 |
|
8 | 8 | class OmnipayController extends Controller |
9 | 9 | { |
10 | | - |
11 | | - private $gateway; |
12 | | - |
13 | | - public function __construct(){ |
14 | | - $this->gateway = resolve('omnipay'); |
15 | | - if (config('omnipay.sandbox')) { |
16 | | - $this->gateway->sandbox(); |
| 10 | + public function pay($service) |
| 11 | + { |
| 12 | + $gateway = resolve('omnipay')->gateway($service); |
| 13 | + switch ($service) { |
| 14 | + case 'alipay': |
| 15 | + $response = $this->alipay($gateway); |
| 16 | + break; |
| 17 | + case 'wechat': |
| 18 | + $response = $this->wechat($gateway); |
| 19 | + break; |
| 20 | + case 'unionpay': |
| 21 | + $response = $this->unionpay($gateway); |
| 22 | + break; |
17 | 23 | } |
| 24 | + $response->redirect(); |
18 | 25 | } |
19 | | - public function pay($service) |
| 26 | + /** |
| 27 | + * [alipay 支付宝购买] |
| 28 | + * @param [type] $gateway [description] |
| 29 | + * @return [type] [description] |
| 30 | + */ |
| 31 | + protected function alipay($gateway) |
20 | 32 | { |
21 | | - $this->gateway->gateway($service); |
| 33 | + if (config('omnipay.debug')) { |
| 34 | + $gateway->sandbox(); |
| 35 | + } |
22 | 36 | $order = [ |
23 | 37 | 'out_trade_no' => date('YmdHis') . mt_rand(1000,9999), |
24 | 38 | 'subject' => 'Alipay Test', |
25 | 39 | 'total_amount' => '0.01', |
26 | 40 | 'product_code' => 'FAST_INSTANT_TRADE_PAY', |
27 | 41 | ]; |
28 | | - $response = $this->gateway->purchase()->setBizContent($order)->send(); |
29 | | - $response->redirect(); |
| 42 | + return $gateway->purchase()->setBizContent($order)->send(); |
30 | 43 | } |
31 | | - public function callback($service, Request $request) |
| 44 | + /** |
| 45 | + * [wechat 微信支付购买] |
| 46 | + * @param [type] $gateway [description] |
| 47 | + * @return [type] [description] |
| 48 | + */ |
| 49 | + protected function wechat($gateway) |
32 | 50 | { |
33 | | - $this->gateway->gateway($service); |
34 | | - $options = [ |
35 | | - 'params' => $request->all() |
| 51 | + return ''; |
| 52 | + } |
| 53 | + /** |
| 54 | + * [unionpay 银联支付购买] |
| 55 | + * @param [type] $gateway [description] |
| 56 | + * @return [type] [description] |
| 57 | + */ |
| 58 | + protected function unionpay($gateway) |
| 59 | + { |
| 60 | + $order = [ |
| 61 | + 'orderId' => date('YmdHis'), //Your order ID |
| 62 | + 'txnTime' => date('YmdHis'), //Should be format 'YmdHis' |
| 63 | + 'orderDesc' => 'My order title', //Order Title |
| 64 | + 'txnAmt' => '100', //Order Total Fee |
36 | 65 | ]; |
| 66 | + return $gateway->purchase($order)->send(); |
| 67 | + } |
37 | 68 |
|
38 | | - $response = $this->gateway->completePurchase($options)->send(); |
39 | | - dd($response->isSuccessful(),$response->isPaid()); |
40 | | - $response =get_class_methods($response); |
| 69 | + public function callback($service, Request $request) |
| 70 | + { |
| 71 | + $gateway = resolve('omnipay')->gateway($service); |
| 72 | + switch ($service) { |
| 73 | + case 'alipay': |
| 74 | + $options = [ |
| 75 | + 'params' => $request->all() |
| 76 | + ]; |
| 77 | + break; |
| 78 | + default: |
| 79 | + $options = [ |
| 80 | + 'request_params' => $request->all() |
| 81 | + ]; |
| 82 | + break; |
| 83 | + } |
| 84 | + $response = $gateway->completePurchase($options)->send(); |
| 85 | + dd($response); |
| 86 | + $response =get_class_methods($response); |
41 | 87 | dd($response); |
42 | 88 | } |
43 | 89 | } |
0 commit comments