| 7073 |
anupam.sin |
1 |
package in.shop2020.recharge.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.order.RechargeOrderStatus;
|
|
|
4 |
import in.shop2020.model.v1.order.RechargePlan;
|
|
|
5 |
import in.shop2020.model.v1.order.RechargeTransaction;
|
|
|
6 |
import in.shop2020.model.v1.order.RechargeType;
|
|
|
7 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
8 |
|
|
|
9 |
import java.math.BigInteger;
|
|
|
10 |
import java.util.ArrayList;
|
|
|
11 |
import java.util.List;
|
|
|
12 |
import java.util.Random;
|
|
|
13 |
|
|
|
14 |
import javax.mail.internet.AddressException;
|
|
|
15 |
import javax.mail.internet.InternetAddress;
|
|
|
16 |
import javax.servlet.http.HttpServletRequest;
|
|
|
17 |
|
|
|
18 |
import org.apache.log4j.Logger;
|
|
|
19 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
20 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
21 |
|
|
|
22 |
@Results({
|
|
|
23 |
@Result(name="recharge-redirect", type="redirectAction", params = {"actionName" , "/", "error", "${errorMessage}"})
|
|
|
24 |
})
|
|
|
25 |
|
|
|
26 |
public class ConfirmController extends BaseController{
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
*
|
|
|
30 |
*/
|
|
|
31 |
private static final long serialVersionUID = 1L;
|
|
|
32 |
private long rechargeOrderId = 0;
|
|
|
33 |
private String amount = "";
|
|
|
34 |
private String operator = "";
|
|
|
35 |
private String number = "";
|
|
|
36 |
private String email = "";
|
|
|
37 |
private String rechargeType = "";
|
|
|
38 |
private String deviceType = "";
|
|
|
39 |
private String storeId = "";
|
|
|
40 |
private String cafNum = "";
|
|
|
41 |
private String simNum = "";
|
|
|
42 |
private String name = "";
|
|
|
43 |
private String plan = "";
|
|
|
44 |
private String circleCode;
|
|
|
45 |
|
|
|
46 |
private String message = "";
|
|
|
47 |
private String errorMessage = "";
|
|
|
48 |
private String totalAmount = "";
|
|
|
49 |
private String couponCode = "";
|
|
|
50 |
private String couponMessage = "";
|
|
|
51 |
private String hiddenUserId = "";
|
|
|
52 |
private long couponAmount = 0;
|
|
|
53 |
private static final BigInteger key = new BigInteger("0333910847013829827302347601486730417451");
|
|
|
54 |
|
|
|
55 |
private static final Random random = new Random();
|
|
|
56 |
private static final int LENGTH = 10;
|
|
|
57 |
private static final String HEADER_X_FORWARDED_FOR = "X-FORWARDED-FOR";
|
|
|
58 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
59 |
|
|
|
60 |
public String index() {
|
|
|
61 |
return "index";
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
public String create() {
|
|
|
65 |
return index();
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
public String createRecharge(){
|
|
|
69 |
try {
|
|
|
70 |
TransactionClient tc = new TransactionClient();
|
|
|
71 |
List<RechargePlan> plans = tc.getClient().getPlansForOperator(Long.parseLong(operator));
|
|
|
72 |
List<String> planNameList = new ArrayList<String>();
|
|
|
73 |
if (plans == null || plans.isEmpty()) {
|
|
|
74 |
setPlan("");
|
|
|
75 |
} else {
|
|
|
76 |
for (RechargePlan tempPlan : plans) {
|
|
|
77 |
planNameList.add(tempPlan.getName());
|
|
|
78 |
}
|
|
|
79 |
if (!planNameList.contains(plan)) {
|
|
|
80 |
errorMessage = "OperatorId : " + operator + " and plan : " + plan + " do not match";
|
|
|
81 |
log.warn("OperatorId : " + operator + " and plan : " + plan + " do not match");
|
|
|
82 |
return "recharge-redirect";
|
|
|
83 |
}
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
RechargeTransaction rechargeOrder = new RechargeTransaction();
|
|
|
87 |
rechargeOrder.setAmount(Long.parseLong(totalAmount));
|
|
|
88 |
rechargeOrder.setEmail(email);
|
|
|
89 |
rechargeOrder.setDeviceNum(number.trim());
|
|
|
90 |
rechargeOrder.setPlan(plan);
|
|
|
91 |
rechargeOrder.setOperatorId(Long.parseLong(operator));
|
|
|
92 |
rechargeOrder.setIsFrc(Long.parseLong(rechargeType) == 1 ? false : true);
|
|
|
93 |
rechargeOrder.setStatus(RechargeOrderStatus.INIT);
|
|
|
94 |
|
|
|
95 |
/****************************************************
|
|
|
96 |
* rechargeOrder.setDiscount(discount); TODO *
|
|
|
97 |
****************************************************/
|
|
|
98 |
|
|
|
99 |
rechargeOrder.setIpAddress(remoteAddr(request));
|
|
|
100 |
TransactionClient tc1 = new TransactionClient();
|
|
|
101 |
rechargeOrder = tc1.getClient().createRechargeTransaction(rechargeOrder);
|
|
|
102 |
setRechargeOrderId(rechargeOrder.getId());
|
|
|
103 |
|
|
|
104 |
} catch (Exception e) {
|
|
|
105 |
log.error("Unable to create recharge order", e);
|
|
|
106 |
errorMessage = "Oops! There seems to be a problem. Please try after some time";
|
|
|
107 |
return "recharge-redirect";
|
|
|
108 |
}
|
|
|
109 |
return index();
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
public String getOperatorName() {
|
|
|
113 |
String operatorName = null;
|
|
|
114 |
if(rechargeType.equals("1")){
|
|
|
115 |
operatorName = HomeController.getMobileProvidersMap().get(Long.parseLong(operator));
|
|
|
116 |
}
|
|
|
117 |
if(rechargeType.equals("2")){
|
|
|
118 |
operatorName = HomeController.getDthProvidersMap().get(Long.parseLong(operator));
|
|
|
119 |
}
|
|
|
120 |
if(operatorName == null){
|
|
|
121 |
operatorName = "N/A";
|
|
|
122 |
}
|
|
|
123 |
return operatorName;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
public String remoteAddr(HttpServletRequest request) {
|
|
|
127 |
String remoteAddr = "";
|
|
|
128 |
String x;
|
|
|
129 |
x = request.getHeader(HEADER_X_FORWARDED_FOR);
|
|
|
130 |
if (x != null && !x.isEmpty()) {
|
|
|
131 |
remoteAddr = x;
|
|
|
132 |
int idx = remoteAddr.lastIndexOf(',');
|
|
|
133 |
if (idx > -1) {
|
|
|
134 |
remoteAddr = remoteAddr.substring(idx + 1).trim();
|
|
|
135 |
}
|
|
|
136 |
} else {
|
|
|
137 |
remoteAddr = request.getRemoteAddr();
|
|
|
138 |
}
|
|
|
139 |
return remoteAddr;
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
private String validateFields() {
|
|
|
143 |
if(amount == null || amount == "") {
|
|
|
144 |
log.warn("Amount received is empty or null");
|
|
|
145 |
return "Amount cannot be empty";
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
if(rechargeType == null || rechargeType == "") {
|
|
|
149 |
log.warn("rechargeType received is empty or null");
|
|
|
150 |
return "Oops! There seems to be a problem. Please try after some time";
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
if(email == null || email == "") {
|
|
|
154 |
log.warn("Email received is empty or null");
|
|
|
155 |
return "Email address cannot be empty";
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
try {
|
|
|
159 |
InternetAddress emailAdd = new InternetAddress(email);
|
|
|
160 |
emailAdd.validate();
|
|
|
161 |
} catch (AddressException e1) {
|
|
|
162 |
log.warn("Invalid email address : " + email, e1);
|
|
|
163 |
return "ERROR : Invalid email address.";
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
if (RechargeType.findByValue(Integer.parseInt(this.rechargeType)) == RechargeType.DTH) {
|
|
|
167 |
if (Long.parseLong(totalAmount) < 250 || Long.parseLong(totalAmount) > 2000) {
|
|
|
168 |
if(operator.equals("1")) {
|
|
|
169 |
return "DishTv recharge amount should be between Rs.250 and Rs.2000";
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
if (!(Long.parseLong(totalAmount) >= 200 && Long.parseLong(totalAmount) < 250)) {
|
|
|
173 |
return "DTH recharge amount should be between Rs.200 and Rs.2000";
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
} else if (RechargeType.findByValue(Integer.parseInt(this.rechargeType)) == RechargeType.MOBILE) {
|
|
|
178 |
if (Long.parseLong(totalAmount) < 10 || Long.parseLong(totalAmount) > 1000) {
|
|
|
179 |
return "Recharge amount should be between Rs.10 and Rs.1000";
|
|
|
180 |
}
|
|
|
181 |
if (number.length() != 10) {
|
|
|
182 |
return "Number should be of 10 digits";
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
} else {
|
|
|
186 |
log.warn("Invalid rechargeType : " + rechargeType);
|
|
|
187 |
return "Oops! There seems to be a problem. Please try after some time";
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
if (operator == null || operator == "") {
|
|
|
191 |
log.warn("Invalid operator : " + operator);
|
|
|
192 |
return "Oops! There seems to be a problem. Please try after some time";
|
|
|
193 |
}
|
|
|
194 |
return "SUCCESS";
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
public String getAmount() {
|
|
|
198 |
return amount;
|
|
|
199 |
}
|
|
|
200 |
public void setAmount(String amount) {
|
|
|
201 |
this.amount = amount;
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
public void setDthamount(String amount) {
|
|
|
205 |
this.amount = amount;
|
|
|
206 |
}
|
|
|
207 |
public String getOperator() {
|
|
|
208 |
return operator;
|
|
|
209 |
}
|
|
|
210 |
public void setOperator(String operator) {
|
|
|
211 |
this.operator = operator;
|
|
|
212 |
}
|
|
|
213 |
public String getNumber() {
|
|
|
214 |
return number;
|
|
|
215 |
}
|
|
|
216 |
public void setNumber(String number) {
|
|
|
217 |
this.number = number;
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
public void setDthnumber(String dthnumber) {
|
|
|
221 |
this.number = dthnumber;
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
public String getEmail() {
|
|
|
226 |
return email;
|
|
|
227 |
}
|
|
|
228 |
public void setEmail(String email) {
|
|
|
229 |
this.email = email;
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
public String getRechargeType() {
|
|
|
233 |
return rechargeType;
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
public void setRechargeType(String rechargeType) {
|
|
|
237 |
this.rechargeType = rechargeType;
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
public void setMessage(String message) {
|
|
|
241 |
this.message = message;
|
|
|
242 |
}
|
|
|
243 |
|
|
|
244 |
public String getMessage() {
|
|
|
245 |
return message;
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
public long getRechargeOrderId() {
|
|
|
249 |
return rechargeOrderId;
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
public void setRechargeOrderId(long l) {
|
|
|
253 |
this.rechargeOrderId = l;
|
|
|
254 |
}
|
|
|
255 |
|
|
|
256 |
public String getTotalAmount() {
|
|
|
257 |
return totalAmount;
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
public void setTotalAmount(String amount) {
|
|
|
261 |
this.totalAmount = amount;
|
|
|
262 |
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
public String getPlan() {
|
|
|
266 |
return plan;
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
public void setPlan(String plan) {
|
|
|
270 |
this.plan = plan;
|
|
|
271 |
}
|
|
|
272 |
|
|
|
273 |
public String getErrorMessage() {
|
|
|
274 |
return errorMessage;
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
public void setErrorMessage(String errorMessage) {
|
|
|
278 |
this.errorMessage = errorMessage;
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
public String getCircleCode() {
|
|
|
282 |
return circleCode;
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
public void setCircleCode(String circleCode) {
|
|
|
286 |
this.circleCode = circleCode;
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
public void setDiscountCode(String discountCode) {
|
|
|
290 |
this.couponCode = discountCode;
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
public String getCouponCode() {
|
|
|
294 |
return couponCode;
|
|
|
295 |
}
|
|
|
296 |
|
|
|
297 |
public void setCouponCode(String couponCode) {
|
|
|
298 |
this.couponCode = couponCode;
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
public void setCouponAmount(long couponAmount) {
|
|
|
302 |
this.couponAmount = couponAmount;
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
public long getCouponAmount() {
|
|
|
306 |
return couponAmount;
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
public void setCouponMessage(String couponMessage) {
|
|
|
310 |
this.couponMessage = couponMessage;
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
public String getCouponMessage() {
|
|
|
314 |
return couponMessage;
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
public void setHash(String hash) {
|
|
|
318 |
this.hiddenUserId = hash;
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
public String getHiddenUserId() {
|
|
|
322 |
return hiddenUserId;
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
public String getDeviceType() {
|
|
|
326 |
return deviceType;
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
public void setDeviceType(String deviceType) {
|
|
|
330 |
this.deviceType = deviceType;
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
public String getStoreId() {
|
|
|
334 |
return storeId;
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
public void setStoreId(String storeId) {
|
|
|
338 |
this.storeId = storeId;
|
|
|
339 |
}
|
|
|
340 |
|
|
|
341 |
public String getCafNum() {
|
|
|
342 |
return cafNum;
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
public void setCafNum(String cafNum) {
|
|
|
346 |
this.cafNum = cafNum;
|
|
|
347 |
}
|
|
|
348 |
|
|
|
349 |
public String getSimNum() {
|
|
|
350 |
return simNum;
|
|
|
351 |
}
|
|
|
352 |
|
|
|
353 |
public void setSimNum(String simNum) {
|
|
|
354 |
this.simNum = simNum;
|
|
|
355 |
}
|
|
|
356 |
|
|
|
357 |
public String getName() {
|
|
|
358 |
return name;
|
|
|
359 |
}
|
|
|
360 |
|
|
|
361 |
public void setName(String name) {
|
|
|
362 |
this.name = name;
|
|
|
363 |
}
|
|
|
364 |
}
|