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