use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticPaymentTaskTest method shouldRejectPaymentWhenCurrencyConversionException.
@Test
public void shouldRejectPaymentWhenCurrencyConversionException() 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);
doThrow(CurrencyConverterException.class).when(moneyService).moveMoney(any(), any(), any(), any(), any());
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.REJECTED)));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticPaymentTaskTest method shouldCreditAccount.
@Test
public void shouldCreditAccount() throws CurrencyConverterException {
// Given
FRDomesticConsent 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));
FRAmount instructedAmount = payment.getInitiation().getInstructedAmount();
// When
acceptDomesticPaymentTask.autoAcceptPayment();
// Then
verify(moneyService).moveMoney(eq(account), eq(instructedAmount), 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 AcceptDomesticScheduledPaymentTaskTest method scheduledPaymentDue_shouldDebitAccount.
@Test
public void scheduledPaymentDue_shouldDebitAccount() throws CurrencyConverterException {
// Given
FRScheduledPayment payment = defaultPayment(DateTime.now().minusDays(1), ScheduledPaymentStatus.PENDING);
given(paymentsService.getPendingAndDueScheduledPayments()).willReturn(Collections.singletonList(payment));
FRAccount account = defaultAccount(DEBIT_ACCOUNT);
given(account2StoreService.getAccount(DEBIT_ACCOUNT)).willReturn(account);
// When
acceptDueScheduledPaymentTask.payDueScheduledPayments();
// Then
verify(moneyService).moveMoney(eq(account), eq(payment.getScheduledPayment().getInstructedAmount()), eq(FRCreditDebitIndicator.DEBIT), eq(payment), any());
verify(paymentsService).updateSchedulePayment(argThat(p -> p.getStatus().equals(ScheduledPaymentStatus.COMPLETED)));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.
the class AcceptDomesticStandingOrderTaskTest method shouldRejectPaymentWhenAnyException.
@Test
public void shouldRejectPaymentWhenAnyException() 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 RuntimeException("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("Failed to execute payment: 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_shouldCreditAccount.
@Test
public void pendingStandingOrder_firstPaymentDue_shouldCreditAccount() throws CurrencyConverterException {
// Given
FRStandingOrder payment = defaultPayment(StandingOrderStatus.PENDING);
given(paymentsService.getActiveStandingOrders()).willReturn(Collections.singletonList(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
acceptDueStandingOrderTask.payDueStandingOrders();
// Then
verify(moneyService).moveMoney(eq(account), any(), eq(FRCreditDebitIndicator.CREDIT), eq(payment), any());
verify(paymentsService).updateStandingOrder(argThat(p -> p.getStatus().equals(StandingOrderStatus.ACTIVE)));
}
Aggregations