Install it using maven:
Just add to your pom.xml the following repository
<repositories>
...
<repository>
<id>mercadopago</id>
<url>https://github.com/mercadopago/sdk-java/raw/master/releases</url>
</repository>
...
</repositories> Then add the dependency
<dependencies>
...
<dependency>
<groupId>com.mercadopago</groupId>
<artifactId>sdk</artifactId>
<version>0.3.4</version>
</dependency>
...
</dependencies>And that's it!
- Get your CLIENT_ID and CLIENT_SECRET in the following address:
- Argentina: https://www.mercadopago.com/mla/herramientas/aplicaciones
- Brazil: https://www.mercadopago.com/mlb/ferramentas/aplicacoes
- México: https://www.mercadopago.com/mlm/herramientas/aplicaciones
- Venezuela: https://www.mercadopago.com/mlv/herramientas/aplicaciones
- Colombia: https://www.mercadopago.com/mco/herramientas/aplicaciones
- Chile: https://www.mercadopago.com/mlc/herramientas/aplicaciones
importcom.mercadopago.MP;
importorg.codehaus.jettison.json.JSONException;
importorg.codehaus.jettison.json.JSONObject;
MPmp = newMP ("CLIENT_ID", "CLIENT_SECRET");JSONObjectpreference = mp.getPreference("PREFERENCE_ID");
System.out.println(preference.toString());JSONObjectcreatePreferenceResult = mp.createPreference("{'items':[{'title':'Prueba','quantity':1,'currency_id':'ARS','unit_price':10.5}]}");
System.out.println(createPreferenceResult.toString());JSONObjectupdatePreferenceResult = mp.updatePreference("PREFERENCE_ID", "{'items':[{'title':'Prueba','quantity':1,'currency_id':'USD','unit_price':2}]}");
System.out.println(updatePreferenceResult.toString());// Sets the filters you wantMap<String, Object> filters = newHashMap<String, Object> ();
filters.put("external_reference", "Bill001");
// Search payment data according to filtersJSONObjectsearchResult = mp.searchPayment (filters);
JSONArrayresults = searchResult.getJSONObject("response").getJSONArray("results");
for (inti = 0; i < results.length(); i++) {
System.out.println(results.getJSONObject(i).getString("id"));
System.out.println(results.getJSONObject(i).getString("external_reference"));
System.out.println(results.getJSONObject(i).getString("status"));
}// Get the payment reported by the IPN. Glossary of attributes response in https://developers.mercadopago.comJSONObjectpayment_info = mp.getPayment("ID");
// Show payment informationif (Integer.parseInt (payment_info.get("status").toString()) == 200) {
out.print(payment_info.get("response"));
}JSONObjectresult = mp.cancelPayment(request.getParameter("ID"));
// Show resultout.print(result);JSONObjectresult = mp.refundPayment(request.getParameter("ID"));
// Show resultout.print(result);- Get your ACCESS_TOKEN in the following address:
- Argentina: https://www.mercadopago.com/mla/account/credentials
- Brazil: https://www.mercadopago.com/mlb/account/credentials
- Mexico: https://www.mercadopago.com/mlm/account/credentials
- Venezuela: https://www.mercadopago.com/mlv/account/credentials
- Colombia: https://www.mercadopago.com/mco/account/credentials
importcom.mercadopago.MP;
importorg.codehaus.jettison.json.JSONException;
importorg.codehaus.jettison.json.JSONObject;
MPmp = newMP ("ACCESS_TOKEN");mp.post ("/v1/payments", paymentData);mp.post ("/v1/customers", "{'email': 'email@test.com'}");mp.get ("/v1/customers/CUSTOMER_ID");- View more Custom checkout related APIs in Developers Site
You can access any other resource from the MercadoPago API using the generic methods:
// Get a resource, with optional URL params. Also you can disable authentication for public APIsmp.get ("/resource/uri", [params], [authenticate=true]);
// Create a resource with "data" and optional URL params.mp.post ("/resource/uri", data, [params]);
// Update a resource with "data" and optional URL params.mp.put ("/resource/uri", data, [params]);
// Delete a resource with optional URL params.mp.delete ("/resource/uri", [params]);For example, if you want to get the Sites list (no params and no authentication):
JSONObjectresult = mp.get ("/sites", null, false);
out.print(result);