Search in sources :

Example 1 with FRFileConsent

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

the class FilePaymentConsentsApiController method createFilePaymentConsentsConsentIdFile.

public ResponseEntity<Void> createFilePaymentConsentsConsentIdFile(String fileParam, String consentId, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    log.trace("Received: '{}'", fileParam);
    FRFileConsent fileConsent = fileConsentRepository.findById(consentId).orElseThrow(() -> new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_ID_NOT_FOUND.toOBError1()));
    // If file already exists it could be idempotent request
    if (!StringUtils.isEmpty(fileConsent.getFileContent())) {
        if (xIdempotencyKey.equals(fileConsent.getIdempotencyKey())) {
            validateIdempotencyRequest(xIdempotencyKey, fileConsent);
            log.info("File already exists for consent: '{}' and has matching idempotent key: '{}'. No action taken but returning 200/OK");
            return ResponseEntity.ok().build();
        } else {
            log.debug("This consent already has a file uploaded and the idempotency key does not match the previous upload so rejecting.");
            throw new OBErrorResponseException(HttpStatus.FORBIDDEN, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_ALREADY_SUBMITTED.toOBError1(fileConsent.getStatus().toOBExternalConsentStatus2Code()));
        }
    }
    // We parse the file and check metadata against the parsed file
    try {
        PaymentFile paymentFile = PaymentFileFactory.createPaymentFile(fileConsent.getFileType(), fileParam);
        log.info("Successfully parsed file of type: '{}' for consent: '{}'", fileConsent.getFileType(), fileConsent.getId());
        FileTransactionCountValidator.validate(fileConsent, paymentFile);
        ControlSumValidator.validate(fileConsent, paymentFile);
        fileConsent.setPayments(paymentFile.getPayments());
        fileConsent.setFileContent(fileParam);
        fileConsent.setUpdated(new Date());
        fileConsent.setStatus(ConsentStatusCode.AWAITINGAUTHORISATION);
        fileConsent.setStatusUpdate(DateTime.now());
        fileConsentRepository.save(fileConsent);
    } catch (OBErrorException e) {
        throw new OBErrorResponseException(e.getObriErrorType().getHttpStatus(), OBRIErrorResponseCategory.REQUEST_INVALID, e.getOBError());
    }
    return ResponseEntity.ok().build();
}
Also used : PaymentFile(com.forgerock.openbanking.common.model.openbanking.forgerock.filepayment.v3_0.PaymentFile) FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) Date(java.util.Date)

Example 2 with FRFileConsent

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

the class FilePaymentsApiController method getFilePaymentsFilePaymentId.

public ResponseEntity<OBWriteFileResponse2> getFilePaymentsFilePaymentId(String filePaymentId, String authorization, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, 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 3 with FRFileConsent

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

the class FilePaymentsApiController method createFilePayments.

public ResponseEntity<OBWriteFileResponse2> createFilePayments(OBWriteFile2 obWriteFile2, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    log.debug("Received payment submission: '{}'", obWriteFile2);
    FRWriteFile frWriteFile = toFRWriteFile(obWriteFile2);
    log.trace("Converted to: '{}'", frWriteFile);
    String paymentId = obWriteFile2.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 4 with FRFileConsent

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

the class OBIEPaymentInitiationReport1Builder method toPaymentReport.

String toPaymentReport(final FRFileConsent consent) {
    log.debug("Create {} report file for consent id: {}", consent.getFileType(), consent.getId());
    final List<OBWriteDomesticResponse1> payments = consent.getPayments().stream().map(payment -> mapDomesticPayment(consent, payment)).collect(Collectors.toList());
    log.debug("Mapped {} domestic payments into OBWriteDomesticResponse1 objects", payments.size());
    final JsonReportFile jsonReportFile = JsonReportFile.builder().data(JsonReportFile.Data.builder().domesticPayments(payments).build()).build();
    log.debug("Created Json Report File: {}", jsonReportFile);
    try {
        log.debug("Serializing Json Report File");
        return objectMapper.writeValueAsString(jsonReportFile);
    } catch (JsonProcessingException e) {
        log.error("Trying to parse consent: {} into report file failed", consent, e);
        throw new FileParseException("Unable to parse payments into report file.", e);
    }
}
Also used : OBWriteDataDomesticResponse1(uk.org.openbanking.datamodel.payment.OBWriteDataDomesticResponse1) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) OBWriteDomesticResponse1(uk.org.openbanking.datamodel.payment.OBWriteDomesticResponse1) FRAmountConverter.toOBActiveOrHistoricCurrencyAndAmount(com.forgerock.openbanking.common.services.openbanking.converter.common.FRAmountConverter.toOBActiveOrHistoricCurrencyAndAmount) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) FileParseException(com.forgerock.openbanking.common.model.openbanking.forgerock.filepayment.v3_0.FileParseException) Collectors(java.util.stream.Collectors) OBCashAccount3(uk.org.openbanking.datamodel.account.OBCashAccount3) OBTransactionIndividualStatus1Code(uk.org.openbanking.datamodel.payment.OBTransactionIndividualStatus1Code) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) Builder(lombok.Builder) Data(lombok.Data) FRFilePayment(com.forgerock.openbanking.common.model.openbanking.forgerock.filepayment.v3_0.FRFilePayment) FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) AllArgsConstructor(lombok.AllArgsConstructor) OBRemittanceInformation1(uk.org.openbanking.datamodel.payment.OBRemittanceInformation1) NoArgsConstructor(lombok.NoArgsConstructor) OBDomestic1(uk.org.openbanking.datamodel.payment.OBDomestic1) OBWriteDomesticResponse1(uk.org.openbanking.datamodel.payment.OBWriteDomesticResponse1) FileParseException(com.forgerock.openbanking.common.model.openbanking.forgerock.filepayment.v3_0.FileParseException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 5 with FRFileConsent

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

the class FilePaymentConsentsApiController method createFilePaymentConsentsConsentIdFile.

public ResponseEntity<Void> createFilePaymentConsentsConsentIdFile(String fileParam, String consentId, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    final String contentTypeOfFile = request.getHeader(CONTENT_TYPE);
    FRFileConsent consent = filePaymentService.getPayment(consentId);
    return rsEndpointWrapperService.filePaymentEndpoint().authorization(authorization).payment(consent).xFapiFinancialId(rsEndpointWrapperService.rsConfiguration.financialId).principal(principal).obVersion(getOBVersion(request.getRequestURI())).filters(f -> {
        f.verifyFileHash(fileParam);
        f.verifyContentTypeHeader(contentTypeOfFile);
        f.verifyIdempotencyKeyLength(xIdempotencyKey);
    }).execute((String tppId) -> {
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-client-id", tppId);
        ParameterizedTypeReference<String> ptr = new ParameterizedTypeReference<String>() {
        };
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), String.class, fileParam);
    });
}
Also used : RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) HttpHeaders(org.springframework.http.HttpHeaders) OBWriteFileConsent3(uk.org.openbanking.datamodel.payment.OBWriteFileConsent3) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) Controller(org.springframework.stereotype.Controller) OBWriteFileConsentResponse4(uk.org.openbanking.datamodel.payment.OBWriteFileConsentResponse4) File(java.io.File) HttpServletRequest(javax.servlet.http.HttpServletRequest) Principal(java.security.Principal) CONTENT_TYPE(org.springframework.http.HttpHeaders.CONTENT_TYPE) ApiVersionUtils.getOBVersion(com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) ResponseEntity(org.springframework.http.ResponseEntity) FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) Collections(java.util.Collections) FilePaymentService(com.forgerock.openbanking.common.services.store.payment.FilePaymentService) Resource(org.springframework.core.io.Resource) HttpHeaders(org.springframework.http.HttpHeaders) FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference)

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