use of uk.org.openbanking.datamodel.payment.OBWriteDomesticStandingOrderResponse5 in project openbanking-aspsp by OpenBankingToolkit.
the class DomesticStandingOrdersApiController method createDomesticStandingOrders.
@Override
public ResponseEntity<OBWriteDomesticStandingOrderResponse5> 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 initiation = payment.getInitiation();
DateTime firstPaymentDateTime = initiation.getFirstPaymentDateTime();
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.getFirstPaymentAmount()).nextPaymentAmount(initiation.getRecurringPaymentAmount()).nextPaymentDateTime(frequencyService.getNextDateTime(initiation.getFirstPaymentDateTime(), initiation.getFrequency())).finalPaymentDateTime(initiation.getFinalPaymentDateTime()).finalPaymentAmount(initiation.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(), OBWriteDomesticStandingOrderResponse5.class, obWriteDomesticStandingOrder3);
});
}
use of uk.org.openbanking.datamodel.payment.OBWriteDomesticStandingOrderResponse5 in project openbanking-aspsp by OpenBankingToolkit.
the class DomesticStandingOrdersApiController method responseEntity.
private OBWriteDomesticStandingOrderResponse5 responseEntity(FRDomesticStandingOrderPaymentSubmission frPaymentSubmission, FRDomesticStandingOrderConsent frDomesticStandingOrderConsent) {
FRReadRefundAccount readRefundAccount = frDomesticStandingOrderConsent.getDomesticStandingOrderConsent().getData().getReadRefundAccount();
FRWriteDomesticStandingOrderDataInitiation initiation = frPaymentSubmission.getDomesticStandingOrder().getData().getInitiation();
Optional<FRDomesticResponseDataRefund> refund = frDomesticResponseDataRefund(readRefundAccount, initiation);
return new OBWriteDomesticStandingOrderResponse5().data(new OBWriteDomesticStandingOrderResponse5Data().domesticStandingOrderId(frPaymentSubmission.getId()).initiation(toOBWriteDomesticStandingOrder3DataInitiation(frDomesticStandingOrderConsent.getDomesticStandingOrderConsent().getData().getInitiation())).creationDateTime(frDomesticStandingOrderConsent.getCreated()).statusUpdateDateTime(frDomesticStandingOrderConsent.getStatusUpdate()).status(toOBWriteDomesticStandingOrderResponse5DataStatus(frDomesticStandingOrderConsent.getStatus())).consentId(frDomesticStandingOrderConsent.getId()).refund(refund.map(FRResponseDataRefundConverter::toOBWriteDomesticResponse4DataRefund).orElse(null))).links(resourceLinkService.toSelfLink(frPaymentSubmission, discovery -> getVersion(discovery).getGetDomesticStandingOrder())).meta(new Meta());
}
Aggregations