Skip to main content

Handling Debit and Credit Transactions

In this document, we will explain the process of handling debit and credit transactions. The process involves determining the type of transaction based on the amount and then processing it accordingly.

The flow starts by checking if the transaction amount is negative or positive. If the amount is negative, it is identified as a debit transaction and processed using the debit handling logic. If the amount is positive, it is identified as a credit transaction and processed using the credit handling logic. Both types of transactions involve preparing an SQL statement to insert a record into the database and executing it. If the insertion is successful, the transaction is considered complete; otherwise, an error is logged.

Flow drill down


Handling Debit and Credit Transactions

The writeInternal method is responsible for processing both debit and credit transactions. It first checks if the transaction amount is negative to determine if it is a debit. If it is, it calls writeDebit to handle the debit transaction. If the amount is positive, it calls writeCredit to handle the credit transaction. This ensures that the correct type of transaction is processed based on the amount.

	public Response writeInternal(
ProcessedTransactionDebitCreditJSON proctranDbCr)
{
com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction myProcessedTransactionDB2 = new com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction();

if (proctranDbCr.getAmount().compareTo(new BigDecimal(0)) < 0)
{
if (myProcessedTransactionDB2.writeDebit(
proctranDbCr.getAccountNumber(), proctranDbCr.getSortCode(),
proctranDbCr.getAmount()))
{
return Response.ok().build();
}
else
{
logger.severe("PROCTRAN Insert debit didn't work");
return Response.serverError().build();
}
}
else
{


Processing Debit Transactions

The writeDebit method handles the logic for processing debit transactions. It prepares the SQL statement to insert a debit record into the database and executes it. If the insertion is successful, it returns true; otherwise, it logs an error and returns false.

	public boolean writeDebit(String accountNumber, String sortcode,
BigDecimal amount2)
{
logger.entering(this.getClass().getName(), WRITE_DEBIT);

sortOutDateTimeTaskString();

openConnection();

logger.log(Level.FINE, () -> ABOUT_TO_INSERT + SQL_INSERT + ">");
try (PreparedStatement stmt = conn.prepareStatement(SQL_INSERT);)
{
stmt.setString(1, PROCTRAN.PROC_TRAN_VALID);
stmt.setString(2, sortcode);
stmt.setString(3,
String.format("%08d", Integer.parseInt(accountNumber)));
stmt.setString(4, dateString);
stmt.setString(5, timeString);
stmt.setString(6, taskRef);
stmt.setString(7, PROCTRAN.PROC_TY_DEBIT);
stmt.setString(8, "INTERNET WTHDRW");


Processing Credit Transactions

The writeCredit method handles the logic for processing credit transactions. Similar to writeDebit, it prepares the SQL statement to insert a credit record into the database and executes it. If the insertion is successful, it returns true; otherwise, it logs an error and returns false.

	public boolean writeCredit(String accountNumber, String sortcode,
BigDecimal amount2)
{
logger.entering(this.getClass().getName(), WRITE_CREDIT, false);
sortOutDateTimeTaskString();

openConnection();

logger.log(Level.FINE, () -> ABOUT_TO_INSERT + SQL_INSERT + ">");
try (PreparedStatement stmt = conn.prepareStatement(SQL_INSERT);)
{
stmt.setString(1, PROCTRAN.PROC_TRAN_VALID);
stmt.setString(2, sortcode);
stmt.setString(3,
String.format("%08d", Integer.parseInt(accountNumber)));
stmt.setString(4, dateString);
stmt.setString(5, timeString);
stmt.setString(6, taskRef);
stmt.setString(7, PROCTRAN.PROC_TY_CREDIT);
stmt.setString(8, "INTERNET RECVED");
stmt.setBigDecimal(9, amount2);


Opening Database Connection

The openConnection method is responsible for establishing a connection to the DB2 database. It first checks if there is an existing connection for the current task. If not, it calls openConnectionInternal to create a new connection. If the connection is closed, it attempts to reopen it.

	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 "


Establishing Internal Database Connection

The openConnectionInternal method establishes a new connection to the DB2 database using JNDI lookup. It sets the transaction isolation level and stores the connection in a map for reuse. If the connection is closed, it attempts to get a new one.

	@SuppressWarnings("unchecked")
void openConnectionInternal()
{
logger.entering(this.getClass().getName(), "openConnectionInternal");
String jndiString = "jdbc/defaultCICSDataSource";
Context ctx;

try
{
ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(jndiString);
logger.log(Level.FINE, () -> "jndi string is " + jndiString);
// If there is no current connection
if (this.conn == null)
{
logger.log(Level.FINE,
() -> "About to attempt to get DB2 connection");
// Try and get a connection
this.conn = ds.getConnection();
this.conn.setTransactionIsolation(
Connection.TRANSACTION_READ_UNCOMMITTED);

Where is this flow used?

This flow is used multiple times in the codebase as represented in the following diagram:

 

This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human