Search in sources :

Example 46 with FRAccount

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount 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);
}
Also used : FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) FRBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRBalance) FRTransaction(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup) Test(org.junit.Test)

Example 47 with FRAccount

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.

the class AccountStoreServiceImpl method get.

@Override
public List<FRAccount> get(String userID) {
    // This is necessary as auth server always uses lowercase user id
    String lowercaseUserId = userID.toLowerCase();
    log.debug("Searching for accounts with user ID: {}", lowercaseUserId);
    ParameterizedTypeReference<List<FRAccount>> ptr = new ParameterizedTypeReference<List<FRAccount>>() {
    };
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(rsStoreRoot + "/api/accounts/search/findByUserId");
    builder.queryParam("userId", lowercaseUserId);
    URI uri = builder.build().encode().toUri();
    ResponseEntity<List<FRAccount>> entity = restTemplate.exchange(uri, HttpMethod.GET, null, ptr);
    return entity.getBody();
}
Also used : FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) List(java.util.List) URI(java.net.URI)

Example 48 with FRAccount

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.

the class AccountsApiController method getAccount.

public ResponseEntity<OBReadAccount2> getAccount(@ApiParam(value = "A unique identifier used to identify the account resource.", required = true) @PathVariable("AccountId") String accountId, @ApiParam(value = "The unique id of the ASPSP to which the request is issued. The unique id will be issued by OB.", required = true) @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "The time when the PSU last logged in with the TPP.  All dates in the HTTP headers are represented as RFC 7231 Full Dates. An example is below:  Sun, 10 Sep 2017 19:43:31 UTC") @RequestHeader(value = "x-fapi-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @ApiParam(value = "The PSU's IP address if the PSU is currently logged in with the TPP.") @RequestHeader(value = "x-fapi-customer-ip-address", required = false) String xFapiCustomerIpAddress, @ApiParam(value = "An RFC4122 UID used as a correlation id.") @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) throws OBErrorResponseException {
    LOGGER.info("Read account {} with permission {}", accountId, permissions);
    FRAccount response = frAccountRepository.byAccountId(accountId, toFRExternalPermissionsCodeList(permissions));
    List<OBAccount2> obAccount2s = singletonList(toOBAccount2(response.getAccount()));
    return ResponseEntity.ok(new OBReadAccount2().data(new OBReadAccount2Data().account(obAccount2s)).links(PaginationUtil.generateLinksOnePager(httpUrl)).meta(PaginationUtil.generateMetaData(1)));
}
Also used : FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) OBReadAccount2Data(uk.org.openbanking.datamodel.account.OBReadAccount2Data) FRFinancialAccountConverter.toOBAccount2(com.forgerock.openbanking.common.services.openbanking.converter.account.FRFinancialAccountConverter.toOBAccount2) OBAccount2(uk.org.openbanking.datamodel.account.OBAccount2) OBReadAccount2(uk.org.openbanking.datamodel.account.OBReadAccount2)

Aggregations

FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)48 Test (org.junit.Test)31 Collections (java.util.Collections)26 Optional (java.util.Optional)25 AccountStoreService (com.forgerock.openbanking.common.services.store.account.AccountStoreService)24 FRAmount (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount)23 RunWith (org.junit.runner.RunWith)23 InjectMocks (org.mockito.InjectMocks)23 Mock (org.mockito.Mock)23 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)23 MoneyService (com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService)22 PaymentNotificationFacade (com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade)22 FRCreditDebitIndicator (com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator)22 FRAccountIdentifier (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier)22 CurrencyConverterException (com.tunyk.currencyconverter.api.CurrencyConverterException)22 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)22 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)22 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)22 BDDMockito.given (org.mockito.BDDMockito.given)22 Mockito.doThrow (org.mockito.Mockito.doThrow)22