Subversion Repositories SmartDukaan

Rev

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

Rev 7073 Rev 7080
Line 1... Line 1...
1
package in.shop2020.recharge.controllers;
1
package in.shop2020.recharge.controllers;
2
 
2
 
3
import in.shop2020.model.v1.order.RechargeOrderStatus;
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.thrift.clients.TransactionClient;
7
import in.shop2020.thrift.clients.TransactionClient;
8
 
8
 
Line 18... Line 18...
18
import org.apache.log4j.Logger;
18
import org.apache.log4j.Logger;
19
import org.apache.struts2.convention.annotation.Result;
19
import org.apache.struts2.convention.annotation.Result;
20
import org.apache.struts2.convention.annotation.Results;
20
import org.apache.struts2.convention.annotation.Results;
21
 
21
 
22
@Results({
22
@Results({
23
    @Result(name="recharge-redirect", type="redirectAction", params = {"actionName" , "/", "error", "${errorMessage}"})
23
    @Result(name="recharge-redirect", type="redirectAction", params = {"actionName" , "/", "errorMsg", "${errorMessage}"}),
-
 
24
    @Result(name="recharge-result", type="redirectAction", params = {"actionName" , "recharge-result", "rechargeId", "${rechargeOrderId}"})
24
})
25
})
25
 
26
 
26
public class ConfirmController extends BaseController{
27
public class ConfirmController extends BaseController{
27
 
28
 
28
    /**
29
    /**
29
     * 
30
     * 
30
     */
31
     */
31
    private static final long serialVersionUID = 1L;
32
    private static final long serialVersionUID = 1L;
32
    private long rechargeOrderId = 0;
33
    private long rechargeOrderId = 0;
33
    private String amount = "";
34
    private String amount = "";
34
    private String operator = "";
-
 
35
    private String number = "";
35
    private String number = "";
36
    private String email = "";
36
    private String email = "";
37
    private String rechargeType = "";
37
    private String rechargeType = "";
38
    private String deviceType = "";
38
    private String deviceType = "";
-
 
39
    private String mobileOperator = "";
-
 
40
    private String dthOperator = "";
39
    private String storeId = "";
41
    private String storeId = "";
40
    private String cafNum = "";
42
    private String cafNum = "";
41
    private String simNum = "";
43
    private String simNum = "";
-
 
44
    private String altNum = "";
42
    private String name = "";
45
    private String name = "";
43
    private String plan = "";
46
    private String plan = "";
44
    private String circleCode;
47
    private String circleId = "";
-
 
48
    private String discount = "";
45
    
49
    
46
    private String message = "";
50
    private String message = "";
47
    private String errorMessage = "";
51
    private String errorMessage = "";
48
    private String totalAmount = "";
52
    private String totalAmount = "";
49
    private String couponCode = "";
53
    private String couponCode = "";
Line 65... Line 69...
65
        return index();
69
        return index();
66
    }
70
    }
67
    
71
    
68
    public String createRecharge(){
72
    public String createRecharge(){
69
        try {
73
        try {
-
 
74
            //TODO REmove this
-
 
75
            setStoreId("1");
-
 
76
            setCircleId("5");
-
 
77
            //
70
            TransactionClient tc = new TransactionClient();
78
            TransactionClient tc = new TransactionClient();
71
            List<RechargePlan> plans = tc.getClient().getPlansForOperator(Long.parseLong(operator));
79
            List<RechargePlan> plans = tc.getClient().getPlansForOperator(Long.parseLong(mobileOperator));
72
            List<String> planNameList = new ArrayList<String>();
80
            List<String> planNameList = new ArrayList<String>();
73
            if (plans == null || plans.isEmpty()) {
81
            if (plans == null || plans.isEmpty()) {
74
                setPlan("");
82
                setPlan("");
75
            } else {
83
            } else {
76
                for (RechargePlan tempPlan : plans) {
84
                for (RechargePlan tempPlan : plans) {
77
                    planNameList.add(tempPlan.getName());
85
                    planNameList.add(tempPlan.getName());
78
                }
86
                }
79
                if (!planNameList.contains(plan)) {
87
                if (!planNameList.contains(plan)) {
80
                    errorMessage = "OperatorId : " + operator + " and plan : " + plan + " do not match";
88
                    errorMessage = "OperatorId : " + mobileOperator + " and plan : " + plan + " do not match";
81
                    log.warn("OperatorId : " + operator + " and plan : " + plan + " do not match");
89
                    log.warn("OperatorId : " + mobileOperator + " and plan : " + plan + " do not match");
82
                    return "recharge-redirect";
90
                    return "recharge-redirect";
83
                }
91
                }
84
            }
92
            }
85
            
93
            
86
            RechargeTransaction rechargeOrder = new RechargeTransaction();
94
            RechargeTransaction rechargeOrder = new RechargeTransaction();
87
            rechargeOrder.setAmount(Long.parseLong(totalAmount));
95
            rechargeOrder.setAmount(Long.parseLong(amount));
88
            rechargeOrder.setEmail(email);
96
            rechargeOrder.setEmail(email);
89
            rechargeOrder.setDeviceNum(number.trim());
97
            rechargeOrder.setDeviceNum(number.trim());
90
            rechargeOrder.setPlan(plan);
98
            rechargeOrder.setPlan(plan);
-
 
99
            if(deviceType.equals("1")) {
-
 
100
                rechargeOrder.setOperatorId(Long.parseLong(mobileOperator));
-
 
101
            } else if (deviceType.equals("2")) {
91
            rechargeOrder.setOperatorId(Long.parseLong(operator));
102
                rechargeOrder.setOperatorId(Long.parseLong(dthOperator));
-
 
103
            }
-
 
104
            
92
            rechargeOrder.setIsFrc(Long.parseLong(rechargeType) == 1 ? false : true);
105
            rechargeOrder.setIsFrc(Long.parseLong(rechargeType) == 1 ? false : true);
-
 
106
            rechargeOrder.setCafNum(cafNum);
-
 
107
            rechargeOrder.setSimNum(simNum);
-
 
108
            
-
 
109
            rechargeOrder.setDiscount(0);
-
 
110
            TransactionClient tcl = new TransactionClient();
-
 
111
            if(rechargeOrder.isIsFrc()) {
-
 
112
                for (FRC frc : tcl.getClient().getFRCs(Long.parseLong(circleId), rechargeOrder.getOperatorId())) {
-
 
113
                    if(frc.getDenomination() == rechargeOrder.getAmount()) {
-
 
114
                        if(frc.getMaxDiscount() < Long.parseLong(discount)) {
-
 
115
                            errorMessage = "MaxDiscount : " + frc.getMaxDiscount() + " is less than discount amount entered";
-
 
116
                            log.warn("MaxDiscount : " + frc.getMaxDiscount() + " is less than discount amount entered");
-
 
117
                            return "recharge-redirect";
-
 
118
                        } else {
-
 
119
                            rechargeOrder.setDiscount(Double.parseDouble(discount));
-
 
120
                            break;
-
 
121
                        }
-
 
122
                    }
-
 
123
                }
-
 
124
            }
93
            rechargeOrder.setStatus(RechargeOrderStatus.INIT);
125
            rechargeOrder.setAlternateNumber(altNum);
-
 
126
            
-
 
127
            /**
-
 
128
             *  WHAT TODO ABOUT THIS???
-
 
129
             */
-
 
130
            rechargeOrder.setStoreId(Long.parseLong(storeId));
-
 
131
            
94
            
132
            
95
            /****************************************************
133
            /****************************************************
-
 
134
             *  TODO        *
96
             * rechargeOrder.setDiscount(discount); TODO        *
135
             * rechargeORder.setCircleId(circle);               *
-
 
136
             *          *
97
             ****************************************************/
137
             ****************************************************/
98
            
138
            
99
            rechargeOrder.setIpAddress(remoteAddr(request));
139
            rechargeOrder.setIpAddress(remoteAddr(request));
100
            TransactionClient tc1 = new TransactionClient();
140
            TransactionClient tc1 = new TransactionClient();
101
            rechargeOrder = tc1.getClient().createRechargeTransaction(rechargeOrder);
141
            rechargeOrder = tc1.getClient().createRechargeTransaction(rechargeOrder);
Line 104... Line 144...
104
        } catch (Exception e) {
144
        } catch (Exception e) {
105
            log.error("Unable to create recharge order", e);
145
            log.error("Unable to create recharge order", e);
106
            errorMessage = "Oops! There seems to be a problem. Please try after some time";
146
            errorMessage = "Oops! There seems to be a problem. Please try after some time";
107
            return "recharge-redirect";
147
            return "recharge-redirect";
108
        }
148
        }
109
        return index();
149
        return "recharge-result";
110
    }
150
    }
111
    
151
    
112
    public String getOperatorName() {
152
    public String getOperatorName() {
113
        String operatorName = null;
153
        String operatorName = null;
114
        if(rechargeType.equals("1")){
154
        if(deviceType.equals("1")){
115
            operatorName = HomeController.getMobileProvidersMap().get(Long.parseLong(operator)); 
155
            operatorName = HomeController.getMobileProvidersMap().get(Long.parseLong(mobileOperator)); 
116
        }
156
        }
117
        if(rechargeType.equals("2")){
157
        if(deviceType.equals("2")){
118
            operatorName = HomeController.getDthProvidersMap().get(Long.parseLong(operator));    
158
            operatorName = HomeController.getDthProvidersMap().get(Long.parseLong(dthOperator));    
119
        }
159
        }
120
        if(operatorName == null){
160
        if(operatorName == null){
121
            operatorName = "N/A";   
161
            operatorName = "N/A";   
122
        }
162
        }
123
        return operatorName;
163
        return operatorName;
Line 163... Line 203...
163
            return "ERROR : Invalid email address.";
203
            return "ERROR : Invalid email address.";
164
        }
204
        }
165
        
205
        
166
        if (RechargeType.findByValue(Integer.parseInt(this.rechargeType)) == RechargeType.DTH) {
206
        if (RechargeType.findByValue(Integer.parseInt(this.rechargeType)) == RechargeType.DTH) {
167
            if (Long.parseLong(totalAmount) < 250 || Long.parseLong(totalAmount) > 2000) {
207
            if (Long.parseLong(totalAmount) < 250 || Long.parseLong(totalAmount) > 2000) {
168
                if(operator.equals("1")) {
208
//                if(operator.equals("1")) {
169
                    return "DishTv recharge amount should be between Rs.250 and Rs.2000";
209
//                    return "DishTv recharge amount should be between Rs.250 and Rs.2000";
170
                }
210
//                }
171
                
211
                
172
                if (!(Long.parseLong(totalAmount) >= 200 && Long.parseLong(totalAmount) < 250)) {
212
                if (!(Long.parseLong(totalAmount) >= 200 && Long.parseLong(totalAmount) < 250)) {
173
                    return "DTH recharge amount should be between Rs.200 and Rs.2000";
213
                    return "DTH recharge amount should be between Rs.200 and Rs.2000";
174
                }
214
                }
175
            }
215
            }
Line 185... Line 225...
185
        } else {
225
        } else {
186
            log.warn("Invalid rechargeType : " + rechargeType);
226
            log.warn("Invalid rechargeType : " + rechargeType);
187
            return "Oops! There seems to be a problem. Please try after some time";
227
            return "Oops! There seems to be a problem. Please try after some time";
188
        }
228
        }
189
        
229
        
190
        if (operator == null || operator == "") {
230
//        if (operator == null || operator == "") {
191
            log.warn("Invalid operator : " + operator);
231
//            log.warn("Invalid operator : " + operator);
192
            return "Oops! There seems to be a problem. Please try after some time";
232
//            return "Oops! There seems to be a problem. Please try after some time";
193
        }
233
//        }
194
        return "SUCCESS";
234
        return "SUCCESS";
195
    }
235
    }
196
    
236
    
197
    public String getAmount() {
237
    public String getAmount() {
198
        return amount;
238
        return amount;
Line 202... Line 242...
202
    }
242
    }
203
 
243
 
204
    public void setDthamount(String amount) {
244
    public void setDthamount(String amount) {
205
        this.amount = amount;
245
        this.amount = amount;
206
    }
246
    }
207
    public String getOperator() {
-
 
208
        return operator;
-
 
209
    }
247
    
210
    public void setOperator(String operator) {
-
 
211
        this.operator = operator;
-
 
212
    }
-
 
213
    public String getNumber() {
248
    public String getNumber() {
214
        return number;
249
        return number;
215
    }
250
    }
216
    public void setNumber(String number) {
251
    public void setNumber(String number) {
217
        this.number = number;
252
        this.number = number;
Line 276... Line 311...
276
 
311
 
277
    public void setErrorMessage(String errorMessage) {
312
    public void setErrorMessage(String errorMessage) {
278
        this.errorMessage = errorMessage;
313
        this.errorMessage = errorMessage;
279
    }
314
    }
280
 
315
 
281
    public String getCircleCode() {
-
 
282
        return circleCode;
-
 
283
    }
-
 
284
 
-
 
285
    public void setCircleCode(String circleCode) {
-
 
286
        this.circleCode = circleCode;
-
 
287
    }
-
 
288
 
-
 
289
    public void setDiscountCode(String discountCode) {
316
    public void setDiscountCode(String discountCode) {
290
        this.couponCode = discountCode;
317
        this.couponCode = discountCode;
291
    }
318
    }
292
    
319
    
293
    public String getCouponCode() {
320
    public String getCouponCode() {
Line 359... Line 386...
359
    }
386
    }
360
 
387
 
361
    public void setName(String name) {
388
    public void setName(String name) {
362
        this.name = name;
389
        this.name = name;
363
    }
390
    }
-
 
391
 
-
 
392
    public void setAltNum(String altNum) {
-
 
393
        this.altNum = altNum;
-
 
394
    }
-
 
395
 
-
 
396
    public String getAltNum() {
-
 
397
        return altNum;
-
 
398
    }
-
 
399
 
-
 
400
    public String getMobileOperator() {
-
 
401
        return mobileOperator;
-
 
402
    }
-
 
403
 
-
 
404
    public void setMobileOperator(String mobileOperator) {
-
 
405
        this.mobileOperator = mobileOperator;
-
 
406
    }
-
 
407
 
-
 
408
    public String getDthOperator() {
-
 
409
        return dthOperator;
-
 
410
    }
-
 
411
 
-
 
412
    public void setDthOperator(String dthOperator) {
-
 
413
        this.dthOperator = dthOperator;
-
 
414
    }
-
 
415
 
-
 
416
    public void setDiscount(String discount) {
-
 
417
        if(discount == null || discount.isEmpty()) {
-
 
418
            this.discount = "0";
-
 
419
        } else {
-
 
420
            this.discount = discount;
-
 
421
        }
-
 
422
    }
-
 
423
 
-
 
424
    public String getDiscount() {
-
 
425
        return discount;
-
 
426
    }
-
 
427
 
-
 
428
    public void setCircleId(String circleId) {
-
 
429
        this.circleId = circleId;
-
 
430
    }
-
 
431
 
-
 
432
    public String getCircleId() {
-
 
433
        return circleId;
-
 
434
    }
364
}
435
}