use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRBalance in project openbanking-aspsp by OpenBankingToolkit.
the class BalancesApiController method getAccountBalances.
@Override
public ResponseEntity<OBReadBalance1> getAccountBalances(@PathVariable("AccountId") String accountId, @RequestParam(value = "page", defaultValue = "0") int page, @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @RequestHeader(value = "Authorization", required = true) String authorization, @RequestHeader(value = "x-fapi-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @RequestHeader(value = "x-fapi-customer-ip-address", required = false) String xFapiCustomerIpAddress, @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent, @RequestHeader(value = "x-ob-permissions", required = true) List<OBExternalPermissions1Code> permissions, @RequestHeader(value = "x-ob-url", required = true) String httpUrl) {
LOGGER.info("Read balances for account {} with minimumPermissions {}", accountId, permissions);
Page<FRBalance> balances = frBalanceRepository.findByAccountId(accountId, PageRequest.of(page, PAGE_LIMIT_BALANCES));
int totalPage = balances.getTotalPages();
return ResponseEntity.ok(new OBReadBalance1().data(new OBReadBalance1Data().balance(balances.getContent().stream().map(b -> toOBReadBalance1DataBalance(b.getBalance())).collect(Collectors.toList()))).links(PaginationUtil.generateLinks(httpUrl, page, totalPage)).meta(PaginationUtil.generateMetaData(totalPage)));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRBalance in project openbanking-aspsp by OpenBankingToolkit.
the class DataCreatorTest method createBalance_existingBalanceOfSameType_reject.
@Test
public void createBalance_existingBalanceOfSameType_reject() {
// Given
OBCashBalance1 interimAvailBalance = new OBCashBalance1().accountId("1").type(OBBalanceType1Code.INTERIMAVAILABLE);
FRBalance frBalance = FRBalance.builder().balance(toFRCashBalance(interimAvailBalance)).accountId(interimAvailBalance.getAccountId()).build();
given(balanceRepository.findByAccountIdAndBalanceType(any(), any())).willReturn(Optional.of(frBalance));
// When
assertThatThrownBy(() -> dataCreator.createBalances(accountDataWithBalance(interimAvailBalance), Collections.singleton(interimAvailBalance.getAccountId()))).satisfies(t -> assertThat(((ResponseStatusException) t).getStatus()).isEqualTo(HttpStatus.BAD_REQUEST));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRBalance in project openbanking-aspsp by OpenBankingToolkit.
the class MoneyServiceTest method shouldCreateTransaction.
@Test
public void shouldCreateTransaction() throws CurrencyConverterException {
// Given
FRBalance balance = defaultBalance(DEBIT_ACCOUNT, "20");
given(balanceStoreService.getBalance(DEBIT_ACCOUNT, OBBalanceType1Code.INTERIMAVAILABLE)).willReturn(Optional.of(balance));
CreateTransaction<FRPaymentSetup> createTransaction = mock(CreateTransaction.class);
FRAccount account = defaultAccount(DEBIT_ACCOUNT);
FRPaymentSetup payment = new FRPaymentSetup();
FRTransaction transaction = JMockData.mock(FRTransaction.class);
FRAmount amount = defaultAmount();
given(createTransaction.createTransaction(account, payment, FRCreditDebitIndicator.DEBIT, balance, amount)).willReturn(transaction);
// When
moneyService.moveMoney(account, amount, FRCreditDebitIndicator.DEBIT, payment, createTransaction);
// Then
verify(transactionStoreService).create(transaction);
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRBalance in project openbanking-aspsp by OpenBankingToolkit.
the class BalanceStoreServiceImpl method getBalance.
@Override
public Optional getBalance(String accountId, OBBalanceType1Code type) {
ParameterizedTypeReference<Optional<FRBalance>> ptr = new ParameterizedTypeReference<Optional<FRBalance>>() {
};
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(rsStoreRoot + "/api/balances/search/findByAccountId");
builder.queryParam("accountId", accountId);
builder.queryParam("type", type.name());
URI uri = builder.build().encode().toUri();
ResponseEntity<Optional<FRBalance>> entity = restTemplate.exchange(uri, HttpMethod.GET, null, ptr);
return entity.getBody();
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRBalance in project openbanking-aspsp by OpenBankingToolkit.
the class BalancesApiController method getBalances.
@Override
public ResponseEntity<OBReadBalance1> getBalances(@RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @RequestParam(value = "page", defaultValue = "0") int page, @RequestHeader(value = "Authorization", required = true) String authorization, @RequestHeader(value = "x-fapi-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @RequestHeader(value = "x-fapi-customer-ip-address", required = false) String xFapiCustomerIpAddress, @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent, @RequestHeader(value = "x-ob-account-ids", required = true) List<String> accountIds, @RequestHeader(value = "x-ob-permissions", required = true) List<OBExternalPermissions1Code> permissions, @RequestHeader(value = "x-ob-url", required = true) String httpUrl) throws OBErrorResponseException {
LOGGER.info("Reading balances from account ids {}", accountIds);
Page<FRBalance> balances = frBalanceRepository.findByAccountIdIn(accountIds, PageRequest.of(page, PAGE_LIMIT_BALANCES));
int totalPage = balances.getTotalPages();
return ResponseEntity.ok(new OBReadBalance1().data(new OBReadBalance1Data().balance(balances.getContent().stream().map(b -> toOBReadBalance1DataBalance(b.getBalance())).collect(Collectors.toList()))).links(PaginationUtil.generateLinks(httpUrl, page, totalPage)).meta(PaginationUtil.generateMetaData(totalPage)));
}
Aggregations