mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 01:11:46 +08:00 
			
		
		
		
	update: add payment handling fee
This commit is contained in:
		| @@ -51,30 +51,34 @@ class PaymentController extends Controller | ||||
|         if (!config('v2board.app_url')) { | ||||
|             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([ | ||||
|             'name' => 'required', | ||||
|             'icon' => 'nullable', | ||||
|             'payment' => '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' => '显示名称不能为空', | ||||
|             'payment.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); | ||||
|         if (!Payment::create($params)) { | ||||
|             abort(500, '保存失败'); | ||||
|   | ||||
| @@ -184,13 +184,17 @@ class OrderController extends Controller | ||||
|         $payment = Payment::find($method); | ||||
|         if (!$payment || $payment->enable !== 1) abort(500, __('Payment method is not available')); | ||||
|         $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([ | ||||
|             '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, | ||||
|             'stripe_token' => $request->input('token') | ||||
|         ]); | ||||
|         $order->update(['payment_id' => $method]); | ||||
|         return response([ | ||||
|             'type' => $result['type'], | ||||
|             'data' => $result['data'] | ||||
| @@ -217,7 +221,9 @@ class OrderController extends Controller | ||||
|             'id', | ||||
|             'name', | ||||
|             'payment', | ||||
|             'icon' | ||||
|             'icon', | ||||
|             'handling_fee_fixed', | ||||
|             'handling_fee_percent' | ||||
|         ]) | ||||
|             ->where('enable', 1)->get(); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user