Search in sources :

Example 1 with OBWriteInternationalConsent2

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

the class InternationalPaymentConsentsApiControllerIT method testCreateInternationalPaymentConsent.

@Test
public void testCreateInternationalPaymentConsent() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    PaymentTestHelper.setupMockTpp(tppRepository);
    OBWriteInternationalConsent2 consentRequest = JMockData.mock(OBWriteInternationalConsent2.class);
    consentRequest.getData().getInitiation().getInstructedAmount().currency("GBP").amount("1.00");
    consentRequest.getData().getInitiation().getCreditor().getPostalAddress().country("GB").addressLine(Collections.singletonList("3 Queens Square"));
    consentRequest.getData().getInitiation().getExchangeRateInformation().unitCurrency("GBP");
    consentRequest.getData().getInitiation().currencyOfTransfer("USD");
    consentRequest.getData().getInitiation().getCreditorAgent().getPostalAddress().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<OBWriteInternationalConsentResponse2> response = Unirest.post("https://rs-store:" + port + "/open-banking/v3.1/pisp/international-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(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").header("x-ob-client-id", PaymentTestHelper.MOCK_CLIENT_ID).body(consentRequest).asObject(OBWriteInternationalConsentResponse2.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(201);
    OBWriteInternationalConsentResponse2 consentResponse = response.getBody();
    FRInternationalConsent consent = repository.findById(consentResponse.getData().getConsentId()).get();
    assertThat(consent.getPispName()).isEqualTo(PaymentTestHelper.MOCK_PISP_NAME);
    assertThat(consent.getPispId()).isEqualTo(PaymentTestHelper.MOCK_PISP_ID);
    assertThat(consent.getId()).isEqualTo(consentResponse.getData().getConsentId());
    assertThat(toOBInternational2(consent.getInitiation())).isEqualTo(consentResponse.getData().getInitiation());
    assertThat(consent.getStatus().toOBExternalConsentStatus1Code()).isEqualTo(consentResponse.getData().getStatus());
    assertThat(consent.getObVersion()).isEqualTo(OBVersion.v3_1);
}
Also used : OBWriteInternationalConsent2(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsent2) OBSupplementaryData1(uk.org.openbanking.datamodel.payment.OBSupplementaryData1) OBWriteInternationalConsentResponse2(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsentResponse2) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with OBWriteInternationalConsent2

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

the class InternationalPaymentConsentsApiControllerIT method testCreateInternationalPaymentConsent_noExchangeRate.

@Test
public void testCreateInternationalPaymentConsent_noExchangeRate() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    PaymentTestHelper.setupMockTpp(tppRepository);
    OBWriteInternationalConsent2 consentRequest = JMockData.mock(OBWriteInternationalConsent2.class);
    consentRequest.getData().getInitiation().getInstructedAmount().currency("GBP").amount("1.00");
    consentRequest.getData().getInitiation().getCreditor().getPostalAddress().country("GB").addressLine(Collections.singletonList("3 Queens Square"));
    consentRequest.getData().getInitiation().currencyOfTransfer("USD");
    consentRequest.getData().getInitiation().setExchangeRateInformation(null);
    consentRequest.getData().getInitiation().getCreditorAgent().getPostalAddress().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<OBWriteInternationalConsentResponse2> response = Unirest.post("https://rs-store:" + port + "/open-banking/v3.1/pisp/international-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(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").header("x-ob-client-id", PaymentTestHelper.MOCK_CLIENT_ID).body(consentRequest).asObject(OBWriteInternationalConsentResponse2.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(201);
    OBWriteInternationalConsentResponse2 consentResponse = response.getBody();
    FRInternationalConsent consent = repository.findById(consentResponse.getData().getConsentId()).get();
    assertThat(consent.getInitiation().getExchangeRateInformation()).isNull();
}
Also used : OBWriteInternationalConsent2(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsent2) OBSupplementaryData1(uk.org.openbanking.datamodel.payment.OBSupplementaryData1) OBWriteInternationalConsentResponse2(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsentResponse2) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with OBWriteInternationalConsent2

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

the class InternationalPaymentConsentsApiController method createInternationalPaymentConsents.

@Override
public ResponseEntity<OBWriteInternationalConsentResponse2> createInternationalPaymentConsents(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBWriteInternationalConsent2 obWriteInternationalConsent2Param, @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.validateRisk(obWriteInternationalConsent2Param.getRisk());
    }).execute((String tppId) -> {
        exchangeRateVerifier.verify(obWriteInternationalConsent2Param.getData().getInitiation().getExchangeRateInformation());
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-client-id", tppId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteInternationalConsentResponse2.class, obWriteInternationalConsent2Param);
    });
}
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) ExchangeRateVerifier(com.forgerock.openbanking.aspsp.rs.api.payment.verifier.ExchangeRateVerifier) DateTimeFormat(org.springframework.format.annotation.DateTimeFormat) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) 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) OBWriteInternationalConsent2(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsent2) Logger(org.slf4j.Logger) HttpHeaders(org.springframework.http.HttpHeaders) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) InternationalPaymentService(com.forgerock.openbanking.common.services.store.payment.InternationalPaymentService) OBWriteInternationalConsentResponse2(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsentResponse2) Principal(java.security.Principal) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) Collections(java.util.Collections) HttpHeaders(org.springframework.http.HttpHeaders)

Aggregations

FRInternationalConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent)3 OBWriteInternationalConsent2 (uk.org.openbanking.datamodel.payment.OBWriteInternationalConsent2)3 OBWriteInternationalConsentResponse2 (uk.org.openbanking.datamodel.payment.OBWriteInternationalConsentResponse2)3 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 OBSupplementaryData1 (uk.org.openbanking.datamodel.payment.OBSupplementaryData1)2 ExchangeRateVerifier (com.forgerock.openbanking.aspsp.rs.api.payment.verifier.ExchangeRateVerifier)1 RSEndpointWrapperService (com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService)1 RsStoreGateway (com.forgerock.openbanking.common.services.store.RsStoreGateway)1 InternationalPaymentService (com.forgerock.openbanking.common.services.store.payment.InternationalPaymentService)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