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