use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDueScheduledPaymentTask method createTransaction.
private FRTransaction createTransaction(Account account, FRScheduledPayment payment, FRCreditDebitIndicator creditDebitCode, Balance balance, FRAmount amount) {
log.info("Create transaction");
String transactionId = UUID.randomUUID().toString();
DateTime bookingDate = new DateTime(payment.getCreated());
FRTransactionData transactionData = FRTransactionData.builder().transactionId(transactionId).status(FRTransactionData.FREntryStatus.BOOKED).valueDateTime(DateTime.now()).accountId(account.getId()).amount(amount).creditDebitIndicator(creditDebitCode).bookingDateTime(bookingDate).statementReferences(new ArrayList<>()).balance(FRTransactionData.FRTransactionCashBalance.builder().amount(balance.getCurrencyAndAmount()).creditDebitIndicator(balance.getCreditDebitIndicator()).type(FRBalanceType.INTERIMBOOKED).build()).build();
if (payment.getScheduledPayment().getReference() != null) {
transactionData.setTransactionReference(payment.getScheduledPayment().getReference());
}
FRTransaction transaction = FRTransaction.builder().id(transactionId).bookingDateTime(bookingDate).accountId(account.getId()).transaction(transactionData).build();
log.info("Transaction created {}", transaction);
return transaction;
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptFilePaymentTask method createTransaction.
private FRTransaction createTransaction(Account account, FRFilePayment payment, FRCreditDebitIndicator creditDebitCode, Balance balance, FRAmount amount) {
log.info("Create transaction");
String transactionId = UUID.randomUUID().toString();
DateTime bookingDate = new DateTime(payment.getCreated());
FRTransactionData transactionData = FRTransactionData.builder().transactionId(transactionId).status(FRTransactionData.FREntryStatus.BOOKED).valueDateTime(DateTime.now()).accountId(account.getId()).amount(amount).creditDebitIndicator(creditDebitCode).bookingDateTime(bookingDate).statementReferences(new ArrayList<>()).balance(FRTransactionData.FRTransactionCashBalance.builder().amount(balance.getCurrencyAndAmount()).creditDebitIndicator(balance.getCreditDebitIndicator()).type(FRBalanceType.INTERIMBOOKED).build()).build();
transactionData.setTransactionReference(payment.getRemittanceReference());
transactionData.setTransactionInformation(payment.getRemittanceUnstructured());
FRTransaction transaction = FRTransaction.builder().id(transactionId).bookingDateTime(bookingDate).accountId(account.getId()).transaction(transactionData).build();
log.info("Transaction created {}", transaction);
return transaction;
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptSinglePaymentTask method createTransaction.
private FRTransaction createTransaction(Account account, FRPaymentSetup paymentSetup, FRCreditDebitIndicator creditDebitCode, Balance balance, FRAmount amount) {
log.info("Create transaction");
String transactionId = UUID.randomUUID().toString();
DateTime bookingDate = new DateTime(paymentSetup.getCreated());
FRTransactionData transactionData = FRTransactionData.builder().accountId(account.getId()).transactionId(transactionId).amount(amount).creditDebitIndicator(creditDebitCode).status(FRTransactionData.FREntryStatus.BOOKED).bookingDateTime(bookingDate).valueDateTime(DateTime.now()).balance(FRTransactionData.FRTransactionCashBalance.builder().amount(balance.getCurrencyAndAmount()).creditDebitIndicator(balance.getCreditDebitIndicator()).type(FRBalanceType.INTERIMBOOKED).build()).build();
if (paymentSetup.getInitiation().getRemittanceInformation() != null) {
transactionData.setTransactionReference(paymentSetup.getInitiation().getRemittanceInformation().getReference());
transactionData.setTransactionInformation(paymentSetup.getInitiation().getRemittanceInformation().getUnstructured());
}
FRTransaction transaction = FRTransaction.builder().id(transactionId).bookingDateTime(bookingDate).accountId(account.getId()).transaction(transactionData).statementIds(// Need a mutable list to be set here so don't use Lombok.singular to init list
new ArrayList<>()).build();
log.info("Transaction created {}", transaction);
return transaction;
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction 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.FRTransaction in project openbanking-aspsp by OpenBankingToolkit.
the class TransactionsApiController method getTransactions.
@Override
public ResponseEntity<OBReadTransaction4> 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> body = FRTransactionRepository.byAccountIdInAndBookingDateTimeBetweenWithPermissions(accountIds, fromBookingDateTime, toBookingDateTime, toFRExternalPermissionsCodeList(permissions), PageRequest.of(page, PAGE_LIMIT_TRANSACTIONS, Sort.Direction.ASC, "bookingDateTime"));
List<OBTransaction4> transactions = body.getContent().stream().map(FRTransaction::getTransaction).map(FRTransactionConverter::toOBTransaction4).map(t -> accountDataInternalIdFilter.apply(t)).collect(Collectors.toList());
// Package the answer
int totalPages = body.getTotalPages();
return ResponseEntity.ok(new OBReadTransaction4().data(new OBReadTransaction4Data().transaction(transactions)).links(PaginationUtil.generateLinks(httpUrl, page, totalPages)).meta(PaginationUtil.generateMetaData(totalPages, firstAvailableDate, lastAvailableDate)));
}
Aggregations