Search in sources :

Example 16 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentConsentsApiControllerIT method testCreateDomesticPaymentConsent_exists_idempotencyKeyExpired.

@Test
// This fails intermittently on code fresh - ignoring until more time available to investigate
@Ignore
public void testCreateDomesticPaymentConsent_exists_idempotencyKeyExpired() throws UnirestException {
    // Given
    final String idempotencyKey = UUID.randomUUID().toString();
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    setupMockTpp(tppRepository);
    OBWriteDomesticConsent1 consentRequest = JMockData.mock(OBWriteDomesticConsent1.class);
    consentRequest.getData().getInitiation().getInstructedAmount().currency("GBP").amount("1.00");
    consentRequest.getData().getInitiation().getCreditorPostalAddress().country("GB").addressLine(Collections.singletonList("3 Queens Square"));
    consentRequest.getRisk().merchantCategoryCode("ABCD").getDeliveryAddress().addressLine(Collections.singletonList("3 Queens Square")).country("GP");
    consentRequest.getData().getAuthorisation().completionDateTime(null);
    OBWriteDomesticConsent4 consent4 = toOBWriteDomesticConsent4(consentRequest);
    FRDomesticConsent existingConsent = JMockData.mock(FRDomesticConsent.class);
    existingConsent.setId(UUID.randomUUID().toString());
    existingConsent.setStatus(ConsentStatusCode.AUTHORISED);
    existingConsent.setDomesticConsent(toFRWriteDomesticConsent(consent4));
    existingConsent.setIdempotencyKey(idempotencyKey);
    existingConsent = repository.save(existingConsent);
    // Created date will be set to now by annotation on initial creation so update it here to 25 hours in past to test idempotency expiry
    existingConsent.setCreated(DateTime.now().minusHours(25));
    repository.save(existingConsent);
    // When
    HttpResponse 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(OBWriteDomesticConsentResponse1.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(400);
}
Also used : FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) OBWriteDomesticConsent1(uk.org.openbanking.datamodel.payment.OBWriteDomesticConsent1) HttpResponse(kong.unirest.HttpResponse) OBWriteDomesticConsentConverter.toOBWriteDomesticConsent4(uk.org.openbanking.datamodel.service.converter.payment.OBWriteDomesticConsentConverter.toOBWriteDomesticConsent4) OBWriteDomesticConsent4(uk.org.openbanking.datamodel.payment.OBWriteDomesticConsent4) Ignore(org.junit.Ignore) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test)

Example 17 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent 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 18 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentsApiControllerIT method testCreateDomesticPaymentSubmission.

@Test
public void testCreateDomesticPaymentSubmission() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    FRDomesticConsent consent = saveConsent();
    OBWriteDomestic2 submissionRequest = new OBWriteDomestic2().risk(toOBRisk1(consent.getRisk())).data(new OBWriteDataDomestic2().consentId(consent.getId()).initiation(toOBDomestic2(consent.getInitiation())));
    // When
    HttpResponse<OBWriteDomesticResponse2> response = Unirest.post("https://rs-store:" + port + "/open-banking/v3.1/pisp/domestic-payments").header(OBHeaders.X_FAPI_FINANCIAL_ID, rsConfiguration.financialId).header(OBHeaders.AUTHORIZATION, "token").header(OBHeaders.X_IDEMPOTENCY_KEY, "x-idempotency-key").header(OBHeaders.X_JWS_SIGNATURE, "x-jws-signature").header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(submissionRequest).asObject(OBWriteDomesticResponse2.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(201);
    OBWriteDomesticResponse2 consentResponse = response.getBody();
    FRDomesticPaymentSubmission submission = submissionRepository.findById(response.getBody().getData().getDomesticPaymentId()).get();
    assertThat(submission.getId()).isEqualTo(consentResponse.getData().getConsentId());
    assertThat(toOBWriteDomestic2(submission.getDomesticPayment())).isEqualTo(submissionRequest);
    assertThat(submission.getObVersion()).isEqualTo(OBVersion.v3_1);
}
Also used : FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) FRDomesticPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticPaymentSubmission) FRWriteDomesticConverter.toOBWriteDomestic2(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteDomesticConverter.toOBWriteDomestic2) OBWriteDomestic2(uk.org.openbanking.datamodel.payment.OBWriteDomestic2) OBWriteDomesticResponse2(uk.org.openbanking.datamodel.payment.OBWriteDomesticResponse2) OBWriteDataDomestic2(uk.org.openbanking.datamodel.payment.OBWriteDataDomestic2) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentsApiControllerIT method saveConsent.

private FRDomesticConsent saveConsent() {
    FRDomesticConsent consent = JMockData.mock(FRDomesticConsent.class);
    consent.setId(IntentType.PAYMENT_DOMESTIC_CONSENT.generateIntentId());
    consent.getInitiation().setInstructedAmount(aValidFRAmount());
    consent.getInitiation().setCreditorPostalAddress(aValidFRPostalAddress());
    consent.getInitiation().setSupplementaryData(FRSupplementaryData.builder().data("{}").build());
    consent.getRisk().setMerchantCategoryCode(aValidFRRisk().getMerchantCategoryCode());
    consent.getRisk().setDeliveryAddress(aValidFRRisk().getDeliveryAddress());
    consent.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED);
    consentRepository.save(consent);
    return consent;
}
Also used : FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)

Example 20 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentsApiControllerIT method testDuplicatePaymentInitiation_validIdempotency_ShouldReturnCreated.

@Test
public void testDuplicatePaymentInitiation_validIdempotency_ShouldReturnCreated() throws Exception {
    // Given
    final String idempotencyKey = UUID.randomUUID().toString();
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    FRDomesticConsent consent = saveConsent();
    FRDomesticPaymentSubmission submission = savePaymentSubmission(consent, idempotencyKey);
    OBWriteDomestic2 obWriteDomestic1 = toOBWriteDomestic2(submission.getDomesticPayment());
    // When
    HttpResponse<String> response = Unirest.post("https://rs-store:" + port + "/open-banking/v3.0/pisp/domestic-payments").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(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(obWriteDomestic1).asObject(String.class);
    log.debug("Response: {} , {}", response.getStatus(), response.getBody());
    // Then
    assertThat(response.getStatus()).isEqualTo(201);
}
Also used : FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) FRDomesticPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticPaymentSubmission) FRWriteDomesticConverter.toOBWriteDomestic2(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteDomesticConverter.toOBWriteDomestic2) OBWriteDomestic2(uk.org.openbanking.datamodel.payment.OBWriteDomestic2) 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)105 Test (org.junit.Test)62 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)50 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)49 FRDomesticPaymentSubmission (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticPaymentSubmission)37 Collections (java.util.Collections)15 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)14 FRWriteDomesticConverter.toOBWriteDomestic2 (com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteDomesticConverter.toOBWriteDomestic2)13 DomesticPaymentService (com.forgerock.openbanking.common.services.store.payment.DomesticPaymentService)13 ResponseEntity (org.springframework.http.ResponseEntity)12 ConsentStatusCode (com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode)11 RSEndpointWrapperService (com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService)9 FRWriteDomestic (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomestic)9 FRWriteDomesticConsent (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsent)9 RsStoreGateway (com.forgerock.openbanking.common.services.store.RsStoreGateway)9 Principal (java.security.Principal)9 FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 DateTime (org.joda.time.DateTime)7 HttpHeaders (org.springframework.http.HttpHeaders)7