use of com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance in project openbanking-aspsp by OpenBankingToolkit.
the class RCSDomesticStandingOrderDetailsApiTest method shouldReturnAllAccountsWhenNoDebtor.
@Test
public void shouldReturnAllAccountsWhenNoDebtor() throws OBErrorException {
// Given
List<AccountWithBalance> accounts = JMockData.mock(new TypeReference<List<AccountWithBalance>>() {
});
FRDomesticStandingOrderConsent consent = JMockData.mock(FRDomesticStandingOrderConsent.class);
consent.getInitiation().setDebtorAccount(null);
given(paymentService.getPayment("")).willReturn(consent);
String clientId = "clientId";
given(tppStoreService.findById(consent.getPispId())).willReturn(Optional.of(Tpp.builder().clientId(clientId).build()));
// When
ResponseEntity responseEntity = api.consentDetails("", accounts, "", "", clientId);
// Then
DomesticStandingOrderPaymentConsentDetails body = (DomesticStandingOrderPaymentConsentDetails) responseEntity.getBody();
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(body.getAccounts()).isEqualTo(accounts);
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance in project openbanking-aspsp by OpenBankingToolkit.
the class RCSDomesticStandingOrderDetailsApi method consentDetails.
@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
log.debug("Received a consent request with consent_request='{}'", remoteConsentRequest);
log.debug("=> The payment id '{}'", consentId);
log.debug("Populate the model with the payment and consent data");
FRDomesticStandingOrderConsent domesticConsent = paymentService.getPayment(consentId);
// Only show the debtor account if specified in consent
if (domesticConsent.getInitiation().getDebtorAccount() != null) {
Optional<AccountWithBalance> matchingUserAccount = accountService.findAccountByIdentification(domesticConsent.getInitiation().getDebtorAccount().getIdentification(), accounts);
if (!matchingUserAccount.isPresent()) {
log.error("The PISP '{}' created the payment request '{}' but the debtor account: {} on the payment consent " + " is not one of the user's accounts: {}.", domesticConsent.getPispId(), consentId, domesticConsent.getInitiation().getDebtorAccount(), accounts);
return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_DEBTOR_ACCOUNT_NOT_FOUND, domesticConsent.getPispId(), consentId, accounts);
}
accounts = Collections.singletonList(matchingUserAccount.get());
}
Optional<Tpp> isTpp = tppStoreService.findById(domesticConsent.getPispId());
if (!isTpp.isPresent()) {
log.error("The TPP '{}' (Client ID {}) that created this consent id '{}' doesn't exist anymore.", domesticConsent.getPispId(), clientId, consentId);
return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
}
Tpp tpp = isTpp.get();
// Verify the pisp is the same than the one that created this payment ^
verifyTppCreatedPayment(clientId, isTpp.get().getClientId(), consentId);
// Associate the payment to this user
domesticConsent.setUserId(username);
paymentService.updatePayment(domesticConsent);
FRWriteDomesticStandingOrderDataInitiation domesticStandingOrder = domesticConsent.getInitiation();
OBStandingOrder6 standingOrder = new OBStandingOrder6().accountId(domesticConsent.getAccountId()).standingOrderId(domesticConsent.getId()).finalPaymentAmount(toOBActiveOrHistoricCurrencyAndAmount4(domesticStandingOrder.getFinalPaymentAmount())).finalPaymentDateTime(domesticStandingOrder.getFinalPaymentDateTime()).firstPaymentAmount(toOBActiveOrHistoricCurrencyAndAmount2(domesticStandingOrder.getFirstPaymentAmount())).firstPaymentDateTime(domesticStandingOrder.getFirstPaymentDateTime()).nextPaymentDateTime(domesticStandingOrder.getRecurringPaymentDateTime()).nextPaymentAmount(toOBActiveOrHistoricCurrencyAndAmount3(domesticStandingOrder.getRecurringPaymentAmount())).frequency(domesticStandingOrder.getFrequency()).creditorAccount(toOBCashAccount51(domesticStandingOrder.getCreditorAccount())).reference(domesticStandingOrder.getReference());
return ResponseEntity.ok(DomesticStandingOrderPaymentConsentDetails.builder().standingOrder(standingOrder).accounts(accounts).username(username).logo(tpp.getLogo()).merchantName(domesticConsent.getPispName()).clientId(clientId).paymentReference(Optional.ofNullable(domesticConsent.getInitiation().getReference()).orElse("")).build());
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance in project openbanking-aspsp by OpenBankingToolkit.
the class RCSFundsConfirmationDetailsApi method consentDetails.
@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
log.debug("Received a consent request with consent_request='{}'", remoteConsentRequest);
log.debug("=> The payment id '{}'", consentId);
log.debug("Populate the model with the payment and consent data");
FRFundsConfirmationConsent consent = fundsConfirmationService.getConsent(consentId);
// Verify that the 'DebtorAccount' matches one of the accounts of the user and define as the selected account.
Optional<AccountWithBalance> matchingUserAccount = accountService.findAccountByIdentification(consent.getDebtorAccount().getIdentification(), accounts);
if (!matchingUserAccount.isPresent()) {
log.error("The PISP '{}' created the funds confirmation request '{}' but the debtor account: {} on the consent " + " is not one of the user's accounts: {}.", consent.getPispId(), consentId, consent.getDebtorAccount(), accounts);
return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_INVALID_FUNDS_CONFIRMATION_REQUEST, consent.getPispId(), consentId, clientId);
}
Optional<Tpp> isTpp = tppStoreService.findById(consent.getPispId());
if (!isTpp.isPresent()) {
log.error("The TPP '{}' (Client ID {}) that created this consent id '{}' doesn't exist anymore.", consent.getPispId(), clientId, consentId);
return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
}
Tpp tpp = isTpp.get();
// Verify the pisp is the same than the one that created this payment ^
verifyTppCreatedPayment(clientId, isTpp.get().getClientId(), consentId);
// Associate the payment to this user
consent.setUserId(username);
fundsConfirmationService.updateConsent(consent);
return ResponseEntity.ok(FundsConfirmationConsentDetails.builder().expirationDateTime(consent.getFundsConfirmationConsent().getExpirationDateTime()).accounts(Collections.singletonList(matchingUserAccount.get())).username(username).logo(tpp.getLogo()).merchantName(consent.getPispName()).clientId(clientId).build());
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance in project openbanking-aspsp by OpenBankingToolkit.
the class RCSInternationalStandingOrderPaymentDetailsApi method consentDetails.
@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
log.debug("Received a consent request with consent_request='{}'", remoteConsentRequest);
log.debug("=> The payment id '{}'", consentId);
log.debug("Populate the model with the payment and consent data");
FRInternationalStandingOrderConsent payment = paymentService.getPayment(consentId);
Optional<Tpp> isTpp = tppStoreService.findById(payment.getPispId());
if (!isTpp.isPresent()) {
log.error("The TPP '{}' (Client ID {}) that created this consent id '{}' doesn't exist anymore.", payment.getPispId(), clientId, consentId);
return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
}
Tpp tpp = isTpp.get();
// Only show the debtor account if specified in consent
if (payment.getInitiation().getDebtorAccount() != null) {
Optional<AccountWithBalance> matchingUserAccount = accountService.findAccountByIdentification(payment.getInitiation().getDebtorAccount().getIdentification(), accounts);
if (!matchingUserAccount.isPresent()) {
log.error("The PISP '{}' created the payment request '{}' but the debtor account: {} on the payment consent " + " is not one of the user's accounts: {}.", payment.getPispId(), consentId, payment.getInitiation().getDebtorAccount(), accounts);
return rcsErrorService.error(OBRIErrorType.RCS_CONSENT_REQUEST_DEBTOR_ACCOUNT_NOT_FOUND, payment.getPispId(), consentId, accounts);
}
accounts = Collections.singletonList(matchingUserAccount.get());
}
// Verify the pisp is the same than the one that created this payment ^
verifyTppCreatedPayment(clientId, isTpp.get().getClientId(), consentId);
// Associate the payment to this user
payment.setUserId(username);
paymentService.updatePayment(payment);
FRWriteInternationalStandingOrderDataInitiation initiation = payment.getInitiation();
OBStandingOrder5 standingOrder = new OBStandingOrder5().accountId(payment.getAccountId()).standingOrderId(payment.getId()).finalPaymentAmount(toAccountOBActiveOrHistoricCurrencyAndAmount(initiation.getInstructedAmount())).finalPaymentDateTime(initiation.getFinalPaymentDateTime()).firstPaymentAmount(toAccountOBActiveOrHistoricCurrencyAndAmount(initiation.getInstructedAmount())).firstPaymentDateTime(initiation.getFirstPaymentDateTime()).nextPaymentDateTime(initiation.getFirstPaymentDateTime()).nextPaymentAmount(toAccountOBActiveOrHistoricCurrencyAndAmount(initiation.getInstructedAmount())).frequency(initiation.getFrequency()).creditorAccount(toOBCashAccount5(initiation.getCreditorAccount())).reference(initiation.getReference());
return ResponseEntity.ok(InternationalStandingOrderPaymentConsentDetails.builder().standingOrder(standingOrder).accounts(accounts).logo(tpp.getLogo()).username(username).merchantName(payment.getPispName()).clientId(clientId).currencyOfTransfer(initiation.getCurrencyOfTransfer()).paymentReference(Optional.ofNullable(payment.getInitiation().getReference()).orElse("")).build());
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance in project openbanking-aspsp by OpenBankingToolkit.
the class AccountStoreServiceImpl method getAccountWithBalances.
@Override
public List<AccountWithBalance> getAccountWithBalances(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<AccountWithBalance>> ptr = new ParameterizedTypeReference<List<AccountWithBalance>>() {
};
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(rsStoreRoot + "/api/accounts/search/findByUserId");
builder.queryParam("userId", lowercaseUserId);
builder.queryParam("withBalance", true);
URI uri = builder.build().encode().toUri();
ResponseEntity<List<AccountWithBalance>> entity = restTemplate.exchange(uri, HttpMethod.GET, null, ptr);
return entity.getBody();
}
Aggregations