Search in sources :

Example 26 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, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    return rsEndpointWrapperService.paymentEndpoint().authorization(authorization).xFapiFinancialId(rsEndpointWrapperService.rsConfiguration.financialId).principal(principal).obVersion(getOBVersion(request.getRequestURI())).filters(f -> {
        f.verifyIdempotencyKeyLength(xIdempotencyKey);
        f.verifyJwsDetachedSignature(xJwsSignature, request);
    }).execute((String tppId) -> {
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-client-id", tppId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteFileConsentResponse4.class, obWriteFileConsent3);
    });
}
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)

Example 27 with OBErrorResponseException

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

the class FilePaymentsApiController method createFilePayments.

public ResponseEntity<OBWriteFileResponse3> createFilePayments(OBWriteFile2 obWriteFile2, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    String consentId = obWriteFile2.getData().getConsentId();
    FRFileConsent payment = paymentsService.getPayment(consentId);
    return rsEndpointWrapperService.paymentSubmissionEndpoint().authorization(authorization).xFapiFinancialId(rsEndpointWrapperService.rsConfiguration.financialId).payment(payment).principal(principal).obVersion(getOBVersion(request.getRequestURI())).filters(f -> {
        f.verifyPaymentIdWithAccessToken();
        f.verifyIdempotencyKeyLength(xIdempotencyKey);
        f.verifyPaymentStatus();
        f.verifyInitiation(toFRWriteFileDataInitiation(obWriteFile2.getData().getInitiation()));
        f.verifyJwsDetachedSignature(xJwsSignature, request);
    }).execute((String tppId) -> {
        // Modify the status of the payment
        log.info("Switch status of payment {} to 'accepted settlement in process'.", consentId);
        payment.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTINPROCESS);
        log.info("Updating payment");
        paymentsService.updatePayment(payment);
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-payment-id", consentId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteFileResponse3.class, obWriteFile2);
    });
}
Also used : RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) HttpHeaders(org.springframework.http.HttpHeaders) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) Controller(org.springframework.stereotype.Controller) OBWriteFile2(uk.org.openbanking.datamodel.payment.OBWriteFile2) File(java.io.File) OBWriteFileResponse3(uk.org.openbanking.datamodel.payment.OBWriteFileResponse3) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) Principal(java.security.Principal) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) 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) OBWritePaymentDetailsResponse1(uk.org.openbanking.datamodel.payment.OBWritePaymentDetailsResponse1) Collections(java.util.Collections) FilePaymentService(com.forgerock.openbanking.common.services.store.payment.FilePaymentService) Resource(org.springframework.core.io.Resource) 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 28 with OBErrorResponseException

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

the class InternationalPaymentConsentsApiController method getInternationalPaymentConsentsConsentIdFundsConfirmation.

public ResponseEntity<OBWriteFundsConfirmationResponse1> getInternationalPaymentConsentsConsentIdFundsConfirmation(String consentId, String authorization, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    FRInternationalConsent payment = paymentsService.getPayment(consentId);
    return rsEndpointWrapperService.paymentEndpoint().authorization(authorization).xFapiFinancialId(rsEndpointWrapperService.rsConfiguration.financialId).payment(payment).principal(principal).obVersion(getOBVersion(request.getRequestURI())).isFundsConfirmationRequest(true).filters(f -> {
        f.verifyConsentStatusForConfirmationOfFund();
    }).execute((String tppId) -> {
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-url", new ServletServerHttpRequest(request).getURI().toString());
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, OBWriteFundsConfirmationResponse1.class);
    });
}
Also used : OBWriteFundsConfirmationResponse1(uk.org.openbanking.datamodel.payment.OBWriteFundsConfirmationResponse1) RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) 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) Controller(org.springframework.stereotype.Controller) ExchangeRateVerifier(com.forgerock.openbanking.aspsp.rs.api.payment.verifier.ExchangeRateVerifier) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) OBWriteInternationalConsent5(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsent5) HttpServletRequest(javax.servlet.http.HttpServletRequest) Principal(java.security.Principal) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ApiVersionUtils.getOBVersion(com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) ResponseEntity(org.springframework.http.ResponseEntity) Collections(java.util.Collections) OBWriteInternationalConsentResponse6(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsentResponse6) HttpHeaders(org.springframework.http.HttpHeaders) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent)

Example 29 with OBErrorResponseException

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

the class InternationalPaymentConsentsApiController method createInternationalPaymentConsents.

public ResponseEntity<OBWriteInternationalConsentResponse6> createInternationalPaymentConsents(OBWriteInternationalConsent5 obWriteInternationalConsent5, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    return rsEndpointWrapperService.paymentEndpoint().authorization(authorization).xFapiFinancialId(rsEndpointWrapperService.rsConfiguration.financialId).principal(principal).obVersion(getOBVersion(request.getRequestURI())).filters(f -> {
        f.verifyIdempotencyKeyLength(xIdempotencyKey);
        f.verifyJwsDetachedSignature(xJwsSignature, request);
        f.validateRisk(obWriteInternationalConsent5.getRisk());
    }).execute((String tppId) -> {
        exchangeRateVerifier.verify(obWriteInternationalConsent5.getData().getInitiation().getExchangeRateInformation());
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-client-id", tppId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteInternationalConsentResponse6.class, obWriteInternationalConsent5);
    });
}
Also used : OBWriteFundsConfirmationResponse1(uk.org.openbanking.datamodel.payment.OBWriteFundsConfirmationResponse1) RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) 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) Controller(org.springframework.stereotype.Controller) ExchangeRateVerifier(com.forgerock.openbanking.aspsp.rs.api.payment.verifier.ExchangeRateVerifier) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) OBWriteInternationalConsent5(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsent5) HttpServletRequest(javax.servlet.http.HttpServletRequest) Principal(java.security.Principal) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ApiVersionUtils.getOBVersion(com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) ResponseEntity(org.springframework.http.ResponseEntity) Collections(java.util.Collections) OBWriteInternationalConsentResponse6(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsentResponse6) HttpHeaders(org.springframework.http.HttpHeaders)

Example 30 with OBErrorResponseException

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

the class InternationalScheduledPaymentsApiController method createInternationalScheduledPayments.

public ResponseEntity<OBWriteInternationalScheduledResponse6> createInternationalScheduledPayments(OBWriteInternationalScheduled3 obWriteInternationalScheduled3, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    String consentId = obWriteInternationalScheduled3.getData().getConsentId();
    FRInternationalScheduledConsent payment = paymentsService.getPayment(consentId);
    return rsEndpointWrapperService.paymentSubmissionEndpoint().authorization(authorization).xFapiFinancialId(rsEndpointWrapperService.rsConfiguration.financialId).payment(payment).principal(principal).obVersion(getOBVersion(request.getRequestURI())).filters(f -> {
        f.verifyPaymentIdWithAccessToken();
        f.verifyIdempotencyKeyLength(xIdempotencyKey);
        f.verifyPaymentStatus();
        f.verifyRiskAndInitiation(toFRWriteInternationalScheduledDataInitiation(obWriteInternationalScheduled3.getData().getInitiation()), toFRRisk(obWriteInternationalScheduled3.getRisk()));
        f.verifyJwsDetachedSignature(xJwsSignature, request);
    }).execute((String tppId) -> {
        // Modify the status of the payment
        log.info("Switch status of payment {} to 'accepted settlement in process'.", consentId);
        FRWriteInternationalScheduledDataInitiation initiation = payment.getInitiation();
        FRScheduledPaymentData scheduledPayment = FRScheduledPaymentData.builder().accountId(payment.getAccountId()).creditorAccount(initiation.getCreditorAccount()).instructedAmount(initiation.getInstructedAmount()).scheduledType(FRScheduledPaymentData.FRScheduleType.EXECUTION).scheduledPaymentDateTime(initiation.getRequestedExecutionDateTime()).scheduledPaymentId(payment.getId()).build();
        String pispId = tppStoreService.findByClientId(tppId).map(tpp -> tpp.getId()).orElse(null);
        scheduledPaymentService.createSchedulePayment(scheduledPayment, pispId);
        payment.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED);
        log.info("Updating payment");
        paymentsService.updatePayment(payment);
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-payment-id", consentId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteInternationalScheduledResponse6.class, obWriteInternationalScheduled3);
    });
}
Also used : RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) FRScheduledPaymentData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRScheduledPaymentData) FRWriteInternationalScheduledDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalScheduledDataInitiation) Controller(org.springframework.stereotype.Controller) HttpServletRequest(javax.servlet.http.HttpServletRequest) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) ApiVersionUtils.getOBVersion(com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion) FRInternationalScheduledConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalScheduledConsent) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) HttpHeaders(org.springframework.http.HttpHeaders) InternationalScheduledPaymentService(com.forgerock.openbanking.common.services.store.payment.InternationalScheduledPaymentService) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) FRWriteInternationalScheduledConsentConverter.toFRWriteInternationalScheduledDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalScheduledConsentConverter.toFRWriteInternationalScheduledDataInitiation) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) Principal(java.security.Principal) OBWriteInternationalScheduledResponse6(uk.org.openbanking.datamodel.payment.OBWriteInternationalScheduledResponse6) ScheduledPaymentService(com.forgerock.openbanking.common.services.store.account.scheduledpayment.ScheduledPaymentService) ResponseEntity(org.springframework.http.ResponseEntity) FRPaymentRiskConverter.toFRRisk(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRPaymentRiskConverter.toFRRisk) OBWritePaymentDetailsResponse1(uk.org.openbanking.datamodel.payment.OBWritePaymentDetailsResponse1) Collections(java.util.Collections) TppStoreService(com.forgerock.openbanking.common.services.store.tpp.TppStoreService) OBWriteInternationalScheduled3(uk.org.openbanking.datamodel.payment.OBWriteInternationalScheduled3) FRScheduledPaymentData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRScheduledPaymentData) HttpHeaders(org.springframework.http.HttpHeaders) FRWriteInternationalScheduledDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalScheduledDataInitiation) FRWriteInternationalScheduledConsentConverter.toFRWriteInternationalScheduledDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalScheduledConsentConverter.toFRWriteInternationalScheduledDataInitiation) FRInternationalScheduledConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalScheduledConsent)

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