Search in sources :

Example 1 with OBWriteInternationalStandingOrder4

use of uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrder4 in project openbanking-aspsp by OpenBankingToolkit.

the class InternationalStandingOrdersApiController method createInternationalStandingOrders.

@Override
public ResponseEntity<OBWriteInternationalStandingOrderResponse6> createInternationalStandingOrders(OBWriteInternationalStandingOrder4 obWriteInternationalStandingOrder4, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    String consentId = obWriteInternationalStandingOrder4.getData().getConsentId();
    FRInternationalStandingOrderConsent 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(toFRWriteInternationalStandingOrderDataInitiation(obWriteInternationalStandingOrder4.getData().getInitiation()), toFRRisk(obWriteInternationalStandingOrder4.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.ACCEPTEDSETTLEMENTCOMPLETED);
        log.info("Updating payment");
        paymentsService.updatePayment(payment);
        FRWriteInternationalStandingOrderDataInitiation initiation = payment.getInitiation();
        FRStandingOrderData standingOrder = FRStandingOrderData.builder().accountId(payment.getAccountId()).standingOrderStatusCode(FRStandingOrderData.FRStandingOrderStatus.ACTIVE).creditorAccount(initiation.getCreditorAccount()).frequency(initiation.getFrequency()).reference(initiation.getReference()).firstPaymentDateTime(initiation.getFirstPaymentDateTime()).firstPaymentAmount(initiation.getInstructedAmount()).nextPaymentAmount(initiation.getInstructedAmount()).nextPaymentDateTime(frequencyService.getNextDateTime(initiation.getFirstPaymentDateTime(), initiation.getFrequency())).finalPaymentDateTime(initiation.getFinalPaymentDateTime()).finalPaymentAmount(initiation.getInstructedAmount()).standingOrderId(payment.getId()).build();
        String pispId = tppStoreService.findPispIdByTppId(tppId);
        standingOrderService.createStandingOrder(standingOrder, pispId);
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-payment-id", consentId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteInternationalStandingOrderResponse6.class, obWriteInternationalStandingOrder4);
    });
}
Also used : RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) FrequencyService(com.forgerock.openbanking.common.services.openbanking.frequency.FrequencyService) 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) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) FRWriteInternationalStandingOrderDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalStandingOrderDataInitiation) InternationalStandingOrderService(com.forgerock.openbanking.common.services.store.payment.InternationalStandingOrderService) HttpHeaders(org.springframework.http.HttpHeaders) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) OBWriteInternationalStandingOrder4(uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrder4) FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) Principal(java.security.Principal) FRInternationalStandingOrderConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderConsent) StandingOrderService(com.forgerock.openbanking.common.services.store.account.standingorder.StandingOrderService) OBWriteInternationalStandingOrderResponse6(uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrderResponse6) 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) FRInternationalStandingOrderConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderConsent) FRWriteInternationalStandingOrderDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalStandingOrderDataInitiation) FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation) FRStandingOrderData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData)

Example 2 with OBWriteInternationalStandingOrder4

use of uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrder4 in project openbanking-aspsp by OpenBankingToolkit.

the class InternationalStandingOrdersApiController method createInternationalStandingOrders.

public ResponseEntity<OBWriteInternationalStandingOrderResponse7> createInternationalStandingOrders(OBWriteInternationalStandingOrder4 obWriteInternationalStandingOrder4, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    String consentId = obWriteInternationalStandingOrder4.getData().getConsentId();
    FRInternationalStandingOrderConsent 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(toFRWriteInternationalStandingOrderDataInitiation(obWriteInternationalStandingOrder4.getData().getInitiation()), toFRRisk(obWriteInternationalStandingOrder4.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.ACCEPTEDSETTLEMENTCOMPLETED);
        log.info("Updating payment");
        paymentsService.updatePayment(payment);
        FRWriteInternationalStandingOrderDataInitiation initiation = payment.getInitiation();
        FRStandingOrderData standingOrder = FRStandingOrderData.builder().accountId(payment.getAccountId()).standingOrderStatusCode(FRStandingOrderData.FRStandingOrderStatus.ACTIVE).creditorAccount(initiation.getCreditorAccount()).frequency(initiation.getFrequency()).reference(initiation.getReference()).firstPaymentDateTime(initiation.getFirstPaymentDateTime()).firstPaymentAmount(initiation.getInstructedAmount()).nextPaymentAmount(initiation.getInstructedAmount()).nextPaymentDateTime(frequencyService.getNextDateTime(initiation.getFirstPaymentDateTime(), initiation.getFrequency())).finalPaymentDateTime(initiation.getFinalPaymentDateTime()).finalPaymentAmount(initiation.getInstructedAmount()).standingOrderId(payment.getId()).build();
        String pispId = tppStoreService.findPispIdByTppId(tppId);
        standingOrderService.createStandingOrder(standingOrder, pispId);
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-payment-id", consentId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteInternationalStandingOrderResponse7.class, obWriteInternationalStandingOrder4);
    });
}
Also used : RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) FrequencyService(com.forgerock.openbanking.common.services.openbanking.frequency.FrequencyService) 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) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) FRWriteInternationalStandingOrderDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalStandingOrderDataInitiation) InternationalStandingOrderService(com.forgerock.openbanking.common.services.store.payment.InternationalStandingOrderService) HttpHeaders(org.springframework.http.HttpHeaders) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) OBWriteInternationalStandingOrder4(uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrder4) FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) Principal(java.security.Principal) FRInternationalStandingOrderConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderConsent) StandingOrderService(com.forgerock.openbanking.common.services.store.account.standingorder.StandingOrderService) OBWriteInternationalStandingOrderResponse7(uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrderResponse7) 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) FRInternationalStandingOrderConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderConsent) FRWriteInternationalStandingOrderDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalStandingOrderDataInitiation) FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation) FRStandingOrderData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData)

Example 3 with OBWriteInternationalStandingOrder4

use of uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrder4 in project openbanking-aspsp by OpenBankingToolkit.

the class InternationalStandingOrdersApiController method createInternationalStandingOrders.

public ResponseEntity<OBWriteInternationalStandingOrderResponse5> createInternationalStandingOrders(OBWriteInternationalStandingOrder4 obWriteInternationalStandingOrder4, String authorization, String xIdempotencyKey, String xJwsSignature, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    String consentId = obWriteInternationalStandingOrder4.getData().getConsentId();
    FRInternationalStandingOrderConsent 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(toFRWriteInternationalStandingOrderDataInitiation(obWriteInternationalStandingOrder4.getData().getInitiation()), toFRRisk(obWriteInternationalStandingOrder4.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.ACCEPTEDSETTLEMENTCOMPLETED);
        log.info("Updating payment");
        paymentsService.updatePayment(payment);
        FRWriteInternationalStandingOrderDataInitiation initiation = payment.getInitiation();
        FRStandingOrderData standingOrder = FRStandingOrderData.builder().accountId(payment.getAccountId()).standingOrderStatusCode(FRStandingOrderData.FRStandingOrderStatus.ACTIVE).creditorAccount(initiation.getCreditorAccount()).frequency(initiation.getFrequency()).reference(initiation.getReference()).firstPaymentDateTime(initiation.getFirstPaymentDateTime()).firstPaymentAmount(initiation.getInstructedAmount()).nextPaymentAmount(initiation.getInstructedAmount()).nextPaymentDateTime(frequencyService.getNextDateTime(initiation.getFirstPaymentDateTime(), initiation.getFrequency())).finalPaymentDateTime(initiation.getFinalPaymentDateTime()).finalPaymentAmount(initiation.getInstructedAmount()).standingOrderId(payment.getId()).build();
        String pispId = tppStoreService.findPispIdByTppId(tppId);
        standingOrderService.createStandingOrder(standingOrder, pispId);
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.add("x-ob-payment-id", consentId);
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, Collections.emptyMap(), OBWriteInternationalStandingOrderResponse5.class, obWriteInternationalStandingOrder4);
    });
}
Also used : RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) OBWriteInternationalStandingOrderResponse5(uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrderResponse5) FrequencyService(com.forgerock.openbanking.common.services.openbanking.frequency.FrequencyService) 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) RSEndpointWrapperService(com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService) FRWriteInternationalStandingOrderDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalStandingOrderDataInitiation) InternationalStandingOrderService(com.forgerock.openbanking.common.services.store.payment.InternationalStandingOrderService) HttpHeaders(org.springframework.http.HttpHeaders) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) OBWriteInternationalStandingOrder4(uk.org.openbanking.datamodel.payment.OBWriteInternationalStandingOrder4) FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) Principal(java.security.Principal) FRInternationalStandingOrderConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderConsent) 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) FRInternationalStandingOrderConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderConsent) FRWriteInternationalStandingOrderDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalStandingOrderDataInitiation) FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation) FRStandingOrderData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData)

Aggregations

RSEndpointWrapperService (com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService)3 FRStandingOrderData (com.forgerock.openbanking.common.model.openbanking.domain.account.FRStandingOrderData)3 FRWriteInternationalStandingOrderDataInitiation (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalStandingOrderDataInitiation)3 ConsentStatusCode (com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode)3 FRInternationalStandingOrderConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderConsent)3 FRPaymentRiskConverter.toFRRisk (com.forgerock.openbanking.common.services.openbanking.converter.payment.FRPaymentRiskConverter.toFRRisk)3 FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation (com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalStandingOrderConsentConverter.toFRWriteInternationalStandingOrderDataInitiation)3 FrequencyService (com.forgerock.openbanking.common.services.openbanking.frequency.FrequencyService)3 RsStoreGateway (com.forgerock.openbanking.common.services.store.RsStoreGateway)3 StandingOrderService (com.forgerock.openbanking.common.services.store.account.standingorder.StandingOrderService)3 InternationalStandingOrderService (com.forgerock.openbanking.common.services.store.payment.InternationalStandingOrderService)3 TppStoreService (com.forgerock.openbanking.common.services.store.tpp.TppStoreService)3 ApiVersionUtils.getOBVersion (com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion)3 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)3 Principal (java.security.Principal)3 Collections (java.util.Collections)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Slf4j (lombok.extern.slf4j.Slf4j)3 DateTime (org.joda.time.DateTime)3 HttpHeaders (org.springframework.http.HttpHeaders)3