Search in sources :

Example 1 with FRWriteFileDataInitiation

use of com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation in project openbanking-aspsp by OpenBankingToolkit.

the class RCSFilePaymentDetailsApi 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");
    FRFileConsent consent = paymentService.getPayment(consentId);
    checkValidPisp(consent, clientId);
    // A null debtor account will let PSU select account when authorising
    if (consent.getInitiation().getDebtorAccount() != null) {
        Optional<AccountWithBalance> matchingUserAccount = accountService.findAccountByIdentification(consent.getInitiation().getDebtorAccount().getIdentification(), accounts);
        if (!matchingUserAccount.isPresent()) {
            log.error("The PISP '{}' created the payment consent '{}' but the debtor account: {} on the consent " + " is not one of the user's accounts: {}.", consent.getPispId(), consent.getId(), consent.getInitiation().getDebtorAccount(), accounts);
            return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_DEBTOR_ACCOUNT_NOT_FOUND, consent.getPispId(), consent.getId(), accounts);
        } else {
            accounts = Collections.singletonList(matchingUserAccount.get());
        }
    }
    associatePaymentToUser(consent, username);
    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.error(OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
    }
    Tpp tpp = isTpp.get();
    FRWriteFileDataInitiation initiation = consent.getWriteFileConsent().getData().getInitiation();
    return ResponseEntity.ok(FilePaymentConsentDetails.builder().accounts(accounts).username(username).merchantName(consent.getPispName()).clientId(clientId).fileReference(initiation.getFileReference()).numberOfTransactions(initiation.getNumberOfTransactions()).totalAmount(new OBActiveOrHistoricCurrencyAndAmount().amount(initiation.getControlSum().toPlainString()).currency(consent.getPayments().get(0).getInstructedAmount().getCurrency())).requestedExecutionDateTime(initiation.getRequestedExecutionDateTime()).paymentReference(Optional.ofNullable(initiation.getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse("")).build());
}
Also used : FRRemittanceInformation(com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRRemittanceInformation) OBActiveOrHistoricCurrencyAndAmount(uk.org.openbanking.datamodel.payment.OBActiveOrHistoricCurrencyAndAmount) FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) Tpp(com.forgerock.openbanking.model.Tpp) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) FRWriteFileDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation)

Example 2 with FRWriteFileDataInitiation

use of com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation in project openbanking-aspsp by OpenBankingToolkit.

the class RCSFilePaymentDetailsApiTest method validFilePayment_accountSpecifiedButNotFound_getErrorRedirect.

@Test
public void validFilePayment_accountSpecifiedButNotFound_getErrorRedirect() throws Exception {
    // Given
    List<AccountWithBalance> accounts = Collections.emptyList();
    FRWriteFileDataInitiation validOBFileWithAccount = getValidOBFile().debtorAccount(FRAccountIdentifier.builder().identification("123").build()).build();
    FRWriteFileConsent writeFileConsent = FRWriteFileConsent.builder().data(FRWriteFileConsentData.builder().initiation(validOBFileWithAccount).build()).build();
    given(paymentService.getPayment(eq(CONSENT_ID))).willReturn(FRFileConsent.builder().id(CONSENT_ID).writeFileConsent(writeFileConsent).pispId(PISP_ID).pispName(PISP_NAME).build());
    givenTppExists();
    given(accountService.findAccountByIdentification(any(), any())).willReturn(Optional.empty());
    given(rcsErrorService.invalidConsentError(any(), any(), any())).willReturn(ResponseEntity.status(HttpStatus.FORBIDDEN).build());
    // When
    ResponseEntity response = rcsFilePaymentDetailsApi.consentDetails("", accounts, USERNAME, CONSENT_ID, CLIENT_ID);
    // Then
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) FRWriteFileConsent(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileConsent) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) FRWriteFileDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation) Test(org.junit.Test)

Example 3 with FRWriteFileDataInitiation

use of com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation in project openbanking-aspsp by OpenBankingToolkit.

the class RCSFilePaymentDetailsApiTest method validFilePayment_accountSpecifiedAndFound_createConsentDetailsWithAllAccounts.

@Test
public void validFilePayment_accountSpecifiedAndFound_createConsentDetailsWithAllAccounts() throws Exception {
    // Given
    List<AccountWithBalance> accounts = singletonList(DEBTOR_ACCOUNT);
    FRWriteFileDataInitiation validOBFileWithAccount = getValidOBFile().debtorAccount(FRAccountIdentifier.builder().identification("123").build()).build();
    FRWriteFileConsent frWriteFileConsent = FRWriteFileConsent.builder().data(FRWriteFileConsentData.builder().initiation(validOBFileWithAccount).build()).build();
    FRAmount amount = FRAmount.builder().currency("GBP").build();
    given(paymentService.getPayment(eq(CONSENT_ID))).willReturn(FRFileConsent.builder().id(CONSENT_ID).writeFileConsent(frWriteFileConsent).pispId(PISP_ID).pispName(PISP_NAME).payments(singletonList(FRFilePayment.builder().instructedAmount(amount).build())).build());
    givenTppExists();
    given(accountService.findAccountByIdentification(any(), any())).willReturn(Optional.of(DEBTOR_ACCOUNT));
    // When
    ResponseEntity response = rcsFilePaymentDetailsApi.consentDetails("", accounts, USERNAME, CONSENT_ID, CLIENT_ID);
    // Then
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
    FilePaymentConsentDetails consentDetails = (FilePaymentConsentDetails) Objects.requireNonNull(response.getBody());
    assertThat(consentDetails.getAccounts()).isEqualTo(accounts);
    assertThat(consentDetails.getClientId()).isEqualTo(CLIENT_ID);
    assertThat(consentDetails.getNumberOfTransactions()).isEqualTo("19");
    assertThat(consentDetails.getMerchantName()).isEqualTo(PISP_NAME);
    verify(paymentService, times(1)).getPayment(any());
}
Also used : FilePaymentConsentDetails(com.forgerock.openbanking.common.model.rcs.consentdetails.FilePaymentConsentDetails) ResponseEntity(org.springframework.http.ResponseEntity) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) FRWriteFileConsent(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileConsent) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) FRWriteFileDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation) Test(org.junit.Test)

Example 4 with FRWriteFileDataInitiation

use of com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation in project openbanking-aspsp by OpenBankingToolkit.

the class RCSFilePaymentDetailsApiTest method validFilePayment_tppNotFound.

@Test
public void validFilePayment_tppNotFound() throws Exception {
    // Given
    FRWriteFileDataInitiation validOBFile = getValidOBFile().build();
    FRWriteFileConsentData writeFileConsentData = FRWriteFileConsentData.builder().initiation(validOBFile).build();
    given(paymentService.getPayment(eq(CONSENT_ID))).willReturn(FRFileConsent.builder().id(CONSENT_ID).writeFileConsent(FRWriteFileConsent.builder().data(writeFileConsentData).build()).pispId(PISP_ID).pispName(PISP_NAME).build());
    given(tppStoreService.findById(any())).willReturn(Optional.empty());
    // When
    assertThatThrownBy(() -> rcsFilePaymentDetailsApi.consentDetails("", Collections.emptyList(), USERNAME, CONSENT_ID, CLIENT_ID)).isInstanceOf(OBErrorException.class).hasMessage("The TPP 'PISP1' that created this intent id 'PFC_123' doesn't exist anymore.");
}
Also used : FRWriteFileConsentData(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileConsentData) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) FRWriteFileDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation) Test(org.junit.Test)

Example 5 with FRWriteFileDataInitiation

use of com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation in project openbanking-aspsp by OpenBankingToolkit.

the class RCSFilePaymentDetailsApiTest method validFilePayment_wrongPisp.

@Test
public void validFilePayment_wrongPisp() throws Exception {
    // Given
    FRWriteFileDataInitiation validOBFile = getValidOBFile().build();
    FRWriteFileConsentData writeFileConsentData = FRWriteFileConsentData.builder().initiation(validOBFile).build();
    given(paymentService.getPayment(eq(CONSENT_ID))).willReturn(FRFileConsent.builder().id(CONSENT_ID).writeFileConsent(FRWriteFileConsent.builder().data(writeFileConsentData).build()).pispId(PISP_ID).pispName(PISP_NAME).build());
    givenTppExists();
    // When
    assertThatThrownBy(() -> rcsFilePaymentDetailsApi.consentDetails("", Collections.emptyList(), USERNAME, CONSENT_ID, "Wrong Client Id")).isInstanceOf(OBErrorException.class).hasMessage("The PISP '" + CLIENT_ID + "' created the payment request '" + CONSENT_ID + "' but it's PISP 'Wrong Client Id' that is requesting consent for it.");
}
Also used : FRWriteFileConsentData(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileConsentData) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) FRWriteFileDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation) Test(org.junit.Test)

Aggregations

FRWriteFileDataInitiation (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation)5 Test (org.junit.Test)4 AccountWithBalance (com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance)3 FRWriteFileConsent (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileConsent)2 FRWriteFileConsentData (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileConsentData)2 OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)2 ResponseEntity (org.springframework.http.ResponseEntity)2 FRAmount (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount)1 FRRemittanceInformation (com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRRemittanceInformation)1 FRFileConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent)1 FilePaymentConsentDetails (com.forgerock.openbanking.common.model.rcs.consentdetails.FilePaymentConsentDetails)1 Tpp (com.forgerock.openbanking.model.Tpp)1 OBActiveOrHistoricCurrencyAndAmount (uk.org.openbanking.datamodel.payment.OBActiveOrHistoricCurrencyAndAmount)1