| Line 1... |
Line 1... |
| 1 |
package in.shop2020.payment.service.handler;
|
1 |
package in.shop2020.payment.service.handler;
|
| 2 |
|
2 |
|
| - |
|
3 |
import in.shop2020.payment.domain.Payment;
|
| 3 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
4 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 4 |
|
5 |
|
| 5 |
import java.io.BufferedReader;
|
6 |
import java.io.BufferedReader;
|
| 6 |
import java.io.InputStreamReader;
|
7 |
import java.io.InputStreamReader;
|
| 7 |
import java.lang.reflect.Type;
|
8 |
import java.lang.reflect.Type;
|
| Line 59... |
Line 60... |
| 59 |
apiUrl = cc.get("payu_api_url");
|
60 |
apiUrl = cc.get("payu_api_url");
|
| 60 |
} catch (Exception e) {
|
61 |
} catch (Exception e) {
|
| 61 |
log.error("Could not initialize Payu Handler!");
|
62 |
log.error("Could not initialize Payu Handler!");
|
| 62 |
}
|
63 |
}
|
| 63 |
}
|
64 |
}
|
| - |
|
65 |
|
| - |
|
66 |
public static Map<String, String> refundPayment(Payment payment, double amount){
|
| - |
|
67 |
Map<String, String> params = new HashMap<String, String>();
|
| - |
|
68 |
Map<String, String> resultMap = new HashMap<String, String>();
|
| - |
|
69 |
String payuId = payment.getGatewayPaymentId();
|
| - |
|
70 |
params.put("key", accountId);
|
| - |
|
71 |
params.put("command", "cancel_refund_transaction");
|
| - |
|
72 |
params.put("var1", payuId);
|
| - |
|
73 |
params.put("var2", new Date().getTime() + "");
|
| - |
|
74 |
params.put("var3", amount + "");
|
| - |
|
75 |
try {
|
| - |
|
76 |
params.put("hash", getSecureHash(params));
|
| - |
|
77 |
} catch (Exception e) {
|
| - |
|
78 |
resultMap.put(ERR_CODE, Errors.CONN_FAILURE.code);
|
| - |
|
79 |
resultMap.put(ERROR, Errors.CONN_FAILURE.message);
|
| - |
|
80 |
return resultMap;
|
| - |
|
81 |
}
|
| - |
|
82 |
String postResponse = "";
|
| - |
|
83 |
try {
|
| - |
|
84 |
postResponse = executePost(apiUrl, getUrlParams(params));
|
| - |
|
85 |
} catch (Exception e) {
|
| - |
|
86 |
resultMap.put(ERR_CODE, Errors.CONN_FAILURE.code);
|
| - |
|
87 |
resultMap.put(ERROR, Errors.CONN_FAILURE.message);
|
| - |
|
88 |
return resultMap;
|
| - |
|
89 |
}
|
| - |
|
90 |
GsonBuilder gsonBuilder = new GsonBuilder();
|
| - |
|
91 |
gsonBuilder
|
| - |
|
92 |
.registerTypeAdapter(Object.class, new NaturalDeserializer());
|
| - |
|
93 |
Gson gson = gsonBuilder.create();
|
| - |
|
94 |
Type t = new TypeToken<Map<String,Object>>() {}.getType();
|
| - |
|
95 |
Map<String, Object> postMap = gson.fromJson(postResponse, t);
|
| - |
|
96 |
if ("0".equals(postMap.get("status"))) {
|
| - |
|
97 |
resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
|
| - |
|
98 |
resultMap.put(ERROR, (String)postMap.get("msg"));
|
| - |
|
99 |
} else if ("1".equals(postMap.get("status"))){
|
| - |
|
100 |
resultMap.put(REF_NO, (String) postMap.get("bank_ref_num"));
|
| - |
|
101 |
if(postMap.get("txn_update_id")!= null) {
|
| - |
|
102 |
resultMap.put("txn_update_id", (String)postMap.get("txn_update_id"));
|
| - |
|
103 |
}
|
| - |
|
104 |
if(postMap.get("request_id")!=null){
|
| - |
|
105 |
resultMap.put("txn_update_id", (String)postMap.get("txn_update_id"));
|
| - |
|
106 |
}
|
| - |
|
107 |
resultMap.put("mihpayid", (String)postMap.get("mihpayid"));
|
| - |
|
108 |
resultMap.put("msg", (String)postMap.get("msg"));
|
| - |
|
109 |
}
|
| - |
|
110 |
log.info("Parsed refund response for payment" + payment.getId());
|
| - |
|
111 |
return resultMap;
|
| - |
|
112 |
}
|
| 64 |
|
113 |
|
| 65 |
public static Map<String, String> captureTransaction(String paymentId,
|
114 |
public static Map<String, String> captureTransaction(String paymentId,
|
| 66 |
String payuId) {
|
115 |
String payuId) {
|
| 67 |
Map<String, String> params = new HashMap<String, String>();
|
116 |
Map<String, String> params = new HashMap<String, String>();
|
| 68 |
Map<String, String> resultMap = new HashMap<String, String>();
|
117 |
Map<String, String> resultMap = new HashMap<String, String>();
|