| 6050 |
anupam.sin |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 6091 |
anupam.sin |
3 |
import in.shop2020.datalogger.DataLogger;
|
|
|
4 |
import in.shop2020.datalogger.EventType;
|
| 6050 |
anupam.sin |
5 |
import in.shop2020.model.v1.order.OrderType;
|
|
|
6 |
import in.shop2020.model.v1.order.RechargeCoupon;
|
|
|
7 |
import in.shop2020.model.v1.order.RechargeOrder;
|
|
|
8 |
import in.shop2020.model.v1.order.RechargeOrderStatus;
|
|
|
9 |
import in.shop2020.model.v1.order.RechargeType;
|
|
|
10 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 6057 |
anupam.sin |
11 |
import in.shop2020.model.v1.order.UserWallet;
|
| 6050 |
anupam.sin |
12 |
import in.shop2020.model.v1.user.Sex;
|
|
|
13 |
import in.shop2020.model.v1.user.User;
|
|
|
14 |
import in.shop2020.model.v1.user.UserContextException;
|
|
|
15 |
import in.shop2020.serving.interceptors.TrackingInterceptor;
|
|
|
16 |
import in.shop2020.serving.utils.DesEncrypter;
|
|
|
17 |
import in.shop2020.serving.utils.Utils;
|
|
|
18 |
import in.shop2020.thrift.clients.HelperClient;
|
|
|
19 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
20 |
import in.shop2020.thrift.clients.UserClient;
|
|
|
21 |
import in.shop2020.utils.HelperServiceException;
|
| 6091 |
anupam.sin |
22 |
import in.shop2020.utils.Mail;
|
| 6050 |
anupam.sin |
23 |
|
|
|
24 |
import java.util.ArrayList;
|
|
|
25 |
import java.util.List;
|
| 6057 |
anupam.sin |
26 |
import java.util.Map;
|
| 6091 |
anupam.sin |
27 |
import java.util.Random;
|
| 6050 |
anupam.sin |
28 |
|
|
|
29 |
import javax.servlet.http.Cookie;
|
|
|
30 |
|
|
|
31 |
import org.apache.log4j.Logger;
|
|
|
32 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
33 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
34 |
import org.apache.thrift.TException;
|
|
|
35 |
import org.apache.thrift.transport.TTransportException;
|
|
|
36 |
|
|
|
37 |
@SuppressWarnings({ "serial", "serial" })
|
|
|
38 |
@Results({
|
| 6091 |
anupam.sin |
39 |
@Result(name="recharge-pay-options-redirect", type="redirectAction", params = {"actionName" , "recharge-pay-options", "rechargeOrderId", "${rechargeOrderId}", "amount", "${amount}", "userId", "${userId}"}),
|
| 6057 |
anupam.sin |
40 |
@Result(name="create-recharge-redirect", type="redirectAction", params = {"actionName" , "wallet-only-payment", "rechargeOrderId", "${rechargeOrderId}"})
|
| 6050 |
anupam.sin |
41 |
})
|
|
|
42 |
|
|
|
43 |
public class ConfirmController extends BaseController{
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
*
|
|
|
47 |
*/
|
|
|
48 |
private static final long serialVersionUID = 1L;
|
| 6057 |
anupam.sin |
49 |
private long rechargeOrderId = 0;
|
| 6050 |
anupam.sin |
50 |
private String amount = "";
|
| 6086 |
anupam.sin |
51 |
private String walletAmountUsed = "0";
|
| 6050 |
anupam.sin |
52 |
private String operator = "";
|
|
|
53 |
private String number = "";
|
|
|
54 |
private String email = "";
|
|
|
55 |
private String rechargeType = "";
|
|
|
56 |
private DesEncrypter desEncrypter = new DesEncrypter("saholic");
|
|
|
57 |
private List<String> couponIds = null;
|
|
|
58 |
private List<RechargeCoupon> coupons = null;
|
| 6058 |
anupam.sin |
59 |
private String userId;
|
| 6057 |
anupam.sin |
60 |
private String message = "";
|
| 6070 |
anupam.sin |
61 |
private String totalAmount = "";
|
| 6091 |
anupam.sin |
62 |
private static final String chars = "abcdefghijklmonpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
|
63 |
private static final Random random = new Random();
|
|
|
64 |
private static final int LENGTH = 10;
|
| 6050 |
anupam.sin |
65 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
66 |
|
|
|
67 |
public String index() {
|
|
|
68 |
return "index";
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
public String create() {
|
| 6086 |
anupam.sin |
72 |
setTotalAmount(amount);
|
| 6057 |
anupam.sin |
73 |
if(userinfo.isLoggedIn()) {
|
|
|
74 |
try {
|
|
|
75 |
TransactionClient tc = new TransactionClient();
|
|
|
76 |
UserWallet wallet = tc.getClient().getUserWallet(userinfo.getUserId());
|
|
|
77 |
long amountA = 0;
|
|
|
78 |
if(wallet.getAmount() == 0){
|
|
|
79 |
setMessage("Your RechargeWallet is empty.");
|
|
|
80 |
} else if ((amountA = wallet.getAmount() - Long.parseLong(amount)) >= 0) {
|
|
|
81 |
setAmount("0");
|
|
|
82 |
setMessage("You now have Rs. " + amountA + " left in your RechargeWallet.");
|
| 6070 |
anupam.sin |
83 |
setWalletAmountUsed("" + (wallet.getAmount() - amountA));
|
| 6057 |
anupam.sin |
84 |
} else {
|
|
|
85 |
setAmount("" + (0-amountA));
|
|
|
86 |
setMessage("You have used all the amount in your RechargeWallet.");
|
| 6070 |
anupam.sin |
87 |
setWalletAmountUsed(("" + wallet.getAmount()));
|
| 6057 |
anupam.sin |
88 |
}
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
} catch (Exception e) {
|
|
|
92 |
log.error("Unable to get user wallet", e);
|
|
|
93 |
}
|
|
|
94 |
}
|
| 6091 |
anupam.sin |
95 |
setUserId("" + createUserAndSendMail(email));
|
| 6050 |
anupam.sin |
96 |
return index();
|
|
|
97 |
|
|
|
98 |
}
|
|
|
99 |
|
| 6070 |
anupam.sin |
100 |
private void setTotalAmount(String amount2) {
|
|
|
101 |
this.totalAmount = amount2;
|
|
|
102 |
|
|
|
103 |
}
|
|
|
104 |
|
| 6050 |
anupam.sin |
105 |
public String createRecharge(){
|
| 6057 |
anupam.sin |
106 |
if(userinfo.isLoggedIn()) {
|
| 6058 |
anupam.sin |
107 |
setUserId("" + userinfo.getUserId());
|
| 6086 |
anupam.sin |
108 |
} else {
|
| 6091 |
anupam.sin |
109 |
//setUserId("686085");
|
| 6057 |
anupam.sin |
110 |
}
|
| 6058 |
anupam.sin |
111 |
|
| 6050 |
anupam.sin |
112 |
try {
|
| 6058 |
anupam.sin |
113 |
TransactionClient tc = new TransactionClient();
|
| 6050 |
anupam.sin |
114 |
RechargeOrder rechargeOrder = new RechargeOrder();
|
| 6070 |
anupam.sin |
115 |
rechargeOrder.setTotalAmount(Long.parseLong(amount) + Long.parseLong(getWalletAmountUsed()));
|
| 6050 |
anupam.sin |
116 |
rechargeOrder.setUserEmailId(email);
|
| 6058 |
anupam.sin |
117 |
rechargeOrder.setUserId(Long.parseLong(userId));
|
| 6050 |
anupam.sin |
118 |
rechargeOrder.setDeviceNumber(number);
|
|
|
119 |
rechargeOrder.setOperatorId(Long.parseLong(operator));
|
| 6057 |
anupam.sin |
120 |
rechargeOrder.setRechargeType(RechargeType.findByValue(Integer.parseInt(rechargeType)));
|
| 6050 |
anupam.sin |
121 |
rechargeOrder.setStatus(RechargeOrderStatus.PAYMENT_PENDING);
|
|
|
122 |
rechargeOrder.setOrderType(OrderType.B2C);
|
| 6070 |
anupam.sin |
123 |
rechargeOrder.setWalletAmount(Long.parseLong(getWalletAmountUsed()));
|
| 6050 |
anupam.sin |
124 |
|
|
|
125 |
rechargeOrder = tc.getClient().createRechargeOrder(rechargeOrder);
|
| 6057 |
anupam.sin |
126 |
setRechargeOrderId(rechargeOrder.getId());
|
| 6050 |
anupam.sin |
127 |
|
|
|
128 |
} catch (TransactionServiceException e) {
|
|
|
129 |
// TODO Auto-generated catch block
|
|
|
130 |
e.printStackTrace();
|
|
|
131 |
} catch (TException e) {
|
|
|
132 |
// TODO Auto-generated catch block
|
|
|
133 |
e.printStackTrace();
|
|
|
134 |
}
|
|
|
135 |
if(amount.equals("0")) {
|
|
|
136 |
return "create-recharge-redirect";
|
|
|
137 |
} else {
|
|
|
138 |
return "recharge-pay-options-redirect";
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
|
| 6091 |
anupam.sin |
142 |
private static String generateNewPassword() {
|
|
|
143 |
char[] buf = new char[LENGTH];
|
|
|
144 |
for (int i = 0; i < buf.length; i++) {
|
|
|
145 |
buf[i] = chars.charAt(random.nextInt(chars.length()));
|
|
|
146 |
}
|
|
|
147 |
return new String(buf);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
private long createUserAndSendMail(String email) {
|
|
|
151 |
User user = null;
|
|
|
152 |
String password = null;
|
|
|
153 |
try{
|
|
|
154 |
UserClient ucl = new UserClient();
|
|
|
155 |
user = ucl.getClient().getUserByEmail(email);
|
|
|
156 |
if(user == null) {
|
|
|
157 |
user = new User();
|
|
|
158 |
user.setEmail(email);
|
|
|
159 |
password = generateNewPassword();
|
|
|
160 |
String encryptedPassword = desEncrypter.encrypt(password);
|
|
|
161 |
user.setPassword(encryptedPassword);
|
|
|
162 |
user.setCommunicationEmail(email);
|
|
|
163 |
UserClient userContextServiceClient = new UserClient();
|
|
|
164 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
165 |
user = userClient.createUser(user);
|
|
|
166 |
}
|
|
|
167 |
//DataLogger.logData(EventType.REGISTER_SUCCESS, getSessionId(), user.getUserId(), email, "", email);
|
|
|
168 |
}catch (UserContextException ux){
|
|
|
169 |
//DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, "", email);
|
|
|
170 |
return -1;
|
|
|
171 |
} catch (TTransportException e) {
|
|
|
172 |
//DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, "", email);
|
|
|
173 |
return -1;
|
|
|
174 |
} catch (TException e) {
|
|
|
175 |
//DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, "", email);
|
|
|
176 |
return -1;
|
|
|
177 |
}
|
|
|
178 |
/*
|
|
|
179 |
List<String> toList = new ArrayList<String>();
|
|
|
180 |
toList.add(email);
|
|
|
181 |
HelperClient helperServiceClient = null;
|
|
|
182 |
try {
|
|
|
183 |
helperServiceClient = new HelperClient();
|
|
|
184 |
in.shop2020.utils.HelperService.Client client = helperServiceClient.getClient();
|
|
|
185 |
Mail mail = new Mail();
|
|
|
186 |
mail.setSubject("Registration successful");
|
|
|
187 |
mail.setTo(toList);
|
|
|
188 |
mail.setData("Your have successfully registered with Saholic.com. Your user name is: " + email + " and your password is: " + password);
|
|
|
189 |
client.sendMail(mail);
|
|
|
190 |
} catch (Exception e) {
|
|
|
191 |
log.error("Unexpected error while mailing the new password");
|
|
|
192 |
return -1;
|
|
|
193 |
}*/
|
|
|
194 |
return user.getUserId();
|
|
|
195 |
}
|
|
|
196 |
|
| 6050 |
anupam.sin |
197 |
public String temp() {
|
|
|
198 |
try {
|
|
|
199 |
UserClient ucl = new UserClient();
|
|
|
200 |
User user = ucl.getClient().getUserByEmail(email);
|
|
|
201 |
if(user == null) {
|
|
|
202 |
user = new User();
|
|
|
203 |
String password = null;
|
|
|
204 |
boolean isValid = true;
|
|
|
205 |
|
|
|
206 |
/**
|
|
|
207 |
* TODO : Generate password
|
|
|
208 |
* password = this.request.getParameter("txtPassword");
|
|
|
209 |
*
|
|
|
210 |
*/
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
if(!Utils.isValidEmail(email)) {
|
|
|
214 |
addActionError("Please enter valid email address.");
|
|
|
215 |
isValid = false;
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
user.setEmail(email);
|
|
|
219 |
String encryptedPassword = desEncrypter.encrypt(password);
|
|
|
220 |
user.setPassword(encryptedPassword);
|
|
|
221 |
user.setCommunicationEmail(email);
|
|
|
222 |
Cookie sourceCookie = (Cookie) cookiesMap.get(TrackingInterceptor.SRC_COOKIE);
|
|
|
223 |
if (sourceCookie != null) {
|
|
|
224 |
DesEncrypter des = new DesEncrypter(TrackingInterceptor.ENCRIPTION_STRING);
|
|
|
225 |
String sourceCookieVal = des.decrypt(sourceCookie.getValue());
|
|
|
226 |
user.setSource(sourceCookieVal);
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
Cookie sourceTimeCookie = (Cookie) cookiesMap.get(TrackingInterceptor.SRC_TIME_COOKIE);
|
|
|
230 |
long sourceTime = 0;
|
|
|
231 |
if (sourceTimeCookie != null) {
|
|
|
232 |
try {
|
|
|
233 |
sourceTime = Long.parseLong(sourceTimeCookie.getValue());
|
|
|
234 |
}
|
|
|
235 |
catch (Exception e) {
|
|
|
236 |
log.warn("Unable to parse session src time cookie.");
|
|
|
237 |
}
|
|
|
238 |
user.setSourceStartTime(sourceTime);
|
|
|
239 |
}
|
|
|
240 |
|
|
|
241 |
user.setSex(Sex.WONT_SAY);
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
UserClient userContextServiceClient;
|
|
|
245 |
userContextServiceClient = new UserClient();
|
|
|
246 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
247 |
user = userClient.createUser(user);
|
|
|
248 |
HelperClient hc = new HelperClient();
|
|
|
249 |
List<String> mailingList = new ArrayList<String>();
|
|
|
250 |
mailingList.add(email);
|
|
|
251 |
hc.getClient().saveUserEmailForSending(mailingList, "help@saholic.com", "Login Details", "/*body*/", "/*source*/", "/*emailType*/", null, null);
|
|
|
252 |
}
|
| 6057 |
anupam.sin |
253 |
//setUserId("" + user.getUserId());
|
| 6050 |
anupam.sin |
254 |
|
|
|
255 |
|
|
|
256 |
/*****************************
|
|
|
257 |
*
|
|
|
258 |
* TODO : Handle Wallets
|
|
|
259 |
*
|
|
|
260 |
*/
|
|
|
261 |
|
|
|
262 |
|
|
|
263 |
//TransactionClient tc = new TransactionClient();
|
|
|
264 |
//setCoupons(tc.getClient().getRechargeCoupons(user.getUserId(), RechargeCouponStatus.ACTIVE));
|
|
|
265 |
} catch (TTransportException e) {
|
|
|
266 |
// TODO Auto-generated catch block
|
|
|
267 |
e.printStackTrace();
|
|
|
268 |
} catch (UserContextException e) {
|
|
|
269 |
// TODO Auto-generated catch block
|
|
|
270 |
e.printStackTrace();
|
|
|
271 |
} catch (TException e) {
|
|
|
272 |
// TODO Auto-generated catch block
|
|
|
273 |
e.printStackTrace();
|
|
|
274 |
} catch (HelperServiceException e) {
|
|
|
275 |
// TODO Auto-generated catch block
|
|
|
276 |
e.printStackTrace();
|
|
|
277 |
}
|
|
|
278 |
return index();
|
|
|
279 |
}
|
|
|
280 |
|
| 6057 |
anupam.sin |
281 |
public String getOperatorName() {
|
|
|
282 |
try {
|
|
|
283 |
TransactionClient tc = new TransactionClient();
|
|
|
284 |
Map<Long, String> providers = tc.getClient().getServiceProviders(RechargeType.findByValue(Integer.parseInt(rechargeType)));
|
|
|
285 |
return providers.get(Long.parseLong(operator));
|
|
|
286 |
} catch(Exception e) {
|
|
|
287 |
log.error("Unable to get operator name");
|
|
|
288 |
}
|
|
|
289 |
return "N/A";
|
|
|
290 |
}
|
|
|
291 |
|
| 6050 |
anupam.sin |
292 |
public String getAmount() {
|
|
|
293 |
return amount;
|
|
|
294 |
}
|
|
|
295 |
public void setAmount(String amount) {
|
|
|
296 |
this.amount = amount;
|
|
|
297 |
}
|
| 6073 |
amit.gupta |
298 |
|
|
|
299 |
public void setDthamount(String amount) {
|
|
|
300 |
this.amount = amount;
|
|
|
301 |
}
|
| 6050 |
anupam.sin |
302 |
public String getOperator() {
|
|
|
303 |
return operator;
|
|
|
304 |
}
|
|
|
305 |
public void setOperator(String operator) {
|
|
|
306 |
this.operator = operator;
|
|
|
307 |
}
|
|
|
308 |
public String getNumber() {
|
|
|
309 |
return number;
|
|
|
310 |
}
|
|
|
311 |
public void setNumber(String number) {
|
|
|
312 |
this.number = number;
|
|
|
313 |
}
|
| 6073 |
amit.gupta |
314 |
|
|
|
315 |
public void setDthnumber(String dthnumber) {
|
|
|
316 |
this.number = dthnumber;
|
|
|
317 |
}
|
|
|
318 |
|
|
|
319 |
|
| 6050 |
anupam.sin |
320 |
public String getEmail() {
|
|
|
321 |
return email;
|
|
|
322 |
}
|
|
|
323 |
public void setEmail(String email) {
|
|
|
324 |
this.email = email;
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
public void setCouponIds(List<String> couponIds) {
|
|
|
328 |
this.couponIds = couponIds;
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
public List<String> getCouponIds() {
|
|
|
332 |
return couponIds;
|
|
|
333 |
}
|
|
|
334 |
|
|
|
335 |
public void setCoupons(List<RechargeCoupon> coupons) {
|
|
|
336 |
this.coupons = coupons;
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
public List<RechargeCoupon> getCoupons() {
|
|
|
340 |
return coupons;
|
|
|
341 |
}
|
|
|
342 |
|
|
|
343 |
public String getRechargeType() {
|
|
|
344 |
return rechargeType;
|
|
|
345 |
}
|
|
|
346 |
|
|
|
347 |
public void setRechargeType(String rechargeType) {
|
|
|
348 |
this.rechargeType = rechargeType;
|
|
|
349 |
}
|
|
|
350 |
|
| 6058 |
anupam.sin |
351 |
public String getUserId() {
|
| 6050 |
anupam.sin |
352 |
return userId;
|
|
|
353 |
}
|
|
|
354 |
|
| 6058 |
anupam.sin |
355 |
public void setUserId(String userId) {
|
|
|
356 |
this.userId = userId;
|
| 6050 |
anupam.sin |
357 |
}
|
|
|
358 |
|
| 6057 |
anupam.sin |
359 |
public boolean isLoggedIn() {
|
|
|
360 |
return userinfo.isLoggedIn();
|
|
|
361 |
}
|
|
|
362 |
|
|
|
363 |
public void setMessage(String message) {
|
|
|
364 |
this.message = message;
|
|
|
365 |
}
|
|
|
366 |
|
|
|
367 |
public String getMessage() {
|
|
|
368 |
return message;
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
public long getRechargeOrderId() {
|
|
|
372 |
return rechargeOrderId;
|
|
|
373 |
}
|
|
|
374 |
|
|
|
375 |
public void setRechargeOrderId(long l) {
|
|
|
376 |
this.rechargeOrderId = l;
|
|
|
377 |
}
|
| 6070 |
anupam.sin |
378 |
|
|
|
379 |
public String getTotalAmount() {
|
|
|
380 |
return totalAmount;
|
|
|
381 |
}
|
|
|
382 |
|
|
|
383 |
public String getWalletAmountUsed() {
|
|
|
384 |
return walletAmountUsed;
|
|
|
385 |
}
|
|
|
386 |
|
|
|
387 |
public void setWalletAmountUsed(String walletAmountUsed) {
|
|
|
388 |
this.walletAmountUsed = walletAmountUsed;
|
|
|
389 |
}
|
| 6057 |
anupam.sin |
390 |
|
| 6050 |
anupam.sin |
391 |
}
|