Search in sources :

Example 1 with Balance

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);
}
Also used : FRTransaction(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction) Balance(com.forgerock.openbanking.common.model.openbanking.persistence.account.Balance) BigDecimal(java.math.BigDecimal)

Example 2 with 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);
}
Also used : Balance(com.forgerock.openbanking.common.model.openbanking.persistence.account.Balance) BigDecimal(java.math.BigDecimal)

Example 3 with Balance

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) FRBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRBalance) Balance(com.forgerock.openbanking.common.model.openbanking.persistence.account.Balance)

Aggregations

Balance (com.forgerock.openbanking.common.model.openbanking.persistence.account.Balance)3 BigDecimal (java.math.BigDecimal)2 FRBalance (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRBalance)1 FRTransaction (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1