Subversion Repositories SmartDukaan

Rev

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

Rev 6215 Rev 6228
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import java.util.HashMap;
-
 
4
import java.util.List;
-
 
5
import java.util.Map;
-
 
6
import java.util.ResourceBundle;
-
 
7
 
-
 
8
import org.apache.log4j.Logger;
-
 
9
import org.apache.struts2.convention.annotation.Result;
-
 
10
import org.apache.struts2.convention.annotation.Results;
-
 
11
import org.apache.thrift.TException;
-
 
12
import org.apache.thrift.transport.TTransportException;
-
 
13
 
-
 
14
import in.shop2020.model.v1.order.RechargeOrder;
3
import in.shop2020.model.v1.order.RechargeOrder;
-
 
4
import in.shop2020.model.v1.order.RechargeType;
15
import in.shop2020.model.v1.user.Address;
5
import in.shop2020.model.v1.user.Address;
16
import in.shop2020.thrift.clients.HelperClient;
6
import in.shop2020.thrift.clients.TransactionClient;
17
import in.shop2020.thrift.clients.UserClient;
7
import in.shop2020.thrift.clients.UserClient;
18
import in.shop2020.utils.HelperServiceException;
-
 
-
 
8
 
19
import in.shop2020.utils.QuickLink;
9
import org.apache.log4j.Logger;
20
 
10
 
21
public class RechargePayOptionsController extends BaseController {
11
public class RechargePayOptionsController extends BaseController {
22
    
12
    
23
    /**
13
    /**
24
     * 
14
     * 
Line 26... Line 16...
26
    
16
    
27
    //private static final ResourceBundle resource = ResourceBundle.getBundle(ProceedToPayController.class.getName());
17
    //private static final ResourceBundle resource = ResourceBundle.getBundle(ProceedToPayController.class.getName());
28
    //private static final boolean SHOW_EBS_TEST_GATEWAY = Boolean.parseBoolean(resource.getString("show_ebs_test_gateway"));
18
    //private static final boolean SHOW_EBS_TEST_GATEWAY = Boolean.parseBoolean(resource.getString("show_ebs_test_gateway"));
29
    private RechargeOrder rechargeOrder = null;
19
    private RechargeOrder rechargeOrder = null;
30
    private String rechargeOrderId = "";
20
    private String rechargeOrderId = "";
31
    private String amount = "";
-
 
32
    private String errorMsg = "";
21
    private String errorMsg = "";
-
 
22
    public final static String ADDRESS = "address";
33
    private String userId = null;
23
    public final static String PHONE = "phone";
34
    private String rechargeType = "";
24
    public final static String NOTHING = "nothing";
35
    
25
    
36
    private static final long serialVersionUID = 2079308723099307749L;
26
    private static final long serialVersionUID = 2079308723099307749L;
37
 
27
 
38
    private static Logger log = Logger.getLogger(Class.class);
28
    private static Logger log = Logger.getLogger(Class.class);
39
    
29
    
40
    public String index() {
30
    public String index() {
-
 
31
        try {
-
 
32
            TransactionClient tcl = new TransactionClient();
-
 
33
            rechargeOrder = tcl.getClient().getRechargeOrder(Long.parseLong(rechargeOrderId));
-
 
34
        } catch (NumberFormatException e) {
-
 
35
            log.error("rechargeOrderId : " + rechargeOrderId + " could not be converted long");
-
 
36
            return "recharge-redirect";
-
 
37
        } catch (Exception e) {
-
 
38
            log.error("Unable to get recharge Order for id : " + rechargeOrderId);
-
 
39
            return "recharge-redirect";
-
 
40
        }
41
        return "index";
41
        return "index";
42
    }
42
    }
43
    
43
    
44
    public String create() {
44
    public String create() {
45
        return index();
45
        return index();
Line 48... Line 48...
48
    /*public boolean shouldShowEbsTestGateway() {
48
    /*public boolean shouldShowEbsTestGateway() {
49
        //return SHOW_EBS_TEST_GATEWAY;
49
        //return SHOW_EBS_TEST_GATEWAY;
50
        return true;
50
        return true;
51
    }*/
51
    }*/
52
    
52
    
53
    /*Please dont delete this. It will be reused.
53
    public String fieldsToShow() {
54
    public boolean isAddressRequired() {
54
        Address address = null;
55
        UserClient ucl;
55
        UserClient ucl;
56
        long addressId = 0;
56
        long addressId = 0;
57
        try {
-
 
58
            ucl = new UserClient();
-
 
59
            addressId = ucl.getClient().getDefaultAddressId(Long.parseLong(userId));
57
        long amount = rechargeOrder.getTotalAmount() - rechargeOrder.getWalletAmount();
60
        } catch (Exception e) {
-
 
61
            log.error("Unable to connect to user service", e);
-
 
62
        }
-
 
63
        if (addressId <= 0) {
-
 
64
            return true;
-
 
65
        } else {
-
 
66
            return false;
-
 
67
        }
-
 
68
    }
-
 
69
    */
-
 
70
    public boolean isPhoneNumberRequired() {
-
 
71
        Address address;
-
 
72
        UserClient ucl;
-
 
73
        if (rechargeType.equals("2")) {                         //2 is DTH recharge
58
        if (rechargeOrder.getRechargeType().equals(RechargeType.DTH)) {
74
            long addressId = 0;
-
 
75
            try {
59
            try {
76
                ucl = new UserClient();
60
                ucl = new UserClient();
77
                addressId = ucl.getClient().getDefaultAddressId(Long.parseLong(userId));
61
                addressId = ucl.getClient().getDefaultAddressId(rechargeOrder.getUserId());
78
                address = ucl.getClient().getAddressById(addressId);
62
                if (addressId != 0) {
79
                if (address == null || address.getPhone().isEmpty() || address.getPhone() == null) {
-
 
80
                    //Phone number will be be required in cases when 
63
                    address = ucl.getClient().getAddressById(addressId);
81
                    //rechargeType is DTH and the user does not have a default address
-
 
82
                    //or if it does not contain a phone number. For all other cases
-
 
83
                    //it will be not be required to be filled in by the user.
-
 
84
                    return true;
-
 
85
                }
64
                }
86
            } catch (Exception e) {
65
            } catch (Exception e) {
87
                log.error("Unable to connect to user service", e);
66
                log.error("Unable to connect to user service", e);
88
                //We dont know if we need his number. Let us ask anyway.
67
                //We don't know if we need customer's address or phone. Let us ask anyway.
-
 
68
                if (amount > 1000)
-
 
69
                    return ADDRESS;
-
 
70
                else
89
                return true;
71
                    return PHONE;
-
 
72
            }
-
 
73
            
-
 
74
            if (amount > 1000) {
-
 
75
                if (address == null) {
-
 
76
                    return ADDRESS;
-
 
77
                }
-
 
78
            } else {
-
 
79
                if (address == null || address.getPhone() == null || address.getPhone().isEmpty()) {
-
 
80
                    return PHONE;
-
 
81
                }
90
            }
82
            }
91
        }
83
        }
-
 
84
        
92
        return false;
85
        return NOTHING; 
93
    }
86
    }
94
 
87
 
95
    public void setRechargeOrder(RechargeOrder rechargeOrder) {
88
    public void setRechargeOrder(RechargeOrder rechargeOrder) {
96
        this.rechargeOrder = rechargeOrder;
89
        this.rechargeOrder = rechargeOrder;
97
    }
90
    }
Line 106... Line 99...
106
 
99
 
107
    public String getRechargeOrderId() {
100
    public String getRechargeOrderId() {
108
        return rechargeOrderId;
101
        return rechargeOrderId;
109
    }
102
    }
110
 
103
 
111
    public void setAmount(String amount) {
-
 
112
        this.amount = amount;
-
 
113
    }
-
 
114
 
-
 
115
    public String getAmount() {
-
 
116
        return amount;
-
 
117
    }
-
 
118
 
-
 
119
    public String getErrorMsg() {
104
    public String getErrorMsg() {
120
        return errorMsg;
105
        return errorMsg;
121
    }
106
    }
122
 
-
 
123
    public String getUserId() {
-
 
124
        return userId;
-
 
125
    }
-
 
126
 
-
 
127
    public void setUserId(String userId) {
-
 
128
        this.userId = userId;
-
 
129
    }
-
 
130
 
-
 
131
    public void setRechargeType(String rechargeType) {
-
 
132
        this.rechargeType = rechargeType;
-
 
133
    }
-
 
134
 
-
 
135
    public String getRechargeType() {
-
 
136
        return rechargeType;
-
 
137
    }
-
 
138
}
107
}
139
108