} if ($invalidSender) { $error['senderError'][] = 'Invalid Character selected to transfer funds from.'; } if ($senderCharacter->name == $recipient) { $error['recipientError'][] = 'You cannot transfer funds to yourself.'; } $recipientCharacter = Character::where('name', $recipient)->first(); if (!$recipientCharacter) { $error['recipientError'][] = 'Recipient character does not exist.'; } $senderBalance = Balance::where('character_id', $senderCharacter->id)->first(); $recipientBalance = Balance::where('character_id', $recipientCharacter->id)->first(); if (!$senderBalance) { $error['senderError'][] = 'No balance found for sender, ensure one exists.'; } if (!$recipientBalance) { $error['recipientError'][] = 'Recipient does not have a balance, they must have a balance before receiving a transaction.'; } if (!empty($error)) { return $this->view->render($response, 'transaction-create.php', ['senderError' => $error['senderError'], 'recipientError' => $error['recipientError'], 'amountError' => $error['amountError'], 'characters' => $characters]); } $transaction = new Transaction(); $transactionCompleted = $transaction->performTransaction($amount, $senderCharacter->id, $recipientCharacter->id); if ($transactionCompleted) { Transaction::create(['sender_character_id' => $senderCharacter->id, 'recipient_character_id' => $recipientCharacter->id, 'amount' => $amount]); Audit::create(['category' => 'Successful Transaction', 'log_note' => 'Transaction successfully completed for the amount of ' . $amount . ' between ' . $senderCharacter->name . ' and ' . $recipientCharacter->name, 'user_id' => $user->id, 'ip_address' => $_SERVER['REMOTE_ADDR']]); } return $this->view->render($response, 'transaction-create.php', ['success' => 'Credits transferred successfully.', 'characters' => $characters]); });
<?php use GalacticBank\Classes\AuthMiddleware; use GalacticBank\Models\Token; use GalacticBank\Models\User; use GalacticBank\Models\Character; use GalacticBank\Models\Transaction; use GalacticBank\Models\Balance; $app->get('/transaction/list/{id}', function ($request, $response, $args) { $token = Token::where('token', $_SESSION['login_token'])->first(); $user = User::where('id', $token->user_id)->first(); $character_id = $args['id']; $character = Character::where('id', $character_id)->first(); $sentTransactions = Transaction::where('sender_character_id', $character->id)->join('Character', 'Character.id', '=', 'Transaction.sender_character_id')->join('Character AS recipientCharacter', 'recipientCharacter.id', '=', 'Transaction.recipient_character_id')->select('Character.name AS senderName', 'recipientCharacter.name AS recipientName', 'Transaction.*')->get(); $receivedTransactions = Transaction::where('recipient_character_id', $character->id)->join('Character', 'Character.id', '=', 'Transaction.sender_character_id')->join('Character AS recipientCharacter', 'recipientCharacter.id', '=', 'Transaction.recipient_character_id')->select('Character.name AS senderName', 'recipientCharacter.name AS recipientName', 'Transaction.*')->get(); $balance = Balance::where('character_id', $character->id)->first(); return $this->view->render($response, 'transactions-previous.php', ['character' => $character, 'sent_transactions' => $sentTransactions, 'received_transactions' => $receivedTransactions, 'balance' => $balance]); })->add(new AuthMiddleware());