Search in sources :

Example 21 with FRDomesticVRPConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticVrpPaymentsEndpointWrapperTest method fail_checkRequestAndConsentInitiationMatch.

@Test
public void fail_checkRequestAndConsentInitiationMatch() throws OBErrorException {
    // Given
    DomesticVrpPaymentsEndpointWrapper domesticVrpPaymentsEndpointWrapper = new DomesticVrpPaymentsEndpointWrapper(endpointWrapperService, tppStoreService, riskValidator);
    // Create the request data
    OBDomesticVRPInitiation requestInitiation = OBDomesticVRPCommonTestDataFactory.aValidOBDomesticVRPInitiation();
    // Create an FR Consent with slightly differing initiation data
    FRDomesticVRPConsent frConsent = FRVrpTestDataFactory.aValidFRDomesticVRPConsent();
    FRWriteDomesticVRPDataInitiation differentInitiationData = (FRWriteDomesticVRPDataInitiation) FRDomesticVRPConverters.toFRDomesticVRPInitiation(requestInitiation);
    differentInitiationData.getDebtorAccount().setIdentification("mismatched identification");
    frConsent.getVrpDetails().getData().setInitiation(differentInitiationData);
    // When
    OBErrorException exception = catchThrowableOfType(() -> domesticVrpPaymentsEndpointWrapper.checkRequestAndConsentInitiationMatch(requestInitiation, frConsent), OBErrorException.class);
    // Then
    assertThat(exception.getObriErrorType()).isEqualTo(OBRIErrorType.REQUEST_VRP_INITIATION_DOESNT_MATCH_CONSENT);
    assertThat(exception.getOBError().getErrorCode()).isEqualTo(OBStandardErrorCodes1.UK_OBIE_RESOURCE_CONSENT_MISMATCH.toString());
}
Also used : OBDomesticVRPInitiation(uk.org.openbanking.datamodel.vrp.OBDomesticVRPInitiation) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) FRWriteDomesticVRPDataInitiation(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRWriteDomesticVRPDataInitiation) Test(org.junit.Test)

Example 22 with FRDomesticVRPConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticVrpPaymentsEndpointWrapperTest method fail_checkCreditorAccountIsInInstructionIfNotInConsent.

/**
 * If the CreditorAccount was not specified in the consent, the CreditorAccount must be specified in the
 * instruction.
 */
@Test
public void fail_checkCreditorAccountIsInInstructionIfNotInConsent() throws OBErrorException {
    // Given
    DomesticVrpPaymentsEndpointWrapper domesticVrpPaymentsEndpointWrapper = new DomesticVrpPaymentsEndpointWrapper(endpointWrapperService, tppStoreService, riskValidator);
    // Create the request data
    OBDomesticVRPRequest vrpRequest = OBDomesticVRPRequestTestDataFactory.aValidOBDomesticVRPRequest();
    vrpRequest.getData().getInitiation().setCreditorAccount(null);
    vrpRequest.getData().getInstruction().setCreditorAccount(null);
    // Create an FR Consent with slightly differing initiation data
    FRDomesticVRPConsent frConsent = FRVrpTestDataFactory.aValidFRDomesticVRPConsent();
    frConsent.getVrpDetails().getData().getInitiation().setCreditorAccount(null);
    // When
    OBErrorException exception = catchThrowableOfType(() -> domesticVrpPaymentsEndpointWrapper.checkCreditorAccountIsInInstructionIfNotInConsent(vrpRequest, frConsent), OBErrorException.class);
    // Then
    assertThat(exception.getObriErrorType()).isEqualTo(OBRIErrorType.REQUEST_VRP_CREDITOR_ACCOUNT_NOT_SPECIFIED);
    assertThat(exception.getOBError().getErrorCode()).isEqualTo(OBStandardErrorCodes1.UK_OBIE_RESOURCE_CONSENT_MISMATCH.toString());
}
Also used : OBDomesticVRPRequest(uk.org.openbanking.datamodel.vrp.OBDomesticVRPRequest) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) Test(org.junit.Test)

Example 23 with FRDomesticVRPConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent in project openbanking-aspsp by OpenBankingToolkit.

the class FRDomesticVRPConsentConverterTest method convertFRDomesticVRPConsentDetailsToOB.

@Test
public void convertFRDomesticVRPConsentDetailsToOB() {
    // given
    FRDomesticVRPConsent frDomesticVRPConsent = getFRDomesticVRPConsent();
    OBDomesticVRPConsentRequest obDomesticVRPConsentRequest = toOBDomesticVRPConsentRequest(frDomesticVRPConsent.getVrpDetails());
    // when
    OBDomesticVRPConsentRequestData obData = obDomesticVRPConsentRequest.getData();
    FRDomesticVRPConsentDetailsData frData = frDomesticVRPConsent.getVrpDetails().getData();
    // then (check few fields)
    assertThat(frData.getReadRefundAccount().getValue()).isEqualTo(obData.getReadRefundAccount().getValue());
    assertThat(frData.getInitiation().getCreditorAccount().getIdentification()).isEqualTo(obData.getInitiation().getCreditorAccount().getIdentification());
    assertThat(frData.getInitiation().getDebtorAccount().getIdentification()).isEqualTo(obData.getInitiation().getDebtorAccount().getIdentification());
    assertThat(frData.getControlParameters().getVrpType().size()).isEqualTo(obData.getControlParameters().getVrPType().size());
    assertThat(frData.getControlParameters().getPeriodicLimits().get(0).getPeriodType().getValue()).isEqualTo(obData.getControlParameters().getPeriodicLimits().get(0).getPeriodType().getValue());
    assertThat(frData.getControlParameters().getPeriodicLimits().get(0).getPeriodAlignment().getValue()).isEqualTo(obData.getControlParameters().getPeriodicLimits().get(0).getPeriodAlignment().getValue());
}
Also used : FRDomesticVRPConsentDetailsData(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsentDetailsData) OBDomesticVRPConsentRequestData(uk.org.openbanking.datamodel.vrp.OBDomesticVRPConsentRequestData) FRDomesticVRPConsentConverter.toOBDomesticVRPConsentRequest(com.forgerock.openbanking.common.services.openbanking.converter.vrp.FRDomesticVRPConsentConverter.toOBDomesticVRPConsentRequest) OBDomesticVRPConsentRequest(uk.org.openbanking.datamodel.vrp.OBDomesticVRPConsentRequest) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) Test(org.junit.Test)

Example 24 with FRDomesticVRPConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticVrpsApiController method domesticVrpPost.

@Override
public /**
 *         @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true)
 *             @RequestHeader(value = "Authorization", required = true) String authorization,
 *
 *             @ApiParam(value = "A detached JWS signature of the body of the payload.", required = true)
 *             @RequestHeader(value = "x-jws-signature", required = true) String xJwsSignature,
 *
 *             @ApiParam(value = "Default", required = true)
 *             @Valid
 *             @RequestBody OBDomesticVRPRequest obDomesticVRPRequest,
 *
 *             @ApiParam(value = "The time when the PSU last logged in with the TPP.  All dates in the HTTP headers are represented as RFC 7231 Full Dates. An example is below:  Sun, 10 Sep 2017 19:43:31 UTC")
 *             @RequestHeader(value = "x-fapi-auth-date", required = false) String xFapiAuthDate,
 *
 *             @ApiParam(value = "The PSU's IP address if the PSU is currently logged in with the TPP.")
 *             @RequestHeader(value = "x-fapi-customer-ip-address", required = false) String xFapiCustomerIpAddress,
 *
 *             @ApiParam(value = "An RFC4122 UID used as a correlation id.")
 *             @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId,
 *
 *             @ApiParam(value = "Indicates the user-agent that the PSU is using.")
 *             @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent,
 */
ResponseEntity<OBDomesticVRPResponse> domesticVrpPost(String authorization, String xJwsSignature, OBDomesticVRPRequest obDomesticVRPRequest, String xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    log.debug("Received VRP payment submission: '{}'", obDomesticVRPRequest);
    String consentId = obDomesticVRPRequest.getData().getConsentId();
    FRDomesticVRPConsent frDomesticVRPConsent = domesticVRPConsentRepository.findById(consentId).orElseThrow(() -> new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_CONSENT_BEHIND_SUBMISSION_NOT_FOUND.toOBError1(consentId)));
    log.debug("Found VRP consent '{}' to match this consent id: {} ", frDomesticVRPConsent, consentId);
    FRDomesticVRPRequest frDomesticVRPRequest = toFRDomesticVRPRequest(obDomesticVRPRequest);
    FRDomesticVrpPaymentSubmission vrpPaymentSubmission = FRDomesticVrpPaymentSubmission.builder().id(consentId).domesticVrpPayment(frDomesticVRPRequest).status(OBDomesticVRPResponseData.StatusEnum.PENDING).created(new Date()).updated(new Date()).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
    vrpPaymentSubmission = new IdempotentRepositoryAdapter<>(paymentSubmissionRepository).idempotentSave(vrpPaymentSubmission);
    return ResponseEntity.status(HttpStatus.CREATED).body(responseEntity(obDomesticVRPRequest, vrpPaymentSubmission, frDomesticVRPConsent));
}
Also used : IdempotentRepositoryAdapter(com.forgerock.openbanking.aspsp.rs.store.repository.IdempotentRepositoryAdapter) FRDomesticVrpPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVrpPaymentSubmission) FRDomesticVRPRequest(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPRequest) FRDomesticVRPConverters.toFRDomesticVRPRequest(com.forgerock.openbanking.common.services.openbanking.converter.vrp.FRDomesticVRPConverters.toFRDomesticVRPRequest) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) Date(java.util.Date)

Example 25 with FRDomesticVRPConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticVrpConsentsApiControllerIT method saveFRConsent.

private FRDomesticVRPConsent saveFRConsent(String consentId, FRReadRefundAccount frReadRefundAccount, ConsentStatusCode consentStatusCode) {
    FRDomesticVRPConsentDetails details = toFRDomesticVRPConsentDetails(aValidOBDomesticVRPConsentRequest());
    FRDomesticVRPConsent consent = JMockData.mock(FRDomesticVRPConsent.class);
    consent.setVrpDetails(details);
    consent.getVrpDetails().getData().setReadRefundAccount(frReadRefundAccount);
    consent.getVrpDetails().getData().getInitiation().setDebtorAccount(aValidFRAccountIdentifier());
    consent.setId(consentId);
    consent.setIdempotencyKey(UUID.randomUUID().toString());
    consent.setStatus(consentStatusCode);
    consent.getRisk().setMerchantCategoryCode(aValidFRRisk().getMerchantCategoryCode());
    consent.getRisk().setDeliveryAddress(aValidFRRisk().getDeliveryAddress());
    consent.setObVersion(OBVersion.v3_1_8);
    repository.save(consent);
    return consent;
}
Also used : FRDomesticVRPConsentDetails(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsentDetails) FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails(com.forgerock.openbanking.common.services.openbanking.converter.vrp.FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent)

Aggregations

FRDomesticVRPConsent (com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent)28 Test (org.junit.Test)20 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 ResponseEntity (org.springframework.http.ResponseEntity)6 OBDomesticVRPRequestTestDataFactory.aValidOBDomesticVRPRequest (uk.org.openbanking.testsupport.vrp.OBDomesticVRPRequestTestDataFactory.aValidOBDomesticVRPRequest)6 FRDomesticVRPConsentDetails (com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsentDetails)5 FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails (com.forgerock.openbanking.common.services.openbanking.converter.vrp.FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails)5 Tpp (com.forgerock.openbanking.model.Tpp)4 OBDomesticVRPRequest (uk.org.openbanking.datamodel.vrp.OBDomesticVRPRequest)4 FRDomesticVrpPaymentSubmission (com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVrpPaymentSubmission)3 OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)3 OBVRPFundsConfirmationRequestTestDataFactory.aValidOBVRPFundsConfirmationRequest (uk.org.openbanking.testsupport.vrp.OBVRPFundsConfirmationRequestTestDataFactory.aValidOBVRPFundsConfirmationRequest)3 ConsentStatusEntry (com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry)2 FRAccountIdentifierTestDataFactory.aValidFRAccountIdentifier (com.forgerock.openbanking.aspsp.rs.store.api.openbanking.testsupport.domain.FRAccountIdentifierTestDataFactory.aValidFRAccountIdentifier)2 FRAccountIdentifier (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier)2 FRDomesticVRPConsentDetailsData (com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsentDetailsData)2 FRWriteDomesticVRPDataInitiation (com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRWriteDomesticVRPDataInitiation)2 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)2 ConsentMetricService (com.forgerock.openbanking.analytics.services.ConsentMetricService)1