Subversion Repositories SmartDukaan

Rev

Rev 6050 | Rev 6058 | 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;
6057 anupam.sin 54
    private long userId;
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()) {
90
            setUserId(userinfo.getUserId());
91
        }
6050 anupam.sin 92
        try {
93
            RechargeOrder rechargeOrder = new RechargeOrder();
94
            rechargeOrder.setTotalAmount(Long.parseLong(amount));
95
            rechargeOrder.setUserEmailId(email);
6057 anupam.sin 96
            rechargeOrder.setUserId(userId);
6050 anupam.sin 97
            rechargeOrder.setDeviceNumber(number);
98
            rechargeOrder.setOperatorId(Long.parseLong(operator));
6057 anupam.sin 99
            rechargeOrder.setRechargeType(RechargeType.findByValue(Integer.parseInt(rechargeType)));
6050 anupam.sin 100
            rechargeOrder.setStatus(RechargeOrderStatus.PAYMENT_PENDING);
101
            rechargeOrder.setOrderType(OrderType.B2C);
6057 anupam.sin 102
            //rechargeOrder.setWalletAmount(walletAmount);
6050 anupam.sin 103
 
104
            TransactionClient tc = new TransactionClient();
105
            rechargeOrder = tc.getClient().createRechargeOrder(rechargeOrder);
6057 anupam.sin 106
            setRechargeOrderId(rechargeOrder.getId());
6050 anupam.sin 107
 
108
        } catch (TransactionServiceException e) {
109
            // TODO Auto-generated catch block
110
            e.printStackTrace();
111
        } catch (TException e) {
112
            // TODO Auto-generated catch block
113
            e.printStackTrace();
114
        }
115
        if(amount.equals("0")) {
116
            return "create-recharge-redirect";
117
        } else {
118
            return "recharge-pay-options-redirect";
119
        }
120
    }
121
 
122
    public String temp() {
123
        try {
124
            UserClient ucl = new UserClient();
125
            User user = ucl.getClient().getUserByEmail(email);
126
            if(user == null) {
127
                user = new User();
128
                String password = null;
129
                boolean isValid = true;
130
 
131
                /**
132
                 * TODO : Generate password
133
                 * password = this.request.getParameter("txtPassword");
134
                 * 
135
                 */
136
 
137
 
138
                if(!Utils.isValidEmail(email))  {
139
                    addActionError("Please enter valid email address.");
140
                    isValid = false;
141
                }
142
 
143
                user.setEmail(email);
144
                String encryptedPassword = desEncrypter.encrypt(password);
145
                user.setPassword(encryptedPassword);
146
                user.setCommunicationEmail(email);
147
                Cookie sourceCookie = (Cookie) cookiesMap.get(TrackingInterceptor.SRC_COOKIE);
148
                if (sourceCookie != null) {
149
                    DesEncrypter des = new DesEncrypter(TrackingInterceptor.ENCRIPTION_STRING);
150
                    String sourceCookieVal = des.decrypt(sourceCookie.getValue());
151
                    user.setSource(sourceCookieVal);
152
                }
153
 
154
                Cookie sourceTimeCookie = (Cookie) cookiesMap.get(TrackingInterceptor.SRC_TIME_COOKIE);
155
                long sourceTime = 0;
156
                if (sourceTimeCookie != null) {
157
                    try {
158
                        sourceTime = Long.parseLong(sourceTimeCookie.getValue());
159
                    }
160
                    catch (Exception e) {
161
                        log.warn("Unable to parse session src time cookie.");
162
                    }
163
                    user.setSourceStartTime(sourceTime);
164
                }
165
 
166
                user.setSex(Sex.WONT_SAY);
167
 
168
 
169
                UserClient userContextServiceClient;
170
                userContextServiceClient = new UserClient();
171
                in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
172
                user = userClient.createUser(user);
173
                HelperClient hc = new HelperClient();
174
                List<String> mailingList = new ArrayList<String>();
175
                mailingList.add(email);
176
                hc.getClient().saveUserEmailForSending(mailingList, "help@saholic.com", "Login Details", "/*body*/", "/*source*/", "/*emailType*/", null, null);
177
            }
6057 anupam.sin 178
            //setUserId("" + user.getUserId());
6050 anupam.sin 179
 
180
 
181
            /*****************************
182
             * 
183
             * TODO : Handle Wallets
184
             * 
185
             */
186
 
187
 
188
            //TransactionClient tc = new TransactionClient();
189
            //setCoupons(tc.getClient().getRechargeCoupons(user.getUserId(), RechargeCouponStatus.ACTIVE));
190
        } catch (TTransportException e) {
191
            // TODO Auto-generated catch block
192
            e.printStackTrace();
193
        } catch (UserContextException e) {
194
            // TODO Auto-generated catch block
195
            e.printStackTrace();
196
        } catch (TException e) {
197
            // TODO Auto-generated catch block
198
            e.printStackTrace();
199
        } catch (HelperServiceException e) {
200
            // TODO Auto-generated catch block
201
            e.printStackTrace();
202
        }
203
        return index();
204
    }
205
 
6057 anupam.sin 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
 
6050 anupam.sin 217
    public String getAmount() {
218
        return amount;
219
    }
220
    public void setAmount(String amount) {
221
        this.amount = amount;
222
    }
223
    public String getOperator() {
224
        return operator;
225
    }
226
    public void setOperator(String operator) {
227
        this.operator = operator;
228
    }
229
    public String getNumber() {
230
        return number;
231
    }
232
    public void setNumber(String number) {
233
        this.number = number;
234
    }
235
    public String getEmail() {
236
        return email;
237
    }
238
    public void setEmail(String email) {
239
        this.email = email;
240
    }
241
 
242
    public void setCouponIds(List<String> couponIds) {
243
        this.couponIds = couponIds;
244
    }
245
 
246
    public List<String> getCouponIds() {
247
        return couponIds;
248
    }
249
 
250
    public void setCoupons(List<RechargeCoupon> coupons) {
251
        this.coupons = coupons;
252
    }
253
 
254
    public List<RechargeCoupon> getCoupons() {
255
        return coupons;
256
    }
257
 
258
    public String getRechargeType() {
259
        return rechargeType;
260
    }
261
 
262
    public void setRechargeType(String rechargeType) {
263
        this.rechargeType = rechargeType;
264
    }
265
 
6057 anupam.sin 266
    public long getUserId() {
6050 anupam.sin 267
        return userId;
268
    }
269
 
6057 anupam.sin 270
    public void setUserId(long l) {
271
        this.userId = l;
6050 anupam.sin 272
    }
273
 
6057 anupam.sin 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;
292
    }
293
 
6050 anupam.sin 294
}