use of com.forgerock.openbanking.common.model.rcs.consentdetails.InternationalPaymentConsentDetails in project openbanking-aspsp by OpenBankingToolkit.
the class RCSInternationalPaymentDetailsApi 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");
FRInternationalConsent payment = paymentService.getPayment(consentId);
// 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.isEmpty()) {
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.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_DEBTOR_ACCOUNT_NOT_FOUND, payment.getPispId(), consentId, accounts);
}
accounts = Collections.singletonList(matchingUserAccount.get());
}
Optional<Tpp> isTpp = tppStoreService.findById(payment.getPispId());
if (isTpp.isEmpty()) {
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();
// 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);
FRWriteInternationalDataInitiation initiation = payment.getInitiation();
FRExchangeRateInformation exchangeRateInformation = payment.getCalculatedExchangeRate();
InternationalPaymentConsentDetails internationalPaymentConsentDetails = InternationalPaymentConsentDetails.builder().instructedAmount(toOBActiveOrHistoricCurrencyAndAmount(initiation.getInstructedAmount())).accounts(accounts).username(username).logo(tpp.getLogo()).merchantName(payment.getPispName()).clientId(clientId).currencyOfTransfer(initiation.getCurrencyOfTransfer()).paymentReference(Optional.ofNullable(initiation.getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse("")).build();
// fix issue https://github.com/OpenBankingToolkit/openbanking-toolkit/issues/13
if (exchangeRateInformation != null) {
internationalPaymentConsentDetails.setRate(new OBExchangeRate2().exchangeRate(exchangeRateInformation.getExchangeRate()).rateType(toOBExchangeRateType2Code(exchangeRateInformation.getRateType())).contractIdentification(exchangeRateInformation.getContractIdentification()).unitCurrency(exchangeRateInformation.getUnitCurrency()));
}
// issue fix
return ResponseEntity.ok(internationalPaymentConsentDetails);
}
use of com.forgerock.openbanking.common.model.rcs.consentdetails.InternationalPaymentConsentDetails in project openbanking-aspsp by OpenBankingToolkit.
the class RCSInternationalPaymentDetailsApiTest method shouldReturnAllAccountsWhenNoDebtor.
@Test
public void shouldReturnAllAccountsWhenNoDebtor() throws OBErrorException {
// Given
List<AccountWithBalance> accounts = JMockData.mock(new TypeReference<>() {
});
FRInternationalConsent consent = JMockData.mock(FRInternationalConsent.class);
consent.getInitiation().setDebtorAccount(null);
given(paymentService.getPayment(any())).willReturn(consent);
given(tppStoreService.findById(consent.getPispId())).willReturn(Optional.of(Tpp.builder().clientId(CLIENT_ID).build()));
// When
ResponseEntity responseEntity = api.consentDetails("abcd", accounts, "testuser", "c123", CLIENT_ID);
// Then
InternationalPaymentConsentDetails body = (InternationalPaymentConsentDetails) Objects.requireNonNull(responseEntity.getBody());
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(body.getAccounts()).isEqualTo(accounts);
}
use of com.forgerock.openbanking.common.model.rcs.consentdetails.InternationalPaymentConsentDetails in project openbanking-aspsp by OpenBankingToolkit.
the class RCSInternationalPaymentDetailsApiTest method shouldReturnRequestedAccountWithOnlyMandatoryFields.
@Test
public void shouldReturnRequestedAccountWithOnlyMandatoryFields() throws OBErrorException {
// Given
List<AccountWithBalance> accounts = JMockData.mock(new TypeReference<>() {
});
FRInternationalConsent consent = JMockData.mock(FRInternationalConsent.class);
FRAccountIdentifier firstAccount = accounts.get(0).getAccount().getAccounts().get(0);
consent.getInitiation().getDebtorAccount().setIdentification(firstAccount.getIdentification());
consent.getInitiation().setExchangeRateInformation(null);
consent.getInitiation().setCreditor(null);
consent.getInitiation().setCreditorAgent(null);
consent.getInitiation().setRemittanceInformation(null);
consent.getInitiation().setSupplementaryData(null);
given(paymentService.getPayment(any())).willReturn(consent);
given(tppStoreService.findById(consent.getPispId())).willReturn(Optional.of(Tpp.builder().clientId(CLIENT_ID).build()));
// When
ResponseEntity responseEntity = api.consentDetails("abcd", accounts, "user1", "c123", CLIENT_ID);
// Then
InternationalPaymentConsentDetails body = (InternationalPaymentConsentDetails) Objects.requireNonNull(responseEntity.getBody());
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(body.getAccounts().size()).isEqualTo(1);
assertThat(body.getAccounts()).containsExactly(accounts.get(0));
}
use of com.forgerock.openbanking.common.model.rcs.consentdetails.InternationalPaymentConsentDetails in project openbanking-aspsp by OpenBankingToolkit.
the class RCSInternationalPaymentDetailsApiTest method shouldReturnRequestedAccountWithNoCreditorAgent.
@Test
public void shouldReturnRequestedAccountWithNoCreditorAgent() throws OBErrorException {
// Given
List<AccountWithBalance> accounts = JMockData.mock(new TypeReference<>() {
});
FRInternationalConsent consent = JMockData.mock(FRInternationalConsent.class);
FRAccountIdentifier firstAccount = accounts.get(0).getAccount().getAccounts().get(0);
consent.getInitiation().getDebtorAccount().setIdentification(firstAccount.getIdentification());
consent.getInitiation().setCreditorAgent(null);
given(paymentService.getPayment(any())).willReturn(consent);
given(tppStoreService.findById(consent.getPispId())).willReturn(Optional.of(Tpp.builder().clientId(CLIENT_ID).build()));
// When
ResponseEntity responseEntity = api.consentDetails("abcd", accounts, "user1", "c123", CLIENT_ID);
// Then
InternationalPaymentConsentDetails body = (InternationalPaymentConsentDetails) Objects.requireNonNull(responseEntity.getBody());
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(body.getAccounts().size()).isEqualTo(1);
assertThat(body.getAccounts()).containsExactly(accounts.get(0));
}
use of com.forgerock.openbanking.common.model.rcs.consentdetails.InternationalPaymentConsentDetails in project openbanking-aspsp by OpenBankingToolkit.
the class RCSInternationalPaymentDetailsApiTest method shouldReturnRequestedAccountWhenDebtor.
@Test
public void shouldReturnRequestedAccountWhenDebtor() throws OBErrorException {
// Given
List<AccountWithBalance> accounts = JMockData.mock(new TypeReference<>() {
});
FRInternationalConsent consent = JMockData.mock(FRInternationalConsent.class);
FRAccountIdentifier firstAccount = accounts.get(0).getAccount().getAccounts().get(0);
consent.getInitiation().getDebtorAccount().setIdentification(firstAccount.getIdentification());
given(paymentService.getPayment(any())).willReturn(consent);
given(tppStoreService.findById(consent.getPispId())).willReturn(Optional.of(Tpp.builder().clientId(CLIENT_ID).build()));
// When
ResponseEntity responseEntity = api.consentDetails("abcd", accounts, "user1", "c123", CLIENT_ID);
// Then
InternationalPaymentConsentDetails body = (InternationalPaymentConsentDetails) Objects.requireNonNull(responseEntity.getBody());
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(body.getAccounts().size()).isEqualTo(1);
assertThat(body.getAccounts()).containsExactly(accounts.get(0));
}
Aggregations