fetchesTransaction = $fetchesTransaction; $this->updatesTransactionStatus = $updatesTransactionStatus; $this->updatesWallet = $updatesWallet; } /** * @param Booking $booking * @return void * @throws \App\Classes\Exceptions\MalformedRequestException */ public function execute(int $transactionId, int $transactionStatus) { $transaction = $this->fetchesTransaction->execute(['id' => $transactionId]); $wallet = $transaction->wallet; switch($transaction->type){ case TransactionType::TOP_UP: $updateWalletAmount = $transaction->amount + $wallet->amount; break; case TransactionType::WITHDRAW: $updateWalletAmount = $wallet->amount - $transaction->amount; break; default: break; } $walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); $this->updatesTransactionStatus->execute($transaction, $transactionStatus); $this->updatesWallet->execute($wallet, $walletOject); return $wallet; } }