Mercado Pago API Exception

446 views Asked by At

I'm receiving this exception everytime that i call one "PreferenceClient" method, pls someone save me The Java code

public static void main(String[] args) throws MPException,  MPApiException {

    String DOMINIO = "127.0.0.1:2020";
    String SUCESSO = "/pagamento/aprovado";
    String FRACASSO = "/pagamento/recusado";
    
    PreferenceClient client = new PreferenceClient();

    PreferenceItemRequest item = 
        PreferenceItemRequest.builder()
            .id("1")
            .title("Camiseta 1")
            .description("Salve")
            .quantity(1)
            .currencyId("BRL")
            .unitPrice(new BigDecimal("100"))
            .build();

    PreferenceBackUrlsRequest backUrls =
        PreferenceBackUrlsRequest.builder()
            .success(DOMINIO + SUCESSO)
            .failure(DOMINIO + FRACASSO)
            .build();

    List<PreferenceTrackRequest> tracks = new ArrayList<>();
    PreferenceTrackRequest googleTrack =
        PreferenceTrackRequest.builder()
            .type("google_ad")
            .build();

    tracks.add(googleTrack);

    PreferenceRequest request =
        PreferenceRequest.builder()
            .backUrls(backUrls)
            .items(Arrays.asList(item))
            .tracks(tracks)
            .build();

    client.create(request);
}
}

The exception:

Exception in thread "main" com.mercadopago.exceptions.MPApiException: Api error. Check response for details at com.mercadopago.net.MPDefaultHttpClient.send(MPDefaultHttpClient.java:142) at com.mercadopago.client.MercadoPagoClient.send(MercadoPagoClient.java:56) at com.mercadopago.client.MercadoPagoClient.send(MercadoPagoClient.java:78) at com.mercadopago.client.preference.PreferenceClient.create(PreferenceClient.java:123) at com.mercadopago.client.preference.PreferenceClient.create(PreferenceClient.java:98) at me.alexfrocha.mercadopago.mp.controllers.HomeController.main(HomeController.java:83)

1

There are 1 answers

0
Alexandre Alves On

I was able to check the response with the following catch:

catch (MPApiException e) {
    var apiResponse = e.getApiResponse();
    var content = apiResponse.getContent();
    System.out.println(content);
}