use of com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator in project openbanking-aspsp by OpenBankingToolkit.
the class FakeDataApiController method generateTransaction.
private FRTransaction generateTransaction(FRAccount account, FRStatement statement, FRBalance balance) {
String name = names.get(ThreadLocalRandom.current().nextInt(names.size()));
long deltaTime = (statement.getStatement().getEndDateTime().getMillis() - statement.getStatement().getStartDateTime().getMillis()) / 1000;
DateTime bookingDate = new DateTime(statement.getStatement().getStartDateTime()).plusSeconds(ThreadLocalRandom.current().nextInt(0, Math.toIntExact(deltaTime)));
DateTime valueDate = new DateTime(bookingDate).plusSeconds(ThreadLocalRandom.current().nextInt(60, 5 * 60));
FRCreditDebitIndicator creditDebitIndicator = FRCreditDebitIndicator.values()[ThreadLocalRandom.current().nextInt(0, FRCreditDebitIndicator.values().length)];
Double transactionAmount = generateAmount(10.0d, 500.0d);
Double balanceAmount = Double.valueOf(balance.getBalance().getAmount().getAmount());
Double finalAmount;
String transactionInformation;
switch(creditDebitIndicator) {
case DEBIT:
finalAmount = balanceAmount - transactionAmount;
transactionInformation = "Cash to " + name;
break;
case CREDIT:
default:
finalAmount = balanceAmount + transactionAmount;
transactionInformation = "Cash from " + name;
}
finalAmount = round(finalAmount, 2);
if (finalAmount <= 0) {
balance.getBalance().getAmount().setAmount(FORMAT_AMOUNT.format(-1 * finalAmount));
balance.getBalance().setCreditDebitIndicator(FRCreditDebitIndicator.CREDIT);
} else {
balance.getBalance().getAmount().setAmount(FORMAT_AMOUNT.format(finalAmount));
balance.getBalance().setCreditDebitIndicator(FRCreditDebitIndicator.DEBIT);
}
FRTransaction transaction = new FRTransaction();
transaction.addStatementId(statement.getId());
transaction.setAccountId(account.getId());
transaction.setBookingDateTime(bookingDate);
transaction.setTransaction(FRTransactionData.builder().accountId(account.getId()).transactionId(UUID.randomUUID().toString()).transactionReference("Ref " + ThreadLocalRandom.current().nextInt(10000)).amount(FRAmount.builder().amount(FORMAT_AMOUNT.format(transactionAmount)).currency(account.getAccount().getCurrency()).build()).creditDebitIndicator(creditDebitIndicator).status(FRTransactionData.FREntryStatus.BOOKED).bookingDateTime(bookingDate).valueDateTime(valueDate).transactionInformation(transactionInformation).bankTransactionCode(FRTransactionData.FRBankTransactionCodeStructure.builder().code("ReceivedCreditTransfer").subCode("DomesticCreditTransfer").build()).proprietaryBankTransactionCode(FRTransactionData.FRProprietaryBankTransactionCodeStructure.builder().code("Transfer").issuer("AlphaBank").build()).balance(FRTransactionData.FRTransactionCashBalance.builder().amount(balance.getBalance().getAmount()).creditDebitIndicator(balance.getBalance().getCreditDebitIndicator()).type(FRBalanceType.INTERIMBOOKED).build()).build());
transaction.setId(transaction.getTransaction().getTransactionId());
LOGGER.debug("FRTransaction1 '{}' generated", transaction);
return transaction;
}
Aggregations