Search in sources :

Example 1 with OBWriteDomesticConsentResponse2

use of uk.org.openbanking.datamodel.payment.OBWriteDomesticConsentResponse2 in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentConsentsApiController method createDomesticPaymentConsents.

@Override
public ResponseEntity<OBWriteDomesticConsentResponse2> createDomesticPaymentConsents(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBWriteDomesticConsent2 obWriteDomesticConsent2Param, @ApiParam(value = "The unique id of the ASPSP to which the request is issued. The unique id will be " + "issued by OB.", required = true) @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "Every request will be processed only once per x-idempotency-key.  The Idempotency Key " + "will be valid for 24 hours.", required = true) @RequestHeader(value = "x-idempotency-key", required = true) String xIdempotencyKey, @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 = "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-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @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, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    return rsEndpointWrapperService.paymentEndpoint().authorization(authorization).xFapiFinancialId(xFapiFinancialId).principal(principal).filters(f -> {
        f.verifyIdempotencyKeyLength(xIdempotencyKey);
        f.verifyJwsDetachedSignature(xJwsSignature, request);
        f.validateBalanceTransferPayment(obWriteDomesticConsent2Param);
        f.validateMoneyTransferPayment(obWriteDomesticConsent2Param);
        f.validatePaymPayment(obWriteDomesticConsent2Param);
        f.validateRisk(obWriteDomesticConsent2Param.getRisk());
    }).execute((String tppId) -> {
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-client-id", tppId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteDomesticConsentResponse2.class, obWriteDomesticConsent2Param);
    });
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) OBWriteFundsConfirmationResponse1(uk.org.openbanking.datamodel.payment.OBWriteFundsConfirmationResponse1) RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) DateTimeFormat(org.springframework.format.annotation.DateTimeFormat) RequestBody(org.springframework.web.bind.annotation.RequestBody) Valid(javax.validation.Valid) HttpServletRequest(javax.servlet.http.HttpServletRequest) HTTP_DATE_FORMAT(com.forgerock.openbanking.constants.OpenBankingConstants.HTTP_DATE_FORMAT) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) DomesticPaymentService(com.forgerock.openbanking.common.services.store.payment.DomesticPaymentService) Logger(org.slf4j.Logger) OBWriteDomesticConsent2(uk.org.openbanking.datamodel.payment.OBWriteDomesticConsent2) HttpHeaders(org.springframework.http.HttpHeaders) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) Principal(java.security.Principal) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) OBWriteDomesticConsentResponse2(uk.org.openbanking.datamodel.payment.OBWriteDomesticConsentResponse2) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) Collections(java.util.Collections) HttpHeaders(org.springframework.http.HttpHeaders)

Example 2 with OBWriteDomesticConsentResponse2

use of uk.org.openbanking.datamodel.payment.OBWriteDomesticConsentResponse2 in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentConsentsApiControllerIT method testCreateDomesticPaymentConsent_exists_idempotencyKeyValid_noActionButReturn201.

@Test
public void testCreateDomesticPaymentConsent_exists_idempotencyKeyValid_noActionButReturn201() throws UnirestException {
    // Given
    final String idempotencyKey = UUID.randomUUID().toString();
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    setupMockTpp(tppRepository);
    OBWriteDomesticConsent4 consentRequest = JMockData.mock(OBWriteDomesticConsent4.class);
    consentRequest.getData().getInitiation().getInstructedAmount().currency("GBP").amount("1.00");
    consentRequest.getData().getInitiation().getCreditorPostalAddress().country("GB").addressLine(Collections.singletonList("3 Queens Square"));
    consentRequest.getData().getInitiation().supplementaryData(null);
    consentRequest.getRisk().merchantCategoryCode("ABCD").getDeliveryAddress().addressLine(Collections.singletonList("3 Queens Square")).country("GP").countrySubDivision("aaa");
    consentRequest.getData().getAuthorisation().completionDateTime(null);
    FRDomesticConsent existingConsent = JMockData.mock(FRDomesticConsent.class);
    existingConsent.setId(UUID.randomUUID().toString());
    existingConsent.setStatus(ConsentStatusCode.AUTHORISED);
    existingConsent.setDomesticConsent(toFRWriteDomesticConsent(consentRequest));
    existingConsent.setIdempotencyKey(idempotencyKey);
    repository.save(existingConsent);
    // When
    HttpResponse<OBWriteDomesticConsentResponse2> response = Unirest.post("https://rs-store:" + port + "/open-banking/v3.1/pisp/domestic-payment-consents/").header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header(OBHeaders.X_IDEMPOTENCY_KEY, idempotencyKey).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(consentRequest).asObject(OBWriteDomesticConsentResponse2.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(201);
    OBWriteDomesticConsentResponse2 consentResponse = response.getBody();
    FRDomesticConsent consent = repository.findById(consentResponse.getData().getConsentId()).get();
    assertThat(consent.getId()).isEqualTo(consentResponse.getData().getConsentId());
    assertThat(toOBDomestic2(consent.getInitiation())).isEqualTo(consentResponse.getData().getInitiation());
    assertThat(consent.getStatus().toOBExternalConsentStatus1Code()).isEqualTo(consentResponse.getData().getStatus());
}
Also used : FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) OBWriteDomesticConsentResponse2(uk.org.openbanking.datamodel.payment.OBWriteDomesticConsentResponse2) OBWriteDomesticConsentConverter.toOBWriteDomesticConsent4(uk.org.openbanking.datamodel.service.converter.payment.OBWriteDomesticConsentConverter.toOBWriteDomesticConsent4) OBWriteDomesticConsent4(uk.org.openbanking.datamodel.payment.OBWriteDomesticConsent4) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test)

Example 3 with OBWriteDomesticConsentResponse2

use of uk.org.openbanking.datamodel.payment.OBWriteDomesticConsentResponse2 in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentConsentsApiControllerIT method testGetDomesticPaymentConsent.

@Test
public void testGetDomesticPaymentConsent() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    FRDomesticConsent consent = JMockData.mock(FRDomesticConsent.class);
    consent.setStatus(ConsentStatusCode.AUTHORISED);
    consent.setIdempotencyKey(UUID.randomUUID().toString());
    consent.getInitiation().setSupplementaryData(FRSupplementaryData.builder().data("{}").build());
    repository.save(consent);
    // When
    HttpResponse<OBWriteDomesticConsentResponse2> response = Unirest.get("https://rs-store:" + port + "/open-banking/v3.1/pisp/domestic-payment-consents/" + consent.getId()).header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").asObject(OBWriteDomesticConsentResponse2.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getBody().getData().getConsentId()).isEqualTo(consent.getId());
    assertThat(response.getBody().getData().getInitiation()).isEqualTo(toOBDomestic2(consent.getInitiation()));
    assertThat(response.getBody().getData().getStatus()).isEqualTo(consent.getStatus().toOBExternalConsentStatus1Code());
    Assertions.assertThat(response.getBody().getData().getCreationDateTime()).isEqualToIgnoringMillis(consent.getCreated());
    Assertions.assertThat(response.getBody().getData().getStatusUpdateDateTime()).isEqualToIgnoringMillis(consent.getStatusUpdate());
}
Also used : FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) OBWriteDomesticConsentResponse2(uk.org.openbanking.datamodel.payment.OBWriteDomesticConsentResponse2) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test)

Example 4 with OBWriteDomesticConsentResponse2

use of uk.org.openbanking.datamodel.payment.OBWriteDomesticConsentResponse2 in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentConsentsApiControllerIT method testCreateDomesticPaymentConsent.

@Test
public void testCreateDomesticPaymentConsent() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    setupMockTpp(tppRepository);
    OBWriteDomesticConsent2 consentRequest = JMockData.mock(OBWriteDomesticConsent2.class);
    consentRequest.getData().getInitiation().getInstructedAmount().currency("GBP").amount("1.00");
    consentRequest.getData().getInitiation().getCreditorPostalAddress().country("GB").addressLine(Collections.singletonList("3 Queens Square"));
    consentRequest.getData().getInitiation().supplementaryData(new OBSupplementaryData1());
    consentRequest.getRisk().merchantCategoryCode("ABCD").getDeliveryAddress().countrySubDivision("Wessex").addressLine(Collections.singletonList("3 Queens Square")).country("GP");
    // When
    HttpResponse<OBWriteDomesticConsentResponse2> response = Unirest.post("https://rs-store:" + port + "/open-banking/v3.1/pisp/domestic-payment-consents/").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(consentRequest).asObject(OBWriteDomesticConsentResponse2.class);
    // Then
    log.error("The response: {}", response);
    assertThat(response.getStatus()).isEqualTo(201);
    OBWriteDomesticConsentResponse2 consentResponse = response.getBody();
    FRDomesticConsent consent = repository.findById(consentResponse.getData().getConsentId()).get();
    assertThat(consent.getPispName()).isEqualTo(MOCK_PISP_NAME);
    assertThat(consent.getPispId()).isEqualTo(MOCK_PISP_ID);
    assertThat(consent.getId()).isEqualTo(consentResponse.getData().getConsentId());
    assertThat(toOBDomestic2(consent.getInitiation())).isEqualTo(consentResponse.getData().getInitiation());
    assertThat(consent.getStatus().toOBExternalConsentStatus1Code()).isEqualTo(consentResponse.getData().getStatus());
    assertThat(consent.getRisk()).isEqualTo(toFRRisk(consentResponse.getRisk()));
    assertThat(consent.getObVersion()).isEqualTo(OBVersion.v3_1);
}
Also used : OBSupplementaryData1(uk.org.openbanking.datamodel.payment.OBSupplementaryData1) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) OBWriteDomesticConsentResponse2(uk.org.openbanking.datamodel.payment.OBWriteDomesticConsentResponse2) OBWriteDomesticConsent2(uk.org.openbanking.datamodel.payment.OBWriteDomesticConsent2) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test)

Example 5 with OBWriteDomesticConsentResponse2

use of uk.org.openbanking.datamodel.payment.OBWriteDomesticConsentResponse2 in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentsApiControllerIT method testGetDomesticPaymentSubmission.

@Test
public void testGetDomesticPaymentSubmission() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    FRDomesticConsent consent = saveConsent();
    FRDomesticPaymentSubmission submission = savePaymentSubmission(consent, UUID.randomUUID().toString());
    // When
    HttpResponse<OBWriteDomesticConsentResponse2> response = Unirest.get("https://rs-store:" + port + "/open-banking/v3.1/pisp/domestic-payments/" + submission.getId()).header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").asObject(OBWriteDomesticConsentResponse2.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getBody().getData().getConsentId()).isEqualTo(consent.getId());
    assertThat(response.getBody().getData().getInitiation()).isEqualTo(toOBDomestic2(submission.getDomesticPayment().getData().getInitiation()));
    assertThat(response.getBody().getData().getCreationDateTime()).isEqualTo(consent.getCreated());
    assertThat(response.getBody().getData().getStatusUpdateDateTime()).isEqualTo(consent.getStatusUpdate());
}
Also used : FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) FRDomesticPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticPaymentSubmission) OBWriteDomesticConsentResponse2(uk.org.openbanking.datamodel.payment.OBWriteDomesticConsentResponse2) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

FRDomesticConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)5 OBWriteDomesticConsentResponse2 (uk.org.openbanking.datamodel.payment.OBWriteDomesticConsentResponse2)5 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 OBWriteDomesticConsent2 (uk.org.openbanking.datamodel.payment.OBWriteDomesticConsent2)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RSEndpointWrapperService (com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService)1 FRDomesticPaymentSubmission (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticPaymentSubmission)1 RsStoreGateway (com.forgerock.openbanking.common.services.store.RsStoreGateway)1 DomesticPaymentService (com.forgerock.openbanking.common.services.store.payment.DomesticPaymentService)1 HTTP_DATE_FORMAT (com.forgerock.openbanking.constants.OpenBankingConstants.HTTP_DATE_FORMAT)1 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)1 ApiParam (io.swagger.annotations.ApiParam)1 Principal (java.security.Principal)1 Collections (java.util.Collections)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Valid (javax.validation.Valid)1 DateTime (org.joda.time.DateTime)1 Logger (org.slf4j.Logger)1