Search in sources :

Example 6 with FRAmount

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)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SinglePaymentService(com.forgerock.openbanking.common.services.store.payment.SinglePaymentService) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) FRWriteDomesticDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticDataInitiation) AccountStoreService(com.forgerock.openbanking.common.services.store.account.AccountStoreService) Mockito.doThrow(org.mockito.Mockito.doThrow) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) BDDMockito.given(org.mockito.BDDMockito.given) FRCreditDebitIndicator(com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup) MoneyService(com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) InjectMocks(org.mockito.InjectMocks) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) FRWriteDomesticConsentData(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsentData) FRWriteDomesticConsent(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsent) Test(org.junit.Test) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) Mockito.verify(org.mockito.Mockito.verify) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) 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) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup) Test(org.junit.Test)

Example 7 with FRAmount

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)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SinglePaymentService(com.forgerock.openbanking.common.services.store.payment.SinglePaymentService) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) FRWriteDomesticDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticDataInitiation) AccountStoreService(com.forgerock.openbanking.common.services.store.account.AccountStoreService) Mockito.doThrow(org.mockito.Mockito.doThrow) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) BDDMockito.given(org.mockito.BDDMockito.given) FRCreditDebitIndicator(com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup) MoneyService(com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) InjectMocks(org.mockito.InjectMocks) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) FRWriteDomesticConsentData(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsentData) FRWriteDomesticConsent(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsent) Test(org.junit.Test) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) Mockito.verify(org.mockito.Mockito.verify) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) 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) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) FRPaymentSetup(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRPaymentSetup) Test(org.junit.Test)

Example 8 with FRAmount

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());
}
Also used : FilePaymentConsentDetails(com.forgerock.openbanking.common.model.rcs.consentdetails.FilePaymentConsentDetails) ResponseEntity(org.springframework.http.ResponseEntity) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) FRWriteFileConsent(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileConsent) FRWriteFileConsentData(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileConsentData) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) Test(org.junit.Test)

Example 9 with FRAmount

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());
}
Also used : FilePaymentConsentDetails(com.forgerock.openbanking.common.model.rcs.consentdetails.FilePaymentConsentDetails) ResponseEntity(org.springframework.http.ResponseEntity) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) FRWriteFileConsent(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileConsent) AccountWithBalance(com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountWithBalance) FRWriteFileDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteFileDataInitiation) Test(org.junit.Test)

Example 10 with FRAmount

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)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) FRWriteDomesticDataInitiation(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticDataInitiation) AccountStoreService(com.forgerock.openbanking.common.services.store.account.AccountStoreService) Mockito.doThrow(org.mockito.Mockito.doThrow) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) 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) InjectMocks(org.mockito.InjectMocks) DomesticPaymentService(com.forgerock.openbanking.common.services.store.payment.DomesticPaymentService) FRAccountIdentifier(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier) FRWriteDomesticConsentData(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsentData) FRWriteDomesticConsent(com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsent) Test(org.junit.Test) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) Mockito.verify(org.mockito.Mockito.verify) CurrencyConverterException(com.tunyk.currencyconverter.api.CurrencyConverterException) Optional(java.util.Optional) PaymentNotificationFacade(com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRAmount(com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) Test(org.junit.Test)

Aggregations

FRAmount (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount)17 Test (org.junit.Test)17 FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)13 MoneyService (com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService)12 PaymentNotificationFacade (com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade)12 FRCreditDebitIndicator (com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator)12 FRAccountIdentifier (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier)12 ConsentStatusCode (com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode)12 AccountStoreService (com.forgerock.openbanking.common.services.store.account.AccountStoreService)12 CurrencyConverterException (com.tunyk.currencyconverter.api.CurrencyConverterException)12 Collections (java.util.Collections)12 Optional (java.util.Optional)12 RunWith (org.junit.runner.RunWith)12 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)12 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)12 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)12 BDDMockito.given (org.mockito.BDDMockito.given)12 InjectMocks (org.mockito.InjectMocks)12 Mock (org.mockito.Mock)12 Mockito.doThrow (org.mockito.Mockito.doThrow)12