Transferring Funds Between Accounts
In this document, we will explain the process of transferring funds between two accounts within the same bank. The process involves several steps including validation, internal transfer, updating account balances, recording the transaction, and ensuring database connectivity.
The flow starts with validating the account number and transfer amount. If valid, it proceeds to check if the source and target accounts are different and if the transfer amount is positive. Then, it verifies the existence and accessibility of both accounts. If all checks pass, it debits the source account and credits the target account. The transaction is then recorded in the database, and the connection to the database is managed to ensure all operations are performed smoothly.
Flow drill down
transferLocalExternal
transferLocalExternal
First, the transferLocalExternal
transferLocalInternal
@PUT
@Path("/transfer/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response transferLocalExternal(@PathParam("id") String accountNumber,
TransferLocalJSON transferLocal)
{
// we use this to move money between two accounts at the same bank
logger.entering(this.getClass().getName(),
"transferLocalExternal(String accountNumber, TransferLocalJSON transferLocal)");
Integer accountNumberInteger;
try
{
accountNumberInteger = Integer.parseInt(accountNumber);
if (accountNumberInteger.intValue() < 1
|| accountNumberInteger.intValue() == 99999999)
{
return null;
}
}
catch (NumberFormatException e)
transferLocalInternal
transferLocalInternal
Next, the transferLocalInternal
debitCredit
public Response transferLocalInternal(@PathParam("id") String accountNumber,
TransferLocalJSON transferLocal)
{
// we use this to move money between two accounts at the same bank
logger.entering(this.getClass().getName(), TRANSFER_LOCAL_INTERNAL);
Response myResponse = null;
// * We are transferring money from account "id" at this bank, to
// another account at this bank
// * The amount MUST be positive
JSONObject response = new JSONObject();
if (Integer.parseInt(accountNumber) == transferLocal.getTargetAccount())
{
JSONObject error = new JSONObject();
error.put(JSON_ERROR_MSG, NEED_DIFFERENT_ACCOUNTS);
logger.log(Level.WARNING, () -> (NEED_DIFFERENT_ACCOUNTS));
myResponse = Response.status(400).entity(error.toString()).build();
logger.exiting(this.getClass().getName(), TRANSFER_LOCAL_INTERNAL,
myResponse);
return myResponse;
debitCredit
debitCredit
Then, the debitCredit
public boolean debitCredit(BigDecimal apiAmount)
{
logger.entering(this.getClass().getName(), DEBIT_CREDIT_ACCOUNT);
Account temp = this.getAccount(
Integer.parseInt(this.getAccountNumber()),
Integer.parseInt(this.getSortcode()));
if (temp == null)
{
logger.log(Level.WARNING,
() -> "Unable to find account " + this.getAccountNumber());
logger.exiting(this.getClass().getName(), DEBIT_CREDIT_ACCOUNT,
false);
return false;
}
openConnection();
String accountNumberString = temp.getAccountNumber();
String sortCodeString = padSortCode(
Integer.parseInt(this.getSortcode()));
String sql1 = SQL_SELECT;
writeTransferLocalInternal
writeTransferLocalInternal
Moving to the writeTransferLocalInternal
writeTransferLocal
public Response writeTransferLocalInternal(
ProcessedTransactionTransferLocalJSON proctranLocal)
{
com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction myProcessedTransactionDB2 = new com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction();
if (myProcessedTransactionDB2.writeTransferLocal(
proctranLocal.getSortCode(), proctranLocal.getAccountNumber(),
proctranLocal.getAmount(),
proctranLocal.getTargetAccountNumber()))
{
return Response.ok().build();
}
else
{
return Response.serverError().build();
}
}
writeTransferLocal
writeTransferLocal
The writeTransferLocal
public boolean writeTransferLocal(String sortCode2, String accountNumber2,
BigDecimal amount2, String targetAccountNumber2)
{
logger.entering(this.getClass().getName(), WRITE_TRANSFER_LOCAL);
sortOutDateTimeTaskString();
String transferDescription = "";
transferDescription = transferDescription
+ PROCTRAN.PROC_TRAN_DESC_XFR_FLAG;
transferDescription = transferDescription.concat(" ");
transferDescription = transferDescription
.concat(padSortCode(Integer.parseInt(sortCode2)));
transferDescription = transferDescription.concat(
padAccountNumber(Integer.parseInt(targetAccountNumber2)));
openConnection();
logger.log(Level.FINE, () -> ABOUT_TO_INSERT + SQL_INSERT + ">");
getAccount
getAccount
The getAccount
public Account getAccount(int accountNumber, int sortCode)
{
logger.entering(this.getClass().getName(), GET_ACCOUNT + accountNumber);
openConnection();
Account temp = null;
String sortCodeString = padSortCode(sortCode);
String sql9999 = "SELECT * from ACCOUNT where ACCOUNT_EYECATCHER LIKE 'ACCT' AND ACCOUNT_SORTCODE like ? order by ACCOUNT_NUMBER DESC";
String sql = SQL_SELECT;
try (PreparedStatement stmt9999 = conn.prepareStatement(sql9999);
PreparedStatement stmt = conn.prepareStatement(sql);)
{
if (accountNumber == 99999999)
{
logger.log(Level.FINE, () -> PRE_SELECT_MSG + sql9999 + ">");
stmt9999.setString(1, sortCodeString);
ResultSet rs = stmt9999.executeQuery();
if (rs.next())
{
openConnection
openConnection
Finally, the openConnection
DB2
protected void openConnection()
{
// Open a connection to the DB2 database
logger.entering(this.getClass().getName(), "openConnection()");
Integer taskNumberInteger = Task.getTask().getTaskNumber();
String db2ConnString = DB2CONN.concat(taskNumberInteger.toString());
logger.log(Level.FINE,
() -> "Attempting to get DB2CONN for task number "
+ taskNumberInteger.toString());
this.conn = (Connection) cornedBeef.get(db2ConnString);
if (this.conn == null)
{
HBankDataAccess.incrementConnCount();
logger.log(Level.FINE,
() -> "Attempting to create DB2CONN for task number "
+ taskNumberInteger.toString());
// Attempt to open a connection
openConnectionInternal();
logger.log(Level.FINE,
() -> "Creation succcessful for DB2CONN for task number "
This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human