use of uk.org.openbanking.datamodel.payment.OBWriteDomesticScheduledResponse4 in project openbanking-aspsp by OpenBankingToolkit.
the class DomesticScheduledPaymentsApiController method responseEntity.
private OBWriteDomesticScheduledResponse4 responseEntity(FRDomesticScheduledPaymentSubmission frPaymentSubmission, FRDomesticScheduledConsent frDomesticScheduledConsent) {
FRReadRefundAccount readRefundAccount = frDomesticScheduledConsent.getDomesticScheduledConsent().getData().getReadRefundAccount();
FRWriteDomesticScheduledDataInitiation initiation = frPaymentSubmission.getDomesticScheduledPayment().getData().getInitiation();
Optional<FRDomesticResponseDataRefund> refund = frDomesticResponseDataRefund(readRefundAccount, initiation);
return new OBWriteDomesticScheduledResponse4().data(new OBWriteDomesticScheduledResponse4Data().domesticScheduledPaymentId(frPaymentSubmission.getId()).initiation(toOBWriteDomesticScheduled2DataInitiation(frDomesticScheduledConsent.getInitiation())).creationDateTime(frDomesticScheduledConsent.getCreated()).statusUpdateDateTime(frDomesticScheduledConsent.getStatusUpdate()).status(toOBWriteDomesticScheduledResponse4DataStatus(frDomesticScheduledConsent.getStatus())).consentId(frDomesticScheduledConsent.getId()).refund(refund.map(FRResponseDataRefundConverter::toOBWriteDomesticResponse4DataRefund).orElse(null))).links(resourceLinkService.toSelfLink(frPaymentSubmission, discovery -> getVersion(discovery).getGetDomesticScheduledPayment())).meta(new Meta());
}
use of uk.org.openbanking.datamodel.payment.OBWriteDomesticScheduledResponse4 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);
});
}
Aggregations