Search in sources :

Example 11 with FRScheduledPayment

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRScheduledPayment in project openbanking-aspsp by OpenBankingToolkit.

the class AcceptDomesticScheduledPaymentTaskTest method shouldRejectPaymentWhenAnyException.

@Test
public void shouldRejectPaymentWhenAnyException() 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);
    doThrow(new RuntimeException("Simulated failure")).when(moneyService).moveMoney(any(), any(), any(), any(), any());
    // 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.REJECTED)));
    assertThat(payment.getRejectionReason()).isEqualTo("Failed to execute payment: Simulated failure");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) FRScheduledPaymentData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRScheduledPaymentData) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) ScheduledPaymentStatus(com.forgerock.openbanking.common.model.openbanking.status.ScheduledPaymentStatus) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) AccountStoreService(com.forgerock.openbanking.common.services.store.account.AccountStoreService) Mockito.doThrow(org.mockito.Mockito.doThrow) BDDMockito.given(org.mockito.BDDMockito.given) FRCreditDebitIndicator(com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator) MoneyService(com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRScheduledPayment(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRScheduledPayment) InjectMocks(org.mockito.InjectMocks) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) DateTime(org.joda.time.DateTime) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) Mockito.verify(org.mockito.Mockito.verify) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) ScheduledPaymentService(com.forgerock.openbanking.common.services.store.account.scheduledpayment.ScheduledPaymentService) Optional(java.util.Optional) PaymentNotificationFacade(com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRScheduledPayment(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRScheduledPayment) Test(org.junit.Test)

Example 12 with FRScheduledPayment

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRScheduledPayment in project openbanking-aspsp by OpenBankingToolkit.

the class AcceptDomesticScheduledPaymentTaskTest method shouldRejectPaymentWhenCurrencyConversionException.

@Test
public void shouldRejectPaymentWhenCurrencyConversionException() 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);
    doThrow(new CurrencyConverterException("Simulated failure")).when(moneyService).moveMoney(any(), any(), any(), any(), any());
    // 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.REJECTED)));
    assertThat(payment.getRejectionReason()).isEqualTo("Can't convert amount in the right currency: Simulated failure");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) FRScheduledPaymentData(com.forgerock.openbanking.common.model.openbanking.domain.account.FRScheduledPaymentData) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) ScheduledPaymentStatus(com.forgerock.openbanking.common.model.openbanking.status.ScheduledPaymentStatus) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) AccountStoreService(com.forgerock.openbanking.common.services.store.account.AccountStoreService) Mockito.doThrow(org.mockito.Mockito.doThrow) BDDMockito.given(org.mockito.BDDMockito.given) FRCreditDebitIndicator(com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator) MoneyService(com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRScheduledPayment(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRScheduledPayment) InjectMocks(org.mockito.InjectMocks) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) DateTime(org.joda.time.DateTime) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) Mockito.verify(org.mockito.Mockito.verify) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) ScheduledPaymentService(com.forgerock.openbanking.common.services.store.account.scheduledpayment.ScheduledPaymentService) Optional(java.util.Optional) PaymentNotificationFacade(com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) FRScheduledPayment(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRScheduledPayment) Test(org.junit.Test)

Example 13 with FRScheduledPayment

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRScheduledPayment in project openbanking-aspsp by OpenBankingToolkit.

the class ScheduledPaymentService method getPendingAndDueScheduledPayments.

public Collection<FRScheduledPayment> getPendingAndDueScheduledPayments() {
    log.debug("Get pending scheduled payments in the store.");
    ParameterizedTypeReference<List<FRScheduledPayment>> ptr = new ParameterizedTypeReference<List<FRScheduledPayment>>() {
    };
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(rsStoreRoot + BASE_RESOURCE_PATH + "search/find");
    builder.queryParam("status", ScheduledPaymentStatus.PENDING);
    builder.queryParam("toDate", DateTime.now().toString(ISODateTimeFormat.dateTimeNoMillis()));
    URI uri = builder.build().encode().toUri();
    log.debug("Calling URI: {}", uri);
    ResponseEntity<List<FRScheduledPayment>> entity = restTemplate.exchange(uri, HttpMethod.GET, null, ptr);
    return entity.getBody();
}
Also used : ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) FRScheduledPayment(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRScheduledPayment) List(java.util.List) URI(java.net.URI)

Example 14 with FRScheduledPayment

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRScheduledPayment in project openbanking-aspsp by OpenBankingToolkit.

the class ScheduledPaymentService method createSchedulePayment.

public void createSchedulePayment(FRScheduledPaymentData scheduledPayment, String pispId) {
    log.debug("Create a scheduled payment in the store. {}", scheduledPayment);
    FRScheduledPayment frScheduledPayment = FRScheduledPayment.builder().scheduledPayment(scheduledPayment).id(scheduledPayment.getScheduledPaymentId()).accountId(scheduledPayment.getAccountId()).status(ScheduledPaymentStatus.PENDING).pispId(pispId).build();
    restTemplate.postForObject(rsStoreRoot + BASE_RESOURCE_PATH, frScheduledPayment, String.class);
}
Also used : FRScheduledPayment(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRScheduledPayment)

Aggregations

FRScheduledPayment (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRScheduledPayment)14 Test (org.junit.Test)6 FRScheduledPaymentData (com.forgerock.openbanking.common.model.openbanking.domain.account.FRScheduledPaymentData)5 CurrencyConverterException (com.tunyk.currencyconverter.api.CurrencyConverterException)5 MoneyService (com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService)4 PaymentNotificationFacade (com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade)4 FRCreditDebitIndicator (com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator)4 FRAccountIdentifier (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier)4 FRAmount (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount)4 FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)4 ScheduledPaymentStatus (com.forgerock.openbanking.common.model.openbanking.status.ScheduledPaymentStatus)4 AccountStoreService (com.forgerock.openbanking.common.services.store.account.AccountStoreService)4 ScheduledPaymentService (com.forgerock.openbanking.common.services.store.account.scheduledpayment.ScheduledPaymentService)4 Collections (java.util.Collections)4 Optional (java.util.Optional)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 DateTime (org.joda.time.DateTime)4 RunWith (org.junit.runner.RunWith)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)4