Search in sources :

Example 26 with AccountWithBalance

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) DomesticStandingOrderPaymentConsentDetails(com.forgerock.openbanking.common.model.rcs.consentdetails.DomesticStandingOrderPaymentConsentDetails) FRDomesticStandingOrderConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticStandingOrderConsent) List(java.util.List) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) Test(org.junit.Test)

Example 27 with AccountWithBalance

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());
}
Also used : FRWriteDomesticStandingOrderDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticStandingOrderDataInitiation) Tpp(com.forgerock.openbanking.model.Tpp) FRDomesticStandingOrderConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticStandingOrderConsent) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) OBStandingOrder6(uk.org.openbanking.datamodel.account.OBStandingOrder6)

Example 28 with AccountWithBalance

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());
}
Also used : Tpp(com.forgerock.openbanking.model.Tpp) FRFundsConfirmationConsent(com.forgerock.openbanking.common.model.openbanking.persistence.funds.FRFundsConfirmationConsent) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance)

Example 29 with AccountWithBalance

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());
}
Also used : FRInternationalStandingOrderConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderConsent) Tpp(com.forgerock.openbanking.model.Tpp) FRWriteInternationalStandingOrderDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalStandingOrderDataInitiation) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) OBStandingOrder5(uk.org.openbanking.datamodel.account.OBStandingOrder5)

Example 30 with AccountWithBalance

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();
}
Also used : ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) List(java.util.List) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) URI(java.net.URI)

Aggregations

AccountWithBalance (com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance)30 Test (org.junit.Test)20 ResponseEntity (org.springframework.http.ResponseEntity)20 FRAccountIdentifier (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier)11 Tpp (com.forgerock.openbanking.model.Tpp)8 FRInternationalConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent)7 InternationalPaymentConsentDetails (com.forgerock.openbanking.common.model.rcs.consentdetails.InternationalPaymentConsentDetails)7 List (java.util.List)5 FRRemittanceInformation (com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRRemittanceInformation)4 FRInternationalScheduledConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalScheduledConsent)4 FRWriteFileConsent (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileConsent)3 FRWriteFileDataInitiation (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation)3 FRExchangeRateInformation (com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRExchangeRateInformation)3 FRDomesticConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)3 FRDomesticScheduledConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticScheduledConsent)3 FRDomesticStandingOrderConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticStandingOrderConsent)3 FRInternationalStandingOrderConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderConsent)3 InternationalSchedulePaymentConsentDetails (com.forgerock.openbanking.common.model.rcs.consentdetails.InternationalSchedulePaymentConsentDetails)3 OBExchangeRate2 (uk.org.openbanking.datamodel.payment.OBExchangeRate2)3 FRAmount (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount)2