Skip to content

Commit

Permalink
fix add custom refund
Browse files Browse the repository at this point in the history
  • Loading branch information
xxl4 committed Aug 7, 2024
1 parent d054975 commit 79f0d96
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Http/Controllers/Api/V1/Admin/Sales/RefundController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public function store(Request $request, OrderRepository $orderRepository, int $o
'refund.shipping' => 'required',
'refund.adjustment_refund' => 'required',
'refund.adjustment_fee' => 'required',
'refund.custom_refund_amount' => 'required', // custom refund amount
'refund.comment' => 'required', // refund comment
'refund.is_refund_money' => 'required',

]);

$data = $request->all();
Expand All @@ -63,6 +67,11 @@ public function store(Request $request, OrderRepository $orderRepository, int $o

$maxRefundAmount = $totals['grand_total']['price'] - $order->refunds()->sum('base_adjustment_refund');

if(!empty($data['refund']['custom_refund_amount'])) {
$refundAmount = $totals['grand_total']['price'] - $totals['shipping']['price'] + $data['refund']['shipping'] + $data['refund']['adjustment_refund'] - $data['refund']['adjustment_fee'];
$data['refund']['adjustment_fee'] = abs($data['refund']['custom_refund_amount'] - $refundAmount);
}

$refundAmount = $totals['grand_total']['price'] - $totals['shipping']['price'] + $data['refund']['shipping'] + $data['refund']['adjustment_refund'] - $data['refund']['adjustment_fee'];

if (! $refundAmount) {
Expand Down

0 comments on commit 79f0d96

Please sign in to comment.