Search in sources :

Example 1 with SearchPaymentsException

use of uk.gov.pay.api.exception.SearchPaymentsException in project pay-publicapi by alphagov.

the class PaginationDecorator method decoratePagination.

public HalRepresentation.HalRepresentationBuilder decoratePagination(HalRepresentation.HalRepresentationBuilder halRepresentationBuilder, SearchPagination pagination, String path) {
    HalRepresentation.HalRepresentationBuilder builder = addPaginationProperties(halRepresentationBuilder, pagination);
    SearchNavigationLinks links = pagination.getLinks();
    try {
        addLink(builder, "self", transformIntoPublicUri(baseUrl, links.getSelf(), path));
        addLink(builder, "first_page", transformIntoPublicUri(baseUrl, links.getFirstPage(), path));
        addLink(builder, "last_page", transformIntoPublicUri(baseUrl, links.getLastPage(), path));
        addLink(builder, "prev_page", transformIntoPublicUri(baseUrl, links.getPrevPage(), path));
        addLink(builder, "next_page", transformIntoPublicUri(baseUrl, links.getNextPage(), path));
    } catch (URISyntaxException ex) {
        throw new SearchPaymentsException(ex);
    }
    return builder;
}
Also used : SearchPaymentsException(uk.gov.pay.api.exception.SearchPaymentsException) HalRepresentation(black.door.hate.HalRepresentation) SearchNavigationLinks(uk.gov.pay.api.model.links.SearchNavigationLinks) URISyntaxException(java.net.URISyntaxException)

Example 2 with SearchPaymentsException

use of uk.gov.pay.api.exception.SearchPaymentsException in project pay-publicapi by alphagov.

the class CardPaymentSearchServiceTest method shouldReturn404WhenSearchingWithNonExistentPageNumber.

@Test
@PactVerification({ "ledger" })
@Pacts(pacts = { "publicapi-ledger-search-payments-page-not-found" })
public void shouldReturn404WhenSearchingWithNonExistentPageNumber() {
    Account account = new Account("123456", TokenPaymentType.CARD, tokenLink);
    var searchParams = new PaymentSearchParams.Builder().withDisplaySize("500").withPageNumber("999").build();
    SearchPaymentsException searchPaymentsException = assertThrows(SearchPaymentsException.class, () -> paymentSearchService.searchLedgerPayments(account, searchParams));
    assertThat(searchPaymentsException, hasProperty("errorStatus", is(404)));
}
Also used : Account(uk.gov.pay.api.auth.Account) SearchPaymentsException(uk.gov.pay.api.exception.SearchPaymentsException) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Example 3 with SearchPaymentsException

use of uk.gov.pay.api.exception.SearchPaymentsException in project pay-publicapi by alphagov.

the class LedgerService method searchPayments.

public PaymentSearchResponse<TransactionResponse> searchPayments(Account account, Map<String, String> paramsAsMap) {
    paramsAsMap.put(PARAM_ACCOUNT_ID, account.getAccountId());
    paramsAsMap.put(PARAM_TRANSACTION_TYPE, PAYMENT_TRANSACTION_TYPE);
    paramsAsMap.put(PARAM_EXACT_REFERENCE_MATCH, "true");
    Response response = client.target(ledgerUriGenerator.transactionsURIWithParams(paramsAsMap)).request().accept(MediaType.APPLICATION_JSON_TYPE).get();
    if (response.getStatus() == SC_OK) {
        try {
            return response.readEntity(new GenericType<PaymentSearchResponse<TransactionResponse>>() {
            });
        } catch (ProcessingException ex) {
            throw new SearchPaymentsException(ex);
        }
    }
    throw new SearchPaymentsException(response);
}
Also used : PaymentSearchResponse(uk.gov.pay.api.model.search.card.PaymentSearchResponse) TransactionResponse(uk.gov.pay.api.model.TransactionResponse) Response(javax.ws.rs.core.Response) SearchPaymentsException(uk.gov.pay.api.exception.SearchPaymentsException) PaymentSearchResponse(uk.gov.pay.api.model.search.card.PaymentSearchResponse) ProcessingException(javax.ws.rs.ProcessingException)

Aggregations

SearchPaymentsException (uk.gov.pay.api.exception.SearchPaymentsException)3 PactVerification (au.com.dius.pact.consumer.PactVerification)1 HalRepresentation (black.door.hate.HalRepresentation)1 URISyntaxException (java.net.URISyntaxException)1 ProcessingException (javax.ws.rs.ProcessingException)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 Account (uk.gov.pay.api.auth.Account)1 TransactionResponse (uk.gov.pay.api.model.TransactionResponse)1 SearchNavigationLinks (uk.gov.pay.api.model.links.SearchNavigationLinks)1 PaymentSearchResponse (uk.gov.pay.api.model.search.card.PaymentSearchResponse)1 Pacts (uk.gov.service.payments.commons.testing.pact.consumers.Pacts)1