| Line 2... |
Line 2... |
| 2 |
|
2 |
|
| 3 |
import in.shop2020.model.v1.order.FRC;
|
3 |
import in.shop2020.model.v1.order.FRC;
|
| 4 |
import in.shop2020.model.v1.order.RechargePlan;
|
4 |
import in.shop2020.model.v1.order.RechargePlan;
|
| 5 |
import in.shop2020.model.v1.order.RechargeTransaction;
|
5 |
import in.shop2020.model.v1.order.RechargeTransaction;
|
| 6 |
import in.shop2020.model.v1.order.RechargeType;
|
6 |
import in.shop2020.model.v1.order.RechargeType;
|
| - |
|
7 |
import in.shop2020.model.v1.order.TelecomCircle;
|
| 7 |
import in.shop2020.thrift.clients.TransactionClient;
|
8 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 8 |
|
9 |
|
| 9 |
import java.math.BigInteger;
|
10 |
import java.math.BigInteger;
|
| 10 |
import java.util.ArrayList;
|
11 |
import java.util.ArrayList;
|
| 11 |
import java.util.List;
|
12 |
import java.util.List;
|
| Line 18... |
Line 19... |
| 18 |
import org.apache.log4j.Logger;
|
19 |
import org.apache.log4j.Logger;
|
| 19 |
import org.apache.struts2.convention.annotation.Result;
|
20 |
import org.apache.struts2.convention.annotation.Result;
|
| 20 |
import org.apache.struts2.convention.annotation.Results;
|
21 |
import org.apache.struts2.convention.annotation.Results;
|
| 21 |
|
22 |
|
| 22 |
@Results({
|
23 |
@Results({
|
| 23 |
@Result(name="recharge-redirect", type="redirectAction", params = {"actionName" , "/", "errorMsg", "${errorMessage}"}),
|
24 |
@Result(name="recharge-redirect", type="redirectAction", params = {"actionName" , "home", "errorMsg", "${errorMessage}"}),
|
| 24 |
@Result(name="recharge-result", type="redirectAction", params = {"actionName" , "recharge-result", "rechargeId", "${rechargeOrderId}"})
|
25 |
@Result(name="recharge-result", type="redirectAction", params = {"actionName" , "recharge-result", "rechargeId", "${rechargeOrderId}"})
|
| 25 |
})
|
26 |
})
|
| 26 |
|
27 |
|
| 27 |
public class ConfirmController extends BaseController{
|
28 |
public class ConfirmController extends BaseController{
|
| 28 |
|
29 |
|
| Line 42... |
Line 43... |
| 42 |
private String cafNum = "";
|
43 |
private String cafNum = "";
|
| 43 |
private String simNum = "";
|
44 |
private String simNum = "";
|
| 44 |
private String altNum = "";
|
45 |
private String altNum = "";
|
| 45 |
private String name = "";
|
46 |
private String name = "";
|
| 46 |
private String plan = "";
|
47 |
private String plan = "";
|
| 47 |
private String circleId = "";
|
- |
|
| 48 |
private String discount = "";
|
48 |
private String discount = "";
|
| - |
|
49 |
private String circlecode = "";
|
| 49 |
|
50 |
|
| 50 |
private String message = "";
|
51 |
private String message = "";
|
| 51 |
private String errorMessage = "";
|
52 |
private String errorMessage = "";
|
| 52 |
private String totalAmount = "";
|
53 |
private String totalAmount = "";
|
| 53 |
private String couponCode = "";
|
54 |
private String couponCode = "";
|
| Line 57... |
Line 58... |
| 57 |
private static final BigInteger key = new BigInteger("0333910847013829827302347601486730417451");
|
58 |
private static final BigInteger key = new BigInteger("0333910847013829827302347601486730417451");
|
| 58 |
|
59 |
|
| 59 |
private static final Random random = new Random();
|
60 |
private static final Random random = new Random();
|
| 60 |
private static final int LENGTH = 10;
|
61 |
private static final int LENGTH = 10;
|
| 61 |
private static final String HEADER_X_FORWARDED_FOR = "X-FORWARDED-FOR";
|
62 |
private static final String HEADER_X_FORWARDED_FOR = "X-FORWARDED-FOR";
|
| - |
|
63 |
private static final String DISHTV = "DISH TV";
|
| 62 |
private static Logger log = Logger.getLogger(Class.class);
|
64 |
private static Logger log = Logger.getLogger(Class.class);
|
| 63 |
|
65 |
|
| 64 |
public String index() {
|
66 |
public String index() {
|
| 65 |
return "index";
|
67 |
return "index";
|
| 66 |
}
|
68 |
}
|
| 67 |
|
69 |
|
| 68 |
public String create() {
|
70 |
public String create() {
|
| - |
|
71 |
try {
|
| - |
|
72 |
String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
|
| - |
|
73 |
if(loginStatus == null || !loginStatus.equals("TRUE")){
|
| - |
|
74 |
return "authfail";
|
| - |
|
75 |
}
|
| - |
|
76 |
|
| - |
|
77 |
String result = validateFields();
|
| - |
|
78 |
if(!result.equals("SUCCESS")) {
|
| - |
|
79 |
errorMessage = result;
|
| - |
|
80 |
return "recharge-redirect";
|
| - |
|
81 |
}
|
| - |
|
82 |
TransactionClient tcl = new TransactionClient();
|
| - |
|
83 |
boolean discountRemove = true;
|
| - |
|
84 |
|
| - |
|
85 |
Long circleId = 0l;
|
| - |
|
86 |
if(circlecode != null && !circlecode.equals("")) {
|
| - |
|
87 |
TransactionClient tcl1 = new TransactionClient();
|
| - |
|
88 |
TelecomCircle circle = tcl1.getClient().getTelecomCircle(-1, circlecode);
|
| - |
|
89 |
if(circle != null) {
|
| - |
|
90 |
circleId = circle.getId();
|
| - |
|
91 |
}
|
| - |
|
92 |
}
|
| - |
|
93 |
|
| - |
|
94 |
if(rechargeType.equals("2")) {
|
| - |
|
95 |
for (FRC frc : tcl.getClient().getFRCs(circleId, Long.parseLong(mobileOperator))) {
|
| - |
|
96 |
if(frc.getDenomination() == Long.parseLong(amount)) {
|
| - |
|
97 |
if(frc.getMaxDiscount() < Long.parseLong(discount)) {
|
| - |
|
98 |
errorMessage = "MaxDiscount : " + frc.getMaxDiscount() + " is less than discount amount entered";
|
| - |
|
99 |
log.warn("MaxDiscount : " + frc.getMaxDiscount() + " is less than discount amount entered");
|
| - |
|
100 |
return "recharge-redirect";
|
| - |
|
101 |
} else {
|
| - |
|
102 |
discountRemove = false;
|
| - |
|
103 |
}
|
| - |
|
104 |
}
|
| - |
|
105 |
}
|
| - |
|
106 |
|
| - |
|
107 |
if(discountRemove) {
|
| - |
|
108 |
setDiscount("0");
|
| - |
|
109 |
}
|
| - |
|
110 |
}
|
| - |
|
111 |
} catch (Exception e) {
|
| - |
|
112 |
log.warn("Unable to get frc for operatorId : " + mobileOperator, e);
|
| - |
|
113 |
}
|
| 69 |
return index();
|
114 |
return index();
|
| 70 |
}
|
115 |
}
|
| 71 |
|
116 |
|
| 72 |
public String createRecharge(){
|
117 |
public String createRecharge(){
|
| 73 |
try {
|
118 |
try {
|
| - |
|
119 |
String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
|
| - |
|
120 |
if(loginStatus == null || !loginStatus.equals("TRUE")){
|
| 74 |
//TODO REmove this
|
121 |
return "authfail";
|
| - |
|
122 |
}
|
| - |
|
123 |
|
| - |
|
124 |
String result = validateFields();
|
| - |
|
125 |
if(!result.equals("SUCCESS")) {
|
| 75 |
setStoreId("1");
|
126 |
errorMessage = result;
|
| 76 |
setCircleId("5");
|
127 |
return "recharge-redirect";
|
| 77 |
//
|
128 |
}
|
| - |
|
129 |
|
| 78 |
TransactionClient tc = new TransactionClient();
|
130 |
TransactionClient tc = new TransactionClient();
|
| 79 |
List<RechargePlan> plans = tc.getClient().getPlansForOperator(Long.parseLong(mobileOperator));
|
131 |
List<RechargePlan> plans = tc.getClient().getPlansForOperator(Long.parseLong(mobileOperator));
|
| 80 |
List<String> planNameList = new ArrayList<String>();
|
132 |
List<String> planNameList = new ArrayList<String>();
|
| 81 |
if (plans == null || plans.isEmpty()) {
|
133 |
if (plans == null || plans.isEmpty()) {
|
| 82 |
setPlan("");
|
134 |
setPlan("");
|
| Line 90... |
Line 142... |
| 90 |
return "recharge-redirect";
|
142 |
return "recharge-redirect";
|
| 91 |
}
|
143 |
}
|
| 92 |
}
|
144 |
}
|
| 93 |
|
145 |
|
| 94 |
RechargeTransaction rechargeOrder = new RechargeTransaction();
|
146 |
RechargeTransaction rechargeOrder = new RechargeTransaction();
|
| - |
|
147 |
|
| 95 |
rechargeOrder.setAmount(Long.parseLong(amount));
|
148 |
rechargeOrder.setAmount(Long.parseLong(amount));
|
| 96 |
rechargeOrder.setEmail(email);
|
149 |
rechargeOrder.setEmail(email);
|
| 97 |
rechargeOrder.setDeviceNum(number.trim());
|
150 |
rechargeOrder.setDeviceNum(number.trim());
|
| 98 |
rechargeOrder.setPlan(plan);
|
151 |
rechargeOrder.setPlan(plan);
|
| - |
|
152 |
rechargeOrder.setAlternateNumber(altNum);
|
| - |
|
153 |
rechargeOrder.setStoreId(Long.parseLong((String) request.getSession().getAttribute("STORE_ID")));
|
| - |
|
154 |
rechargeOrder.setIpAddress(remoteAddr(request));
|
| - |
|
155 |
rechargeOrder.setDeviceType(RechargeType.findByValue((int) Long.parseLong(deviceType)));
|
| - |
|
156 |
rechargeOrder.setName(name);
|
| - |
|
157 |
rechargeOrder.setIsFrc(Long.parseLong(rechargeType) == 1 ? false : true);
|
| - |
|
158 |
rechargeOrder.setCafNum(cafNum);
|
| - |
|
159 |
rechargeOrder.setSimNum(simNum);
|
| - |
|
160 |
|
| 99 |
if(deviceType.equals("1")) {
|
161 |
if(deviceType.equals("1")) {
|
| 100 |
rechargeOrder.setOperatorId(Long.parseLong(mobileOperator));
|
162 |
rechargeOrder.setOperatorId(Long.parseLong(mobileOperator));
|
| 101 |
} else if (deviceType.equals("2")) {
|
163 |
} else if (deviceType.equals("2")) {
|
| 102 |
rechargeOrder.setOperatorId(Long.parseLong(dthOperator));
|
164 |
rechargeOrder.setOperatorId(Long.parseLong(dthOperator));
|
| 103 |
}
|
165 |
}
|
| 104 |
|
166 |
|
| 105 |
rechargeOrder.setIsFrc(Long.parseLong(rechargeType) == 1 ? false : true);
|
167 |
rechargeOrder.setPaymentAmount(Long.parseLong(amount) - Long.parseLong(discount));
|
| - |
|
168 |
|
| - |
|
169 |
Long circleId = 0l;
|
| - |
|
170 |
if(circlecode != null && !circlecode.equals("")) {
|
| - |
|
171 |
TransactionClient tcl1 = new TransactionClient();
|
| - |
|
172 |
TelecomCircle circle = tcl1.getClient().getTelecomCircle(-1, circlecode);
|
| - |
|
173 |
if(circle != null) {
|
| - |
|
174 |
circleId = circle.getId();
|
| - |
|
175 |
if(rechargeOrder.isIsFrc()) {
|
| - |
|
176 |
Long storeCircle = (Long.parseLong((String) request.getSession().getAttribute("CIRCLE_ID")));
|
| - |
|
177 |
if(storeCircle == circle.getId()) {
|
| - |
|
178 |
rechargeOrder.setCircleId(storeCircle);
|
| - |
|
179 |
} else {
|
| - |
|
180 |
errorMessage = "FRC is not possible because this number is of : " + circle.getName() + " circle.";
|
| - |
|
181 |
log.warn("FRC is not possible because this number is of : " + circle.getName() + " circle & storeCircle : " + storeCircle);
|
| - |
|
182 |
return "recharge-redirect";
|
| - |
|
183 |
}
|
| - |
|
184 |
} else {
|
| 106 |
rechargeOrder.setCafNum(cafNum);
|
185 |
rechargeOrder.setCircleId(circle.getId());
|
| - |
|
186 |
}
|
| - |
|
187 |
} else {
|
| 107 |
rechargeOrder.setSimNum(simNum);
|
188 |
rechargeOrder.setCircleId(0);
|
| - |
|
189 |
}
|
| - |
|
190 |
}
|
| 108 |
|
191 |
|
| 109 |
rechargeOrder.setDiscount(0);
|
192 |
rechargeOrder.setDiscount(0);
|
| 110 |
TransactionClient tcl = new TransactionClient();
|
193 |
TransactionClient tcl = new TransactionClient();
|
| 111 |
if(rechargeOrder.isIsFrc()) {
|
194 |
if(rechargeOrder.isIsFrc()) {
|
| 112 |
for (FRC frc : tcl.getClient().getFRCs(Long.parseLong(circleId), rechargeOrder.getOperatorId())) {
|
195 |
for (FRC frc : tcl.getClient().getFRCs(circleId, rechargeOrder.getOperatorId())) {
|
| 113 |
if(frc.getDenomination() == rechargeOrder.getAmount()) {
|
196 |
if(frc.getDenomination() == rechargeOrder.getAmount()) {
|
| 114 |
if(frc.getMaxDiscount() < Long.parseLong(discount)) {
|
197 |
if(frc.getMaxDiscount() < Long.parseLong(discount)) {
|
| 115 |
errorMessage = "MaxDiscount : " + frc.getMaxDiscount() + " is less than discount amount entered";
|
198 |
errorMessage = "MaxDiscount : " + frc.getMaxDiscount() + " is less than discount amount entered";
|
| 116 |
log.warn("MaxDiscount : " + frc.getMaxDiscount() + " is less than discount amount entered");
|
199 |
log.warn("MaxDiscount : " + frc.getMaxDiscount() + " is less than discount amount entered");
|
| 117 |
return "recharge-redirect";
|
200 |
return "recharge-redirect";
|
| 118 |
} else {
|
201 |
} else {
|
| 119 |
rechargeOrder.setDiscount(Double.parseDouble(discount));
|
202 |
rechargeOrder.setDiscount(Double.parseDouble(discount));
|
| 120 |
break;
|
- |
|
| 121 |
}
|
203 |
}
|
| 122 |
}
|
204 |
}
|
| 123 |
}
|
205 |
}
|
| 124 |
}
|
206 |
}
|
| 125 |
rechargeOrder.setAlternateNumber(altNum);
|
- |
|
| 126 |
|
- |
|
| 127 |
/**
|
- |
|
| 128 |
* WHAT TODO ABOUT THIS???
|
- |
|
| 129 |
*/
|
- |
|
| 130 |
rechargeOrder.setStoreId(Long.parseLong(storeId));
|
- |
|
| 131 |
|
207 |
|
| 132 |
|
- |
|
| 133 |
/****************************************************
|
- |
|
| 134 |
* TODO *
|
- |
|
| 135 |
* rechargeORder.setCircleId(circle); *
|
- |
|
| 136 |
* *
|
- |
|
| 137 |
****************************************************/
|
- |
|
| 138 |
|
- |
|
| 139 |
rechargeOrder.setIpAddress(remoteAddr(request));
|
- |
|
| 140 |
TransactionClient tc1 = new TransactionClient();
|
208 |
TransactionClient tc1 = new TransactionClient();
|
| 141 |
rechargeOrder = tc1.getClient().createRechargeTransaction(rechargeOrder);
|
209 |
rechargeOrder = tc1.getClient().createRechargeTransaction(rechargeOrder);
|
| 142 |
setRechargeOrderId(rechargeOrder.getId());
|
210 |
setRechargeOrderId(rechargeOrder.getId());
|
| 143 |
|
211 |
|
| 144 |
} catch (Exception e) {
|
212 |
} catch (Exception e) {
|
| Line 188... |
Line 256... |
| 188 |
if(rechargeType == null || rechargeType == "") {
|
256 |
if(rechargeType == null || rechargeType == "") {
|
| 189 |
log.warn("rechargeType received is empty or null");
|
257 |
log.warn("rechargeType received is empty or null");
|
| 190 |
return "Oops! There seems to be a problem. Please try after some time";
|
258 |
return "Oops! There seems to be a problem. Please try after some time";
|
| 191 |
}
|
259 |
}
|
| 192 |
|
260 |
|
| 193 |
if(email == null || email == "") {
|
261 |
if(deviceType == null || rechargeType == "") {
|
| 194 |
log.warn("Email received is empty or null");
|
262 |
log.warn("rechargeType received is empty or null");
|
| 195 |
return "Email address cannot be empty";
|
- |
|
| 196 |
}
|
- |
|
| 197 |
|
- |
|
| 198 |
try {
|
- |
|
| 199 |
InternetAddress emailAdd = new InternetAddress(email);
|
263 |
return "Oops! There seems to be a problem. Please try after some time";
|
| 200 |
emailAdd.validate();
|
- |
|
| 201 |
} catch (AddressException e1) {
|
- |
|
| 202 |
log.warn("Invalid email address : " + email, e1);
|
- |
|
| 203 |
return "ERROR : Invalid email address.";
|
- |
|
| 204 |
}
|
264 |
}
|
| 205 |
|
265 |
|
| 206 |
if (RechargeType.findByValue(Integer.parseInt(this.rechargeType)) == RechargeType.DTH) {
|
266 |
if (RechargeType.findByValue(Integer.parseInt(this.deviceType)) == RechargeType.DTH) {
|
| 207 |
if (Long.parseLong(totalAmount) < 250 || Long.parseLong(totalAmount) > 2000) {
|
267 |
if (Long.parseLong(totalAmount) < 250 || Long.parseLong(totalAmount) > 2000) {
|
| 208 |
// if(operator.equals("1")) {
|
268 |
if(rechargeType.equals("2") && getOperatorName().equals(DISHTV)) {
|
| 209 |
// return "DishTv recharge amount should be between Rs.250 and Rs.2000";
|
269 |
return "DishTv recharge amount should be between Rs.250 and Rs.2000";
|
| 210 |
// }
|
270 |
}
|
| 211 |
|
271 |
|
| 212 |
if (!(Long.parseLong(totalAmount) >= 200 && Long.parseLong(totalAmount) < 250)) {
|
272 |
if (!(Long.parseLong(totalAmount) >= 200 && Long.parseLong(totalAmount) < 250)) {
|
| 213 |
return "DTH recharge amount should be between Rs.200 and Rs.2000";
|
273 |
return "DTH recharge amount should be between Rs.200 and Rs.2000";
|
| 214 |
}
|
274 |
}
|
| 215 |
}
|
275 |
}
|
| 216 |
|
276 |
|
| 217 |
} else if (RechargeType.findByValue(Integer.parseInt(this.rechargeType)) == RechargeType.MOBILE) {
|
277 |
} else if (RechargeType.findByValue(Integer.parseInt(this.deviceType)) == RechargeType.MOBILE) {
|
| 218 |
if (Long.parseLong(totalAmount) < 10 || Long.parseLong(totalAmount) > 1000) {
|
278 |
if (Long.parseLong(amount) < 10 || Long.parseLong(amount) > 1000) {
|
| 219 |
return "Recharge amount should be between Rs.10 and Rs.1000";
|
279 |
return "Recharge amount should be between Rs.10 and Rs.1000";
|
| 220 |
}
|
280 |
}
|
| 221 |
if (number.length() != 10) {
|
281 |
if (number.length() != 10) {
|
| 222 |
return "Number should be of 10 digits";
|
282 |
return "Number should be of 10 digits";
|
| 223 |
}
|
283 |
}
|
| 224 |
|
284 |
|
| 225 |
} else {
|
285 |
} else {
|
| 226 |
log.warn("Invalid rechargeType : " + rechargeType);
|
286 |
log.warn("Invalid rechargeType : " + deviceType);
|
| - |
|
287 |
return "Oops! There seems to be a problem. Please try after some time";
|
| - |
|
288 |
}
|
| - |
|
289 |
|
| - |
|
290 |
if (mobileOperator == null || mobileOperator == "") {
|
| - |
|
291 |
log.warn("Invalid operator : " + mobileOperator);
|
| - |
|
292 |
return "Oops! There seems to be a problem. Please try after some time";
|
| - |
|
293 |
}
|
| - |
|
294 |
|
| - |
|
295 |
if (dthOperator == null || dthOperator == "") {
|
| - |
|
296 |
log.warn("Invalid operator : " + dthOperator);
|
| 227 |
return "Oops! There seems to be a problem. Please try after some time";
|
297 |
return "Oops! There seems to be a problem. Please try after some time";
|
| 228 |
}
|
298 |
}
|
| 229 |
|
299 |
|
| 230 |
// if (operator == null || operator == "") {
|
- |
|
| 231 |
// log.warn("Invalid operator : " + operator);
|
- |
|
| 232 |
// return "Oops! There seems to be a problem. Please try after some time";
|
- |
|
| 233 |
// }
|
- |
|
| 234 |
return "SUCCESS";
|
300 |
return "SUCCESS";
|
| 235 |
}
|
301 |
}
|
| 236 |
|
302 |
|
| 237 |
public String getAmount() {
|
303 |
public String getAmount() {
|
| 238 |
return amount;
|
304 |
return amount;
|
| Line 423... |
Line 489... |
| 423 |
|
489 |
|
| 424 |
public String getDiscount() {
|
490 |
public String getDiscount() {
|
| 425 |
return discount;
|
491 |
return discount;
|
| 426 |
}
|
492 |
}
|
| 427 |
|
493 |
|
| 428 |
public void setCircleId(String circleId) {
|
494 |
public void setCirclecode(String circlecode) {
|
| 429 |
this.circleId = circleId;
|
495 |
this.circlecode = circlecode;
|
| 430 |
}
|
496 |
}
|
| 431 |
|
497 |
|
| 432 |
public String getCircleId() {
|
498 |
public String getCirclecode() {
|
| 433 |
return circleId;
|
499 |
return circlecode;
|
| 434 |
}
|
500 |
}
|
| 435 |
}
|
501 |
}
|