json Ejemplosdecreacióndepagos con el del SDK para Java de MercadoPago

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json Ejemplosdecreacióndepagos 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"
}

以上是关于json Ejemplosdecreacióndepagos con el del SDK para Java de MercadoPago的主要内容,如果未能解决你的问题,请参考以下文章

json MIR24 photobank弹性指数结构

go语言快速入门 JSON处理 24

(23/24) webpack实战技巧:如何在webpack环境中使用Json

Restkit 0.24.0:如何将对象(包括对多关系)序列化为 JSON

升级到 0.24.1 后,react native fetch 返回 Blob 而不是 JSON

相同内容 yaml 与 json 格式对比