Search in sources :

Example 46 with OBErrorResponseException

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

the class InternationalPaymentsApiController method createInternationalPayments.

public ResponseEntity<OBWriteInternationalResponse5> createInternationalPayments(OBWriteInternational3 obWriteInternational3, 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: '{}'", obWriteInternational3);
    FRWriteInternational frWriteInternational = toFRWriteInternational(obWriteInternational3);
    log.trace("Converted to: '{}'", frWriteInternational);
    String paymentId = obWriteInternational3.getData().getConsentId();
    FRInternationalConsent paymentConsent = internationalConsentRepository.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);
    FRInternationalPaymentSubmission frPaymentSubmission = FRInternationalPaymentSubmission.builder().id(paymentId).internationalPayment(frWriteInternational).created(new Date()).updated(new Date()).idempotencyKey(xIdempotencyKey).obVersion(VersionPathExtractor.getVersionFromPath(request)).build();
    frPaymentSubmission = new IdempotentRepositoryAdapter<>(internationalPaymentSubmissionRepository).idempotentSave(frPaymentSubmission);
    return ResponseEntity.status(HttpStatus.CREATED).body(responseEntity(frPaymentSubmission, paymentConsent));
}
Also used : IdempotentRepositoryAdapter(com.forgerock.openbanking.aspsp.rs.store.repository.IdempotentRepositoryAdapter) FRWriteInternational(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternational) FRWriteInternationalConverter.toFRWriteInternational(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalConverter.toFRWriteInternational) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) FRInternationalPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalPaymentSubmission) Date(java.util.Date)

Example 47 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) OBWriteInternationalConsentResponse4(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsentResponse4) 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) OBWriteInternationalConsent4(uk.org.openbanking.datamodel.payment.OBWriteInternationalConsent4) HttpHeaders(org.springframework.http.HttpHeaders) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent)

Example 48 with OBErrorResponseException

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

the class InternationalPaymentsApiController method createInternationalPayments.

public ResponseEntity<OBWriteInternationalResponse4> createInternationalPayments(OBWriteInternational3 obWriteInternational3, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    String consentId = obWriteInternational3.getData().getConsentId();
    FRInternationalConsent 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(toFRWriteInternationalDataInitiation(obWriteInternational3.getData().getInitiation()), toFRRisk(obWriteInternational3.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);
        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(), OBWriteInternationalResponse4.class, obWriteInternational3);
    });
}
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) InternationalPaymentService(com.forgerock.openbanking.common.services.store.payment.InternationalPaymentService) Controller(org.springframework.stereotype.Controller) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) 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) FRPaymentRiskConverter.toFRRisk(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRPaymentRiskConverter.toFRRisk) FRWriteInternationalConsentConverter.toFRWriteInternationalDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalConsentConverter.toFRWriteInternationalDataInitiation) OBWriteInternational3(uk.org.openbanking.datamodel.payment.OBWriteInternational3) OBWritePaymentDetailsResponse1(uk.org.openbanking.datamodel.payment.OBWritePaymentDetailsResponse1) Collections(java.util.Collections) OBWriteInternationalResponse4(uk.org.openbanking.datamodel.payment.OBWriteInternationalResponse4) HttpHeaders(org.springframework.http.HttpHeaders) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent)

Example 49 with OBErrorResponseException

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

the class InternationalScheduledPaymentsApiController method createInternationalScheduledPayments.

public ResponseEntity<OBWriteInternationalScheduledResponse4> 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(), OBWriteInternationalScheduledResponse4.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) OBWriteInternationalScheduledResponse4(uk.org.openbanking.datamodel.payment.OBWriteInternationalScheduledResponse4) Principal(java.security.Principal) 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)

Example 50 with OBErrorResponseException

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

the class DomesticStandingOrdersApiController method createDomesticStandingOrders.

public ResponseEntity<OBWriteDomesticStandingOrderResponse4> createDomesticStandingOrders(OBWriteDomesticStandingOrder3 obWriteDomesticStandingOrder3, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    String consentId = obWriteDomesticStandingOrder3.getData().getConsentId();
    FRDomesticStandingOrderConsent 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(toFRWriteDomesticStandingOrderDataInitiation(obWriteDomesticStandingOrder3.getData().getInitiation()), toFRRisk(obWriteDomesticStandingOrder3.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);
        FRWriteDomesticStandingOrderDataInitiation paymentInitiation = payment.getDomesticStandingOrderConsent().getData().getInitiation();
        DateTime firstPaymentDateTime = paymentInitiation.getFirstPaymentDateTime();
        FRStandingOrderData standingOrder = FRStandingOrderData.builder().accountId(payment.getAccountId()).standingOrderStatusCode(FRStandingOrderData.FRStandingOrderStatus.ACTIVE).creditorAccount(paymentInitiation.getCreditorAccount()).frequency(paymentInitiation.getFrequency()).reference(paymentInitiation.getReference()).firstPaymentDateTime(paymentInitiation.getFirstPaymentDateTime()).firstPaymentAmount(paymentInitiation.getFirstPaymentAmount()).nextPaymentAmount(paymentInitiation.getRecurringPaymentAmount()).nextPaymentDateTime(frequencyService.getNextDateTime(paymentInitiation.getFirstPaymentDateTime(), paymentInitiation.getFrequency())).finalPaymentDateTime(paymentInitiation.getFinalPaymentDateTime()).finalPaymentAmount(paymentInitiation.getFinalPaymentAmount()).standingOrderId(payment.getId()).build();
        String pispId = tppStoreService.findByClientId(tppId).map(tpp -> tpp.getId()).orElse(null);
        standingOrderService.createStandingOrder(standingOrder, pispId);
        log.info("Updating standing order '{}'", payment.getId());
        payment.setStatus(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED);
        paymentsService.updatePayment(payment);
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-payment-id", consentId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteDomesticStandingOrderResponse4.class, obWriteDomesticStandingOrder3);
    });
}
Also used : RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) FrequencyService(com.forgerock.openbanking.common.services.openbanking.frequency.FrequencyService) Controller(org.springframework.stereotype.Controller) OBWriteDomesticStandingOrderResponse4(uk.org.openbanking.datamodel.payment.OBWriteDomesticStandingOrderResponse4) HttpServletRequest(javax.servlet.http.HttpServletRequest) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) ApiVersionUtils.getOBVersion(com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion) FRDomesticStandingOrderConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticStandingOrderConsent) FRWriteDomesticStandingOrderConsentConverter.toFRWriteDomesticStandingOrderDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteDomesticStandingOrderConsentConverter.toFRWriteDomesticStandingOrderDataInitiation) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) DomesticStandingOrderService(com.forgerock.openbanking.common.services.store.payment.DomesticStandingOrderService) HttpHeaders(org.springframework.http.HttpHeaders) FRWriteDomesticStandingOrderDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticStandingOrderDataInitiation) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) OBWriteDomesticStandingOrder3(uk.org.openbanking.datamodel.payment.OBWriteDomesticStandingOrder3) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) Principal(java.security.Principal) StandingOrderService(com.forgerock.openbanking.common.services.store.account.standingorder.StandingOrderService) FRStandingOrderData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData) 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) HttpHeaders(org.springframework.http.HttpHeaders) FRWriteDomesticStandingOrderConsentConverter.toFRWriteDomesticStandingOrderDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteDomesticStandingOrderConsentConverter.toFRWriteDomesticStandingOrderDataInitiation) FRWriteDomesticStandingOrderDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticStandingOrderDataInitiation) FRDomesticStandingOrderConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticStandingOrderConsent) FRStandingOrderData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData) DateTime(org.joda.time.DateTime)

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