update: payment add custom notify domain name

This commit is contained in:
tokumeikoi 2022-02-23 16:07:18 +08:00
parent 2ceb910812
commit 4eb3e23ddc
6 changed files with 31 additions and 24 deletions

View File

@ -26,7 +26,12 @@ class PaymentController extends Controller
{
$payments = Payment::all();
foreach ($payments as $k => $v) {
$payments[$k]['notify_url'] = url("/api/v1/guest/payment/notify/{$v->payment}/{$v->uuid}");
$notifyUrl = url("/api/v1/guest/payment/notify/{$v->payment}/{$v->uuid}");
if ($v->notify_domain) {
$parseUrl = parse_url($notifyUrl);
$notifyUrl = $v->notify_domain . $parseUrl['path'];
}
$payments[$k]['notify_url'] = $notifyUrl;
}
return response([
'data' => $payments
@ -58,22 +63,20 @@ class PaymentController extends Controller
'data' => true
]);
}
$request->validate([
$params = $request->validate([
'name' => 'required',
'icon' => 'nullable',
'payment' => 'required',
'config' => 'required'
'config' => 'required',
'notify_domain' => 'nullable|url'
], [
'name.required' => '显示名称不能为空',
'payment.required' => '网关参数不能为空',
'config.required' => '配置参数不能为空'
'config.required' => '配置参数不能为空',
'notify_domain.url' => '自定义通知域名格式有误'
]);
if (!Payment::create([
'name' => $request->input('name'),
'icon' => $request->input('icon'),
'payment' => $request->input('payment'),
'config' => $request->input('config'),
'uuid' => Helper::randomChar(8)
])) {
$params['uuid'] = Helper::randomChar(8);
if (!Payment::create($params)) {
abort(500, '保存失败');
}
return response([

View File

@ -32,25 +32,16 @@ class MGate {
'label' => 'AppSecret',
'description' => '',
'type' => 'input',
],
'notify_domain' => [
'label' => '通知域名(选填)',
'description' => '用于接收来自网关的支付通知',
'type' => 'input'
]
];
}
public function pay($order)
{
if (isset($this->config['notify_domain'])) {
$parseUrl = parse_url($order['notify_url']);
$notifyUrl = "{$parseUrl['scheme']}://{$this->config['notify_domain']}{$parseUrl['path']}";
}
$params = [
'out_trade_no' => $order['trade_no'],
'total_amount' => $order['total_amount'],
'notify_url' => $notifyUrl ?? $order['notify_url'],
'notify_url' => $order['notify_url'],
'return_url' => $order['return_url']
];
$params['app_id'] = $this->config['mgate_app_id'];

View File

@ -26,6 +26,7 @@ class PaymentService
$this->config['enable'] = $payment['enable'];
$this->config['id'] = $payment['id'];
$this->config['uuid'] = $payment['uuid'];
$this->config['notify_domain'] = $payment['notify_domain'];
};
$this->payment = new $this->class($this->config);
if (isset($this->payment->customResult)) $this->customResult = $this->payment->customResult;
@ -39,8 +40,15 @@ class PaymentService
public function pay($order)
{
// custom notify domain name
$notifyUrl = url("/api/v1/guest/payment/notify/{$this->method}/{$this->config['uuid']}");
if ($this->config['notify_domain']) {
$parseUrl = parse_url($notifyUrl);
$notifyUrl = $this->config['notify_domain'] . $parseUrl['path'];
}
return $this->payment->pay([
'notify_url' => url("/api/v1/guest/payment/notify/{$this->method}/{$this->config['uuid']}"),
'notify_url' => $notifyUrl,
'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order/' . $order['trade_no'],
'trade_no' => $order['trade_no'],
'total_amount' => $order['total_amount'],

View File

@ -144,6 +144,7 @@ CREATE TABLE `v2_payment` (
`name` varchar(255) NOT NULL,
`icon` varchar(255) DEFAULT NULL,
`config` text NOT NULL,
`notify_domain` varchar(128) DEFAULT NULL,
`enable` tinyint(1) NOT NULL DEFAULT '0',
`sort` int(11) DEFAULT NULL,
`created_at` int(11) NOT NULL,
@ -389,4 +390,4 @@ CREATE TABLE `v2_user` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 2022-02-19 16:59:30
-- 2022-02-23 07:42:04

View File

@ -504,3 +504,7 @@ CREATE TABLE `v2_stat_user` (
`updated_at` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
ALTER TABLE `v2_payment`
ADD `notify_domain` varchar(128) COLLATE 'utf8mb4_general_ci' NULL AFTER `config`;

File diff suppressed because one or more lines are too long