Skip to content

Instantly share code, notes, and snippets.

@oludouglas
Created May 14, 2018 06:10
Show Gist options
  • Save oludouglas/db13aaf51c6117638e6da4c7a7028435 to your computer and use it in GitHub Desktop.
Save oludouglas/db13aaf51c6117638e6da4c7a7028435 to your computer and use it in GitHub Desktop.
@Override
@WebMethod(operationName = "fundsTransfer")
public TransferResponse fundsTransfer(
@WebParam(name = "transferRequest") @XmlElement(required = true) TransferRequest[] transferRequest) {
if (transferRequest == null) {
return TransferResponse.builder().responseCode("").responseMsg("").build();
}
try (TxnManager manager = TxnManager.getSession()) {
AccountRequest balanceBuild = new AccountRequest();
double totalAmount = 0;
for (int i = 0; i < transferRequest.length; i++) {
if (transferRequest[i].getIsMainTxn().equals("Y")) {
balanceBuild = AccountRequest.builder().accountNo(transferRequest[i].getFromAccount())
.acctTypeCode(transferRequest[i].getAcctTypeCode())
.currencyCode(transferRequest[i].getFromAcctCrncy())
.location(transferRequest[i].getLocation()).outletCode(transferRequest[i].getOutletCode())
.phoneNo(transferRequest[i].getPhoneNo()).referenceNo(transferRequest[i].getReferenceNo())
.build();
}
totalAmount += transferRequest[i].getTxnAmount();
}
double availBal = manager.queryAccountBalance(balanceBuild).getAvailBal();
if (availBal < totalAmount) {
// insufficient funds
return TransferResponse.builder().responseCode("51").responseMsg("").build();
}
TransferResponse main_txn_response = null, non_main_txn;
for (int i = 0; i < transferRequest.length; i++) {
non_main_txn = manager.processFundsTransfer(transferRequest[i]);
transferRequest[i].setOrigTxnReference(non_main_txn.getStanCode());
if (transferRequest[i].getIsMainTxn().equals("Y"))
main_txn_response = non_main_txn;
// If the transaction posting was not successful then reverse
if (!"00".equals(non_main_txn.getResponseCode())) {
for (int j = 0; j < i; j++) {
// Check for only those transactions that posted in the previous loop
if (transferRequest[j].getOrigTxnReference() != null
&& transferRequest[j].getOrigTxnReference().length() >= 6) {
manager.processFundsTransfer(transferRequest[j]);// what to do with the response
// perhaps log the reversal status
}
}
break;
}
}
return main_txn_response != null ? main_txn_response
: TransferResponse.builder().responseCode("").responseMsg("").build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment