mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 09:39:10 +08:00
feature: added epay & mGate payment
This commit is contained in:
parent
e500fb77dc
commit
cff5d205bc
@ -85,12 +85,12 @@ class ConfigController extends Controller
|
||||
'bitpayx_name' => config('v2board.bitpayx_name', '在线支付'),
|
||||
'bitpayx_enable' => (int)config('v2board.bitpayx_enable', 0),
|
||||
'bitpayx_appsecret' => config('v2board.bitpayx_appsecret'),
|
||||
// vGate
|
||||
'vgate_name' => config('v2board.vgate_name', '在线支付'),
|
||||
'vgate_enable' => (int)config('v2board.vgate_enable', 0),
|
||||
'vgate_url' => config('v2board.vgate_url'),
|
||||
'vgate_app_id' => config('v2board.vgate_app_id'),
|
||||
'vgate_app_secret' => config('v2board.vgate_app_secret'),
|
||||
// mGate
|
||||
'mgate_name' => config('v2board.mgate_name', '在线支付'),
|
||||
'mgate_enable' => (int)config('v2board.mgate_enable', 0),
|
||||
'mgate_url' => config('v2board.mgate_url'),
|
||||
'mgate_app_id' => config('v2board.mgate_app_id'),
|
||||
'mgate_app_secret' => config('v2board.mgate_app_secret'),
|
||||
// Epay
|
||||
'epay_name' => config('v2board.epay_name', '在线支付'),
|
||||
'epay_enable' => (int)config('v2board.epay_enable', 0),
|
||||
|
@ -6,11 +6,12 @@ use App\Services\OrderService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use Library\Epay;
|
||||
use Omnipay\Omnipay;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Library\BitpayX;
|
||||
use Library\PayTaro;
|
||||
use Library\MGate;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
@ -128,12 +129,22 @@ class OrderController extends Controller
|
||||
]));
|
||||
}
|
||||
|
||||
public function payTaroNotify(Request $request)
|
||||
public function mgateNotify(Request $request)
|
||||
{
|
||||
// Log::info('payTaroNotify: ' . json_encode($request->input()));
|
||||
$mgate = new MGate(config('v2board.mgate_url'), config('v2board.mgate_app_id'), config('v2board.mgate_app_secret'));
|
||||
if (!$mgate->verify($request->input())) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
if (!$this->handle($request->input('out_trade_no'), $request->input('trade_no'))) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
die('success');
|
||||
}
|
||||
|
||||
$payTaro = new PayTaro(config('v2board.paytaro_app_id'), config('v2board.paytaro_app_secret'));
|
||||
if (!$payTaro->verify($request->input())) {
|
||||
public function epayNotify(Request $request)
|
||||
{
|
||||
$epay = new Epay(config('v2board.epay_url'), config('v2board.epay_pid'), config('v2board.epay_key'));
|
||||
if (!$epay->verify($request->input())) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
if (!$this->handle($request->input('out_trade_no'), $request->input('trade_no'))) {
|
||||
|
@ -18,7 +18,8 @@ use Omnipay\Omnipay;
|
||||
use Stripe\Stripe;
|
||||
use Stripe\Source;
|
||||
use Library\BitpayX;
|
||||
use Library\PayTaro;
|
||||
use Library\MGate;
|
||||
use Library\Epay;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
@ -213,12 +214,12 @@ class OrderController extends Controller
|
||||
'data' => $this->bitpayX($order)
|
||||
]);
|
||||
case 5:
|
||||
if (!(int)config('v2board.paytaro_enable')) {
|
||||
if (!(int)config('v2board.mgate_enable')) {
|
||||
abort(500, '支付方式不可用');
|
||||
}
|
||||
return response([
|
||||
'type' => 1,
|
||||
'data' => $this->payTaro($order)
|
||||
'data' => $this->mgate($order)
|
||||
]);
|
||||
case 6:
|
||||
if (!(int)config('v2board.stripe_card_enable')) {
|
||||
@ -228,6 +229,14 @@ class OrderController extends Controller
|
||||
'type' => 2,
|
||||
'data' => $this->stripeCard($order, $request->input('token'))
|
||||
]);
|
||||
case 7:
|
||||
if (!(int)config('v2board.epay_enable')) {
|
||||
abort(500, '支付方式不可用');
|
||||
}
|
||||
return response([
|
||||
'type' => 1,
|
||||
'data' => $this->epay($order)
|
||||
]);
|
||||
default:
|
||||
abort(500, '支付方式不存在');
|
||||
}
|
||||
@ -282,9 +291,9 @@ class OrderController extends Controller
|
||||
array_push($data, $bitpayX);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.paytaro_enable')) {
|
||||
if ((int)config('v2board.mgate_enable')) {
|
||||
$obj = new \StdClass();
|
||||
$obj->name = config('v2board.paytaro_name', '在线支付');
|
||||
$obj->name = config('v2board.mgate_name', '在线支付');
|
||||
$obj->method = 5;
|
||||
$obj->icon = 'wallet';
|
||||
array_push($data, $obj);
|
||||
@ -298,6 +307,14 @@ class OrderController extends Controller
|
||||
array_push($data, $obj);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.epay_enable')) {
|
||||
$obj = new \StdClass();
|
||||
$obj->name = config('v2board.epay_name', '在线支付');
|
||||
$obj->method = 7;
|
||||
$obj->icon = 'wallet';
|
||||
array_push($data, $obj);
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => $data
|
||||
]);
|
||||
@ -454,16 +471,28 @@ class OrderController extends Controller
|
||||
return isset($result['payment_url']) ? $result['payment_url'] : false;
|
||||
}
|
||||
|
||||
private function payTaro($order)
|
||||
private function mgate($order)
|
||||
{
|
||||
$payTaro = new PayTaro(config('v2board.paytaro_app_id'), config('v2board.paytaro_app_secret'));
|
||||
$result = $payTaro->pay([
|
||||
'app_id' => config('v2board.paytaro_app_id'),
|
||||
$mgate = new MGate(config('v2board_mgate_url'), config('v2board.mgate_app_id'), config('v2board.mgate_app_secret'));
|
||||
$result = $mgate->pay([
|
||||
'app_id' => config('v2board.mgate_app_id'),
|
||||
'out_trade_no' => $order->trade_no,
|
||||
'total_amount' => $order->total_amount,
|
||||
'notify_url' => url('/api/v1/guest/order/payTaroNotify'),
|
||||
'notify_url' => url('/api/v1/guest/order/mgateNotify'),
|
||||
'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order'
|
||||
]);
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function epay($order)
|
||||
{
|
||||
$epay = new Epay(config('v2board.epay_url'), config('v2board.epay_pid'), config('v2board.epay_key'));
|
||||
return $epay->pay([
|
||||
'money' => $order->total_amount / 100,
|
||||
'name' => $order->trade_no,
|
||||
'notify_url' => url('/api/v1/guest/order/epayNotify'),
|
||||
'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order',
|
||||
'out_trade_no' => $order->trade_no
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -60,12 +60,12 @@ class ConfigSave extends FormRequest
|
||||
'bitpayx_name' => '',
|
||||
'bitpayx_enable' => 'in:0,1',
|
||||
'bitpayx_appsecret' => '',
|
||||
// vGate
|
||||
'vgate_name' => '',
|
||||
'vgate_enable' => 'in:0,1',
|
||||
'vgate_url' => 'nullable|url',
|
||||
'vgate_app_id' => '',
|
||||
'vgate_app_secret' => '',
|
||||
// mGate
|
||||
'mgate_name' => '',
|
||||
'mgate_enable' => 'in:0,1',
|
||||
'mgate_url' => 'nullable|url',
|
||||
'mgate_app_id' => '',
|
||||
'mgate_app_secret' => '',
|
||||
// Epay
|
||||
'epay_name' => '',
|
||||
'epay_enable' => 'in:0,1',
|
||||
|
@ -16,7 +16,8 @@ class GuestRoute
|
||||
$router->post('/order/alipayNotify', 'Guest\\OrderController@alipayNotify');
|
||||
$router->post('/order/stripeNotify', 'Guest\\OrderController@stripeNotify');
|
||||
$router->post('/order/bitpayXNotify', 'Guest\\OrderController@bitpayXNotify');
|
||||
$router->post('/order/payTaroNotify', 'Guest\\OrderController@payTaroNotify');
|
||||
$router->post('/order/mgateNotify', 'Guest\\OrderController@mgateNotify');
|
||||
$router->post('/order/epayNotify', 'Guset\\OrderController@epayNotify');
|
||||
// Telegram
|
||||
$router->post('/telegram/webhook', 'Guest\\TelegramController@webhook');
|
||||
});
|
||||
|
42
library/Epay.php
Normal file
42
library/Epay.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Library;
|
||||
|
||||
class Epay
|
||||
{
|
||||
private $pid;
|
||||
private $key;
|
||||
private $url;
|
||||
|
||||
public function __construct($url, $pid, $key)
|
||||
{
|
||||
$this->pid = $pid;
|
||||
$this->key = $key;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function pay($params)
|
||||
{
|
||||
$params['pid'] = $this->pid;
|
||||
ksort($params);
|
||||
reset($params);
|
||||
$str = stripslashes(urldecode(http_build_query($params))) . $this->key;
|
||||
$params['sign'] = md5($str);
|
||||
$params['sign_type'] = 'MD5';
|
||||
return $this->url . '/submit.php?' . http_build_query($params);
|
||||
}
|
||||
|
||||
public function verify($params)
|
||||
{
|
||||
$sign = $params['sign'];
|
||||
unset($params['sign']);
|
||||
unset($params['sign_type']);
|
||||
ksort($params);
|
||||
reset($params);
|
||||
$str = stripslashes(urldecode(http_build_query($params))) . $this->key;
|
||||
if ($sign !== md5($str)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -4,15 +4,17 @@ namespace Library;
|
||||
|
||||
use \Curl\Curl;
|
||||
|
||||
class PayTaro
|
||||
class MGate
|
||||
{
|
||||
private $appId;
|
||||
private $appSecret;
|
||||
private $url;
|
||||
|
||||
public function __construct($appId, $appSecret)
|
||||
public function __construct($url, $appId, $appSecret)
|
||||
{
|
||||
$this->appId = $appId;
|
||||
$this->appSecret = $appSecret;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function pay($params)
|
||||
@ -21,7 +23,7 @@ class PayTaro
|
||||
$str = http_build_query($params) . $this->appSecret;
|
||||
$params['sign'] = md5($str);
|
||||
$curl = new Curl();
|
||||
$curl->post('https://api.paytaro.com/v1/gateway/fetch', http_build_query($params));
|
||||
$curl->post($this->url . '/v1/gateway/fetch', http_build_query($params));
|
||||
$result = $curl->response;
|
||||
if (!$result) {
|
||||
abort(500, '网络异常');
|
Loading…
Reference in New Issue
Block a user