Search in sources :

Example 1 with SearchRefundsException

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

the class LedgerService method searchRefunds.

public SearchRefundsResponseFromLedger searchRefunds(Account account, Map<String, String> paramsAsMap) {
    paramsAsMap.put(PARAM_ACCOUNT_ID, account.getAccountId());
    paramsAsMap.put(PARAM_TRANSACTION_TYPE, REFUND_TRANSACTION_TYPE);
    Response response = client.target(ledgerUriGenerator.transactionsURIWithParams(paramsAsMap)).request().accept(MediaType.APPLICATION_JSON_TYPE).get();
    if (response.getStatus() == SC_OK) {
        try {
            return response.readEntity(SearchRefundsResponseFromLedger.class);
        } catch (ProcessingException exception) {
            throw new SearchRefundsException(exception);
        }
    }
    throw new SearchRefundsException(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) SearchRefundsException(uk.gov.pay.api.exception.SearchRefundsException) ProcessingException(javax.ws.rs.ProcessingException)

Example 2 with SearchRefundsException

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

the class SearchRefundsServiceTest method shouldReturn404WhenSearchingWithNonExistentPageNumber.

@Test
@PactVerification({ "ledger" })
@Pacts(pacts = { "publicapi-ledger-search-refunds-page-not-found" })
public void shouldReturn404WhenSearchingWithNonExistentPageNumber() {
    Account account = new Account(ACCOUNT_ID, TokenPaymentType.CARD, tokenLink);
    RefundsParams params = new RefundsParams(null, null, "999", "500", null, null);
    SearchRefundsException searchRefundsException = assertThrows(SearchRefundsException.class, () -> searchRefundsService.searchLedgerRefunds(account, params));
    assertThat(searchRefundsException, hasProperty("errorStatus", is(404)));
}
Also used : Account(uk.gov.pay.api.auth.Account) SearchRefundsException(uk.gov.pay.api.exception.SearchRefundsException) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test) Pacts(uk.gov.service.payments.commons.testing.pact.consumers.Pacts)

Aggregations

SearchRefundsException (uk.gov.pay.api.exception.SearchRefundsException)2 PactVerification (au.com.dius.pact.consumer.PactVerification)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 PaymentSearchResponse (uk.gov.pay.api.model.search.card.PaymentSearchResponse)1 Pacts (uk.gov.service.payments.commons.testing.pact.consumers.Pacts)1