Subversion Repositories SmartDukaan

Rev

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

Rev 6228 Rev 6249
Line 19... Line 19...
19
 
19
 
20
import java.util.ArrayList;
20
import java.util.ArrayList;
21
import java.util.List;
21
import java.util.List;
22
import java.util.Random;
22
import java.util.Random;
23
 
23
 
-
 
24
import nl.captcha.Captcha;
-
 
25
 
24
import org.apache.log4j.Logger;
26
import org.apache.log4j.Logger;
25
import org.apache.struts2.convention.annotation.Result;
27
import org.apache.struts2.convention.annotation.Result;
26
import org.apache.struts2.convention.annotation.Results;
28
import org.apache.struts2.convention.annotation.Results;
27
import org.apache.thrift.TException;
29
import org.apache.thrift.TException;
28
import org.apache.thrift.transport.TTransportException;
30
import org.apache.thrift.transport.TTransportException;
Line 49... Line 51...
49
    private DesEncrypter desEncrypter = new DesEncrypter("saholic");
51
    private DesEncrypter desEncrypter = new DesEncrypter("saholic");
50
    private List<String> couponIds = null;
52
    private List<String> couponIds = null;
51
    private List<RechargeCoupon> coupons = null;
53
    private List<RechargeCoupon> coupons = null;
52
    private String userId;
54
    private String userId;
53
    private String message = "";
55
    private String message = "";
-
 
56
    private String errorMessage = "";
54
    private String totalAmount = "";
57
    private String totalAmount = "";
55
    private String plan = "";
58
    private String plan = "";
56
    private static final String chars = "abcdefghijklmonpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
59
    private static final String chars = "abcdefghijklmonpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
57
    private static final Random random = new Random();
60
    private static final Random random = new Random();
58
    private static final int LENGTH = 10;
61
    private static final int LENGTH = 10;
Line 113... Line 116...
113
    	}
116
    	}
114
    	return 0 + "";
117
    	return 0 + "";
115
    	
118
    	
116
    }
119
    }
117
    
120
    
118
    private void setTotalAmount(String amount2) {
-
 
119
        this.totalAmount  = amount2;
-
 
120
        
-
 
121
    }
-
 
122
 
-
 
123
    public String createRecharge(){
121
    public String createRecharge(){
-
 
122
        if (amount.equals("0")) {
-
 
123
            if (!verifyCaptcha()) {
-
 
124
                setErrorMessage("Invalid captcha. Try Again.");
-
 
125
                log.info("Invalid captcha error msg has been added");
-
 
126
                return index();
-
 
127
            }
-
 
128
        }
124
        try {
129
        try {
125
            TransactionClient tc = new TransactionClient();
130
            TransactionClient tc = new TransactionClient();
126
            RechargeOrder rechargeOrder = new RechargeOrder();
131
            RechargeOrder rechargeOrder = new RechargeOrder();
127
            rechargeOrder.setTotalAmount(Long.parseLong(amount) + Long.parseLong(getWalletAmountUsed()));
132
            rechargeOrder.setTotalAmount(Long.parseLong(totalAmount));
128
            rechargeOrder.setUserEmailId(email);
133
            rechargeOrder.setUserEmailId(email);
129
            rechargeOrder.setUserId(Long.parseLong(userId));
134
            rechargeOrder.setUserId(Long.parseLong(userId));
130
            rechargeOrder.setDeviceNumber(number);
135
            rechargeOrder.setDeviceNumber(number);
131
            rechargeOrder.setPlan(plan);
136
            rechargeOrder.setPlan(plan);
132
            rechargeOrder.setOperatorId(Long.parseLong(operator));
137
            rechargeOrder.setOperatorId(Long.parseLong(operator));
Line 147... Line 152...
147
        } else {
152
        } else {
148
            return "recharge-pay-options-redirect";
153
            return "recharge-pay-options-redirect";
149
        }
154
        }
150
    }
155
    }
151
    
156
    
-
 
157
    private boolean verifyCaptcha() {
-
 
158
        String cookieCaptchaAnswer = getCookie(Captcha.NAME, true, "saholic");
-
 
159
        String captchaReceived = (String) request.getParameter("captcha_response_field");
-
 
160
        
-
 
161
        if (captchaReceived.equalsIgnoreCase(cookieCaptchaAnswer)) {
-
 
162
            try {
-
 
163
                DataLogger.logData(EventType.CAPTCHA_SUCCESS, getSessionId(), userinfo.getUserId(), userinfo.getEmail());
-
 
164
            } catch (Exception e1) {
-
 
165
                log.warn("Unable to log orders through the datalogger", e1);
-
 
166
            }
-
 
167
            return true;
-
 
168
        } 
-
 
169
        else {
-
 
170
            try {
-
 
171
                DataLogger.logData(EventType.CAPTCHA_FAILED, getSessionId(), userinfo.getUserId(), userinfo.getEmail());
-
 
172
            } catch (Exception e1) {
-
 
173
                log.warn("Unable to log orders through the datalogger", e1);
-
 
174
            }
-
 
175
            return false;
-
 
176
        }
-
 
177
    }
-
 
178
    
152
    private static String generateNewPassword() {
179
    private static String generateNewPassword() {
153
        char[] buf = new char[LENGTH];
180
        char[] buf = new char[LENGTH];
154
        for (int i = 0; i < buf.length; i++) {
181
        for (int i = 0; i < buf.length; i++) {
155
            buf[i] = chars.charAt(random.nextInt(chars.length()));
182
            buf[i] = chars.charAt(random.nextInt(chars.length()));
156
        }
183
        }
Line 299... Line 326...
299
    }
326
    }
300
 
327
 
301
    public String getTotalAmount() {
328
    public String getTotalAmount() {
302
        return totalAmount;
329
        return totalAmount;
303
    }
330
    }
-
 
331
    
-
 
332
    public void setTotalAmount(String amount) {
-
 
333
        this.totalAmount  = amount;
-
 
334
        
-
 
335
    }
304
 
336
 
305
    public String getWalletAmountUsed() {
337
    public String getWalletAmountUsed() {
306
        return walletAmountUsed;
338
        return walletAmountUsed;
307
    }
339
    }
308
 
340
 
Line 315... Line 347...
315
    }
347
    }
316
 
348
 
317
    public void setPlan(String plan) {
349
    public void setPlan(String plan) {
318
        this.plan = plan;
350
        this.plan = plan;
319
    }
351
    }
-
 
352
 
-
 
353
    public String getErrorMessage() {
-
 
354
        return errorMessage;
-
 
355
    }
-
 
356
 
-
 
357
    public void setErrorMessage(String errorMessage) {
-
 
358
        this.errorMessage = errorMessage;
-
 
359
    }
320
    
360
    
321
}
361
}