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