Search in sources :

Example 11 with FRScheduledPaymentData

use of com.forgerock.openbanking.common.model.openbanking.domain.account.FRScheduledPaymentData in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticScheduledPaymentsApiController method createDomesticScheduledPayments.

@Override
public ResponseEntity<OBWriteDomesticScheduledResponse4> createDomesticScheduledPayments(OBWriteDomesticScheduled2 obWriteDomesticScheduled2, String authorization, String xIdempotencyKey, String xJwsSignature, String xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    String consentId = obWriteDomesticScheduled2.getData().getConsentId();
    FRDomesticScheduledConsent 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(toFRWriteDomesticScheduledDataInitiation(obWriteDomesticScheduled2.getData().getInitiation()), toFRRisk(obWriteDomesticScheduled2.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);
        FRWriteDomesticScheduledDataInitiation 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();
        // optionals
        if (initiation.getRemittanceInformation() != null) {
            if (!StringUtils.isEmpty(initiation.getRemittanceInformation().getReference())) {
                scheduledPayment.setReference(initiation.getRemittanceInformation().getReference());
            }
        }
        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(), OBWriteDomesticScheduledResponse4.class, obWriteDomesticScheduled2);
    });
}
Also used : RsStoreGateway(com.forgerock.openbanking.common.services.store.RsStoreGateway) FRScheduledPaymentData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRScheduledPaymentData) FRWriteDomesticScheduledConsentConverter.toFRWriteDomesticScheduledDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteDomesticScheduledConsentConverter.toFRWriteDomesticScheduledDataInitiation) Controller(org.springframework.stereotype.Controller) DomesticScheduledPaymentService(com.forgerock.openbanking.common.services.store.payment.DomesticScheduledPaymentService) 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) OBWriteDomesticScheduledResponse4(uk.org.openbanking.datamodel.payment.OBWriteDomesticScheduledResponse4) HttpHeaders(org.springframework.http.HttpHeaders) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) HttpStatus(org.springframework.http.HttpStatus) FRWriteDomesticScheduledDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticScheduledDataInitiation) FRDomesticScheduledConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticScheduledConsent) Slf4j(lombok.extern.slf4j.Slf4j) OBWriteDomesticScheduled2(uk.org.openbanking.datamodel.payment.OBWriteDomesticScheduled2) 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) StringUtils(org.springframework.util.StringUtils) FRScheduledPaymentData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRScheduledPaymentData) HttpHeaders(org.springframework.http.HttpHeaders) FRWriteDomesticScheduledConsentConverter.toFRWriteDomesticScheduledDataInitiation(com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteDomesticScheduledConsentConverter.toFRWriteDomesticScheduledDataInitiation) FRWriteDomesticScheduledDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticScheduledDataInitiation) FRDomesticScheduledConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticScheduledConsent)

Aggregations

FRScheduledPaymentData (com.forgerock.openbanking.common.model.openbanking.domain.account.FRScheduledPaymentData)11 RSEndpointWrapperService (com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService)10 ConsentStatusCode (com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode)10 FRPaymentRiskConverter.toFRRisk (com.forgerock.openbanking.common.services.openbanking.converter.payment.FRPaymentRiskConverter.toFRRisk)10 RsStoreGateway (com.forgerock.openbanking.common.services.store.RsStoreGateway)10 ScheduledPaymentService (com.forgerock.openbanking.common.services.store.account.scheduledpayment.ScheduledPaymentService)10 TppStoreService (com.forgerock.openbanking.common.services.store.tpp.TppStoreService)10 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)10 Principal (java.security.Principal)10 Collections (java.util.Collections)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 HttpHeaders (org.springframework.http.HttpHeaders)10 ResponseEntity (org.springframework.http.ResponseEntity)10 Controller (org.springframework.stereotype.Controller)10 DateTime (org.joda.time.DateTime)9 ApiVersionUtils.getOBVersion (com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion)6 Slf4j (lombok.extern.slf4j.Slf4j)6 HttpStatus (org.springframework.http.HttpStatus)6 OBWritePaymentDetailsResponse1 (uk.org.openbanking.datamodel.payment.OBWritePaymentDetailsResponse1)6 FRWriteDomesticScheduledDataInitiation (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticScheduledDataInitiation)5