Search in sources :

Example 1 with SinglePaymentConsentDecision

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);
    }
}
Also used : SinglePaymentService(com.forgerock.openbanking.common.services.store.payment.SinglePaymentService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) OBRIErrorType(com.forgerock.openbanking.model.error.OBRIErrorType) IOException(java.io.IOException) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) AccountStoreService(com.forgerock.openbanking.common.services.store.account.AccountStoreService) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) Optional(java.util.Optional) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup) ConsentDecisionDelegate(com.forgerock.openbanking.aspsp.rs.rcs.api.rcs.decisions.ConsentDecisionDelegate) SinglePaymentConsentDecision(com.forgerock.openbanking.common.model.rcs.consentdecision.SinglePaymentConsentDecision) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) SinglePaymentConsentDecision(com.forgerock.openbanking.common.model.rcs.consentdecision.SinglePaymentConsentDecision) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ConsentDecisionDelegate (com.forgerock.openbanking.aspsp.rs.rcs.api.rcs.decisions.ConsentDecisionDelegate)1 FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)1 ConsentStatusCode (com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode)1 FRPaymentSetup (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup)1 SinglePaymentConsentDecision (com.forgerock.openbanking.common.model.rcs.consentdecision.SinglePaymentConsentDecision)1 AccountStoreService (com.forgerock.openbanking.common.services.store.account.AccountStoreService)1 SinglePaymentService (com.forgerock.openbanking.common.services.store.payment.SinglePaymentService)1 OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)1 OBRIErrorType (com.forgerock.openbanking.model.error.OBRIErrorType)1 IOException (java.io.IOException)1 List (java.util.List)1 Optional (java.util.Optional)1 Slf4j (lombok.extern.slf4j.Slf4j)1