Search in sources :

Example 1 with OBWriteInternationalScheduledResponse4

use of uk.org.openbanking.datamodel.payment.OBWriteInternationalScheduledResponse4 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)

Aggregations

RSEndpointWrapperService (com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService)1 FRScheduledPaymentData (com.forgerock.openbanking.common.model.openbanking.domain.account.FRScheduledPaymentData)1 FRWriteInternationalScheduledDataInitiation (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalScheduledDataInitiation)1 ConsentStatusCode (com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode)1 FRInternationalScheduledConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalScheduledConsent)1 FRPaymentRiskConverter.toFRRisk (com.forgerock.openbanking.common.services.openbanking.converter.payment.FRPaymentRiskConverter.toFRRisk)1 FRWriteInternationalScheduledConsentConverter.toFRWriteInternationalScheduledDataInitiation (com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteInternationalScheduledConsentConverter.toFRWriteInternationalScheduledDataInitiation)1 RsStoreGateway (com.forgerock.openbanking.common.services.store.RsStoreGateway)1 ScheduledPaymentService (com.forgerock.openbanking.common.services.store.account.scheduledpayment.ScheduledPaymentService)1 InternationalScheduledPaymentService (com.forgerock.openbanking.common.services.store.payment.InternationalScheduledPaymentService)1 TppStoreService (com.forgerock.openbanking.common.services.store.tpp.TppStoreService)1 ApiVersionUtils.getOBVersion (com.forgerock.openbanking.common.utils.ApiVersionUtils.getOBVersion)1 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)1 Principal (java.security.Principal)1 Collections (java.util.Collections)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Slf4j (lombok.extern.slf4j.Slf4j)1 DateTime (org.joda.time.DateTime)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpStatus (org.springframework.http.HttpStatus)1