Subversion Repositories SmartDukaan

Rev

Rev 6457 | Rev 6504 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6457 Rev 6495
Line 17... Line 17...
17
import in.shop2020.thrift.clients.TransactionClient;
17
import in.shop2020.thrift.clients.TransactionClient;
18
import in.shop2020.thrift.clients.UserClient;
18
import in.shop2020.thrift.clients.UserClient;
19
import in.shop2020.utils.DataLogger;
19
import in.shop2020.utils.DataLogger;
20
import in.shop2020.utils.Mail;
20
import in.shop2020.utils.Mail;
21
 
21
 
-
 
22
import java.math.BigInteger;
22
import java.util.ArrayList;
23
import java.util.ArrayList;
23
import java.util.HashMap;
24
import java.util.HashMap;
24
import java.util.List;
25
import java.util.List;
25
import java.util.Map;
26
import java.util.Map;
26
import java.util.Random;
27
import java.util.Random;
27
 
28
 
-
 
29
import javax.mail.internet.AddressException;
-
 
30
import javax.mail.internet.InternetAddress;
-
 
31
 
28
import nl.captcha.Captcha;
32
import nl.captcha.Captcha;
29
 
33
 
30
import org.apache.log4j.Logger;
34
import org.apache.log4j.Logger;
31
import org.apache.struts2.convention.annotation.Result;
35
import org.apache.struts2.convention.annotation.Result;
32
import org.apache.struts2.convention.annotation.Results;
36
import org.apache.struts2.convention.annotation.Results;
Line 61... Line 65...
61
    private String totalAmount = "";
65
    private String totalAmount = "";
62
    private String plan = "";
66
    private String plan = "";
63
    private String circleCode;
67
    private String circleCode;
64
    private String couponCode = "";
68
    private String couponCode = "";
65
    private String couponMessage = "";
69
    private String couponMessage = "";
-
 
70
    private String hiddenUserId = "";
66
    private long couponAmount = 0;
71
    private long couponAmount = 0;
67
    private static final String chars = "abcdefghijklmonpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
72
    private static final String chars = "abcdefghijklmonpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
-
 
73
    private static final BigInteger key = new BigInteger("0333910847013829827302347601486730417451");
-
 
74
    
68
    private static final Random random = new Random();
75
    private static final Random random = new Random();
69
    private static final int LENGTH = 10;
76
    private static final int LENGTH = 10;
70
    private static Logger log = Logger.getLogger(Class.class);
77
    private static Logger log = Logger.getLogger(Class.class);
71
    
78
    
72
    public String index() {
79
    public String index() {
Line 95... Line 102...
95
                return "recharge-redirect";
102
                return "recharge-redirect";
96
            } else {
103
            } else {
97
                setUserId("" + tempUserId);
104
                setUserId("" + tempUserId);
98
            }
105
            }
99
        }
106
        }
-
 
107
        
-
 
108
        setHash(encrypt(getUserId()));
100
        return index();
109
        return index();
101
    }
110
    }
102
 
111
 
103
    private void calculateAmounts() {
112
    private void calculateAmounts() {
104
        
113
        
Line 135... Line 144...
135
    		log.error("Unable to get service provider for Device number " + number + " and rechargeType : " +  rechargeType, e);
144
    		log.error("Unable to get service provider for Device number " + number + " and rechargeType : " +  rechargeType, e);
136
    	}
145
    	}
137
    	return "Oops! There seems to be a problem. Please try after some time";
146
    	return "Oops! There seems to be a problem. Please try after some time";
138
    	
147
    	
139
    }
148
    }
-
 
149
 
-
 
150
    private String validateFields() {
-
 
151
        if(amount == null || amount == "") {
-
 
152
            log.warn("Amount received is empty or null");
-
 
153
            return "Amount cannot be empty";
-
 
154
        }
-
 
155
        
-
 
156
        if(rechargeType == null || rechargeType == "") {
-
 
157
            log.warn("rechargeType received is empty or null");
-
 
158
            return "Oops! There seems to be a problem. Please try after some time";
-
 
159
        }
-
 
160
        
-
 
161
        if(email == null || email == "") {
-
 
162
            log.warn("Email received is empty or null");
-
 
163
            return "Email address cannot be empty";
-
 
164
        }
-
 
165
        
-
 
166
        try {
-
 
167
            InternetAddress emailAdd = new InternetAddress(email);
-
 
168
            emailAdd.validate();
-
 
169
        } catch (AddressException e1) {
-
 
170
            log.warn("Invalid email address : " + email, e1);
-
 
171
            return "ERROR : Invalid email address.";
-
 
172
        }
-
 
173
        
-
 
174
        if (RechargeType.findByValue(Integer.parseInt(this.rechargeType)) == RechargeType.DTH) {
-
 
175
            if (Long.parseLong(totalAmount) < 200 || Long.parseLong(totalAmount) > 9999) {
-
 
176
                return "DTH recharge amount should be between Rs.200 and Rs.9999";
-
 
177
            }
-
 
178
          
-
 
179
        } else if (RechargeType.findByValue(Integer.parseInt(this.rechargeType)) == RechargeType.MOBILE) {
-
 
180
            if (Long.parseLong(totalAmount) < 10 || Long.parseLong(totalAmount) > 1000) {
-
 
181
                return "Recharge amount should be between Rs.10 and Rs.1000";
-
 
182
            }
-
 
183
            if (number.length() != 10) {
-
 
184
                return "Number should be of 10 digits";
-
 
185
            }
-
 
186
            
-
 
187
        } else {
-
 
188
            log.warn("Invalid rechargeType : " + rechargeType);
-
 
189
            return "Oops! There seems to be a problem. Please try after some time";
-
 
190
        }
-
 
191
        
-
 
192
        if (operator == null || operator == "") {
-
 
193
            log.warn("Invalid operator : " + operator);
-
 
194
            return "Oops! There seems to be a problem. Please try after some time";
-
 
195
        }
-
 
196
        return "SUCCESS";
-
 
197
    }
140
    
198
    
141
    public boolean shouldPromptForWallet(){
199
    public boolean shouldPromptForWallet(){
142
        if(!isLoggedIn()) {
200
        if(!isLoggedIn()) {
143
            try {
201
            try {
144
                TransactionClient tc = new TransactionClient();
202
                TransactionClient tc = new TransactionClient();
Line 164... Line 222...
164
                    this.couponAmount = couponAmount;
222
                    this.couponAmount = couponAmount;
165
                }
223
                }
166
            }
224
            }
167
            
225
            
168
            if(couponAmount == 0) {
226
            if(couponAmount == 0) {
169
                couponCode = null;
227
                couponCode = "";
170
            }
228
            }
171
            
229
            
172
            if(userinfo.isLoggedIn()) {
230
            if(userinfo.isLoggedIn()) {
173
                calculateAmounts();
231
                calculateAmounts();
174
            } else {
232
            } else {
175
                setAmount("" + (Long.parseLong(amount) - couponAmount));
233
                setAmount("" + (Long.parseLong(amount) - couponAmount));
176
            }
234
            }
177
            return index();
235
            return index();
178
        } catch (Exception e) {
236
        } catch (Exception e) {
179
            log.error("Unable to apply recharge coupon : " + couponCode, e);
237
            log.error("Unable to apply recharge coupon : " + couponCode, e);
180
            couponResult = new HashMap<Long, String>();
-
 
181
            setCouponMessage("Currently this coupon is unavailable");
238
            setCouponMessage("Currently this coupon is unavailable");
182
        }
239
        }
183
        return index();
240
        return index();
184
    }
241
    }
185
    
242
    
Line 189... Line 246...
189
                setErrorMessage("Invalid captcha. Try Again.");
246
                setErrorMessage("Invalid captcha. Try Again.");
190
                log.info("Invalid captcha error msg has been added");
247
                log.info("Invalid captcha error msg has been added");
191
                return index();
248
                return index();
192
            }
249
            }
193
        }
250
        }
-
 
251
        
-
 
252
        String decryptedUserId = decrypt(hiddenUserId);
-
 
253
        if(!userId.equals(decryptedUserId)) {
-
 
254
            log.warn("userId and hash do not match");
-
 
255
            errorMessage = "Oops! There seems to be a problem. Please try after some time";
-
 
256
            return "recharge-redirect";
-
 
257
        }
-
 
258
        
-
 
259
        errorMessage = validateFields();
-
 
260
        if (!errorMessage.equals("SUCCESS")) {
-
 
261
            return "recharge-redirect";
-
 
262
        }
-
 
263
        
194
        try {
264
        try {
195
            TransactionClient tc = new TransactionClient();
265
            TransactionClient tc = new TransactionClient();
196
            List<RechargePlan> plans = tc.getClient().getPlansForOperator(Long.parseLong(operator));
266
            List<RechargePlan> plans = tc.getClient().getPlansForOperator(Long.parseLong(operator));
197
            List<String> planNameList = new ArrayList<String>();
267
            List<String> planNameList = new ArrayList<String>();
198
            if (plans == null || plans.isEmpty()) {
268
            if (plans == null || plans.isEmpty()) {
Line 225... Line 295...
225
            
295
            
226
            PromotionClient pc = new PromotionClient();
296
            PromotionClient pc = new PromotionClient();
227
            Map<Long, String> couponResult = null;
297
            Map<Long, String> couponResult = null;
228
            couponResult = pc.getClient().applyRechargeCoupon(couponCode, Long.parseLong(totalAmount), Long.parseLong(userId));
298
            couponResult = pc.getClient().applyRechargeCoupon(couponCode, Long.parseLong(totalAmount), Long.parseLong(userId));
229
            if(couponResult != null) {
299
            if(couponResult != null) {
-
 
300
                if (!couponResult.containsValue(couponCode)) {
-
 
301
                    couponCode = "";
-
 
302
                    couponAmount = 0;
-
 
303
                }
-
 
304
                
230
                for (long couponAmount : couponResult.keySet()) {
305
                for (long couponAmount : couponResult.keySet()) {
231
                    setCouponMessage(couponResult.get(couponAmount));
306
                    setCouponMessage(couponResult.get(couponAmount));
232
                    this.couponAmount = couponAmount;
307
                    this.couponAmount = couponAmount;
233
                }
308
                }
-
 
309
            } else {
-
 
310
                couponCode = "";
-
 
311
                couponAmount = 0;
234
            }
312
            }
235
            
313
            
236
            if (Long.parseLong(totalAmount) != Long.parseLong(amount) + Long.parseLong(walletAmountUsed) + couponAmount){
314
            if (Long.parseLong(totalAmount) != Long.parseLong(amount) + Long.parseLong(walletAmountUsed) + couponAmount){
237
                errorMessage = "Oops! There seems to be a problem. Please try after some time";
315
                errorMessage = "Oops! There seems to be a problem. Please try after some time";
238
                log.warn("WalletAmount : " + walletAmountUsed + " plus couponAmount : " + couponAmount + " plus amount to be paid : " +
316
                log.warn("WalletAmount : " + walletAmountUsed + " plus couponAmount : " + couponAmount + " plus amount to be paid : " +
Line 352... Line 430...
352
    		operatorName = "N/A";	
430
    		operatorName = "N/A";	
353
    	}
431
    	}
354
    	return operatorName;
432
    	return operatorName;
355
    }
433
    }
356
    
434
    
-
 
435
    public String encrypt(String strToEncrypt) {
-
 
436
        BigInteger strBigInt = new BigInteger(strToEncrypt.getBytes());
-
 
437
        System.out.println(strBigInt);
-
 
438
        BigInteger hashedPasswd = key.xor(strBigInt);
-
 
439
        System.out.println(hashedPasswd);
-
 
440
        return (hashedPasswd.toString(16));
-
 
441
    }
-
 
442
    
-
 
443
    public String decrypt(String encrypted) {
-
 
444
        try
-
 
445
        {
-
 
446
            BigInteger encryptedBigInt = new BigInteger(encrypted, 16);
-
 
447
            System.out.println(encryptedBigInt);
-
 
448
            BigInteger strBigInt = encryptedBigInt.xor(key);
-
 
449
            System.out.println(strBigInt);
-
 
450
            String decrypted = new String(strBigInt.toByteArray());
-
 
451
            return decrypted;
-
 
452
        } catch (Exception e) {
-
 
453
            System.out.println("oops");
-
 
454
            return "";
-
 
455
        }
-
 
456
    }
-
 
457
    
357
    public String getAmount() {
458
    public String getAmount() {
358
        return amount;
459
        return amount;
359
    }
460
    }
360
    public void setAmount(String amount) {
461
    public void setAmount(String amount) {
361
        this.amount = amount;
462
        this.amount = amount;
362
        this.totalAmount = amount;
-
 
363
    }
463
    }
364
 
464
 
365
    public void setDthamount(String amount) {
465
    public void setDthamount(String amount) {
366
    	this.amount = amount;
466
    	this.amount = amount;
367
    }
467
    }
Line 509... Line 609...
509
 
609
 
510
    public String getCouponMessage() {
610
    public String getCouponMessage() {
511
        return couponMessage;
611
        return couponMessage;
512
    }
612
    }
513
    
613
    
-
 
614
    public void setHash(String hash) {
-
 
615
        this.hiddenUserId = hash;
-
 
616
    }
-
 
617
    
-
 
618
    public String getHiddenUserId() {
-
 
619
        return hiddenUserId;
-
 
620
    }
514
}
621
}