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

@ -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();