use of com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptSinglePaymentTaskTest method shouldRejectPaymentWhenAnyException.
@Test
public void shouldRejectPaymentWhenAnyException() throws CurrencyConverterException {
// Given
FRPaymentSetup payment = defaultPayment();
given(paymentsService.getAllPaymentsInProcess()).willReturn(Collections.singleton(payment));
FRAccount account = defaultAccount(DEBIT_ACCOUNT);
given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(account);
doThrow(new RuntimeException()).when(moneyService).moveMoney(any(), any(), any(), any(), any());
// When
autoAcceptPaymentTask.autoAcceptPayment();
// Then
FRAmount instructedAmount = payment.getInitiation().getInstructedAmount();
verify(moneyService).moveMoney(eq(account), eq(instructedAmount), eq(FRCreditDebitIndicator.DEBIT), eq(payment), any());
verify(paymentsService).updatePayment(argThat(p -> p.getStatus().equals(ConsentStatusCode.REJECTED)));
}
use of com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptSinglePaymentTaskTest method shouldRejectPaymentWhenCurrencyConversionException.
@Test
public void shouldRejectPaymentWhenCurrencyConversionException() throws CurrencyConverterException {
// Given
FRPaymentSetup payment = defaultPayment();
given(paymentsService.getAllPaymentsInProcess()).willReturn(Collections.singleton(payment));
FRAccount account = defaultAccount(DEBIT_ACCOUNT);
given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(account);
doThrow(CurrencyConverterException.class).when(moneyService).moveMoney(any(), any(), any(), any(), any());
// When
autoAcceptPaymentTask.autoAcceptPayment();
// Then
FRAmount instructedAmount = payment.getInitiation().getInstructedAmount();
verify(moneyService).moveMoney(eq(account), eq(instructedAmount), eq(FRCreditDebitIndicator.DEBIT), eq(payment), any());
verify(paymentsService).updatePayment(argThat(p -> p.getStatus().equals(ConsentStatusCode.REJECTED)));
}
use of com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount in project openbanking-aspsp by OpenBankingToolkit.
the class RCSFilePaymentDetailsApiTest method validFilePayment_noAccountSpecified_createConsentDetailsWithAllAccounts.
@Test
public void validFilePayment_noAccountSpecified_createConsentDetailsWithAllAccounts() throws Exception {
// Given
List<AccountWithBalance> accounts = singletonList(DEBTOR_ACCOUNT);
FRWriteFileConsentData data = FRWriteFileConsentData.builder().initiation(getValidOBFile().build()).build();
FRWriteFileConsent writeFileConsent = FRWriteFileConsent.builder().data(data).build();
FRAmount amount = FRAmount.builder().currency("GBP").build();
given(paymentService.getPayment(eq(CONSENT_ID))).willReturn(FRFileConsent.builder().id(CONSENT_ID).writeFileConsent(writeFileConsent).pispId(PISP_ID).pispName(PISP_NAME).payments(Arrays.asList(FRFilePayment.builder().instructedAmount(amount).build())).build());
givenTppExists();
// When
ResponseEntity response = rcsFilePaymentDetailsApi.consentDetails("", accounts, USERNAME, CONSENT_ID, CLIENT_ID);
// Then
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
FilePaymentConsentDetails consentDetails = (FilePaymentConsentDetails) Objects.requireNonNull(response.getBody());
assertThat(consentDetails.getAccounts()).isEqualTo(accounts);
assertThat(consentDetails.getClientId()).isEqualTo(CLIENT_ID);
assertThat(consentDetails.getNumberOfTransactions()).isEqualTo("19");
assertThat(consentDetails.getMerchantName()).isEqualTo(PISP_NAME);
verify(paymentService, times(1)).getPayment(any());
}
use of com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount in project openbanking-aspsp by OpenBankingToolkit.
the class RCSFilePaymentDetailsApiTest method validFilePayment_accountSpecifiedAndFound_createConsentDetailsWithAllAccounts.
@Test
public void validFilePayment_accountSpecifiedAndFound_createConsentDetailsWithAllAccounts() throws Exception {
// Given
List<AccountWithBalance> accounts = singletonList(DEBTOR_ACCOUNT);
FRWriteFileDataInitiation validOBFileWithAccount = getValidOBFile().debtorAccount(FRAccountIdentifier.builder().identification("123").build()).build();
FRWriteFileConsent frWriteFileConsent = FRWriteFileConsent.builder().data(FRWriteFileConsentData.builder().initiation(validOBFileWithAccount).build()).build();
FRAmount amount = FRAmount.builder().currency("GBP").build();
given(paymentService.getPayment(eq(CONSENT_ID))).willReturn(FRFileConsent.builder().id(CONSENT_ID).writeFileConsent(frWriteFileConsent).pispId(PISP_ID).pispName(PISP_NAME).payments(singletonList(FRFilePayment.builder().instructedAmount(amount).build())).build());
givenTppExists();
given(accountService.findAccountByIdentification(any(), any())).willReturn(Optional.of(DEBTOR_ACCOUNT));
// When
ResponseEntity response = rcsFilePaymentDetailsApi.consentDetails("", accounts, USERNAME, CONSENT_ID, CLIENT_ID);
// Then
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
FilePaymentConsentDetails consentDetails = (FilePaymentConsentDetails) Objects.requireNonNull(response.getBody());
assertThat(consentDetails.getAccounts()).isEqualTo(accounts);
assertThat(consentDetails.getClientId()).isEqualTo(CLIENT_ID);
assertThat(consentDetails.getNumberOfTransactions()).isEqualTo("19");
assertThat(consentDetails.getMerchantName()).isEqualTo(PISP_NAME);
verify(paymentService, times(1)).getPayment(any());
}
use of com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticPaymentTaskTest method shouldDebitAccount.
@Test
public void shouldDebitAccount() throws CurrencyConverterException {
// Given
FRDomesticConsent payment = defaultPayment();
given(paymentsService.getAllPaymentsInProcess()).willReturn(Collections.singleton(payment));
FRAccount account = defaultAccount(DEBIT_ACCOUNT);
given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(account);
FRAmount instructedAmount = payment.getInitiation().getInstructedAmount();
// When
acceptDomesticPaymentTask.autoAcceptPayment();
// Then
verify(moneyService).moveMoney(eq(account), eq(instructedAmount), eq(FRCreditDebitIndicator.DEBIT), eq(payment), any());
verify(paymentsService).updatePayment(argThat(p -> p.getStatus().equals(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED)));
}
Aggregations