update: add payment handling fee

This commit is contained in:
tokumeikoi 2022-03-17 14:50:02 +08:00
parent 1111c6f13d
commit a5ea79493c
14 changed files with 60 additions and 32 deletions

View File

@ -51,30 +51,34 @@ class PaymentController extends Controller
if (!config('v2board.app_url')) { if (!config('v2board.app_url')) {
abort(500, '请在站点配置中配置站点地址'); abort(500, '请在站点配置中配置站点地址');
} }
if ($request->input('id')) {
$payment = Payment::find($request->input('id'));
if (!$payment) abort(500, '支付方式不存在');
try {
$payment->update($request->input());
} catch (\Exception $e) {
abort(500, '更新失败');
}
return response([
'data' => true
]);
}
$params = $request->validate([ $params = $request->validate([
'name' => 'required', 'name' => 'required',
'icon' => 'nullable', 'icon' => 'nullable',
'payment' => 'required', 'payment' => 'required',
'config' => 'required', 'config' => 'required',
'notify_domain' => 'nullable|url' 'notify_domain' => 'nullable|url',
'handling_fee_fixed' => 'nullable|integer',
'handling_fee_percent' => 'nullable|numeric|between:0.1,100'
], [ ], [
'name.required' => '显示名称不能为空', 'name.required' => '显示名称不能为空',
'payment.required' => '网关参数不能为空', 'payment.required' => '网关参数不能为空',
'config.required' => '配置参数不能为空', 'config.required' => '配置参数不能为空',
'notify_domain.url' => '自定义通知域名格式有误' 'notify_domain.url' => '自定义通知域名格式有误',
'handling_fee_fixed.integer' => '固定手续费格式有误',
'handling_fee_percent.between' => '百分比手续费范围须在0.1-100之间'
]); ]);
if ($request->input('id')) {
$payment = Payment::find($request->input('id'));
if (!$payment) abort(500, '支付方式不存在');
try {
$payment->update($params);
} catch (\Exception $e) {
abort(500, $e->getMessage());
}
return response([
'data' => true
]);
}
$params['uuid'] = Helper::randomChar(8); $params['uuid'] = Helper::randomChar(8);
if (!Payment::create($params)) { if (!Payment::create($params)) {
abort(500, '保存失败'); abort(500, '保存失败');

View File

@ -184,13 +184,17 @@ class OrderController extends Controller
$payment = Payment::find($method); $payment = Payment::find($method);
if (!$payment || $payment->enable !== 1) abort(500, __('Payment method is not available')); if (!$payment || $payment->enable !== 1) abort(500, __('Payment method is not available'));
$paymentService = new PaymentService($payment->payment, $payment->id); $paymentService = new PaymentService($payment->payment, $payment->id);
if ($order->total_amount > 0 && ($payment->handling_fee_fixed || $payment->handling_fee_percent)) {
$order->handling_amount = ($order->total_amount * ($payment->handling_fee_percent / 100)) + $payment->handling_fee_fixed;
}
$order->payment_id = $method;
if (!$order->save()) abort(500, __('Request failed, please try again later'));
$result = $paymentService->pay([ $result = $paymentService->pay([
'trade_no' => $tradeNo, 'trade_no' => $tradeNo,
'total_amount' => $order->total_amount, 'total_amount' => isset($order->handling_amount) ? ($order->total_amount + $order->handling_amount) : $order->total_amount,
'user_id' => $order->user_id, 'user_id' => $order->user_id,
'stripe_token' => $request->input('token') 'stripe_token' => $request->input('token')
]); ]);
$order->update(['payment_id' => $method]);
return response([ return response([
'type' => $result['type'], 'type' => $result['type'],
'data' => $result['data'] 'data' => $result['data']
@ -217,7 +221,9 @@ class OrderController extends Controller
'id', 'id',
'name', 'name',
'payment', 'payment',
'icon' 'icon',
'handling_fee_fixed',
'handling_fee_percent'
]) ])
->where('enable', 1)->get(); ->where('enable', 1)->get();

View File

@ -120,6 +120,7 @@ CREATE TABLE `v2_order` (
`trade_no` varchar(36) NOT NULL, `trade_no` varchar(36) NOT NULL,
`callback_no` varchar(255) DEFAULT NULL, `callback_no` varchar(255) DEFAULT NULL,
`total_amount` int(11) NOT NULL, `total_amount` int(11) NOT NULL,
`handling_amount` int(11) DEFAULT NULL,
`discount_amount` int(11) DEFAULT NULL, `discount_amount` int(11) DEFAULT NULL,
`surplus_amount` int(11) DEFAULT NULL COMMENT '剩余价值', `surplus_amount` int(11) DEFAULT NULL COMMENT '剩余价值',
`refund_amount` int(11) DEFAULT NULL COMMENT '退款金额', `refund_amount` int(11) DEFAULT NULL COMMENT '退款金额',
@ -145,6 +146,8 @@ CREATE TABLE `v2_payment` (
`icon` varchar(255) DEFAULT NULL, `icon` varchar(255) DEFAULT NULL,
`config` text NOT NULL, `config` text NOT NULL,
`notify_domain` varchar(128) DEFAULT NULL, `notify_domain` varchar(128) DEFAULT NULL,
`handling_fee_fixed` int(11) DEFAULT NULL,
`handling_fee_percent` decimal(5,2) DEFAULT NULL,
`enable` tinyint(1) NOT NULL DEFAULT '0', `enable` tinyint(1) NOT NULL DEFAULT '0',
`sort` int(11) DEFAULT NULL, `sort` int(11) DEFAULT NULL,
`created_at` int(11) NOT NULL, `created_at` int(11) NOT NULL,
@ -374,4 +377,4 @@ CREATE TABLE `v2_user` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 2022-03-10 15:45:02 -- 2022-03-17 05:35:39

View File

@ -517,3 +517,10 @@ ADD INDEX `record_at` (`record_at`);
ALTER TABLE `v2_stat_server` ALTER TABLE `v2_stat_server`
CHANGE `u` `u` bigint NOT NULL AFTER `server_type`, CHANGE `u` `u` bigint NOT NULL AFTER `server_type`,
CHANGE `d` `d` bigint NOT NULL AFTER `u`; CHANGE `d` `d` bigint NOT NULL AFTER `u`;
ALTER TABLE `v2_payment`
ADD `handling_fee_fixed` int(11) NULL AFTER `notify_domain`,
ADD `handling_fee_percent` decimal(5,2) NULL AFTER `handling_fee_fixed`;
ALTER TABLE `v2_order`
ADD `handling_amount` int(11) NULL AFTER `total_amount`;

File diff suppressed because one or more lines are too long

View File

@ -54,7 +54,7 @@ window.settings.i18n['en-US'] = {
'佣金将会在确认后会到达你的佣金账户。': 'The commission will reach your commission account after review.', '佣金将会在确认后会到达你的佣金账户。': 'The commission will reach your commission account after review.',
'邀请码管理': 'Invitation Code Management', '邀请码管理': 'Invitation Code Management',
'生成邀请码': 'Generate invitation code', '生成邀请码': 'Generate invitation code',
'佣金发放记录': '佣金发放记录', '佣金发放记录': 'Commission Income Record',
'复制成功': 'Copied successfully', '复制成功': 'Copied successfully',
'密码': 'Password', '密码': 'Password',
'登入': 'Login', '登入': 'Login',
@ -244,5 +244,6 @@ window.settings.i18n['en-US'] = {
'该订阅无法续费,仅允许新用户购买': 'This subscription cannot be renewed and is only available to new users.', '该订阅无法续费,仅允许新用户购买': 'This subscription cannot be renewed and is only available to new users.',
'重置当月流量': 'Reset current month usage', '重置当月流量': 'Reset current month usage',
'流量明细仅保留近月数据以供查询。': 'Only keep the most recent month\'s usage for checking the transfer data details.', '流量明细仅保留近月数据以供查询。': 'Only keep the most recent month\'s usage for checking the transfer data details.',
'扣费倍率': 'Fee deduction rate' '扣费倍率': 'Fee deduction rate',
'支付手续费': '支付手续费'
}; };

View File

@ -54,12 +54,12 @@ window.settings.i18n['ja-JP'] = {
'佣金将会在确认后会到达你的佣金账户。': 'コミッションは承認処理完了後にカウントされます', '佣金将会在确认后会到达你的佣金账户。': 'コミッションは承認処理完了後にカウントされます',
'邀请码管理': '招待コードの管理', '邀请码管理': '招待コードの管理',
'生成邀请码': '招待コードを生成', '生成邀请码': '招待コードを生成',
'佣金发放记录': '佣金发放记录', '佣金发放记录': 'コミッション履歴',
'复制成功': 'クリップボードにコピーされました', '复制成功': 'クリップボードにコピーされました',
'密码': 'パスワード', '密码': 'パスワード',
'登入': 'ログイン', '登入': 'ログイン',
'注册': '新規登録', '注册': '新規登録',
'忘记密码': 'パスワードをお忘れの方は[こちら]', '忘记密码': 'パスワードをお忘れの方',
'# 订单号': '受注番号', '# 订单号': '受注番号',
'周期': 'サイクル', '周期': 'サイクル',
'订单金额': 'ご注文金額', '订单金额': 'ご注文金額',
@ -244,5 +244,6 @@ window.settings.i18n['ja-JP'] = {
'该订阅无法续费,仅允许新用户购买': '該当プランは継続利用できません、新規ユーザーのみが購入可能です', '该订阅无法续费,仅允许新用户购买': '該当プランは継続利用できません、新規ユーザーのみが購入可能です',
'重置当月流量': '使用済みデータ量のカウントリセット', '重置当月流量': '使用済みデータ量のカウントリセット',
'流量明细仅保留近月数据以供查询。': 'データ通信明細は当月分のみ表示されます', '流量明细仅保留近月数据以供查询。': 'データ通信明細は当月分のみ表示されます',
'扣费倍率': '適応レート' '扣费倍率': '適応レート',
'支付手续费': '支付手续费'
}; };

View File

@ -244,5 +244,6 @@ window.settings.i18n['ko-KR'] = {
'该订阅无法续费,仅允许新用户购买': '이 구독은 갱신할 수 없습니다. 신규 사용자만 구매할 수 있습니다.', '该订阅无法续费,仅允许新用户购买': '이 구독은 갱신할 수 없습니다. 신규 사용자만 구매할 수 있습니다.',
'重置当月流量': '이번 달 트래픽 초기화', '重置当月流量': '이번 달 트래픽 초기화',
'流量明细仅保留近月数据以供查询。': '귀하의 트래픽 세부 정보는 최근 몇 달 동안만 유지됩니다', '流量明细仅保留近月数据以供查询。': '귀하의 트래픽 세부 정보는 최근 몇 달 동안만 유지됩니다',
'扣费倍率': '수수료 공제율' '扣费倍率': '수수료 공제율',
'支付手续费': '支付手续费'
}; };

View File

@ -54,7 +54,7 @@ window.settings.i18n['vi-VN'] = {
'佣金将会在确认后会到达你的佣金账户。': 'Sau khi xác nhận tiền hoa hồng sẽ gửi đến tài khoản hoa hồng của bạn.', '佣金将会在确认后会到达你的佣金账户。': 'Sau khi xác nhận tiền hoa hồng sẽ gửi đến tài khoản hoa hồng của bạn.',
'邀请码管理': 'Quản lý mã mời', '邀请码管理': 'Quản lý mã mời',
'生成邀请码': 'Tạo mã mời', '生成邀请码': 'Tạo mã mời',
'佣金发放记录': '佣金发放记录', '佣金发放记录': 'Hồ sơ hoa hồng',
'复制成功': 'Sao chép thành công', '复制成功': 'Sao chép thành công',
'密码': 'Mật khẩu', '密码': 'Mật khẩu',
'登入': 'Đăng nhập', '登入': 'Đăng nhập',
@ -244,5 +244,6 @@ window.settings.i18n['vi-VN'] = {
'该订阅无法续费,仅允许新用户购买': 'Đăng ký này không thể gia hạn, chỉ người dùng mới được phép mua', '该订阅无法续费,仅允许新用户购买': 'Đăng ký này không thể gia hạn, chỉ người dùng mới được phép mua',
'重置当月流量': 'Đặt lại dung lượng tháng hiện tại', '重置当月流量': 'Đặt lại dung lượng tháng hiện tại',
'流量明细仅保留近月数据以供查询。': 'Chi tiết dung lượng chỉ lưu dữ liệu của những tháng gần đây để truy vấn.', '流量明细仅保留近月数据以供查询。': 'Chi tiết dung lượng chỉ lưu dữ liệu của những tháng gần đây để truy vấn.',
'扣费倍率': 'Tỷ lệ khấu trừ' '扣费倍率': 'Tỷ lệ khấu trừ',
'支付手续费': '支付手续费'
}; };

View File

@ -244,5 +244,6 @@ window.settings.i18n['zh-CN'] = {
'该订阅无法续费,仅允许新用户购买': '该订阅无法续费,仅允许新用户购买', '该订阅无法续费,仅允许新用户购买': '该订阅无法续费,仅允许新用户购买',
'重置当月流量': '重置当月流量', '重置当月流量': '重置当月流量',
'流量明细仅保留近月数据以供查询。': '流量明细仅保留近一个月数据以供查询。', '流量明细仅保留近月数据以供查询。': '流量明细仅保留近一个月数据以供查询。',
'扣费倍率': '扣费倍率' '扣费倍率': '扣费倍率',
'支付手续费': '支付手续费'
}; };

View File

@ -244,5 +244,6 @@ window.settings.i18n['zh-TW'] = {
'该订阅无法续费,仅允许新用户购买': '该订阅无法续费,仅允许新用户购买', '该订阅无法续费,仅允许新用户购买': '该订阅无法续费,仅允许新用户购买',
'重置当月流量': '重置当月流量', '重置当月流量': '重置当月流量',
'流量明细仅保留近月数据以供查询。': '流量明细仅保留近月数据以供查询。', '流量明细仅保留近月数据以供查询。': '流量明细仅保留近月数据以供查询。',
'扣费倍率': '扣费倍率' '扣费倍率': '扣费倍率',
'支付手续费': '支付手续费'
}; };

File diff suppressed because one or more lines are too long

View File

@ -86,5 +86,6 @@
"The traffic usage in :app_name has reached 80%": "The traffic usage in :app_name has reached 80%", "The traffic usage in :app_name has reached 80%": "The traffic usage in :app_name has reached 80%",
"The service in :app_name is about to expire": "The service in :app_name is about to expire", "The service in :app_name is about to expire": "The service in :app_name is about to expire",
"The coupon can only be used :limit_use_with_user per person": "The coupon can only be used :limit_use_with_user per person", "The coupon can only be used :limit_use_with_user per person": "The coupon can only be used :limit_use_with_user per person",
"The coupon code cannot be used for this period": "The coupon code cannot be used for this period" "The coupon code cannot be used for this period": "The coupon code cannot be used for this period",
"Request failed, please try again later": "Request failed, please try again later"
} }

View File

@ -86,5 +86,6 @@
"The traffic usage in :app_name has reached 80%": "在 :app_name 的已用流量已达到 80%", "The traffic usage in :app_name has reached 80%": "在 :app_name 的已用流量已达到 80%",
"The service in :app_name is about to expire": "在 :app_name 的服务即将到期", "The service in :app_name is about to expire": "在 :app_name 的服务即将到期",
"The coupon can only be used :limit_use_with_user per person": "该优惠券每人只能用 :limit_use_with_user 次", "The coupon can only be used :limit_use_with_user per person": "该优惠券每人只能用 :limit_use_with_user 次",
"The coupon code cannot be used for this period": "此优惠券无法用于该付款周期" "The coupon code cannot be used for this period": "此优惠券无法用于该付款周期",
"Request failed, please try again later": "请求失败,请稍后再试"
} }