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;
}
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);
}
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());
}
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);
}
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());
}
Aggregations