use of com.forgerock.openbanking.common.model.rcs.consentdecision.SinglePaymentConsentDecision in project openbanking-aspsp by OpenBankingToolkit.
the class SinglePaymentConsentDecisionDelegate method consentDecision.
@Override
public void consentDecision(String consentDecisionSerialised, boolean decision) throws IOException, OBErrorException {
SinglePaymentConsentDecision singlePaymentConsentDecision = objectMapper.readValue(consentDecisionSerialised, SinglePaymentConsentDecision.class);
if (decision) {
List<FRAccount> accounts = accountsService.get(getUserIDBehindConsent());
Optional<FRAccount> isAny = accounts.stream().filter(account -> account.getId().equals(singlePaymentConsentDecision.getAccountId())).findAny();
if (!isAny.isPresent()) {
log.error("The account selected {} is not own by this user {}. List accounts {}", singlePaymentConsentDecision.getAccountId(), getUserIDBehindConsent(), accounts);
throw new OBErrorException(OBRIErrorType.RCS_CONSENT_DECISION_INVALID_ACCOUNT, getUserIDBehindConsent(), singlePaymentConsentDecision.getAccountId(), accounts);
}
payment.setStatus(ConsentStatusCode.ACCEPTEDCUSTOMERPROFILE);
payment.setAccountId(singlePaymentConsentDecision.getAccountId());
paymentsService.updatePayment(payment);
} else {
log.debug("The current payment '{}' has been deny", payment.getId());
payment.setStatus(ConsentStatusCode.REJECTED);
paymentsService.updatePayment(payment);
}
}
Aggregations