'Updated Transaction', 'message' => 'You have successfully updated a transaction' ]; } /** @var FetchesCompany */ private $fetchesCompany; /** @var FetchesTransaction */ private $fetchesTransaction; /** @var UpdatesTransactionStatus */ private $updatesTransactionStatus; /** @var DeletesDocument */ private $deletesDocument; /** @var CreditWalletProcessor */ private $creditWalletProcessor; /** @var CalculatesBookingPayableAmount */ private $calculatesBookingPayableAmount; /** @var CalculatesBookingRefundAmount */ private $calculatesBookingRefundAmount; /** * CreatePaymentVerificationDocumentLogic constructor. * @param FetchesCompany $fetchesCompany * @param FetchesTransaction $fetchesTransaction * @param UpdatesTransactionStatus $updatesTransactionStatus * @param DeletesDocument $deletesDocument * @param CreditWalletProcessor $creditWalletProcessor * @param CalculatesBookingPayableAmount $calculatesBookingPayableAmount * @param CalculatesBookingRefundAmount $calculatesBookingRefundAmount */ public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, DeletesDocument $deletesDocument, CreditWalletProcessor $creditWalletProcessor, CalculatesBookingPayableAmount $calculatesBookingPayableAmount, CalculatesBookingRefundAmount $calculatesBookingRefundAmount) { $this->fetchesCompany = $fetchesCompany; $this->fetchesTransaction = $fetchesTransaction; $this->updatesTransactionStatus = $updatesTransactionStatus; $this->deletesDocument = $deletesDocument; $this->creditWalletProcessor = $creditWalletProcessor; $this->calculatesBookingPayableAmount = $calculatesBookingPayableAmount; $this->calculatesBookingRefundAmount = $calculatesBookingRefundAmount; } /** * @param Request $request * @return JsonResponse * @throws \App\Classes\Exceptions\MalformedRequestException */ public function logic(Request $request) : JsonResponse { $refundTransaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); $refundTransaction = $this->updatesTransactionStatus->execute($refundTransaction, $request->route('status')); $paymentTransaction = $refundTransaction->owner; $supplierRefundTransaction = $paymentTransaction->transactions()->supplierRefunds()->where('status', [ApprovalStatus::PENDING_VERIFICATION])->first(); $booking = $paymentTransaction->owner; $reference = $refundTransaction->amount == $paymentTransaction->amount ? 'Fully Refund for Ref. ' . $booking->marking : 'Partially Refund for Ref. ' . $booking->marking; $refundAmount = $this->calculatesBookingRefundAmount->calculateRefundAmount($paymentTransaction, $booking->fix_currency_id); if ($refundTransaction->status == ApprovalStatus::APPROVED) { $this->creditWalletProcessor->execute($booking->company, $refundTransaction->type, $refundTransaction->amount, $reference); $po_transaction = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first(); if ($po_transaction) { $this->updatesTransactionStatus->execute($po_transaction, (float) number_format($po_transaction->amount, 2, '.', '') === (float) number_format((float)$booking->fix_amount - $refundAmount, 2, '.', '') ? ApprovalStatus::PENDING_VERIFICATION : ApprovalStatus::PENDING_SUBMISSION); } } if ($supplierRefundTransaction) { $this->updatesTransactionStatus->execute($supplierRefundTransaction, $request->route('status')); } $paidAmount = $paymentTransaction->original_amount - $refundAmount; if (!$paidAmount > 0) { $this->updatesTransactionStatus->execute($paymentTransaction, ApprovalStatus::REFUNDED); } return $this->response([]); } }