Search in sources :

Example 61 with Tpp

use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.

the class PaymentTestHelper method setupMockTpp.

public static Tpp setupMockTpp(TppRepository tppRepository) {
    Tpp tpp = new Tpp();
    tpp.officialName = MOCK_PISP_NAME;
    tpp.id = MOCK_PISP_ID;
    when(tppRepository.findByClientId(eq(MOCK_CLIENT_ID))).thenReturn(tpp);
    return tpp;
}
Also used : Tpp(com.forgerock.openbanking.model.Tpp)

Example 62 with Tpp

use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.

the class CallbackUrlsApiControllerIT method setUp.

@Before
public void setUp() {
    tpp = new Tpp();
    tpp.setId(UUID.randomUUID().toString());
    given(tppRepository.findByClientId(any())).willReturn(tpp);
    clientId = UUID.randomUUID().toString();
    Unirest.config().setObjectMapper(new JacksonObjectMapper(objectMapper)).verifySsl(false);
}
Also used : Tpp(com.forgerock.openbanking.model.Tpp) JacksonObjectMapper(kong.unirest.JacksonObjectMapper) Before(org.junit.Before)

Example 63 with Tpp

use of com.forgerock.openbanking.model.Tpp 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 64 with Tpp

use of com.forgerock.openbanking.model.Tpp 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 65 with Tpp

use of com.forgerock.openbanking.model.Tpp 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)

Aggregations

Tpp (com.forgerock.openbanking.model.Tpp)131 ConsentStatusEntry (com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry)39 Test (org.junit.Test)28 OIDCRegistrationResponse (com.forgerock.openbanking.model.oidc.OIDCRegistrationResponse)19 Before (org.junit.Before)13 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 JacksonObjectMapper (kong.unirest.JacksonObjectMapper)11 OAuth2InvalidClientException (com.forgerock.openbanking.common.error.exception.oauth2.OAuth2InvalidClientException)9 OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)9 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)9 AccountWithBalance (com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance)8 URI (java.net.URI)8 FRInternationalStandingOrderConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRInternationalStandingOrderConsent)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)7 FRWriteInternationalStandingOrderConsent (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteInternationalStandingOrderConsent)6 FRDomesticConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)6 FRDomesticScheduledConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticScheduledConsent)6 FRDomesticStandingOrderConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticStandingOrderConsent)6