Subversion Repositories SmartDukaan

Rev

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

Rev 6050 Rev 6057
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import in.shop2020.model.v1.order.OrderType;
3
import in.shop2020.model.v1.order.OrderType;
4
import in.shop2020.model.v1.order.RechargeCoupon;
4
import in.shop2020.model.v1.order.RechargeCoupon;
5
import in.shop2020.model.v1.order.RechargeCouponStatus;
-
 
6
import in.shop2020.model.v1.order.RechargeOrder;
5
import in.shop2020.model.v1.order.RechargeOrder;
7
import in.shop2020.model.v1.order.RechargeOrderStatus;
6
import in.shop2020.model.v1.order.RechargeOrderStatus;
8
import in.shop2020.model.v1.order.RechargeType;
7
import in.shop2020.model.v1.order.RechargeType;
9
import in.shop2020.model.v1.order.TransactionServiceException;
8
import in.shop2020.model.v1.order.TransactionServiceException;
10
import in.shop2020.model.v1.user.Coupon;
9
import in.shop2020.model.v1.order.UserWallet;
11
import in.shop2020.model.v1.user.Sex;
10
import in.shop2020.model.v1.user.Sex;
12
import in.shop2020.model.v1.user.User;
11
import in.shop2020.model.v1.user.User;
13
import in.shop2020.model.v1.user.UserContextException;
12
import in.shop2020.model.v1.user.UserContextException;
14
import in.shop2020.serving.interceptors.TrackingInterceptor;
13
import in.shop2020.serving.interceptors.TrackingInterceptor;
15
import in.shop2020.serving.utils.DesEncrypter;
14
import in.shop2020.serving.utils.DesEncrypter;
Line 19... Line 18...
19
import in.shop2020.thrift.clients.UserClient;
18
import in.shop2020.thrift.clients.UserClient;
20
import in.shop2020.utils.HelperServiceException;
19
import in.shop2020.utils.HelperServiceException;
21
 
20
 
22
import java.util.ArrayList;
21
import java.util.ArrayList;
23
import java.util.List;
22
import java.util.List;
-
 
23
import java.util.Map;
24
 
24
 
25
import javax.servlet.http.Cookie;
25
import javax.servlet.http.Cookie;
26
 
26
 
27
import org.apache.log4j.Logger;
27
import org.apache.log4j.Logger;
28
import org.apache.struts2.convention.annotation.Result;
28
import org.apache.struts2.convention.annotation.Result;
Line 30... Line 30...
30
import org.apache.thrift.TException;
30
import org.apache.thrift.TException;
31
import org.apache.thrift.transport.TTransportException;
31
import org.apache.thrift.transport.TTransportException;
32
 
32
 
33
@SuppressWarnings({ "serial", "serial" })
33
@SuppressWarnings({ "serial", "serial" })
34
@Results({
34
@Results({
35
    @Result(name="pay-options-redirect", type="redirectAction", params = {"actionName" , "recharge-pay-options", "rechargeOrderId", "${rechargeOrderId}"}),
35
    @Result(name="recharge-pay-options-redirect", type="redirectAction", params = {"actionName" , "recharge-pay-options", "rechargeOrderId", "${rechargeOrderId}", "amount", "${amount}"}),
36
    @Result(name="create-recharge-redirect", type="redirectAction", params = {"actionName" , "recharge-payment", "rechargeOrderId", "${rechargeOrderId}"})
36
    @Result(name="create-recharge-redirect", type="redirectAction", params = {"actionName" , "wallet-only-payment", "rechargeOrderId", "${rechargeOrderId}"})
37
})
37
})
38
 
38
 
39
public class ConfirmController extends BaseController{
39
public class ConfirmController extends BaseController{
40
 
40
 
41
    /**
41
    /**
42
     * 
42
     * 
43
     */
43
     */
44
    private static final long serialVersionUID = 1L;
44
    private static final long serialVersionUID = 1L;
-
 
45
    private long rechargeOrderId = 0;
45
    private String amount = "";
46
    private String amount = "";
46
    private String operator = "";
47
    private String operator = "";
47
    private String number = "";
48
    private String number = "";
48
    private String email = "";
49
    private String email = "";
49
    private String rechargeType = "";
50
    private String rechargeType = "";
50
    private DesEncrypter desEncrypter = new DesEncrypter("saholic");
51
    private DesEncrypter desEncrypter = new DesEncrypter("saholic");
51
    private List<String> couponIds = null;
52
    private List<String> couponIds = null;
52
    private List<RechargeCoupon> coupons = null;
53
    private List<RechargeCoupon> coupons = null;
53
    private String userId;
54
    private long userId;
-
 
55
    private String message = "";
54
    private static Logger log = Logger.getLogger(Class.class);
56
    private static Logger log = Logger.getLogger(Class.class);
55
    
57
    
56
    public String index() {
58
    public String index() {
57
        return "index";
59
        return "index";
58
    }
60
    }
59
    
61
    
60
    public String create() {
62
    public String create() {
-
 
63
        
-
 
64
        if(userinfo.isLoggedIn()) {
-
 
65
            try {
-
 
66
            TransactionClient tc = new TransactionClient();
-
 
67
            UserWallet wallet = tc.getClient().getUserWallet(userinfo.getUserId());
-
 
68
            long amountA = 0;
-
 
69
            if(wallet.getAmount() == 0){
-
 
70
                setMessage("Your RechargeWallet is empty.");
-
 
71
            } else if ((amountA = wallet.getAmount() - Long.parseLong(amount)) >= 0) {
-
 
72
                setAmount("0");
-
 
73
                setMessage("You now have Rs. " + amountA + " left in your RechargeWallet.");
-
 
74
            } else {
-
 
75
                setAmount("" + (0-amountA));
-
 
76
                setMessage("You have used all the amount in your RechargeWallet.");
-
 
77
            }
-
 
78
            
-
 
79
                
-
 
80
            } catch (Exception e) {
-
 
81
                log.error("Unable to get user wallet", e);
-
 
82
            }
-
 
83
        }
61
        return index();
84
        return index();
62
        
85
        
63
    }
86
    }
64
    
87
    
65
    public String createRecharge(){
88
    public String createRecharge(){
-
 
89
        if(userinfo.isLoggedIn()) {
-
 
90
            setUserId(userinfo.getUserId());
-
 
91
        }
66
        try {
92
        try {
67
            RechargeOrder rechargeOrder = new RechargeOrder();
93
            RechargeOrder rechargeOrder = new RechargeOrder();
68
            rechargeOrder.setTotalAmount(Long.parseLong(amount));
94
            rechargeOrder.setTotalAmount(Long.parseLong(amount));
69
            rechargeOrder.setUserEmailId(email);
95
            rechargeOrder.setUserEmailId(email);
70
            rechargeOrder.setUserId(Long.parseLong(userId));
96
            rechargeOrder.setUserId(userId);
71
            rechargeOrder.setDeviceNumber(number);
97
            rechargeOrder.setDeviceNumber(number);
72
            rechargeOrder.setOperatorId(Long.parseLong(operator));
98
            rechargeOrder.setOperatorId(Long.parseLong(operator));
73
            rechargeOrder.setRechargeType(RechargeType.valueOf(rechargeType));
99
            rechargeOrder.setRechargeType(RechargeType.findByValue(Integer.parseInt(rechargeType)));
74
            rechargeOrder.setStatus(RechargeOrderStatus.PAYMENT_PENDING);
100
            rechargeOrder.setStatus(RechargeOrderStatus.PAYMENT_PENDING);
75
            rechargeOrder.setOrderType(OrderType.B2C);
101
            rechargeOrder.setOrderType(OrderType.B2C);
-
 
102
            //rechargeOrder.setWalletAmount(walletAmount);
76
            
103
            
77
            TransactionClient tc = new TransactionClient();
104
            TransactionClient tc = new TransactionClient();
78
            rechargeOrder = tc.getClient().createRechargeOrder(rechargeOrder);
105
            rechargeOrder = tc.getClient().createRechargeOrder(rechargeOrder);
-
 
106
            setRechargeOrderId(rechargeOrder.getId());
79
            
107
            
80
        } catch (TransactionServiceException e) {
108
        } catch (TransactionServiceException e) {
81
            // TODO Auto-generated catch block
109
            // TODO Auto-generated catch block
82
            e.printStackTrace();
110
            e.printStackTrace();
83
        } catch (TException e) {
111
        } catch (TException e) {
Line 145... Line 173...
145
                HelperClient hc = new HelperClient();
173
                HelperClient hc = new HelperClient();
146
                List<String> mailingList = new ArrayList<String>();
174
                List<String> mailingList = new ArrayList<String>();
147
                mailingList.add(email);
175
                mailingList.add(email);
148
                hc.getClient().saveUserEmailForSending(mailingList, "help@saholic.com", "Login Details", "/*body*/", "/*source*/", "/*emailType*/", null, null);
176
                hc.getClient().saveUserEmailForSending(mailingList, "help@saholic.com", "Login Details", "/*body*/", "/*source*/", "/*emailType*/", null, null);
149
            }
177
            }
150
            setUserId("" + user.getUserId());
178
            //setUserId("" + user.getUserId());
151
            
179
            
152
            
180
            
153
            /*****************************
181
            /*****************************
154
             * 
182
             * 
155
             * TODO : Handle Wallets
183
             * TODO : Handle Wallets
Line 173... Line 201...
173
            e.printStackTrace();
201
            e.printStackTrace();
174
        }
202
        }
175
        return index();
203
        return index();
176
    }
204
    }
177
    
205
    
-
 
206
    public String getOperatorName() {
-
 
207
        try {
-
 
208
        TransactionClient tc = new TransactionClient();
-
 
209
        Map<Long, String> providers = tc.getClient().getServiceProviders(RechargeType.findByValue(Integer.parseInt(rechargeType)));
-
 
210
        return providers.get(Long.parseLong(operator));
-
 
211
        } catch(Exception e) {
-
 
212
        log.error("Unable to get operator name");
-
 
213
        }
-
 
214
        return "N/A";
-
 
215
    }
-
 
216
    
178
    public String getAmount() {
217
    public String getAmount() {
179
        return amount;
218
        return amount;
180
    }
219
    }
181
    public void setAmount(String amount) {
220
    public void setAmount(String amount) {
182
        this.amount = amount;
221
        this.amount = amount;
Line 222... Line 261...
222
 
261
 
223
    public void setRechargeType(String rechargeType) {
262
    public void setRechargeType(String rechargeType) {
224
        this.rechargeType = rechargeType;
263
        this.rechargeType = rechargeType;
225
    }
264
    }
226
 
265
 
227
    public String getUserId() {
266
    public long getUserId() {
228
        return userId;
267
        return userId;
229
    }
268
    }
230
 
269
 
231
    public void setUserId(String userId) {
270
    public void setUserId(long l) {
232
        this.userId = userId;
271
        this.userId = l;
-
 
272
    }
-
 
273
    
-
 
274
    public boolean isLoggedIn() {
-
 
275
        return userinfo.isLoggedIn();
-
 
276
    }
-
 
277
 
-
 
278
    public void setMessage(String message) {
-
 
279
        this.message = message;
-
 
280
    }
-
 
281
 
-
 
282
    public String getMessage() {
-
 
283
        return message;
-
 
284
    }
-
 
285
 
-
 
286
    public long getRechargeOrderId() {
-
 
287
        return rechargeOrderId;
-
 
288
    }
-
 
289
 
-
 
290
    public void setRechargeOrderId(long l) {
-
 
291
        this.rechargeOrderId = l;
233
    }
292
    }
234
    
293
    
235
}
294
}