| Line 215... |
Line 215... |
| 215 |
log.info("Key: " + entry.getKey() + ", Value: " + entry.getValue());
|
215 |
log.info("Key: " + entry.getKey() + ", Value: " + entry.getValue());
|
| 216 |
}
|
216 |
}
|
| 217 |
|
217 |
|
| 218 |
return resultMap;
|
218 |
return resultMap;
|
| 219 |
}
|
219 |
}
|
| - |
|
220 |
|
| - |
|
221 |
/**
|
| - |
|
222 |
* Refund the amount which was captured for this payment Id. Makes
|
| - |
|
223 |
* requests over the network and so internet connectivity is must for it to
|
| - |
|
224 |
* succeed.
|
| - |
|
225 |
*
|
| - |
|
226 |
* @param amount
|
| - |
|
227 |
* The amount to be refunded.
|
| - |
|
228 |
* @param paymentId
|
| - |
|
229 |
* The payment ID generated by the gateway.
|
| - |
|
230 |
* @return A Map. The Map will definitely have status and will have error
|
| - |
|
231 |
* information in case of error and txn information in case of
|
| - |
|
232 |
* success. In case there is an error in processing, the returned
|
| - |
|
233 |
* result map will be empty.
|
| - |
|
234 |
*/
|
| - |
|
235 |
public static Map<String, String> refundPayment(Payment payment, double amount){
|
| - |
|
236 |
String paymentId = payment.getGatewayPaymentId();
|
| - |
|
237 |
System.out.println("Refunding amount: Rs " + amount + " for payment Id: " + paymentId);
|
| - |
|
238 |
URL url = null;
|
| - |
|
239 |
URLConnection urlConn = null;
|
| - |
|
240 |
DataOutputStream printout;
|
| - |
|
241 |
BufferedReader reader;
|
| - |
|
242 |
Map<String, String> resultMap = new HashMap<String, String>();
|
| - |
|
243 |
|
| - |
|
244 |
//Prepare resultMap to elicit failure behaviour in case anything goes wrong.
|
| - |
|
245 |
resultMap.put(STATUS, "");
|
| - |
|
246 |
|
| - |
|
247 |
/*
|
| - |
|
248 |
* HDFC Insanity
|
| - |
|
249 |
*
|
| - |
|
250 |
* If we don't set this property, all payments through HDFC will fail if
|
| - |
|
251 |
* the first payment is made through EBS.
|
| - |
|
252 |
*
|
| - |
|
253 |
* The JAR file provided by HDFC requires that the instances of
|
| - |
|
254 |
* HttpsURLConnection returned by a call to URL.openConnection be an
|
| - |
|
255 |
* instance of com.sun.net.ssl.HttpsURLConnection. Java versions before
|
| - |
|
256 |
* 1.4 used to return an instance of this class which goes against the
|
| - |
|
257 |
* current policy of using instances of undocumented internal classes of
|
| - |
|
258 |
* JDK since they can change at any time. This behaviour was changed in
|
| - |
|
259 |
* JAVA 1.4 to return instances of javax.net.ssl.HttpsURLConnection.
|
| - |
|
260 |
* However, it appears, that to allow clients with JDK 1.4 and earlier,
|
| - |
|
261 |
* HDFC favours the use of the deprecated class.
|
| - |
|
262 |
*/
|
| - |
|
263 |
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
|
| - |
|
264 |
|
| - |
|
265 |
try {
|
| - |
|
266 |
// URL of CGI-Bin script.
|
| - |
|
267 |
url = new URL("https://secure.ebs.in/api/1_0");
|
| - |
|
268 |
// URL connection channel.
|
| - |
|
269 |
urlConn = url.openConnection();
|
| - |
|
270 |
//urlConn.setRequestMethod("POST");
|
| - |
|
271 |
} catch (MalformedURLException e1) {
|
| - |
|
272 |
log.error(Errors.CAPTURE_FAILURE.message, e1);
|
| - |
|
273 |
resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
|
| - |
|
274 |
resultMap.put(ERROR, Errors.CAPTURE_FAILURE.message);
|
| - |
|
275 |
return resultMap;
|
| - |
|
276 |
} catch (IOException e) {
|
| - |
|
277 |
log.error("Unable to initialize connection to EBS API server", e);
|
| - |
|
278 |
resultMap.put(ERR_CODE, Errors.CONN_FAILURE.code);
|
| - |
|
279 |
resultMap.put(ERROR, Errors.CONN_FAILURE.message);
|
| - |
|
280 |
return resultMap;
|
| - |
|
281 |
}
|
| - |
|
282 |
|
| - |
|
283 |
// Let the run-time system (RTS) know that we want input.
|
| - |
|
284 |
urlConn.setDoInput (true);
|
| - |
|
285 |
// Let the RTS know that we want to do output.
|
| - |
|
286 |
urlConn.setDoOutput (true);
|
| - |
|
287 |
// No caching, we want the real thing.
|
| - |
|
288 |
urlConn.setUseCaches (false);
|
| - |
|
289 |
// Specify the content type.
|
| - |
|
290 |
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
| - |
|
291 |
// Send POST output.
|
| - |
|
292 |
try {
|
| - |
|
293 |
printout = new DataOutputStream (urlConn.getOutputStream ());
|
| - |
|
294 |
String content =
|
| - |
|
295 |
"Action=" + URLEncoder.encode("refund", "UTF-8") +
|
| - |
|
296 |
"&AccountID=" + URLEncoder.encode(accountId, "UTF-8") +
|
| - |
|
297 |
"&SecretKey=" + URLEncoder.encode(secretKey, "UTF-8") +
|
| - |
|
298 |
"&Amount=" + URLEncoder.encode(""+amount, "UTF-8") +
|
| - |
|
299 |
"&PaymentID=" + URLEncoder.encode(paymentId, "UTF-8") +
|
| - |
|
300 |
"&submitted=Submit";
|
| - |
|
301 |
printout.writeBytes (content);
|
| - |
|
302 |
printout.flush ();
|
| - |
|
303 |
printout.close ();
|
| - |
|
304 |
|
| - |
|
305 |
// Get response data.
|
| - |
|
306 |
reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
|
| - |
|
307 |
resultMap = parseCaptureOutput(reader);
|
| - |
|
308 |
resultMap.put(REFUND_TXN_ID, resultMap.get(CAPTURE_TXN_ID));
|
| - |
|
309 |
resultMap.put(REFUND_TIME, resultMap.get(CAPTURE_TIME));
|
| - |
|
310 |
resultMap.remove(CAPTURE_TXN_ID);
|
| - |
|
311 |
resultMap.remove(CAPTURE_TIME);
|
| - |
|
312 |
reader.close ();
|
| - |
|
313 |
}
|
| - |
|
314 |
catch(ConnectException e) {
|
| - |
|
315 |
log.error("Unable to initialize connection to EBS API server", e);
|
| - |
|
316 |
resultMap.put(ERR_CODE, Errors.CONN_FAILURE.code);
|
| - |
|
317 |
resultMap.put(ERROR, Errors.CONN_FAILURE.message);
|
| - |
|
318 |
return resultMap;
|
| - |
|
319 |
}
|
| - |
|
320 |
catch (IOException e) {
|
| - |
|
321 |
log.error(Errors.CAPTURE_FAILURE.message, e);
|
| - |
|
322 |
resultMap.clear();
|
| - |
|
323 |
resultMap.put(STATUS, "");
|
| - |
|
324 |
resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
|
| - |
|
325 |
resultMap.put(ERROR, Errors.CAPTURE_FAILURE.message);
|
| - |
|
326 |
}
|
| - |
|
327 |
|
| - |
|
328 |
return resultMap;
|
| 220 |
|
329 |
}
|
| - |
|
330 |
|
| 221 |
public static void main(String[] args){
|
331 |
public static void main(String[] args){
|
| 222 |
//TODO: The following call has been deprecated now. Need to create a payment object to make this call now.
|
332 |
//TODO: The following call has been deprecated now. Need to create a payment object to make this call now.
|
| 223 |
// capturePayment(30450.00, "2412653");
|
333 |
// capturePayment(30450.00, "2412653");
|
| 224 |
|
334 |
|
| 225 |
// <output transactionId="4793507" paymentId="2411078" amount="25005" dateTime="2011-05-16 09:03:15" mode="TEST" referenceNo="4" transactionType="Captured" status="Processing" />";
|
335 |
// <output transactionId="4793507" paymentId="2411078" amount="25005" dateTime="2011-05-16 09:03:15" mode="TEST" referenceNo="4" transactionType="Captured" status="Processing" />";
|