use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticStandingOrderTaskTest method shouldRejectPaymentWhenCurrencyConversionException.
@Test
public void shouldRejectPaymentWhenCurrencyConversionException() throws CurrencyConverterException {
// Given
FRStandingOrder payment = defaultPayment(StandingOrderStatus.PENDING);
given(paymentsService.getActiveStandingOrders()).willReturn(Collections.singletonList(payment));
FRAccount account = defaultAccount(DEBIT_ACCOUNT);
given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(account);
doThrow(new CurrencyConverterException("Simulated failure")).when(moneyService).moveMoney(any(), any(), any(), any(), any());
// When
acceptDueStandingOrderTask.payDueStandingOrders();
// Then
verify(moneyService).moveMoney(eq(account), any(), eq(FRCreditDebitIndicator.DEBIT), eq(payment), any());
verify(paymentsService).updateStandingOrder(argThat(p -> p.getStatus().equals(StandingOrderStatus.REJECTED)));
assertThat(payment.getRejectionReason()).isEqualTo("Can't convert amount in the right currency: Simulated failure");
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticStandingOrderTaskTest method pendingStandingOrder_firstPaymentDue_shouldDebitAccount.
@Test
public void pendingStandingOrder_firstPaymentDue_shouldDebitAccount() throws CurrencyConverterException {
// Given
FRStandingOrder payment = defaultPayment(StandingOrderStatus.PENDING);
given(paymentsService.getActiveStandingOrders()).willReturn(Collections.singletonList(payment));
FRAccount account = defaultAccount(DEBIT_ACCOUNT);
given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(account);
// When
acceptDueStandingOrderTask.payDueStandingOrders();
// Then
verify(moneyService).moveMoney(eq(account), any(), eq(FRCreditDebitIndicator.DEBIT), eq(payment), any());
verify(paymentsService).updateStandingOrder(argThat(p -> p.getStatus().equals(StandingOrderStatus.ACTIVE)));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticStandingOrderTaskTest method pendingStandingOrder_recurringPaymentDue_shouldDebitAccount.
@Test
public void pendingStandingOrder_recurringPaymentDue_shouldDebitAccount() throws CurrencyConverterException {
// Given
FRStandingOrder payment = defaultPayment(StandingOrderStatus.ACTIVE);
given(paymentsService.getActiveStandingOrders()).willReturn(Collections.singletonList(payment));
FRAccount account = defaultAccount(DEBIT_ACCOUNT);
given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(account);
given(frequencyService.getNextDateTime(any(), any())).willReturn(DateTime.now().minusDays(1));
// When
acceptDueStandingOrderTask.payDueStandingOrders();
// Then
verify(moneyService).moveMoney(eq(account), any(), eq(FRCreditDebitIndicator.DEBIT), eq(payment), any());
verify(paymentsService).updateStandingOrder(argThat(p -> p.getStatus().equals(StandingOrderStatus.ACTIVE)));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptInternationalPaymentTaskTest method shouldCreditAccount.
@Test
public void shouldCreditAccount() throws CurrencyConverterException {
// Given
FRInternationalConsent payment = defaultPayment();
given(paymentsService.getAllPaymentsInProcess()).willReturn(Collections.singleton(payment));
given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(defaultAccount(DEBIT_ACCOUNT));
FRAccount account = defaultAccount(CREDIT_ACCOUNT);
given(account2StoreService.findAccountByIdentification(CREDIT_ACCOUNT)).willReturn(Optional.of(account));
// When
acceptDomesticPaymentTask.autoAcceptPayment();
// Then
FRAmount amount = payment.getInitiation().getInstructedAmount();
verify(moneyService).moveMoney(eq(account), eq(amount), eq(FRCreditDebitIndicator.CREDIT), eq(payment), any());
verify(paymentsService).updatePayment(argThat(p -> p.getStatus().equals(ConsentStatusCode.ACCEPTEDSETTLEMENTCOMPLETED)));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount 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)));
}
Aggregations