Search in sources :

Example 1 with TransactionSearchResults

use of uk.gov.pay.api.ledger.model.TransactionSearchResults in project pay-publicapi by alphagov.

the class TransactionSearchService method processResponse.

private TransactionSearchResults processResponse(Response connectorResponse) {
    PaymentSearchResponse<TransactionResponse> response;
    try {
        response = connectorResponse.readEntity(new GenericType<PaymentSearchResponse<TransactionResponse>>() {
        });
    } catch (ProcessingException ex) {
        throw new SearchTransactionsException(ex);
    }
    List<PaymentForSearchResult> chargeFromResponses = response.getPayments().stream().map(this::getPaymentForSearchResult).collect(toList());
    return new TransactionSearchResults(response.getTotal(), response.getCount(), response.getPage(), chargeFromResponses, transformLinks(response.getLinks()));
}
Also used : GenericType(javax.ws.rs.core.GenericType) TransactionResponse(uk.gov.pay.api.model.TransactionResponse) PaymentForSearchResult(uk.gov.pay.api.model.search.card.PaymentForSearchResult) TransactionSearchResults(uk.gov.pay.api.ledger.model.TransactionSearchResults) ProcessingException(javax.ws.rs.ProcessingException) SearchTransactionsException(uk.gov.pay.api.exception.SearchTransactionsException)

Example 2 with TransactionSearchResults

use of uk.gov.pay.api.ledger.model.TransactionSearchResults in project pay-publicapi by alphagov.

the class TransactionSearchServiceTest method testSearchTransaction.

@Test
@PactVerification({ "ledger" })
@Pacts(pacts = { "publicapi-ledger-search-transaction" })
public void testSearchTransaction() {
    Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, "a-token-link");
    TransactionSearchParams searchParams = new TransactionSearchParams();
    TransactionSearchResults searchResults = transactionSearchService.doSearch(account, searchParams);
    PaymentForSearchResult payment = searchResults.getResults().get(0);
    assertThat(payment.getAmount(), is(1000L));
    assertThat(payment.getState(), is(new PaymentState("created", false)));
    assertThat(payment.getDescription(), is("Test description"));
    assertThat(payment.getReference(), is("aReference"));
    assertThat(payment.getLanguage(), is(SupportedLanguage.ENGLISH));
    assertThat(payment.getPaymentId(), is(CHARGE_ID));
    assertThat(payment.getReturnUrl().get(), is("https://example.org"));
    assertThat(payment.getEmail().get(), is("someone@example.org"));
    assertThat(payment.getPaymentProvider(), is("sandbox"));
    assertThat(payment.getCreatedDate(), is("2018-09-22T10:13:16.067Z"));
    assertThat(payment.getDelayedCapture(), is(false));
    assertThat(payment.getCardDetails().get().getCardHolderName(), is("J. Smith"));
    assertThat(payment.getCardDetails().get().getCardBrand(), is(""));
    Address address = payment.getCardDetails().get().getBillingAddress().get();
    assertThat(address.getLine1(), is("line1"));
    assertThat(address.getLine2(), is("line2"));
    assertThat(address.getPostcode(), is("AB1 2CD"));
    assertThat(address.getCity(), is("London"));
    assertThat(address.getCountry(), is("GB"));
    assertThat(payment.getLinks().getSelf().getHref(), containsString("v1/payments/" + CHARGE_ID));
    assertThat(payment.getLinks().getSelf().getMethod(), is("GET"));
    assertThat(payment.getLinks().getRefunds().getHref(), containsString("v1/payments/" + CHARGE_ID + "/refunds"));
    assertThat(payment.getLinks().getRefunds().getMethod(), is("GET"));
    assertThat(searchResults.getCount(), is(1));
    assertThat(searchResults.getTotal(), is(1));
    assertThat(searchResults.getPage(), is(1));
    assertThat(searchResults.getLinks().getSelf().getHref(), containsString("/v1/transactions?display_size=500&page=1"));
    assertThat(searchResults.getLinks().getFirstPage().getHref(), containsString("/v1/transactions?display_size=500&page=1"));
    assertThat(searchResults.getLinks().getLastPage().getHref(), containsString("/v1/transactions?display_size=500&page=1"));
}
Also used : Account(uk.gov.pay.api.auth.Account) TransactionSearchParams(uk.gov.pay.api.ledger.model.TransactionSearchParams) Address(uk.gov.pay.api.model.Address) PaymentForSearchResult(uk.gov.pay.api.model.search.card.PaymentForSearchResult) PaymentState(uk.gov.pay.api.model.PaymentState) TransactionSearchResults(uk.gov.pay.api.ledger.model.TransactionSearchResults) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Aggregations

TransactionSearchResults (uk.gov.pay.api.ledger.model.TransactionSearchResults)2 PaymentForSearchResult (uk.gov.pay.api.model.search.card.PaymentForSearchResult)2 PactVerification (au.com.dius.pact.consumer.PactVerification)1 ProcessingException (javax.ws.rs.ProcessingException)1 GenericType (javax.ws.rs.core.GenericType)1 Test (org.junit.Test)1 Account (uk.gov.pay.api.auth.Account)1 SearchTransactionsException (uk.gov.pay.api.exception.SearchTransactionsException)1 TransactionSearchParams (uk.gov.pay.api.ledger.model.TransactionSearchParams)1 Address (uk.gov.pay.api.model.Address)1 PaymentState (uk.gov.pay.api.model.PaymentState)1 TransactionResponse (uk.gov.pay.api.model.TransactionResponse)1 Pacts (uk.gov.service.payments.commons.testing.pact.consumers.Pacts)1