use of com.forgerock.openbanking.common.model.openbanking.persistence.account.Balance in project openbanking-aspsp by OpenBankingToolkit.
the class MoneyService method moveMoney.
public <T> void moveMoney(Account account, FRAmount amount, FRCreditDebitIndicator creditDebitCode, T payment, CreateTransaction<T> createTransaction) throws CurrencyConverterException {
Optional<Balance> balanceIf = balanceStoreService.getBalance(account.getId(), OBBalanceType1Code.INTERIMAVAILABLE);
// Verify account for a balance
if (!balanceIf.isPresent()) {
throw new IllegalStateException("No balance found of type '" + OBBalanceType1Code.INTERIMAVAILABLE + "' for account id '" + account.getId() + "'");
}
Balance balance = balanceIf.get();
BigDecimal finalAmount = computeAmount(amount, creditDebitCode, balance);
updateBalance(balance, finalAmount);
FRTransaction transaction = createTransaction.createTransaction(account, payment, creditDebitCode, balance, amount);
addTransactionToLatestStatement(account, transaction);
transaction = transactionStoreService.create(transaction);
log.info("Transaction created {}", transaction);
balanceStoreService.updateBalance(balance);
log.info("Balance updated {}", balance);
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.Balance in project openbanking-aspsp by OpenBankingToolkit.
the class FundsAvailabilityService method isFundsAvailable.
public boolean isFundsAvailable(String accountId, String amount) {
Preconditions.checkArgument(!StringUtils.isEmpty(accountId), "Account Id cannot be empty");
Preconditions.checkArgument(!StringUtils.isEmpty(amount), "Amount cannot be empty");
Optional<Balance> balanceIf = balanceStoreService.getBalance(accountId, OBBalanceType1Code.INTERIMAVAILABLE);
// Verify account for a balance
Balance balance = balanceIf.orElseThrow(() -> new IllegalStateException("No balance found of type '" + OBBalanceType1Code.INTERIMAVAILABLE + "' for account id '" + accountId + "'"));
BigDecimal currentBalance = balance.getAmount();
BigDecimal requestAmount = new BigDecimal(amount);
log.debug("Check if balance: '{}' from accountId: '{}' is sufficient to cover the amount: '{}'", currentBalance.toPlainString(), accountId, amount);
return (currentBalance.compareTo(requestAmount) >= 0);
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.Balance in project openbanking-aspsp by OpenBankingToolkit.
the class BalanceStoreServiceImpl method updateBalance.
/**
* update balance
*
* @param balance a balance
*/
@Override
public void updateBalance(Balance balance) {
HttpEntity<Balance> request = new HttpEntity<>(balance, new HttpHeaders());
restTemplate.exchange(rsStoreRoot + "/api/balances/", HttpMethod.PUT, request, Void.class);
}
Aggregations