Skip to content

Commit 38972ad

Browse files
committed
增加post回调 重定向根据驱动区分
1 parent 39aead6 commit 38972ad

File tree

4 files changed

+79
-21
lines changed

4 files changed

+79
-21
lines changed

src/App/Http/Controllers/OmnipayController.php

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,83 @@
77

88
class OmnipayController extends Controller
99
{
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;
1723
}
24+
$response->redirect();
1825
}
19-
public function pay($service)
26+
/**
27+
* [alipay 支付宝购买]
28+
* @param [type] $gateway [description]
29+
* @return [type] [description]
30+
*/
31+
protected function alipay($gateway)
2032
{
21-
$this->gateway->gateway($service);
33+
if (config('omnipay.debug')) {
34+
$gateway->sandbox();
35+
}
2236
$order = [
2337
'out_trade_no' => date('YmdHis') . mt_rand(1000,9999),
2438
'subject' => 'Alipay Test',
2539
'total_amount' => '0.01',
2640
'product_code' => 'FAST_INSTANT_TRADE_PAY',
2741
];
28-
$response = $this->gateway->purchase()->setBizContent($order)->send();
29-
$response->redirect();
42+
return $gateway->purchase()->setBizContent($order)->send();
3043
}
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)
3250
{
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
3665
];
66+
return $gateway->purchase($order)->send();
67+
}
3768

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);
4187
dd($response);
4288
}
4389
}

src/Config/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
Ignited\LaravelOmnipay\LaravelOmnipayServiceProvider::class,
1414
CoreCMF\Omnipay\Providers\EventServiceProvider::class,//事件服务
1515
],
16-
'sandbox' => true,
16+
'debug' => true,
1717
];

src/Config/laravel-omnipay.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
return [
44

55
// The default gateway to use
6-
'default' => 'alipay',
6+
'default' => 'paypal',
77

88
// Add in each gateway here
99
'gateways' => [
@@ -26,6 +26,17 @@
2626
'returnUrl' => 'http://corecmf.dev/Omnipay/alipay/callback',
2727
'notifyUrl' => 'http://corecmf.dev/Omnipay/alipay'
2828
]
29-
]
29+
],
30+
'unionpay' => [
31+
'driver' => 'UnionPay_Express',
32+
'options' => [
33+
'merId' => '777290058151800',
34+
'certPath' => storage_path('app/certificates/unionpay/unionpay_acp.pfx'),
35+
'certPassword' =>'000000',
36+
'certDir'=> storage_path('app/certificates/unionpay'),
37+
'returnUrl' => 'http://corecmf.dev/Omnipay/unionpay/callback',
38+
'notifyUrl' => 'http://corecmf.dev/Omnipay/unionpay'
39+
]
40+
]
3041
]
3142
];

src/Routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
Route::group(['prefix' => 'Omnipay', 'middleware' => 'web', 'namespace' => 'CoreCMF\Omnipay\App\Http\Controllers', 'as' => 'Omnipay.'], function () {
1919
Route::get('{service}', [ 'as' => 'pay', 'uses' => 'OmnipayController@pay']);
2020
Route::get('{service}/callback', [ 'as' => 'callback', 'uses' => 'OmnipayController@callback']);
21+
Route::post('{service}/callback', [ 'as' => 'callback', 'uses' => 'OmnipayController@callback']);
2122
});

0 commit comments

Comments
 (0)