use of uk.org.openbanking.datamodel.account.OBReadTransaction2 in project openbanking-aspsp by OpenBankingToolkit.
the class TransactionsApiController method getAccountStatementTransactions.
@Override
public ResponseEntity<OBReadTransaction2> getAccountStatementTransactions(@ApiParam(value = "A unique identifier used to identify the account resource.", required = true) @PathVariable("AccountId") String accountId, @ApiParam(value = "Page number.", required = false, defaultValue = "0") @RequestParam(value = "page", defaultValue = "0") int page, @ApiParam(value = "A unique identifier used to identify the statement resource.", required = true) @PathVariable("StatementId") String statementId, @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 UTC ISO 8601 Date Time to filter transactions FROM NB Time component is optional " + "- set to 00:00:00 for just Date. The parameter must NOT have a timezone set") @RequestParam(value = FROM_BOOKING_DATE_TIME, required = false) @DateTimeFormat(pattern = BOOKED_TIME_DATE_FORMAT) DateTime fromBookingDateTime, @ApiParam(value = "The UTC ISO 8601 Date Time to filter transactions TO NB Time component is optional " + "- set to 00:00:00 for just Date. The parameter must NOT have a timezone set") @RequestParam(value = TO_BOOKING_DATE_TIME, required = false) @DateTimeFormat(pattern = BOOKED_TIME_DATE_FORMAT) DateTime toBookingDateTime, @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, @ApiParam(value = "Indicates the user-agent that the PSU is using.") @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent, @RequestHeader(value = "x-ob-first-available-date", required = false) @DateTimeFormat(pattern = AVAILABLE_DATE_FORMAT) DateTime firstAvailableDate, @RequestHeader(value = "x-ob-last-available-date", required = false) @DateTimeFormat(pattern = AVAILABLE_DATE_FORMAT) DateTime lastAvailableDate, @RequestHeader(value = "x-ob-permissions", required = true) List<OBExternalPermissions1Code> permissions, @RequestHeader(value = "x-ob-url", required = true) String httpUrl) throws OBErrorResponseException {
LOGGER.info("Reading transations from account id {}, statement id {}, fromBookingDate {} toBookingDate {} " + "minimumPermissions {} pageNumber {} ", accountId, statementId, fromBookingDateTime, toBookingDateTime, permissions, page);
if (toBookingDateTime == null) {
toBookingDateTime = DateTime.now();
}
if (fromBookingDateTime == null) {
fromBookingDateTime = toBookingDateTime.minusYears(100);
}
Page<FRTransaction> response = frTransactionRepository.byAccountIdAndStatementIdAndBookingDateTimeBetweenWithPermissions(accountId, statementId, fromBookingDateTime, toBookingDateTime, toFRExternalPermissionsCodeList(permissions), PageRequest.of(page, PAGE_LIMIT_TRANSACTIONS, Sort.Direction.ASC, "bookingDateTime"));
List<OBTransaction2> transactions = response.getContent().stream().map(t -> toOBTransaction2(t.getTransaction())).collect(Collectors.toList());
// Package the answer
int totalPages = response.getTotalPages();
return ResponseEntity.ok(new OBReadTransaction2().data(new OBReadTransaction2Data().transaction(transactions)).links(PaginationUtil.generateLinks(httpUrl, page, totalPages)).meta(PaginationUtil.generateMetaData(totalPages, firstAvailableDate, lastAvailableDate)));
}
use of uk.org.openbanking.datamodel.account.OBReadTransaction2 in project openbanking-aspsp by OpenBankingToolkit.
the class TransactionsApiController method getTransactions.
@Override
public ResponseEntity<OBReadTransaction2> getTransactions(@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 = "Page number.", required = false, defaultValue = "0") @RequestParam(value = "page", defaultValue = "0") int page, @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, @ApiParam(value = "The UTC ISO 8601 Date Time to filter transactions FROM NB Time component is optional " + "- set to 00:00:00 for just Date. The parameter must NOT have a timezone set") @RequestParam(value = FROM_BOOKING_DATE_TIME, required = false) @DateTimeFormat(pattern = BOOKED_TIME_DATE_FORMAT) DateTime fromBookingDateTime, @ApiParam(value = "The UTC ISO 8601 Date Time to filter transactions TO NB Time component is optional " + "- set to 00:00:00 for just Date. The parameter must NOT have a timezone set") @RequestParam(value = TO_BOOKING_DATE_TIME, required = false) @DateTimeFormat(pattern = BOOKED_TIME_DATE_FORMAT) DateTime toBookingDateTime, @ApiParam(value = "Indicates the user-agent that the PSU is using.") @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent, @RequestHeader(value = "x-ob-first-available-date", required = false) @DateTimeFormat(pattern = AVAILABLE_DATE_FORMAT) DateTime firstAvailableDate, @RequestHeader(value = "x-ob-last-available-date", required = false) @DateTimeFormat(pattern = AVAILABLE_DATE_FORMAT) DateTime lastAvailableDate, @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 transations from account ids {}, fromBookingDate {} toBookingDate {} " + "minimumPermissions {} pageNumber {} ", accountIds, fromBookingDateTime, toBookingDateTime, permissions, page);
if (toBookingDateTime == null) {
toBookingDateTime = DateTime.now();
}
if (fromBookingDateTime == null) {
fromBookingDateTime = toBookingDateTime.minusYears(100);
}
Page<FRTransaction> response = frTransactionRepository.byAccountIdInAndBookingDateTimeBetweenWithPermissions(accountIds, fromBookingDateTime, toBookingDateTime, toFRExternalPermissionsCodeList(permissions), PageRequest.of(page, PAGE_LIMIT_TRANSACTIONS, Sort.Direction.ASC, "bookingDateTime"));
List<OBTransaction2> transactions = response.getContent().stream().map(t -> toOBTransaction2(t.getTransaction())).collect(Collectors.toList());
// Package the answer
int totalPages = response.getTotalPages();
return ResponseEntity.ok(new OBReadTransaction2().data(new OBReadTransaction2Data().transaction(transactions)).links(PaginationUtil.generateLinks(httpUrl, page, totalPages)).meta(PaginationUtil.generateMetaData(totalPages, firstAvailableDate, lastAvailableDate)));
}
use of uk.org.openbanking.datamodel.account.OBReadTransaction2 in project openbanking-aspsp by OpenBankingToolkit.
the class TransactionsApiControllerIT method getAccountStatementTransactionShouldBeOk.
@Test
public void getAccountStatementTransactionShouldBeOk() throws Exception {
// Given
String jws = jws("accounts");
this.mockAuthenticationCollector();
this.mockTppStoreService();
mockAccessTokenVerification(jws);
mockAuthenticationCollector();
mockAccountPermissions(Arrays.asList(FRExternalPermissionsCode.READSTATEMENTSDETAIL, FRExternalPermissionsCode.READTRANSACTIONSDETAIL, FRExternalPermissionsCode.READTRANSACTIONSCREDITS, FRExternalPermissionsCode.READTRANSACTIONSDEBITS));
OBReadTransaction2 transaction = new OBReadTransaction2();
given(rsStoreGateway.toRsStore(any(), any(), any(), any())).willReturn(ResponseEntity.ok(transaction));
// When
HttpResponse<OBReadTransaction2> response = Unirest.get("https://rs-api:" + port + "/open-banking/v2.0/accounts/100000123/statements/1000001234/transactions").header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "Bearer " + jws).asObject(OBReadTransaction2.class);
// Then
assertThat(response.getStatus()).isEqualTo(200);
}
use of uk.org.openbanking.datamodel.account.OBReadTransaction2 in project openbanking-aspsp by OpenBankingToolkit.
the class TransactionsApiControllerIT method getAccountTransactionShouldBeOk.
@Test
public void getAccountTransactionShouldBeOk() throws Exception {
// Given
String jws = jws("accounts");
this.mockAuthenticationCollector();
this.mockTppStoreService();
mockAccessTokenVerification(jws);
mockAccountPermissions(Arrays.asList(FRExternalPermissionsCode.READTRANSACTIONSDETAIL, FRExternalPermissionsCode.READTRANSACTIONSCREDITS, FRExternalPermissionsCode.READTRANSACTIONSDEBITS));
OBReadTransaction2 transaction = new OBReadTransaction2();
given(rsStoreGateway.toRsStore(any(), any(), any(), any())).willReturn(ResponseEntity.ok(transaction));
// When
HttpResponse<OBReadTransaction2> response = Unirest.get("https://rs-api:" + port + "/open-banking/v2.0/accounts/100000123/transactions").header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "Bearer " + jws).asObject(OBReadTransaction2.class);
// Then
assertThat(response.getStatus()).isEqualTo(200);
}
use of uk.org.openbanking.datamodel.account.OBReadTransaction2 in project openbanking-aspsp by OpenBankingToolkit.
the class TransactionsApiControllerIT method getAccountTransactionShouldNotGetMoreTransactionThatConsentAllows.
@Test
public void getAccountTransactionShouldNotGetMoreTransactionThatConsentAllows() throws Exception {
// Given
String jws = jws("accounts");
this.mockAuthenticationCollector();
this.mockTppStoreService();
this.mockAccessTokenVerification(jws);
mockAccountPermissions(Arrays.asList(FRExternalPermissionsCode.READTRANSACTIONSDETAIL, FRExternalPermissionsCode.READTRANSACTIONSCREDITS, FRExternalPermissionsCode.READTRANSACTIONSDEBITS));
OBReadTransaction2 transaction = new OBReadTransaction2();
given(rsStoreGateway.toRsStore(any(), any(), any(), any())).willReturn(ResponseEntity.ok(transaction));
DateTime older = DateTime.now().minusDays(5);
DateTime newer = DateTime.now().plusDays(5);
// When
HttpResponse<OBReadTransaction2> response = Unirest.get("https://rs-api:" + port + "/open-banking/v2.0/accounts/100000123/transactions").header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "Bearer " + jws).queryString(TO_BOOKING_DATE_TIME, DateTimeFormat.forPattern(BOOKED_TIME_DATE_FORMAT).print(newer)).queryString(FROM_BOOKING_DATE_TIME, DateTimeFormat.forPattern(BOOKED_TIME_DATE_FORMAT).print(older)).asObject(OBReadTransaction2.class);
assertThat(response.getStatus()).isEqualTo(200);
ImmutableMap<String, String> params = ImmutableMap.<String, String>builder().put(TO_BOOKING_DATE_TIME, DateTimeFormat.forPattern(BOOKED_TIME_DATE_FORMAT).print(CONSENT_TO)).put(FROM_BOOKING_DATE_TIME, DateTimeFormat.forPattern(BOOKED_TIME_DATE_FORMAT).print(CONSENT_FROM)).build();
verify(rsStoreGateway).toRsStore(any(), any(), eq(params), any());
}
Aggregations