Search in sources :

Example 16 with FRFileConsent

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

the class FilePaymentsApiController method createFilePayments.

@Override
public ResponseEntity<OBWriteFileResponse1> createFilePayments(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBWriteFile1 obWriteFile1, @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 {
    String consentId = obWriteFile1.getData().getConsentId();
    FRFileConsent payment = paymentsService.getPayment(consentId);
    return rsEndpointWrapperService.paymentSubmissionEndpoint().authorization(authorization).xFapiFinancialId(xFapiFinancialId).payment(payment).principal(principal).filters(f -> {
        f.verifyPaymentIdWithAccessToken();
        f.verifyIdempotencyKeyLength(xIdempotencyKey);
        f.verifyPaymentStatus();
        f.verifyInitiation(toFRWriteFileDataInitiation(obWriteFile1.getData().getInitiation()));
        f.verifyJwsDetachedSignature(xJwsSignature, request);
    }).execute((String tppId) -> {
        // Modify the status of the payment
        LOGGER.info("Switch status of payment {} to 'accepted settlement in process'.", consentId);
        payment.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTINPROCESS);
        LOGGER.info("Updating payment");
        paymentsService.updatePayment(payment);
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-payment-id", consentId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteFileResponse1.class, obWriteFile1);
    });
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) OBWriteFileResponse1(uk.org.openbanking.datamodel.payment.OBWriteFileResponse1) Controller(org.springframework.stereotype.Controller) OBWriteFile1(uk.org.openbanking.datamodel.payment.OBWriteFile1) DateTimeFormat(org.springframework.format.annotation.DateTimeFormat) RequestBody(org.springframework.web.bind.annotation.RequestBody) Valid(javax.validation.Valid) HttpServletRequest(javax.servlet.http.HttpServletRequest) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) HTTP_DATE_FORMAT(com.forgerock.openbanking.constants.OpenBankingConstants.HTTP_DATE_FORMAT) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) FilePaymentService(com.forgerock.openbanking.common.services.store.payment.FilePaymentService) Resource(org.springframework.core.io.Resource) Logger(org.slf4j.Logger) HttpHeaders(org.springframework.http.HttpHeaders) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) Principal(java.security.Principal) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) Collections(java.util.Collections) FRWriteFileConsentConverter.toFRWriteFileDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteFileConsentConverter.toFRWriteFileDataInitiation) HttpHeaders(org.springframework.http.HttpHeaders) FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent)

Example 17 with FRFileConsent

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

the class FilePaymentsApiController method getFilePaymentsFilePaymentId.

@Override
public ResponseEntity getFilePaymentsFilePaymentId(@ApiParam(value = "FilePaymentId", required = true) @PathVariable("FilePaymentId") String filePaymentId, @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 = "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 {
    Optional<FRFilePaymentSubmission> isPaymentSubmission = filePaymentSubmissionRepository.findById(filePaymentId);
    if (!isPaymentSubmission.isPresent()) {
        throw new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_SUBMISSION_NOT_FOUND.toOBError1(filePaymentId));
    }
    FRFilePaymentSubmission frPaymentSubmission = isPaymentSubmission.get();
    Optional<FRFileConsent> isPaymentSetup = fileConsentRepository.findById(filePaymentId);
    if (!isPaymentSetup.isPresent()) {
        throw new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_CONSENT_BEHIND_SUBMISSION_NOT_FOUND.toOBError1(filePaymentId));
    }
    FRFileConsent frPaymentSetup = isPaymentSetup.get();
    return ResponseEntity.ok(responseEntity(frPaymentSubmission, frPaymentSetup));
}
Also used : FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) FRFilePaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFilePaymentSubmission)

Example 18 with FRFileConsent

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

the class FilePaymentsApiController method createFilePayments.

@Override
public ResponseEntity createFilePayments(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBWriteFile1 obWriteFile1, @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 {
    log.debug("Received payment submission: '{}'", obWriteFile1);
    FRWriteFile frWriteFile = toFRWriteFile(obWriteFile1);
    log.trace("Converted to: '{}'", frWriteFile);
    String paymentId = frWriteFile.getData().getConsentId();
    FRFileConsent paymentConsent = fileConsentRepository.findById(paymentId).orElseThrow(() -> new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_CONSENT_BEHIND_SUBMISSION_NOT_FOUND.toOBError1(paymentId)));
    log.debug("Found consent '{}' to match this payment id: {} ", paymentConsent, paymentId);
    FRFilePaymentSubmission frPaymentSubmission = FRFilePaymentSubmission.builder().id(paymentId).filePayment(frWriteFile).created(new Date()).updated(new Date()).idempotencyKey(xIdempotencyKey).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
    frPaymentSubmission = new IdempotentRepositoryAdapter<>(filePaymentSubmissionRepository).idempotentSave(frPaymentSubmission);
    return ResponseEntity.status(HttpStatus.CREATED).body(responseEntity(frPaymentSubmission, paymentConsent));
}
Also used : IdempotentRepositoryAdapter(com.forgerock.openbanking.aspsp.rs.store.repository.IdempotentRepositoryAdapter) FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) FRWriteFile(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFile) FRWriteFileConverter.toFRWriteFile(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteFileConverter.toFRWriteFile) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) FRFilePaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFilePaymentSubmission) Date(java.util.Date)

Example 19 with FRFileConsent

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

the class FilePaymentConsentsApiControllerIT method testCreateFilePaymentConsentsFile.

@Test
public void testCreateFilePaymentConsentsFile() throws UnirestException {
    // Given
    String fileConsentId = UUID.randomUUID().toString();
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    setupMockTpp(tppRepository);
    String fileContent = utf8FileToString.apply("OBIEPaymentInitiation_3_0.json");
    FRFileConsent existingConsent = JMockData.mock(FRFileConsent.class);
    existingConsent.setStatus(ConsentStatusCode.AWAITINGUPLOAD);
    existingConsent.setId(fileConsentId);
    existingConsent.setFileContent(null);
    existingConsent.setPayments(Collections.emptyList());
    OBWriteFileConsent3 obWriteFileConsent3 = new OBWriteFileConsent3().data(new OBWriteFileConsent3Data().initiation(new OBWriteFile2DataInitiation().fileHash("kdjfklsdjflksjf").numberOfTransactions("3").controlSum(new BigDecimal("66.0")).fileType(PaymentFileType.UK_OBIE_PAYMENT_INITIATION_V3_0.getFileType())));
    existingConsent.setWriteFileConsent(toFRWriteFileConsent(obWriteFileConsent3));
    repository.save(existingConsent);
    // When
    HttpResponse response = Unirest.post("https://rs-store:" + port + "/open-banking/v3.1/pisp/file-payment-consents/" + fileConsentId + "/file").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, UUID.randomUUID().toString()).header(CONTENT_TYPE, "plain/xml").header(ACCEPT, "application/json").header("x-ob-client-id", MOCK_CLIENT_ID).body(fileContent).asObject(String.class);
    // Then
    log.debug("Response: {}", response);
    assertThat(response.getStatus()).isEqualTo(200);
    FRFileConsent consent = repository.findById(fileConsentId).get();
    assertThat(consent.getId()).isEqualTo(fileConsentId);
    assertThat(consent.getStatus().toOBExternalConsentStatus2Code()).isEqualTo(OBExternalConsentStatus2Code.AWAITINGAUTHORISATION);
    assertThat(consent.getFileContent()).isEqualTo(fileContent);
}
Also used : FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) OBWriteFileConsent3(uk.org.openbanking.datamodel.payment.OBWriteFileConsent3) OBWriteFileConsent3Data(uk.org.openbanking.datamodel.payment.OBWriteFileConsent3Data) OBWriteFile2DataInitiation(uk.org.openbanking.datamodel.payment.OBWriteFile2DataInitiation) HttpResponse(kong.unirest.HttpResponse) BigDecimal(java.math.BigDecimal) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test)

Example 20 with FRFileConsent

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

the class FilePaymentsApiControllerIT method testCreateInternationalPaymentSubmission.

@Test
public void testCreateInternationalPaymentSubmission() throws UnirestException {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    FRFileConsent consent = saveConsent();
    OBWriteFile2 submissionRequest = new OBWriteFile2().data(new OBWriteFile2Data().consentId(consent.getId()).initiation(toOBWriteFile2DataInitiation(consent.getInitiation())));
    // When
    HttpResponse<OBWriteFileResponse2> response = Unirest.post("https://rs-store:" + port + "/open-banking/v3.1/pisp/file-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(OBWriteFileResponse2.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(201);
    OBWriteFileResponse2 consentResponse = response.getBody();
    FRFilePaymentSubmission submission = submissionRepository.findById(response.getBody().getData().getFilePaymentId()).get();
    assertThat(submission.getId()).isEqualTo(consentResponse.getData().getConsentId());
    assertThat(toOBWriteFile2(submission.getFilePayment())).isEqualTo(submissionRequest);
    assertThat(submission.getObVersion()).isEqualTo(OBVersion.v3_1);
}
Also used : FRWriteFileConverter.toOBWriteFile2(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteFileConverter.toOBWriteFile2) FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) FRFilePaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFilePaymentSubmission) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

FRFileConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent)45 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)29 FRFilePaymentSubmission (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFilePaymentSubmission)13 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)12 Date (java.util.Date)12 Test (org.junit.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 RSEndpointWrapperService (com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService)8 RsStoreGateway (com.forgerock.openbanking.common.services.store.RsStoreGateway)8 FilePaymentService (com.forgerock.openbanking.common.services.store.payment.FilePaymentService)8 Principal (java.security.Principal)8 Collections (java.util.Collections)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 DateTime (org.joda.time.DateTime)8 Resource (org.springframework.core.io.Resource)8 HttpHeaders (org.springframework.http.HttpHeaders)8 ResponseEntity (org.springframework.http.ResponseEntity)7 Controller (org.springframework.stereotype.Controller)7 FRWriteFile (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFile)5 Tpp (com.forgerock.openbanking.model.Tpp)5