use of uk.org.openbanking.datamodel.payment.OBWriteDomesticStandingOrderResponse6 in project openbanking-aspsp by OpenBankingToolkit.
the class DomesticStandingOrdersApiController method createDomesticStandingOrders.
public ResponseEntity<OBWriteDomesticStandingOrderResponse6> 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(), OBWriteDomesticStandingOrderResponse6.class, obWriteDomesticStandingOrder3);
});
}
use of uk.org.openbanking.datamodel.payment.OBWriteDomesticStandingOrderResponse6 in project openbanking-aspsp by OpenBankingToolkit.
the class DomesticStandingOrdersApiController method responseEntity.
private OBWriteDomesticStandingOrderResponse6 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 OBWriteDomesticStandingOrderResponse6().data(new OBWriteDomesticStandingOrderResponse6Data().domesticStandingOrderId(frPaymentSubmission.getId()).initiation(toOBWriteDomesticStandingOrderConsentResponse6DataInitiation(initiation)).creationDateTime(frDomesticStandingOrderConsent.getCreated()).statusUpdateDateTime(frDomesticStandingOrderConsent.getStatusUpdate()).status(toOBWriteDomesticStandingOrderResponse6DataStatus(frDomesticStandingOrderConsent.getStatus())).debtor(toOBCashAccountDebtor4(frDomesticStandingOrderConsent.getInitiation().getDebtorAccount())).consentId(frDomesticStandingOrderConsent.getId()).refund(refund.map(FRResponseDataRefundConverter::toOBWriteDomesticResponse5DataRefund).orElse(null))).links(resourceLinkService.toSelfLink(frPaymentSubmission, discovery -> getVersion(discovery).getGetDomesticStandingOrder())).meta(new Meta());
}
Aggregations