diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index bdd482dc..31c847f3 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -107,18 +107,23 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $refund = $transaction->transactions()->refunds()->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->sum('original_amount'); $isFullyRefund = round($refund + $request->input('amount'), 2) == round((float) $transaction->original_amount, 2); if ($isFullyRefund) { - $request->merge(['amount' => $transaction->original_amount]); + Log::info('isFullyRefund: ' . ($refund + $request->input('amount'))); + // $request->merge(['amount' => $transaction->original_amount]); } $refundInPending = $transaction->transactions()->refunds()->where('status', ApprovalStatus::PENDING_VERIFICATION)->sum('original_amount'); - if(($refund + $request->input('amount') > $transaction->original_amount) && !$isFullyRefund) throw new MalformedRequestException('Your refund must not be greater than '. $transaction->original_amount .'.'); + Log::info('refund 1: ' . $refund); + Log::info('refund 2: ' . $request->input('amount')); + Log::info('refund 3: ' . ($refund + $request->input('amount'))); + if(($refund + $request->input('amount') > $transaction->original_amount)) throw new MalformedRequestException('Your refund must not be greater than '. $transaction->original_amount .'.'); // $transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $request->input('amount')); // $transactionRefundCalculationObject->init(); // full refund - if ((float)$request->input('amount') === (float)$transaction->original_amount) { + // if ((float)$request->input('amount') === (float)$transaction->original_amount) { + if($isFullyRefund) { $refundAmount = $transaction->original_amount / $transaction->currency_rate; $service_charges_to_refund = $transaction->service_charge; } else { @@ -138,7 +143,7 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $conversionObjectBeforeCurrentRefund = new CurrencyConversionObject($bookingAmountBeforeCurrentRefund, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method); - $conversionObjectAfterRefund = new CurrencyConversionObject($isFullyRefund ? $request->input('amount') : $bookingAmountAfterRefunded, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method); + $conversionObjectAfterRefund = new CurrencyConversionObject($isFullyRefund ? $transaction->original_amount : $bookingAmountAfterRefunded, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method); $quotationBeforeCurrentRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectBeforeCurrentRefund, $voucherCode, $redemptionId, $booking);