joelibaceta
11/23/2016 - 11:32 AM

Ejemplos de creación de pagos con el del SDK para Java de MercadoPago

Ejemplos de creación de pagos con el del SDK para Java de MercadoPago

// Implementacion Minima de un Pago usando el SDK para Java de MercadoPago

//import com.mercadopago.MP;
//import org.codehaus.jettison.json.JSONArray;
//import org.codehaus.jettison.json.JSONObject;

	MP mp = new MP("ACCESS_TOKEN");

        JSONObject payment = null;
        try {
		JSONObject payment = new JSONObject();
		
		payment.put("transaction_amount", 100);
	        payment.put("token", "CARDTOKEN");
            	payment.put("description", "Title of what you are paying for");
            	payment.put("installments", 1);
            	payment.put("binary_mode", true);
            	payment.put("payment_method_id", "visa");
            	payment.put("payer", (new JSONObject()).put("email", "mail@sample.com"));
		
            	payment = mp.post("/v1/payments", payment.toString());
		
            	System.out.println(payment.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
// Implementacion Minima de un Pago usando el SDK para Java de MercadoPago con Datos recomendados para control de prevencion del Fraude

MP mp = new MP("ACCESS_TOKEN");
 
        try {
                JSONObject payment = new JSONObject();
                JSONObject payer = new JSONObject();
                JSONObject item = new JSONObject();
                JSONObject additional_info = new JSONObject();
		
		payment.put("transaction_amount", 100);
	        payment.put("token", "CARDTOKEN");
            	payment.put("description", "Title of what you are paying for");
            	payment.put("installments", 1);
            	payment.put("binary_mode", true);
            	payment.put("payment_method_id", "visa");
            	payment.put("payer", (new JSONObject()).put("email", "mail@sample.com"));
                
                JSONObject payer_phone = new JSONObject();
            	JSONObject payer_address = new JSONObject();

            	payer_phone.put("area_code", "11");
            	payer_phone.put("number", "4444-4444");

            	payer_address.put("street_name", "Street");
            	payer_address.put("street_number", "123");
            	payer_address.put("zip_code", "5700");

            	payer.put("first_name", "user-name");
            	payer.put("last_name", "user-surname");
            	payer.put("phone", payer_phone);
            	payer.put("address", payer_address);
	
                item.put("id", "item-ID-1234");
                item.put("title", "item-ID-1234");
                item.put("picture_url", "https://www.mercadopago.com/org-img/MP3/home/logomp3.gif");
                item.put("description", "Item description");
                item.put("category_id", "art");
                item.put("quantity", 1);
                item.put("unit_price", 100);

                JSONArray items = new JSONArray();
                
                items.put(item);

                additional_info.put("items", items);
                additional_info.put("payer", payer);
                
                payment.put("additional_info", additional_info);
		
            	payment = mp.post("/v1/payments", payment.toString()); 
                
                System.out.println(payment.toString());
                
        } catch (Exception e) {
            e.printStackTrace();
        }
// Implementacion Minima de un Pago en Cuotas usando el SDK para Java de MercadoPago con Datos recomendados para control de prevencion del Fraude

MP mp = new MP("ACCESS_TOKEN"); // ACCESS_TOKEN debe ser reemplazado por las credenciales del integrador
  
        try {
             	JSONObject payment = new JSONObject();
		
		payment.put("transaction_amount", 100);
	        payment.put("token", "CARDTOKEN");
            	payment.put("description", "Title of what you are paying for");
            	payment.put("installments", 3);
            	payment.put("binary_mode", true);
             	payment.put("issuer_id", "338");
            	payment.put("payment_method_id", "visa");
            	payment.put("payer", (new JSONObject()).put("email", "mail@sample.com"));
		
            	payment = mp.post("/v1/payments", payment.toString());
          
             	System.out.println(payment.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
// Respuesta entregada al realizar un pago 

{
	"payment_id" : Payment_ID,
	"status" : "Payment status",
	"status_detail" : "Payment status detail",
	"amount" : "10",
	"reason": "Title of what you are paying for",
	"currency_id" : "CURRENCY_ID",
	"installments" : 3,
	"payment_method_id" : "visa",
	"card_token_id" : "card_token",
	"payer_email" : "payer@email.com",
	"external_reference" : "1234",
	"statement_descriptor" : "MERCADOPAGO"
}