Search in sources :

Example 1 with TransactionSearchParams

use of uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams in project pay-ledger by alphagov.

the class TransactionService method findByGatewayTransactionId.

public Optional<TransactionView> findByGatewayTransactionId(String gatewayTransactionId, String paymentProvider) {
    TransactionSearchParams searchParams = new TransactionSearchParams();
    searchParams.setGatewayTransactionId(gatewayTransactionId);
    searchParams.setTransactionType(PAYMENT);
    return transactionDao.searchTransactions(searchParams).stream().map(transactionEntity -> TransactionView.from(transactionFactory.createTransactionEntity(transactionEntity), DEFAULT_STATUS_VERSION)).filter(transaction -> paymentProvider.equalsIgnoreCase(transaction.getPaymentProvider())).findFirst();
}
Also used : EventDigest(uk.gov.pay.ledger.event.model.EventDigest) EventDao(uk.gov.pay.ledger.event.dao.EventDao) PaginationBuilder(uk.gov.pay.ledger.util.pagination.PaginationBuilder) Inject(com.google.inject.Inject) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) PAYMENT(uk.gov.pay.ledger.transaction.model.TransactionType.PAYMENT) TransactionFactory(uk.gov.pay.ledger.transaction.model.TransactionFactory) Transaction(uk.gov.pay.ledger.transaction.model.Transaction) Map(java.util.Map) TransactionEvent(uk.gov.pay.ledger.transaction.model.TransactionEvent) CsvTransactionFactory(uk.gov.pay.ledger.transaction.model.CsvTransactionFactory) Logger(org.slf4j.Logger) TransactionsForTransactionResponse(uk.gov.pay.ledger.transaction.model.TransactionsForTransactionResponse) Event(uk.gov.pay.ledger.event.model.Event) TransactionSearchParams(uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TransactionSearchResponse(uk.gov.pay.ledger.transaction.model.TransactionSearchResponse) TransactionEventResponse(uk.gov.pay.ledger.transaction.model.TransactionEventResponse) Collectors(java.util.stream.Collectors) TransactionEntity(uk.gov.pay.ledger.transaction.entity.TransactionEntity) String.format(java.lang.String.format) List(java.util.List) TransactionType(uk.gov.pay.ledger.transaction.model.TransactionType) Response(javax.ws.rs.core.Response) TransactionView(uk.gov.pay.ledger.transaction.search.model.TransactionView) TransactionEntityFactory(uk.gov.pay.ledger.event.model.TransactionEntityFactory) WebApplicationException(javax.ws.rs.WebApplicationException) Optional(java.util.Optional) TransactionDao(uk.gov.pay.ledger.transaction.dao.TransactionDao) UriInfo(javax.ws.rs.core.UriInfo) Comparator(java.util.Comparator) TransactionSearchParams(uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams)

Example 2 with TransactionSearchParams

use of uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams in project pay-ledger by alphagov.

the class TransactionDaoSearchIT method shouldFilterByGatewayPayoutIdWhenSpecified.

@Test
public void shouldFilterByGatewayPayoutIdWhenSpecified() {
    String gatewayAccountId = "account-id-" + nextLong();
    String gatewayPayoutId = "payout-id-" + nextLong();
    TransactionFixture transaction = aTransactionFixture().withGatewayAccountId(gatewayAccountId).withGatewayPayoutId(gatewayPayoutId).withCreatedDate(now().minusDays(1)).withTransactionType("PAYMENT").insert(rule.getJdbi());
    TransactionFixture refund = aTransactionFixture().withGatewayAccountId(gatewayAccountId).withGatewayPayoutId(gatewayPayoutId).withTransactionType("REFUND").insert(rule.getJdbi());
    aTransactionFixture().withGatewayAccountId(gatewayAccountId).withGatewayPayoutId(gatewayPayoutId + "different-id").withTransactionType("PAYMENT").insert(rule.getJdbi());
    TransactionSearchParams searchParams = new TransactionSearchParams();
    searchParams.setGatewayPayoutId(gatewayPayoutId);
    List<TransactionEntity> transactionList = transactionDao.searchTransactions(searchParams);
    assertThat(transactionList.size(), Matchers.is(2));
    assertThat(transactionList.get(0).getExternalId(), is(refund.getExternalId()));
    assertThat(transactionList.get(0).getGatewayPayoutId(), is(refund.getGatewayPayoutId()));
    assertThat(transactionList.get(1).getExternalId(), is(transaction.getExternalId()));
    assertThat(transactionList.get(1).getGatewayPayoutId(), is(transaction.getGatewayPayoutId()));
}
Also used : TransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture) TransactionFixture.aTransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture.aTransactionFixture) TransactionSearchParams(uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams) TransactionEntity(uk.gov.pay.ledger.transaction.entity.TransactionEntity) Test(org.junit.jupiter.api.Test)

Example 3 with TransactionSearchParams

use of uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams in project pay-ledger by alphagov.

the class TransactionDaoSearchIT method getTotalWithLimitForSearchShouldApplyLimitTotalSizeCorrectly.

@Test
public void getTotalWithLimitForSearchShouldApplyLimitTotalSizeCorrectly() {
    String gatewayAccountId = "account-id-" + nextLong();
    aPersistedTransactionList(gatewayAccountId, 15, rule.getJdbi(), true);
    aTransactionFixture().withGatewayAccountId(gatewayAccountId).withReference("to_exclude").insert(rule.getJdbi());
    aTransactionFixture().withGatewayAccountId(randomAlphanumeric(26)).withReference("to_exclude").insert(rule.getJdbi());
    TransactionSearchParams searchParams = new TransactionSearchParams();
    searchParams.setAccountIds(List.of(gatewayAccountId));
    searchParams.setReference("reference");
    searchParams.setEmail("example.org");
    searchParams.setCardHolderName("smith");
    searchParams.setLastDigitsCardNumber("1234");
    searchParams.setFromDate("2019-10-01T10:00:00.000Z");
    searchParams.setToDate(now().plusDays(2).toString());
    searchParams.setLimitTotalSize(15L);
    Long total = transactionDao.getTotalWithLimitForSearch(searchParams);
    assertThat(total, is(15L));
}
Also used : TransactionSearchParams(uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams) RandomUtils.nextLong(org.apache.commons.lang3.RandomUtils.nextLong) Test(org.junit.jupiter.api.Test)

Example 4 with TransactionSearchParams

use of uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams in project pay-ledger by alphagov.

the class TransactionDaoSearchIT method shouldReturn1Record_whenSearchingByEmail.

@Test
public void shouldReturn1Record_whenSearchingByEmail() {
    String gatewayAccountId = "account-id-" + nextLong();
    for (int i = 0; i < 2; i++) {
        aTransactionFixture().withGatewayAccountId(gatewayAccountId).withEmail("testemail" + i + "@example.org").insert(rule.getJdbi());
    }
    TransactionSearchParams searchParams = new TransactionSearchParams();
    searchParams.setAccountIds(List.of(gatewayAccountId));
    searchParams.setEmail("testemail1");
    List<TransactionEntity> transactionList = transactionDao.searchTransactions(searchParams);
    assertThat(transactionList.size(), is(1));
    assertThat(transactionList.get(0).getEmail(), is("testemail1@example.org"));
    Long total = transactionDao.getTotalForSearch(searchParams);
    assertThat(total, is(1L));
}
Also used : TransactionSearchParams(uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams) TransactionEntity(uk.gov.pay.ledger.transaction.entity.TransactionEntity) RandomUtils.nextLong(org.apache.commons.lang3.RandomUtils.nextLong) Test(org.junit.jupiter.api.Test)

Example 5 with TransactionSearchParams

use of uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams in project pay-ledger by alphagov.

the class TransactionDaoSearchIT method shouldReturn2Records_whenTransactionTypeIsSpecified.

@Test
public void shouldReturn2Records_whenTransactionTypeIsSpecified() {
    String gatewayAccountId = "account-id-" + nextLong();
    for (int i = 0; i < 4; i++) {
        aTransactionFixture().withGatewayAccountId(gatewayAccountId).withTransactionType(i % 2 == 0 ? "REFUND" : "PAYMENT").insert(rule.getJdbi());
    }
    TransactionSearchParams searchParams = new TransactionSearchParams();
    searchParams.setAccountIds(List.of(gatewayAccountId));
    searchParams.setTransactionType(TransactionType.REFUND);
    List<TransactionEntity> transactionList = transactionDao.searchTransactions(searchParams);
    assertThat(transactionList.size(), Matchers.is(2));
    assertTrue(transactionList.stream().allMatch(e -> "REFUND".equals(e.getTransactionType())));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PayoutFixtureBuilder.aPayoutFixture(uk.gov.pay.ledger.util.fixture.PayoutFixture.PayoutFixtureBuilder.aPayoutFixture) BeforeEach(org.junit.jupiter.api.BeforeEach) LedgerConfig(uk.gov.pay.ledger.app.LedgerConfig) DatabaseTestHelper.aDatabaseTestHelper(uk.gov.pay.ledger.util.DatabaseTestHelper.aDatabaseTestHelper) Mock(org.mockito.Mock) ZonedDateTime(java.time.ZonedDateTime) JsonParser(com.google.gson.JsonParser) AppWithPostgresAndSqsExtension(uk.gov.pay.ledger.extension.AppWithPostgresAndSqsExtension) JsonElement(com.google.gson.JsonElement) Transaction(uk.gov.pay.ledger.transaction.model.Transaction) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Map(java.util.Map) TransactionState(uk.gov.pay.ledger.transaction.state.TransactionState) ZoneOffset(java.time.ZoneOffset) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ReportingConfig(uk.gov.pay.ledger.app.config.ReportingConfig) TransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture) ImmutableMap(com.google.common.collect.ImmutableMap) TransactionFixture.aPersistedTransactionList(uk.gov.pay.ledger.util.fixture.TransactionFixture.aPersistedTransactionList) TransactionSearchParams(uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.when(org.mockito.Mockito.when) TransactionEntity(uk.gov.pay.ledger.transaction.entity.TransactionEntity) DatabaseTestHelper(uk.gov.pay.ledger.util.DatabaseTestHelper) Test(org.junit.jupiter.api.Test) List(java.util.List) TransactionType(uk.gov.pay.ledger.transaction.model.TransactionType) CommaDelimitedSetParameter(uk.gov.pay.ledger.util.CommaDelimitedSetParameter) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric) ZonedDateTime.now(java.time.ZonedDateTime.now) RandomUtils.nextLong(org.apache.commons.lang3.RandomUtils.nextLong) TransactionFixture.aTransactionFixture(uk.gov.pay.ledger.util.fixture.TransactionFixture.aTransactionFixture) TransactionSearchParams(uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams) TransactionEntity(uk.gov.pay.ledger.transaction.entity.TransactionEntity) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionSearchParams (uk.gov.pay.ledger.transaction.search.common.TransactionSearchParams)31 Test (org.junit.jupiter.api.Test)26 TransactionEntity (uk.gov.pay.ledger.transaction.entity.TransactionEntity)25 RandomUtils.nextLong (org.apache.commons.lang3.RandomUtils.nextLong)15 TransactionFixture (uk.gov.pay.ledger.util.fixture.TransactionFixture)5 TransactionFixture.aTransactionFixture (uk.gov.pay.ledger.util.fixture.TransactionFixture.aTransactionFixture)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Transaction (uk.gov.pay.ledger.transaction.model.Transaction)4 JsonElement (com.google.gson.JsonElement)3 CommaDelimitedSetParameter (uk.gov.pay.ledger.util.CommaDelimitedSetParameter)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ZonedDateTime (java.time.ZonedDateTime)2 List (java.util.List)2 Map (java.util.Map)2 TransactionEntityFactory (uk.gov.pay.ledger.event.model.TransactionEntityFactory)2 CsvTransactionFactory (uk.gov.pay.ledger.transaction.model.CsvTransactionFactory)2 TransactionFactory (uk.gov.pay.ledger.transaction.model.TransactionFactory)2 TransactionType (uk.gov.pay.ledger.transaction.model.TransactionType)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 JsonParser (com.google.gson.JsonParser)1