Search in sources :

Example 6 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentApiControllerTest method getDomesticPaymentConsent.

@Test
public void getDomesticPaymentConsent() {
    // Given
    FRDomesticConsent expectedConsent = new FRDomesticConsent();
    expectedConsent.id = "expectedId123";
    when(repository.findById(eq("pay123"))).thenReturn(Optional.of(expectedConsent));
    // When
    ResponseEntity resp = controller.get("pay123");
    // Then
    assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(((FRDomesticConsent) Objects.requireNonNull(resp.getBody())).id).isEqualTo("expectedId123");
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent) Test(org.junit.Test)

Example 7 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent 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)));
}
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)

Example 8 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent 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)));
}
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)

Example 9 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentsApiController method getDomesticPaymentsDomesticPaymentId.

@Override
public ResponseEntity getDomesticPaymentsDomesticPaymentId(@ApiParam(value = "DomesticPaymentId", required = true) @PathVariable("DomesticPaymentId") String domesticPaymentId, @ApiParam(value = "The unique id of the ASPSP to which the request is issued. The unique id will be issued by OB.", required = true) @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "The time when the PSU last logged in with the TPP.  All dates in the HTTP headers are represented as RFC 7231 Full Dates. An example is below:  Sun, 10 Sep 2017 19:43:31 UTC") @RequestHeader(value = "x-fapi-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @ApiParam(value = "The PSU's IP address if the PSU is currently logged in with the TPP.") @RequestHeader(value = "x-fapi-customer-ip-address", required = false) String xFapiCustomerIpAddress, @ApiParam(value = "An RFC4122 UID used as a correlation id.") @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, @ApiParam(value = "Indicates the user-agent that the PSU is using.") @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    Optional<FRDomesticPaymentSubmission> isPaymentSubmission = domesticPaymentSubmissionRepository.findById(domesticPaymentId);
    if (!isPaymentSubmission.isPresent()) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Payment submission '" + domesticPaymentId + "' can't be found");
    }
    FRDomesticPaymentSubmission frPaymentSubmission = isPaymentSubmission.get();
    Optional<FRDomesticConsent> isPaymentSetup = domesticConsentRepository.findById(domesticPaymentId);
    if (!isPaymentSetup.isPresent()) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Payment setup behind payment submission '" + domesticPaymentId + "' can't be found");
    }
    FRDomesticConsent frPaymentSetup = isPaymentSetup.get();
    return ResponseEntity.ok(responseEntity(frPaymentSubmission, frPaymentSetup));
}
Also used : FRDomesticPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticPaymentSubmission) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)

Example 10 with FRDomesticConsent

use of com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticPaymentsApiController method getDomesticPaymentsDomesticPaymentId.

public ResponseEntity getDomesticPaymentsDomesticPaymentId(String domesticPaymentId, String authorization, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    Optional<FRDomesticPaymentSubmission> isPaymentSubmission = domesticPaymentSubmissionRepository.findById(domesticPaymentId);
    if (!isPaymentSubmission.isPresent()) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Payment submission '" + domesticPaymentId + "' can't be found");
    }
    FRDomesticPaymentSubmission frPaymentSubmission = isPaymentSubmission.get();
    Optional<FRDomesticConsent> isPaymentSetup = domesticConsentRepository.findById(domesticPaymentId);
    if (!isPaymentSetup.isPresent()) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Payment setup behind payment submission '" + domesticPaymentId + "' can't be found");
    }
    FRDomesticConsent frPaymentSetup = isPaymentSetup.get();
    return ResponseEntity.ok(responseEntity(frPaymentSubmission, frPaymentSetup));
}
Also used : FRDomesticPaymentSubmission(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticPaymentSubmission) FRDomesticConsent(com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)

Aggregations

FRDomesticConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticConsent)105 Test (org.junit.Test)62 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)50 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)49 FRDomesticPaymentSubmission (com.forgerock.openbanking.common.model.openbanking.persistence.payment.FRDomesticPaymentSubmission)37 Collections (java.util.Collections)15 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)14 FRWriteDomesticConverter.toOBWriteDomestic2 (com.forgerock.openbanking.common.services.openbanking.converter.payment.FRWriteDomesticConverter.toOBWriteDomestic2)13 DomesticPaymentService (com.forgerock.openbanking.common.services.store.payment.DomesticPaymentService)13 ResponseEntity (org.springframework.http.ResponseEntity)12 ConsentStatusCode (com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode)11 RSEndpointWrapperService (com.forgerock.openbanking.aspsp.rs.wrappper.RSEndpointWrapperService)9 FRWriteDomestic (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomestic)9 FRWriteDomesticConsent (com.forgerock.openbanking.common.model.openbanking.domain.payment.FRWriteDomesticConsent)9 RsStoreGateway (com.forgerock.openbanking.common.services.store.RsStoreGateway)9 Principal (java.security.Principal)9 FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 DateTime (org.joda.time.DateTime)7 HttpHeaders (org.springframework.http.HttpHeaders)7