Search in sources :

Example 1 with FRAccountIdentifier

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

the class FRAccountIdentifierConverterTest method OBFundsConfirmationConsent1DataDebtorAccount_toFRAccountIdentifier.

@Test
public void OBFundsConfirmationConsent1DataDebtorAccount_toFRAccountIdentifier() {
    // Given
    OBFundsConfirmationConsent1DataDebtorAccount obFundsConfirmationConsent1DataDebtorAccount = new OBFundsConfirmationConsent1DataDebtorAccount();
    obFundsConfirmationConsent1DataDebtorAccount.schemeName(this.schemeName).identification(this.identification).name(this.name).secondaryIdentification(this.secondaryIdentification);
    // When
    FRAccountIdentifier accountIdentifier = toFRAccountIdentifier(obFundsConfirmationConsent1DataDebtorAccount);
    // Then
    assertThat(accountIdentifier.getSchemeName()).isEqualTo(this.schemeName);
    assertThat(accountIdentifier.getIdentification()).isEqualTo(this.identification);
    assertThat(accountIdentifier.getName()).isEqualTo(this.name);
    assertThat(accountIdentifier.getSecondaryIdentification()).isEqualTo(this.secondaryIdentification);
}
Also used : FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) FRAccountIdentifierConverter.toFRAccountIdentifier(com.forgerock.openbanking.common.services.openbanking.converter.common.FRAccountIdentifierConverter.toFRAccountIdentifier) OBFundsConfirmationConsent1DataDebtorAccount(uk.org.openbanking.datamodel.fund.OBFundsConfirmationConsent1DataDebtorAccount) FRAccountIdentifierConverter.toOBFundsConfirmationConsent1DataDebtorAccount(com.forgerock.openbanking.common.services.openbanking.converter.common.FRAccountIdentifierConverter.toOBFundsConfirmationConsent1DataDebtorAccount) Test(org.junit.Test)

Example 2 with FRAccountIdentifier

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

the class FRResponseDataRefundFactory method frInternationalResponseDataRefund.

/**
 * Creates a {@link FRInternationalResponseDataRefund}, so long as the provided {@link FRReadRefundAccount} is
 * set to 'Yes' and the initiation's debit account is null. Otherwise returns an empty {@link Optional}.
 *
 * @param frReadRefundAccount The {@link FRReadRefundAccount} indicating if a refund should be issued.
 * @param initiation          {@link FRDomesticDataInitiation} The payment's initiation data.
 * @return The {@link Optional} {@link FRDomesticResponseDataRefund} instance.
 */
public static Optional<FRInternationalResponseDataRefund> frInternationalResponseDataRefund(FRReadRefundAccount frReadRefundAccount, FRInternationalDataInitiation initiation) {
    if (hasRefund(frReadRefundAccount) && initiation.getDebtorAccount() != null) {
        FRAccountIdentifier debtorAccount = initiation.getDebtorAccount();
        FRFinancialCreditor creditor = initiation.getCreditor();
        FRFinancialAgent creditorAgent = initiation.getCreditorAgent();
        return Optional.of(FRInternationalResponseDataRefund.builder().account(FRAccountIdentifier.builder().schemeName(debtorAccount.getSchemeName()).identification(debtorAccount.getIdentification()).name(debtorAccount.getName()).secondaryIdentification(debtorAccount.getSecondaryIdentification()).build()).creditor(creditor == null ? null : FRFinancialCreditor.builder().name(creditor.getName()).postalAddress(creditor.getPostalAddress()).build()).agent(creditorAgent == null ? null : FRFinancialAgent.builder().schemeName(creditorAgent.getSchemeName()).identification(creditorAgent.getIdentification()).name(creditorAgent.getName()).postalAddress(creditorAgent.getPostalAddress()).build()).build());
    }
    return Optional.empty();
}
Also used : FRFinancialCreditor(com.forgerock.openbanking.common.model.openbanking.domain.common.FRFinancialCreditor) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) FRFinancialAgent(com.forgerock.openbanking.common.model.openbanking.domain.common.FRFinancialAgent)

Example 3 with FRAccountIdentifier

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

the class DomesticVrpConsentsApiControllerIT method getFundsConfirmation_not_available.

@Test
public void getFundsConfirmation_not_available() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    OBVRPFundsConfirmationRequest request = aValidOBVRPFundsConfirmationRequest();
    FRDomesticVRPConsent consent = saveFRConsent(request.getData().getConsentId(), FRReadRefundAccount.NO, ConsentStatusCode.AUTHORISED);
    given(fundsAvailabilityService.isFundsAvailable(any(), any())).willReturn(false);
    FRAccountIdentifier accountIdentifier = consent.getVrpDetails().getData().getInitiation().getDebtorAccount();
    given(accountRepository.findByUserID(any())).willReturn(Collections.singletonList(FRAccount.builder().account(FRFinancialAccount.builder().accounts(Collections.singletonList(accountIdentifier)).build()).id("111").build()));
    // When
    HttpResponse<OBVRPFundsConfirmationResponse> response = Unirest.post(RS_STORE_URL + port + CONTEXT_PATH + consent.getId() + "/funds-confirmation").header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header(OBHeaders.X_IDEMPOTENCY_KEY, UUID.randomUUID().toString()).header(OBHeaders.X_JWS_SIGNATURE, "x-jws-signature").header("x-ob-client-id", MOCK_CLIENT_ID).header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(request).asObject(OBVRPFundsConfirmationResponse.class);
    // Then
    if (response.getParsingError().isPresent()) {
        log.error("The response: {}", response);
        log.error("Parsing error", response.getParsingError().get());
    }
    assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
    OBVRPFundsConfirmationResponseData responseData = response.getBody().getData();
    OBVRPFundsConfirmationRequestData requestData = request.getData();
    assertThat(responseData.getConsentId()).isEqualTo(requestData.getConsentId());
    assertThat(responseData.getReference()).isEqualTo(requestData.getReference());
    assertThat(responseData.getFundsConfirmationId()).isNotNull();
    assertThat(responseData.getInstructedAmount()).isEqualTo(requestData.getInstructedAmount());
    assertThat(responseData.getFundsAvailableResult().getFundsAvailable()).isEqualTo(OBPAFundsAvailableResult1.FundsAvailableEnum.NOTAVAILABLE);
}
Also used : FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) FRAccountIdentifierTestDataFactory.aValidFRAccountIdentifier(com.forgerock.openbanking.aspsp.rs.store.api.openbanking.testsupport.domain.FRAccountIdentifierTestDataFactory.aValidFRAccountIdentifier) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) OBVRPFundsConfirmationRequestTestDataFactory.aValidOBVRPFundsConfirmationRequest(uk.org.openbanking.testsupport.vrp.OBVRPFundsConfirmationRequestTestDataFactory.aValidOBVRPFundsConfirmationRequest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test)

Example 4 with FRAccountIdentifier

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

the class DomesticVrpConsentsApiControllerIT method getFundsConfirmation_available.

@Test
public void getFundsConfirmation_available() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    OBVRPFundsConfirmationRequest request = aValidOBVRPFundsConfirmationRequest();
    FRDomesticVRPConsent consent = saveFRConsent(request.getData().getConsentId(), FRReadRefundAccount.NO, ConsentStatusCode.AUTHORISED);
    given(fundsAvailabilityService.isFundsAvailable(any(), any())).willReturn(true);
    FRAccountIdentifier accountIdentifier = consent.getVrpDetails().getData().getInitiation().getDebtorAccount();
    given(accountRepository.findByUserID(any())).willReturn(Collections.singletonList(FRAccount.builder().account(FRFinancialAccount.builder().accounts(Collections.singletonList(accountIdentifier)).build()).id("111").build()));
    // When
    HttpResponse<OBVRPFundsConfirmationResponse> response = Unirest.post(RS_STORE_URL + port + CONTEXT_PATH + consent.getId() + "/funds-confirmation").header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header(OBHeaders.X_IDEMPOTENCY_KEY, UUID.randomUUID().toString()).header(OBHeaders.X_JWS_SIGNATURE, "x-jws-signature").header("x-ob-client-id", MOCK_CLIENT_ID).header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(request).asObject(OBVRPFundsConfirmationResponse.class);
    // Then
    if (response.getParsingError().isPresent()) {
        log.error("The response: {}", response);
        log.error("Parsing error", response.getParsingError().get());
    }
    assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
    OBVRPFundsConfirmationResponseData responseData = response.getBody().getData();
    OBVRPFundsConfirmationRequestData requestData = request.getData();
    assertThat(responseData.getConsentId()).isEqualTo(requestData.getConsentId());
    assertThat(responseData.getReference()).isEqualTo(requestData.getReference());
    assertThat(responseData.getFundsConfirmationId()).isNotNull();
    assertThat(responseData.getInstructedAmount()).isEqualTo(requestData.getInstructedAmount());
    assertThat(responseData.getFundsAvailableResult().getFundsAvailable()).isEqualTo(OBPAFundsAvailableResult1.FundsAvailableEnum.AVAILABLE);
}
Also used : FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) FRAccountIdentifierTestDataFactory.aValidFRAccountIdentifier(com.forgerock.openbanking.aspsp.rs.store.api.openbanking.testsupport.domain.FRAccountIdentifierTestDataFactory.aValidFRAccountIdentifier) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) OBVRPFundsConfirmationRequestTestDataFactory.aValidOBVRPFundsConfirmationRequest(uk.org.openbanking.testsupport.vrp.OBVRPFundsConfirmationRequestTestDataFactory.aValidOBVRPFundsConfirmationRequest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test)

Example 5 with FRAccountIdentifier

use of com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier 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));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) InternationalPaymentConsentDetails(com.forgerock.openbanking.common.model.rcs.consentdetails.InternationalPaymentConsentDetails) Test(org.junit.Test)

Aggregations

FRAccountIdentifier (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier)17 Test (org.junit.Test)15 AccountWithBalance (com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance)11 ResponseEntity (org.springframework.http.ResponseEntity)11 FRInternationalConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent)5 InternationalPaymentConsentDetails (com.forgerock.openbanking.common.model.rcs.consentdetails.InternationalPaymentConsentDetails)5 FRAccountIdentifierTestDataFactory.aValidFRAccountIdentifier (com.forgerock.openbanking.aspsp.rs.store.api.openbanking.testsupport.domain.FRAccountIdentifierTestDataFactory.aValidFRAccountIdentifier)2 FRInternationalScheduledConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalScheduledConsent)2 FRDomesticVRPConsent (com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent)2 InternationalSchedulePaymentConsentDetails (com.forgerock.openbanking.common.model.rcs.consentdetails.InternationalSchedulePaymentConsentDetails)2 FRAccountIdentifierConverter.toFRAccountIdentifier (com.forgerock.openbanking.common.services.openbanking.converter.common.FRAccountIdentifierConverter.toFRAccountIdentifier)2 FRAccountIdentifierConverter.toOBFundsConfirmationConsent1DataDebtorAccount (com.forgerock.openbanking.common.services.openbanking.converter.common.FRAccountIdentifierConverter.toOBFundsConfirmationConsent1DataDebtorAccount)2 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 OBFundsConfirmationConsent1DataDebtorAccount (uk.org.openbanking.datamodel.fund.OBFundsConfirmationConsent1DataDebtorAccount)2 OBVRPFundsConfirmationRequestTestDataFactory.aValidOBVRPFundsConfirmationRequest (uk.org.openbanking.testsupport.vrp.OBVRPFundsConfirmationRequestTestDataFactory.aValidOBVRPFundsConfirmationRequest)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)1 FRExternalPermissionsCode (com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRExternalPermissionsCode)1 FRFinancialAgent (com.forgerock.openbanking.common.model.openbanking.domain.common.FRFinancialAgent)1