Search in sources :

Example 41 with OBErrorResponseException

use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticStandingOrdersApiController method createDomesticStandingOrders.

public ResponseEntity<OBWriteDomesticStandingOrderResponse6> createDomesticStandingOrders(OBWriteDomesticStandingOrder3 obWriteDomesticStandingOrder3, 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: '{}'", obWriteDomesticStandingOrder3);
    FRWriteDomesticStandingOrder frWriteDomesticStandingOrder = toFRWriteDomesticStandingOrder(obWriteDomesticStandingOrder3);
    log.trace("Converted to: '{}'", frWriteDomesticStandingOrder);
    String paymentId = obWriteDomesticStandingOrder3.getData().getConsentId();
    FRDomesticStandingOrderConsent paymentConsent = domesticStandingOrderConsentRepository.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);
    FRDomesticStandingOrderPaymentSubmission frPaymentSubmission = FRDomesticStandingOrderPaymentSubmission.builder().id(paymentId).domesticStandingOrder(frWriteDomesticStandingOrder).created(new Date()).updated(new Date()).idempotencyKey(xIdempotencyKey).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
    frPaymentSubmission = new IdempotentRepositoryAdapter<>(domesticStandingOrderPaymentSubmissionRepository).idempotentSave(frPaymentSubmission);
    return ResponseEntity.status(HttpStatus.CREATED).body(responseEntity(frPaymentSubmission, paymentConsent));
}
Also used : IdempotentRepositoryAdapter(com.forgerock.openbanking.aspsp.rs.store.repository.IdempotentRepositoryAdapter) FRWriteDomesticStandingOrderConverter.toFRWriteDomesticStandingOrder(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteDomesticStandingOrderConverter.toFRWriteDomesticStandingOrder) FRWriteDomesticStandingOrder(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticStandingOrder) FRDomesticStandingOrderPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticStandingOrderPaymentSubmission) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) FRDomesticStandingOrderConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticStandingOrderConsent) Date(java.util.Date)

Example 42 with OBErrorResponseException

use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.

the class FilePaymentConsentsApiController method createFilePaymentConsents.

public ResponseEntity<OBWriteFileConsentResponse4> createFilePaymentConsents(OBWriteFileConsent3 obWriteFileConsent3, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    log.debug("Received: '{}'", obWriteFileConsent3);
    FRWriteFileConsent frWriteFileConsent = toFRWriteFileConsent(obWriteFileConsent3);
    log.trace("Converted to: '{}'", frWriteFileConsent);
    final Tpp tpp = Optional.ofNullable(tppRepository.findByClientId(clientId)).orElseThrow(() -> new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, "TPP not found for client id", Collections.singletonList(OBRIErrorType.REQUEST_INVALID_HEADER.toOBError1("x-ob-client-id"))));
    log.debug("Got TPP '{}' for client Id '{}'", tpp, clientId);
    Optional<FRFileConsent> consentByIdempotencyKey = fileConsentRepository.findByIdempotencyKeyAndPispId(xIdempotencyKey, tpp.getId());
    if (consentByIdempotencyKey.isPresent()) {
        validateIdempotencyRequest(xIdempotencyKey, frWriteFileConsent, consentByIdempotencyKey.get(), () -> consentByIdempotencyKey.get().getWriteFileConsent());
        log.info("Idempotent request is valid. Returning [201 CREATED] but take no further action.");
        return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(consentByIdempotencyKey.get()));
    }
    log.debug("No consent with matching idempotency key has been found. Creating new consent.");
    FRFileConsent fileConsent = FRFileConsent.builder().id(IntentType.PAYMENT_FILE_CONSENT.generateIntentId()).status(ConsentStatusCode.AWAITINGUPLOAD).writeFileConsent(frWriteFileConsent).pispId(tpp.getId()).pispName(tpp.getOfficialName()).statusUpdate(DateTime.now()).updated(new Date()).idempotencyKey(xIdempotencyKey).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
    log.debug("Saving consent: '{}'", fileConsent);
    consentMetricService.sendConsentActivity(new ConsentStatusEntry(fileConsent.getId(), fileConsent.getStatus().name()));
    fileConsent = fileConsentRepository.save(fileConsent);
    log.info("Created consent id: '{}'", fileConsent.getId());
    return ResponseEntity.status(HttpStatus.CREATED).body(packageResponse(fileConsent));
}
Also used : FRWriteFileConsent(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileConsent) FRWriteFileConsentConverter.toFRWriteFileConsent(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteFileConsentConverter.toFRWriteFileConsent) Tpp(com.forgerock.openbanking.model.Tpp) FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) Date(java.util.Date) ConsentStatusEntry(com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry)

Example 43 with OBErrorResponseException

use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.

the class FilePaymentsApiController method getFilePaymentsFilePaymentId.

public ResponseEntity<OBWriteFileResponse3> 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 44 with OBErrorResponseException

use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.

the class FilePaymentsApiController method getFilePaymentsFilePaymentIdReportFile.

public ResponseEntity getFilePaymentsFilePaymentIdReportFile(String filePaymentId, String authorization, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    FRFileConsent consent = fileConsentRepository.findById(filePaymentId).orElseThrow(() -> new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.PAYMENT_ID_NOT_FOUND.toOBError1(filePaymentId)));
    log.debug("Consent '{}' exists so generating a report file for type: '{}'", consent.getId(), consent.getStatus(), consent.getFileType());
    try {
        final String reportFile = paymentReportFileService.createPaymentReport(consent);
        log.debug("Generated report file for consent: '{}'", consent.getId());
        return ResponseEntity.ok(reportFile);
    } catch (UnsupportedFileTypeException exception) {
        return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("{ \"Description\" : \"Report for file type " + consent.getFileType().getFileType() + " not supported\" }");
    }
}
Also used : FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) UnsupportedFileTypeException(com.forgerock.openbanking.common.model.openbanking.forgerock.filepayment.v3_0.UnsupportedFileTypeException)

Example 45 with OBErrorResponseException

use of com.forgerock.openbanking.exceptions.OBErrorResponseException in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticVrpConsentsApiController method domesticVrpConsentsFundsConfirmation.

@Override
public ResponseEntity domesticVrpConsentsFundsConfirmation(String consentId, String authorization, String xJwsSignature, OBVRPFundsConfirmationRequest obVRPFundsConfirmationRequest, String xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    log.debug("(store) Request to get a VRP funds confirmation, consentId '{}', mode test '{}'", consentId, StringUtils.hasLength(request.getHeader(OpenBankingHttpHeaders.X_OB_MODE_TEST)));
    boolean areFundsAvailable = false;
    // check header 'x-ob-mode-test' to restrict the behaviour for test purposes
    if (StringUtils.hasLength(request.getHeader(OpenBankingHttpHeaders.X_OB_MODE_TEST))) {
        areFundsAvailable = true;
    } else {
        Optional<FRDomesticVRPConsent> optional = domesticVRPConsentRepository.findById(consentId);
        if (!optional.isPresent()) {
            log.warn("(store) Domestic VRP payment consent '{}' to confirm funds can't be found", consentId);
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Domestic VRP payment consent '" + consentId + "' to confirm funds can't be found");
        }
        FRDomesticVRPConsent domesticVrpConsent = optional.get();
        if (!domesticVrpConsent.getStatus().equals(ConsentStatusCode.AUTHORISED)) {
            log.error("(store) Funds confirmation for VRP payment consent Id '{}, with status '{}' can't be requested" + " because the consent status hasn't '{}'", consentId, domesticVrpConsent.getStatus().getValue(), ConsentStatusCode.AUTHORISED.getValue());
            throw new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.CONSENT_STATUS_NOT_AUTHORISED.toOBError1(consentId));
        }
        // Check if funds are available on the account selected in consent
        String accountIdentification = domesticVrpConsent.getVrpDetails().getData().getInitiation().getDebtorAccount().getIdentification();
        Collection<FRAccount> accountsByUserID = accountRepository.findByUserID(Objects.requireNonNull(domesticVrpConsent.getUserId()));
        Optional<FRAccount> accountOptional = accountsByUserID.stream().filter(account -> account.getAccount().getAccounts().stream().filter(a -> a.getIdentification().equals(accountIdentification)).findFirst().isPresent()).findFirst();
        if (!accountOptional.isPresent()) {
            log.warn("(store) VRP consent '{}', debtor account with identitication '{}' can't be found", consentId, accountIdentification);
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("VRP consent '" + consentId + "', debtor account with identitication '" + accountIdentification + "' to confirm funds can't be found");
        }
        areFundsAvailable = fundsAvailabilityService.isFundsAvailable(accountOptional.get().getId(), obVRPFundsConfirmationRequest.getData().getInstructedAmount().getAmount());
    }
    OBVRPFundsConfirmationRequestData data = obVRPFundsConfirmationRequest.getData();
    return ResponseEntity.status(HttpStatus.OK).body(new OBVRPFundsConfirmationResponse().data(new OBVRPFundsConfirmationResponseData().fundsConfirmationId(UUID.randomUUID().toString()).consentId(consentId).creationDateTime(DateTime.now()).reference(data.getReference()).fundsAvailableResult(new OBPAFundsAvailableResult1().fundsAvailable(areFundsAvailable ? OBPAFundsAvailableResult1.FundsAvailableEnum.AVAILABLE : OBPAFundsAvailableResult1.FundsAvailableEnum.NOTAVAILABLE).fundsAvailableDateTime(DateTime.now())).instructedAmount(data.getInstructedAmount())));
}
Also used : IntentType(com.forgerock.openbanking.common.model.openbanking.IntentType) Tpp(com.forgerock.openbanking.model.Tpp) Controller(org.springframework.stereotype.Controller) ConsentStatusEntry(com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry) FRDomesticVRPConsentConverter.toOBDomesticVRPConsentResponse(com.forgerock.openbanking.common.services.openbanking.converter.vrp.FRDomesticVRPConsentConverter.toOBDomesticVRPConsentResponse) TppRepository(com.forgerock.openbanking.repositories.TppRepository) uk.org.openbanking.datamodel.vrp(uk.org.openbanking.datamodel.vrp) HttpServletRequest(javax.servlet.http.HttpServletRequest) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) FRDomesticVRPConsentDetails(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsentDetails) FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails(com.forgerock.openbanking.common.services.openbanking.converter.vrp.FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails) OBRIErrorResponseCategory(com.forgerock.openbanking.model.error.OBRIErrorResponseCategory) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FundsAvailabilityService(com.forgerock.openbanking.common.services.openbanking.FundsAvailabilityService) DiscoveryConfigurationProperties(com.forgerock.openbanking.common.conf.discovery.DiscoveryConfigurationProperties) IdempotencyService.validateIdempotencyRequest(com.forgerock.openbanking.common.services.openbanking.IdempotencyService.validateIdempotencyRequest) Collection(java.util.Collection) FRAccountRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.accounts.FRAccountRepository) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) VersionPathExtractor(com.forgerock.openbanking.aspsp.rs.store.utils.VersionPathExtractor) OBRIErrorType(com.forgerock.openbanking.model.error.OBRIErrorType) UUID(java.util.UUID) Objects(java.util.Objects) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) OBDiscoveryAPILinksVrpPayment(uk.org.openbanking.datamodel.discovery.OBDiscoveryAPILinksVrpPayment) Principal(java.security.Principal) OpenBankingHttpHeaders(com.forgerock.openbanking.common.constants.OpenBankingHttpHeaders) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) DomesticVRPConsentRepository(com.forgerock.openbanking.aspsp.rs.store.repository.vrp.DomesticVRPConsentRepository) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) ConsentMetricService(com.forgerock.openbanking.analytics.services.ConsentMetricService) ResourceLinkService(com.forgerock.openbanking.common.conf.discovery.ResourceLinkService) StringUtils(org.springframework.util.StringUtils) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException)

Aggregations

OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)213 ResponseEntity (org.springframework.http.ResponseEntity)140 Controller (org.springframework.stereotype.Controller)129 DateTime (org.joda.time.DateTime)121 HttpHeaders (org.springframework.http.HttpHeaders)108 Collections (java.util.Collections)103 Principal (java.security.Principal)102 HttpServletRequest (javax.servlet.http.HttpServletRequest)102 RsStoreGateway (com.forgerock.openbanking.common.services.store.RsStoreGateway)101 RSEndpointWrapperService (com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService)100 ApiParam (io.swagger.annotations.ApiParam)69 PathVariable (org.springframework.web.bind.annotation.PathVariable)69 RequestHeader (org.springframework.web.bind.annotation.RequestHeader)69 DateTimeFormat (org.springframework.format.annotation.DateTimeFormat)63 HTTP_DATE_FORMAT (com.forgerock.openbanking.constants.OpenBankingConstants.HTTP_DATE_FORMAT)59 ApiVersionUtils.getOBVersion (com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion)55 Logger (org.slf4j.Logger)50 LoggerFactory (org.slf4j.LoggerFactory)50 RequestBody (org.springframework.web.bind.annotation.RequestBody)49 Valid (javax.validation.Valid)48