Search in sources :

Example 1 with AccountWithBalance

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance in project openbanking-aspsp by OpenBankingToolkit.

the class RCSFilePaymentDetailsApi method consentDetails.

@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
    log.debug("Received a consent request with consent_request='{}'", remoteConsentRequest);
    log.debug("=> The payment id '{}'", consentId);
    log.debug("Populate the model with the payment and consent data");
    FRFileConsent consent = paymentService.getPayment(consentId);
    checkValidPisp(consent, clientId);
    // A null debtor account will let PSU select account when authorising
    if (consent.getInitiation().getDebtorAccount() != null) {
        Optional<AccountWithBalance> matchingUserAccount = accountService.findAccountByIdentification(consent.getInitiation().getDebtorAccount().getIdentification(), accounts);
        if (!matchingUserAccount.isPresent()) {
            log.error("The PISP '{}' created the payment consent '{}' but the debtor account: {} on the consent " + " is not one of the user's accounts: {}.", consent.getPispId(), consent.getId(), consent.getInitiation().getDebtorAccount(), accounts);
            return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_DEBTOR_ACCOUNT_NOT_FOUND, consent.getPispId(), consent.getId(), accounts);
        } else {
            accounts = Collections.singletonList(matchingUserAccount.get());
        }
    }
    associatePaymentToUser(consent, username);
    Optional<Tpp> isTpp = tppStoreService.findById(consent.getPispId());
    if (!isTpp.isPresent()) {
        log.error("The TPP '{}' (Client ID {}) that created this consent id '{}' doesn't exist anymore.", consent.getPispId(), clientId, consentId);
        return rcsErrorService.error(OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
    }
    Tpp tpp = isTpp.get();
    FRWriteFileDataInitiation initiation = consent.getWriteFileConsent().getData().getInitiation();
    return ResponseEntity.ok(FilePaymentConsentDetails.builder().accounts(accounts).username(username).merchantName(consent.getPispName()).clientId(clientId).fileReference(initiation.getFileReference()).numberOfTransactions(initiation.getNumberOfTransactions()).totalAmount(new OBActiveOrHistoricCurrencyAndAmount().amount(initiation.getControlSum().toPlainString()).currency(consent.getPayments().get(0).getInstructedAmount().getCurrency())).requestedExecutionDateTime(initiation.getRequestedExecutionDateTime()).paymentReference(Optional.ofNullable(initiation.getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse("")).build());
}
Also used : FRRemittanceInformation(com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRRemittanceInformation) OBActiveOrHistoricCurrencyAndAmount(uk.org.openbanking.datamodel.payment.OBActiveOrHistoricCurrencyAndAmount) FRFileConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRFileConsent) Tpp(com.forgerock.openbanking.model.Tpp) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) FRWriteFileDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation)

Example 2 with AccountWithBalance

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance in project openbanking-aspsp by OpenBankingToolkit.

the class RCSInternationalPaymentDetailsApi method consentDetails.

@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
    log.debug("Received a consent request with consent_request='{}'", remoteConsentRequest);
    log.debug("=> The payment id '{}'", consentId);
    log.debug("Populate the model with the payment and consent data");
    FRInternationalConsent payment = paymentService.getPayment(consentId);
    // Only show the debtor account if specified in consent
    if (payment.getInitiation().getDebtorAccount() != null) {
        Optional<AccountWithBalance> matchingUserAccount = accountService.findAccountByIdentification(payment.getInitiation().getDebtorAccount().getIdentification(), accounts);
        if (matchingUserAccount.isEmpty()) {
            log.error("The PISP '{}' created the payment request '{}' but the debtor account: {} on the payment consent " + " is not one of the user's accounts: {}.", payment.getPispId(), consentId, payment.getInitiation().getDebtorAccount(), accounts);
            return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_DEBTOR_ACCOUNT_NOT_FOUND, payment.getPispId(), consentId, accounts);
        }
        accounts = Collections.singletonList(matchingUserAccount.get());
    }
    Optional<Tpp> isTpp = tppStoreService.findById(payment.getPispId());
    if (isTpp.isEmpty()) {
        log.error("The TPP '{}' (Client ID {}) that created this consent id '{}' doesn't exist anymore.", payment.getPispId(), clientId, consentId);
        return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
    }
    Tpp tpp = isTpp.get();
    // Verify the pisp is the same than the one that created this payment ^
    verifyTppCreatedPayment(clientId, isTpp.get().getClientId(), consentId);
    // Associate the payment to this user
    payment.setUserId(username);
    paymentService.updatePayment(payment);
    FRWriteInternationalDataInitiation initiation = payment.getInitiation();
    FRExchangeRateInformation exchangeRateInformation = payment.getCalculatedExchangeRate();
    InternationalPaymentConsentDetails internationalPaymentConsentDetails = InternationalPaymentConsentDetails.builder().instructedAmount(toOBActiveOrHistoricCurrencyAndAmount(initiation.getInstructedAmount())).accounts(accounts).username(username).logo(tpp.getLogo()).merchantName(payment.getPispName()).clientId(clientId).currencyOfTransfer(initiation.getCurrencyOfTransfer()).paymentReference(Optional.ofNullable(initiation.getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse("")).build();
    // fix issue https://github.com/OpenBankingToolkit/openbanking-toolkit/issues/13
    if (exchangeRateInformation != null) {
        internationalPaymentConsentDetails.setRate(new OBExchangeRate2().exchangeRate(exchangeRateInformation.getExchangeRate()).rateType(toOBExchangeRateType2Code(exchangeRateInformation.getRateType())).contractIdentification(exchangeRateInformation.getContractIdentification()).unitCurrency(exchangeRateInformation.getUnitCurrency()));
    }
    // issue fix
    return ResponseEntity.ok(internationalPaymentConsentDetails);
}
Also used : OBExchangeRate2(uk.org.openbanking.datamodel.payment.OBExchangeRate2) Tpp(com.forgerock.openbanking.model.Tpp) FRInternationalConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent) FRWriteInternationalDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalDataInitiation) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) InternationalPaymentConsentDetails(com.forgerock.openbanking.common.model.rcs.consentdetails.InternationalPaymentConsentDetails) FRExchangeRateInformation(com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRExchangeRateInformation)

Example 3 with AccountWithBalance

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance in project openbanking-aspsp by OpenBankingToolkit.

the class RCSInternationalScheduledPaymentDetailsApi method consentDetails.

@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
    log.debug("Received a consent request with consent_request='{}'", remoteConsentRequest);
    log.debug("=> The payment id '{}'", consentId);
    log.debug("Populate the model with the payment and consent data");
    FRInternationalScheduledConsent payment = paymentService.getPayment(consentId);
    // Only show the debtor account if specified in consent
    if (payment.getInitiation().getDebtorAccount() != null) {
        Optional<AccountWithBalance> matchingUserAccount = accountService.findAccountByIdentification(payment.getInitiation().getDebtorAccount().getIdentification(), accounts);
        if (!matchingUserAccount.isPresent()) {
            log.error("The PISP '{}' created the payment request '{}' but the debtor account: {} on the payment consent " + " is not one of the user's accounts: {}.", payment.getPispId(), consentId, payment.getInitiation().getDebtorAccount(), accounts);
            return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_DEBTOR_ACCOUNT_NOT_FOUND, payment.getPispId(), consentId, accounts);
        }
        accounts = Collections.singletonList(matchingUserAccount.get());
    }
    Optional<Tpp> isTpp = tppStoreService.findById(payment.getPispId());
    if (!isTpp.isPresent()) {
        log.error("The TPP '{}' (Client ID {}) that created this consent id '{}' doesn't exist anymore.", payment.getPispId(), clientId, consentId);
        return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
    }
    Tpp tpp = isTpp.get();
    // Verify the pisp is the same than the one that created this payment ^
    verifyTppCreatedPayment(clientId, isTpp.get().getClientId(), consentId);
    // Associate the payment to this user
    payment.setUserId(username);
    paymentService.updatePayment(payment);
    final FRWriteInternationalScheduledDataInitiation initiation = payment.getInitiation();
    final OBScheduledPayment1 obScheduledPayment = new OBScheduledPayment1().accountId(payment.getAccountId()).scheduledPaymentId(initiation.getInstructionIdentification()).scheduledPaymentDateTime(initiation.getRequestedExecutionDateTime()).creditorAccount(toOBCashAccount3(initiation.getCreditorAccount())).instructedAmount(toOBActiveOrHistoricCurrencyAndAmount(initiation.getInstructedAmount())).reference(initiation.getRemittanceInformation().getReference());
    FRExchangeRateInformation exchangeRateInformation = payment.getCalculatedExchangeRate();
    return ResponseEntity.ok(InternationalSchedulePaymentConsentDetails.builder().scheduledPayment(obScheduledPayment).rate(new OBExchangeRate2().exchangeRate(exchangeRateInformation.getExchangeRate()).rateType(toOBExchangeRateType2Code(exchangeRateInformation.getRateType())).contractIdentification(exchangeRateInformation.getContractIdentification()).unitCurrency(exchangeRateInformation.getUnitCurrency())).accounts(accounts).username(username).logo(tpp.getLogo()).merchantName(payment.getPispName()).clientId(clientId).currencyOfTransfer(initiation.getCurrencyOfTransfer()).paymentReference(Optional.ofNullable(initiation.getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse("")).build());
}
Also used : FRRemittanceInformation(com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRRemittanceInformation) OBExchangeRate2(uk.org.openbanking.datamodel.payment.OBExchangeRate2) FRWriteInternationalScheduledDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalScheduledDataInitiation) Tpp(com.forgerock.openbanking.model.Tpp) OBScheduledPayment1(uk.org.openbanking.datamodel.account.OBScheduledPayment1) FRInternationalScheduledConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalScheduledConsent) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) FRExchangeRateInformation(com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRExchangeRateInformation)

Example 4 with AccountWithBalance

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance in project openbanking-aspsp by OpenBankingToolkit.

the class RCSDomesticPaymentDetailsApi method consentDetails.

@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
    log.debug("Received a consent request with consent_request='{}'", remoteConsentRequest);
    log.debug("=> The payment id '{}'", consentId);
    log.debug("Populate the model with the payment and consent data");
    FRDomesticConsent domesticConsent = paymentService.getPayment(consentId);
    // Only show the debtor account if specified in consent
    if (domesticConsent.getInitiation().getDebtorAccount() != null) {
        Optional<AccountWithBalance> matchingUserAccount = accountService.findAccountByIdentification(domesticConsent.getInitiation().getDebtorAccount().getIdentification(), accounts);
        if (matchingUserAccount.isEmpty()) {
            log.error("The PISP '{}' created the payment request '{}' but the debtor account: {} on the payment consent " + " is not one of the user's accounts: {}.", domesticConsent.getPispId(), consentId, domesticConsent.getInitiation().getDebtorAccount(), accounts);
            return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_DEBTOR_ACCOUNT_NOT_FOUND, domesticConsent.getPispId(), consentId, accounts);
        }
        accounts = Collections.singletonList(matchingUserAccount.get());
    }
    Optional<Tpp> isTpp = tppStoreService.findById(domesticConsent.getPispId());
    if (isTpp.isEmpty()) {
        log.error("The TPP '{}' (Client ID {}) that created this consent id '{}' doesn't exist anymore.", domesticConsent.getPispId(), clientId, consentId);
        return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
    }
    Tpp tpp = isTpp.get();
    // Verify the pisp is the same than the one that created this payment ^
    verifyTppCreatedPayment(clientId, tpp.getClientId(), consentId);
    // Associate the payment to this user
    domesticConsent.setUserId(username);
    paymentService.updatePayment(domesticConsent);
    return ResponseEntity.ok(DomesticPaymentConsentDetails.builder().instructedAmount(toOBActiveOrHistoricCurrencyAndAmount(domesticConsent.getInitiation().getInstructedAmount())).accounts(accounts).username(username).logo(tpp.getLogo()).merchantName(domesticConsent.getPispName()).clientId(clientId).paymentReference(Optional.ofNullable(domesticConsent.getInitiation().getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse("")).build());
}
Also used : FRRemittanceInformation(com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRRemittanceInformation) Tpp(com.forgerock.openbanking.model.Tpp) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance)

Example 5 with AccountWithBalance

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance in project openbanking-aspsp by OpenBankingToolkit.

the class RCSDomesticSchedulePaymentDetailsApi method consentDetails.

@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
    log.debug("Received a consent request with consent_request='{}'", remoteConsentRequest);
    log.debug("=> The payment id '{}'", consentId);
    log.debug("Populate the model with the payment and consent data");
    FRDomesticScheduledConsent domesticConsent = paymentService.getPayment(consentId);
    // Only show the debtor account if specified in consent
    if (domesticConsent.getInitiation().getDebtorAccount() != null) {
        Optional<AccountWithBalance> matchingUserAccount = accountService.findAccountByIdentification(domesticConsent.getInitiation().getDebtorAccount().getIdentification(), accounts);
        if (!matchingUserAccount.isPresent()) {
            log.error("The PISP '{}' created the payment request '{}' but the debtor account: {} on the payment consent " + " is not one of the user's accounts: {}.", domesticConsent.getPispId(), consentId, domesticConsent.getInitiation().getDebtorAccount(), accounts);
            return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_DEBTOR_ACCOUNT_NOT_FOUND, domesticConsent.getPispId(), consentId, accounts);
        }
        accounts = Collections.singletonList(matchingUserAccount.get());
    }
    Optional<Tpp> isTpp = tppStoreService.findById(domesticConsent.getPispId());
    if (!isTpp.isPresent()) {
        log.error("The TPP '{}' (Client ID {}) that created this consent id '{}' doesn't exist anymore.", domesticConsent.getPispId(), clientId, consentId);
        return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
    }
    Tpp tpp = isTpp.get();
    // Verify the pisp is the same than the one that created this payment ^
    verifyTppCreatedPayment(clientId, isTpp.get().getClientId(), consentId);
    // Associate the payment to this user
    domesticConsent.setUserId(username);
    paymentService.updatePayment(domesticConsent);
    FRWriteDomesticScheduledDataInitiation domesticScheduled = domesticConsent.getInitiation();
    OBScheduledPayment1 obScheduledPayment1 = new OBScheduledPayment1().accountId(domesticConsent.getAccountId()).scheduledPaymentId(domesticScheduled.getInstructionIdentification()).scheduledPaymentDateTime(domesticScheduled.getRequestedExecutionDateTime()).creditorAccount(toOBCashAccount3(domesticScheduled.getCreditorAccount())).instructedAmount(toOBActiveOrHistoricCurrencyAndAmount(domesticScheduled.getInstructedAmount())).reference(domesticScheduled.getRemittanceInformation().getReference());
    return ResponseEntity.ok(DomesticSchedulePaymentConsentDetails.builder().scheduledPayment(obScheduledPayment1).accounts(accounts).username(username).logo(tpp.getLogo()).merchantName(domesticConsent.getPispName()).clientId(clientId).paymentReference(Optional.ofNullable(domesticConsent.getInitiation().getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse("")).build());
}
Also used : FRRemittanceInformation(com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRRemittanceInformation) FRWriteDomesticScheduledDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticScheduledDataInitiation) FRDomesticScheduledConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticScheduledConsent) Tpp(com.forgerock.openbanking.model.Tpp) OBScheduledPayment1(uk.org.openbanking.datamodel.account.OBScheduledPayment1) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance)

Aggregations

AccountWithBalance (com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance)30 Test (org.junit.Test)20 ResponseEntity (org.springframework.http.ResponseEntity)20 FRAccountIdentifier (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier)11 Tpp (com.forgerock.openbanking.model.Tpp)8 FRInternationalConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalConsent)7 InternationalPaymentConsentDetails (com.forgerock.openbanking.common.model.rcs.consentdetails.InternationalPaymentConsentDetails)7 List (java.util.List)5 FRRemittanceInformation (com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRRemittanceInformation)4 FRInternationalScheduledConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalScheduledConsent)4 FRWriteFileConsent (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileConsent)3 FRWriteFileDataInitiation (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation)3 FRExchangeRateInformation (com.forgerock.openbanking.common.model.openbanking.domain.payment.common.FRExchangeRateInformation)3 FRDomesticConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)3 FRDomesticScheduledConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticScheduledConsent)3 FRDomesticStandingOrderConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticStandingOrderConsent)3 FRInternationalStandingOrderConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderConsent)3 InternationalSchedulePaymentConsentDetails (com.forgerock.openbanking.common.model.rcs.consentdetails.InternationalSchedulePaymentConsentDetails)3 OBExchangeRate2 (uk.org.openbanking.datamodel.payment.OBExchangeRate2)3 FRAmount (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount)2