Subversion Repositories SmartDukaan

Rev

Rev 13539 | Rev 13546 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 13539 Rev 13540
Line 23... Line 23...
23
import org.apache.http.client.entity.UrlEncodedFormEntity;
23
import org.apache.http.client.entity.UrlEncodedFormEntity;
24
import org.apache.http.client.methods.HttpPost;
24
import org.apache.http.client.methods.HttpPost;
25
import org.apache.http.impl.client.DefaultHttpClient;
25
import org.apache.http.impl.client.DefaultHttpClient;
26
import org.apache.http.message.BasicNameValuePair;
26
import org.apache.http.message.BasicNameValuePair;
27
import org.apache.log4j.Logger;
27
import org.apache.log4j.Logger;
-
 
28
import org.json.JSONException;
-
 
29
import org.json.JSONObject;
28
 
30
 
29
import com.google.gson.Gson;
31
import com.google.gson.Gson;
30
import com.google.gson.GsonBuilder;
32
import com.google.gson.GsonBuilder;
31
import com.google.gson.JsonArray;
33
import com.google.gson.JsonArray;
32
import com.google.gson.JsonDeserializationContext;
34
import com.google.gson.JsonDeserializationContext;
Line 86... Line 88...
86
			resultMap.put(ERR_CODE, Errors.CONN_FAILURE.code);
88
			resultMap.put(ERR_CODE, Errors.CONN_FAILURE.code);
87
			resultMap.put(ERROR, Errors.CONN_FAILURE.message);
89
			resultMap.put(ERROR, Errors.CONN_FAILURE.message);
88
			return resultMap;
90
			return resultMap;
89
		}
91
		}
90
		log.info("postResponse====" + postResponse);
92
		log.info("postResponse====" + postResponse);
91
		GsonBuilder gsonBuilder = new GsonBuilder();
93
		JSONObject postMap = null;
92
		gsonBuilder
94
		try {
93
				.registerTypeAdapter(Object.class, new NaturalDeserializer());
-
 
94
		Gson gson = gsonBuilder.create();
-
 
95
		Type t = new TypeToken<Map<String,Object>>() {}.getType();
-
 
96
		Map<String, Object> postMap =  gson.fromJson(postResponse, t);
95
			postMap = new JSONObject(postResponse);
-
 
96
		
97
		log.info("postMap.get(\"status\")=======" + postMap.get("status"));
97
			log.info("postMap.get(\"status\")=======" + postMap.get("status"));
98
		if (0 == ((Integer)postMap.get("status")).intValue()) {
98
			if (0 == ((Integer)postMap.get("status")).intValue()) {
-
 
99
				log.info("Some error occurred at Payu");
99
			resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
100
				resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
100
			resultMap.put(ERROR, (String)postMap.get("msg"));
101
				resultMap.put(ERROR, (String)postMap.get("msg"));
101
		} else if (1 == ((Integer)postMap.get("status")).intValue()){
102
			} else if (1 == ((Integer)postMap.get("status")).intValue()){
102
			log.info("postMap.containsKey(\"bank_ref_num\")========" + postMap.containsKey("bank_ref_num")); 
103
				log.info("postMap.containsKey(\"bank_ref_num\")========" + postMap.has("bank_ref_num")); 
103
			resultMap.put(REF_NO, (String) postMap.get("bank_ref_num"));
104
				resultMap.put(REF_NO, (String) postMap.get("bank_ref_num"));
104
			if(postMap.get("txn_update_id")!= null) {
105
				if(postMap.get("txn_update_id")!= null) {
105
				resultMap.put("txn_update_id", (String)postMap.get("txn_update_id"));
106
					resultMap.put("txn_update_id", (String)postMap.get("txn_update_id"));
106
			}
107
				}
107
			if(postMap.get("request_id")!=null){
108
				if(postMap.get("request_id")!=null){
108
				resultMap.put("txn_update_id", (String)postMap.get("txn_update_id"));
109
					resultMap.put("txn_update_id", (String)postMap.get("txn_update_id"));
-
 
110
				}
-
 
111
				resultMap.put("mihpayid", (String)postMap.get("mihpayid"));
-
 
112
				resultMap.put("msg", (String)postMap.get("msg"));
109
			}
113
			}
-
 
114
		} catch (JSONException e) {
-
 
115
			log.error("Could not Parse json");
110
			resultMap.put("mihpayid", (String)postMap.get("mihpayid"));
116
			resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
111
			resultMap.put("msg", (String)postMap.get("msg"));
117
			resultMap.put(ERROR, "Could not parse refund");
112
		}
118
		}
113
		log.info("Parsed refund response for payment" + payment.getId());
119
		log.info("Parsed refund response for payment" + payment.getId());
114
		return resultMap;
120
		return resultMap;
115
	}
121
	}
116
 
122
 
Line 258... Line 264...
258
		}
264
		}
259
	}
265
	}
260
	
266
	
261
	public static void main (String arg[]){
267
	public static void main (String arg[]){
262
		String jsonText = "{\"amit\":0, \"babu\":{\"a\":\"Awesome\"}}";
268
		String jsonText = "{\"amit\":0, \"babu\":{\"a\":\"Awesome\"}}";
263
		System.out.println(jsonText);
269
/*		System.out.println(jsonText);
264
		GsonBuilder gsonBuilder = new GsonBuilder();
270
		GsonBuilder gsonBuilder = new GsonBuilder();
265
		gsonBuilder
271
		gsonBuilder
266
				.registerTypeAdapter(Object.class, new NaturalDeserializer());
272
				.registerTypeAdapter(Object.class, new NaturalDeserializer());
267
		Gson gson = gsonBuilder.create();
273
		Gson gson = gsonBuilder.create();
268
		Type t = new TypeToken<Map<String,Object>>() {}.getType();
274
		Type t = new TypeToken<Map<String,Object>>() {}.getType();
269
		Map<String, Object> postMap =  gson.fromJson(jsonText, t);
275
		Map<String, Object> postMap =  gson.fromJson(jsonText, t);
270
		/*Map<String, Object> postMap = (Map<String, Object>) gson.fromJson(
276
		Map<String, Object> postMap = (Map<String, Object>) gson.fromJson(
271
				jsonText, Object.class);*/
277
				jsonText, Object.class);
272
		System.out.println(postMap);
278
		System.out.println(postMap);
273
		System.out.println(0 == ((Integer)postMap.get("amit")).intValue());
279
		System.out.println(0 == ((Integer)postMap.get("amit")).intValue());*/
-
 
280
		try {
-
 
281
			JSONObject jo = new JSONObject(jsonText);
-
 
282
			System.out.println(jo);
-
 
283
			System.out.println(0 == ((Integer)jo.get("amit")).intValue());
-
 
284
		} catch (JSONException e) {
-
 
285
			// TODO Auto-generated catch block
-
 
286
			e.printStackTrace();
-
 
287
		}
274
	}
288
	}
275
}
289
}