Subversion Repositories SmartDukaan

Rev

Rev 6057 | Rev 6070 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6050 anupam.sin 1
package in.shop2020.serving.controllers;
2
 
3
import in.shop2020.model.v1.order.OrderType;
4
import in.shop2020.model.v1.order.RechargeCoupon;
5
import in.shop2020.model.v1.order.RechargeOrder;
6
import in.shop2020.model.v1.order.RechargeOrderStatus;
7
import in.shop2020.model.v1.order.RechargeType;
8
import in.shop2020.model.v1.order.TransactionServiceException;
6057 anupam.sin 9
import in.shop2020.model.v1.order.UserWallet;
6050 anupam.sin 10
import in.shop2020.model.v1.user.Sex;
11
import in.shop2020.model.v1.user.User;
12
import in.shop2020.model.v1.user.UserContextException;
13
import in.shop2020.serving.interceptors.TrackingInterceptor;
14
import in.shop2020.serving.utils.DesEncrypter;
15
import in.shop2020.serving.utils.Utils;
16
import in.shop2020.thrift.clients.HelperClient;
17
import in.shop2020.thrift.clients.TransactionClient;
18
import in.shop2020.thrift.clients.UserClient;
19
import in.shop2020.utils.HelperServiceException;
20
 
21
import java.util.ArrayList;
22
import java.util.List;
6057 anupam.sin 23
import java.util.Map;
6050 anupam.sin 24
 
25
import javax.servlet.http.Cookie;
26
 
27
import org.apache.log4j.Logger;
28
import org.apache.struts2.convention.annotation.Result;
29
import org.apache.struts2.convention.annotation.Results;
30
import org.apache.thrift.TException;
31
import org.apache.thrift.transport.TTransportException;
32
 
33
@SuppressWarnings({ "serial", "serial" })
34
@Results({
6057 anupam.sin 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" , "wallet-only-payment", "rechargeOrderId", "${rechargeOrderId}"})
6050 anupam.sin 37
})
38
 
39
public class ConfirmController extends BaseController{
40
 
41
    /**
42
     * 
43
     */
44
    private static final long serialVersionUID = 1L;
6057 anupam.sin 45
    private long rechargeOrderId = 0;
6050 anupam.sin 46
    private String amount = "";
47
    private String operator = "";
48
    private String number = "";
49
    private String email = "";
50
    private String rechargeType = "";
51
    private DesEncrypter desEncrypter = new DesEncrypter("saholic");
52
    private List<String> couponIds = null;
53
    private List<RechargeCoupon> coupons = null;
6058 anupam.sin 54
    private String userId;
6057 anupam.sin 55
    private String message = "";
6050 anupam.sin 56
    private static Logger log = Logger.getLogger(Class.class);
57
 
58
    public String index() {
59
        return "index";
60
    }
61
 
62
    public String create() {
6057 anupam.sin 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
        }
6050 anupam.sin 84
        return index();
85
 
86
    }
87
 
88
    public String createRecharge(){
6057 anupam.sin 89
        if(userinfo.isLoggedIn()) {
6058 anupam.sin 90
            setUserId("" + userinfo.getUserId());
6057 anupam.sin 91
        }
6058 anupam.sin 92
 
6050 anupam.sin 93
        try {
6058 anupam.sin 94
            TransactionClient tc = new TransactionClient();
95
            UserWallet wallet = tc.getClient().getUserWallet(Long.parseLong(userId));
96
 
6050 anupam.sin 97
            RechargeOrder rechargeOrder = new RechargeOrder();
6058 anupam.sin 98
            rechargeOrder.setTotalAmount(Long.parseLong(amount) + wallet.getAmount());
6050 anupam.sin 99
            rechargeOrder.setUserEmailId(email);
6058 anupam.sin 100
            rechargeOrder.setUserId(Long.parseLong(userId));
6050 anupam.sin 101
            rechargeOrder.setDeviceNumber(number);
102
            rechargeOrder.setOperatorId(Long.parseLong(operator));
6057 anupam.sin 103
            rechargeOrder.setRechargeType(RechargeType.findByValue(Integer.parseInt(rechargeType)));
6050 anupam.sin 104
            rechargeOrder.setStatus(RechargeOrderStatus.PAYMENT_PENDING);
105
            rechargeOrder.setOrderType(OrderType.B2C);
6058 anupam.sin 106
            rechargeOrder.setWalletAmount(wallet.getAmount());
6050 anupam.sin 107
 
108
            rechargeOrder = tc.getClient().createRechargeOrder(rechargeOrder);
6057 anupam.sin 109
            setRechargeOrderId(rechargeOrder.getId());
6050 anupam.sin 110
 
111
        } catch (TransactionServiceException e) {
112
            // TODO Auto-generated catch block
113
            e.printStackTrace();
114
        } catch (TException e) {
115
            // TODO Auto-generated catch block
116
            e.printStackTrace();
117
        }
118
        if(amount.equals("0")) {
119
            return "create-recharge-redirect";
120
        } else {
121
            return "recharge-pay-options-redirect";
122
        }
123
    }
124
 
125
    public String temp() {
126
        try {
127
            UserClient ucl = new UserClient();
128
            User user = ucl.getClient().getUserByEmail(email);
129
            if(user == null) {
130
                user = new User();
131
                String password = null;
132
                boolean isValid = true;
133
 
134
                /**
135
                 * TODO : Generate password
136
                 * password = this.request.getParameter("txtPassword");
137
                 * 
138
                 */
139
 
140
 
141
                if(!Utils.isValidEmail(email))  {
142
                    addActionError("Please enter valid email address.");
143
                    isValid = false;
144
                }
145
 
146
                user.setEmail(email);
147
                String encryptedPassword = desEncrypter.encrypt(password);
148
                user.setPassword(encryptedPassword);
149
                user.setCommunicationEmail(email);
150
                Cookie sourceCookie = (Cookie) cookiesMap.get(TrackingInterceptor.SRC_COOKIE);
151
                if (sourceCookie != null) {
152
                    DesEncrypter des = new DesEncrypter(TrackingInterceptor.ENCRIPTION_STRING);
153
                    String sourceCookieVal = des.decrypt(sourceCookie.getValue());
154
                    user.setSource(sourceCookieVal);
155
                }
156
 
157
                Cookie sourceTimeCookie = (Cookie) cookiesMap.get(TrackingInterceptor.SRC_TIME_COOKIE);
158
                long sourceTime = 0;
159
                if (sourceTimeCookie != null) {
160
                    try {
161
                        sourceTime = Long.parseLong(sourceTimeCookie.getValue());
162
                    }
163
                    catch (Exception e) {
164
                        log.warn("Unable to parse session src time cookie.");
165
                    }
166
                    user.setSourceStartTime(sourceTime);
167
                }
168
 
169
                user.setSex(Sex.WONT_SAY);
170
 
171
 
172
                UserClient userContextServiceClient;
173
                userContextServiceClient = new UserClient();
174
                in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
175
                user = userClient.createUser(user);
176
                HelperClient hc = new HelperClient();
177
                List<String> mailingList = new ArrayList<String>();
178
                mailingList.add(email);
179
                hc.getClient().saveUserEmailForSending(mailingList, "help@saholic.com", "Login Details", "/*body*/", "/*source*/", "/*emailType*/", null, null);
180
            }
6057 anupam.sin 181
            //setUserId("" + user.getUserId());
6050 anupam.sin 182
 
183
 
184
            /*****************************
185
             * 
186
             * TODO : Handle Wallets
187
             * 
188
             */
189
 
190
 
191
            //TransactionClient tc = new TransactionClient();
192
            //setCoupons(tc.getClient().getRechargeCoupons(user.getUserId(), RechargeCouponStatus.ACTIVE));
193
        } catch (TTransportException e) {
194
            // TODO Auto-generated catch block
195
            e.printStackTrace();
196
        } catch (UserContextException e) {
197
            // TODO Auto-generated catch block
198
            e.printStackTrace();
199
        } catch (TException e) {
200
            // TODO Auto-generated catch block
201
            e.printStackTrace();
202
        } catch (HelperServiceException e) {
203
            // TODO Auto-generated catch block
204
            e.printStackTrace();
205
        }
206
        return index();
207
    }
208
 
6057 anupam.sin 209
    public String getOperatorName() {
210
        try {
211
        TransactionClient tc = new TransactionClient();
212
        Map<Long, String> providers = tc.getClient().getServiceProviders(RechargeType.findByValue(Integer.parseInt(rechargeType)));
213
        return providers.get(Long.parseLong(operator));
214
        } catch(Exception e) {
215
        log.error("Unable to get operator name");
216
        }
217
        return "N/A";
218
    }
219
 
6050 anupam.sin 220
    public String getAmount() {
221
        return amount;
222
    }
223
    public void setAmount(String amount) {
224
        this.amount = amount;
225
    }
226
    public String getOperator() {
227
        return operator;
228
    }
229
    public void setOperator(String operator) {
230
        this.operator = operator;
231
    }
232
    public String getNumber() {
233
        return number;
234
    }
235
    public void setNumber(String number) {
236
        this.number = number;
237
    }
238
    public String getEmail() {
239
        return email;
240
    }
241
    public void setEmail(String email) {
242
        this.email = email;
243
    }
244
 
245
    public void setCouponIds(List<String> couponIds) {
246
        this.couponIds = couponIds;
247
    }
248
 
249
    public List<String> getCouponIds() {
250
        return couponIds;
251
    }
252
 
253
    public void setCoupons(List<RechargeCoupon> coupons) {
254
        this.coupons = coupons;
255
    }
256
 
257
    public List<RechargeCoupon> getCoupons() {
258
        return coupons;
259
    }
260
 
261
    public String getRechargeType() {
262
        return rechargeType;
263
    }
264
 
265
    public void setRechargeType(String rechargeType) {
266
        this.rechargeType = rechargeType;
267
    }
268
 
6058 anupam.sin 269
    public String getUserId() {
6050 anupam.sin 270
        return userId;
271
    }
272
 
6058 anupam.sin 273
    public void setUserId(String userId) {
274
        this.userId = userId;
6050 anupam.sin 275
    }
276
 
6057 anupam.sin 277
    public boolean isLoggedIn() {
278
        return userinfo.isLoggedIn();
279
    }
280
 
281
    public void setMessage(String message) {
282
        this.message = message;
283
    }
284
 
285
    public String getMessage() {
286
        return message;
287
    }
288
 
289
    public long getRechargeOrderId() {
290
        return rechargeOrderId;
291
    }
292
 
293
    public void setRechargeOrderId(long l) {
294
        this.rechargeOrderId = l;
295
    }
296
 
6050 anupam.sin 297
}