Subversion Repositories SmartDukaan

Rev

Rev 6050 | Rev 6215 | 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 java.util.ArrayList;
4
import java.util.List;
5
 
6
import in.shop2020.datalogger.EventType;
7
import in.shop2020.model.v1.order.Order;
8
import in.shop2020.model.v1.order.RechargeOrder;
9
import in.shop2020.model.v1.order.TransactionServiceException;
10
import in.shop2020.model.v1.user.Address;
11
import in.shop2020.model.v1.user.ShoppingCartException;
12
import in.shop2020.model.v1.user.UserContextException;
13
import in.shop2020.serving.interceptors.TrackingInterceptor;
14
import in.shop2020.serving.services.CodPaymentService;
15
import in.shop2020.serving.services.CommonPaymentService;
16
import in.shop2020.serving.services.EbsPaymentService;
17
import in.shop2020.serving.services.HdfcEmiPaymentService;
18
import in.shop2020.serving.services.HdfcPaymentService;
19
import in.shop2020.serving.services.IPaymentService;
20
import in.shop2020.serving.utils.Utils;
21
import in.shop2020.thrift.clients.TransactionClient;
22
import in.shop2020.thrift.clients.UserClient;
23
import in.shop2020.utils.DataLogger;
24
 
25
import nl.captcha.Captcha;
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
 
34
@Results({
35
    @Result(name="recharge-redirect", type="redirectAction", params = {"actionName" , "recharge"}),
36
    @Result(name="recharge-pay-options-redirect", type="redirectAction", params = {"actionName" , "recharge-pay-options", "rechargeOrderId", "${rechargeOrderId}"}),
37
    @Result(name="ebs-pay-redirect", type="redirect", location="/ebs-pay/${paymentId}/edit"),
38
    @Result(name="cod-redirect", type="redirect", location="/pay-success?paymentId=${paymentId}")
39
})
40
 
41
 
42
public class RechargePaymentController extends BaseController {
43
 
44
    /**
45
     * 
46
     */
47
    private String rechargeOrderId = "";
48
    private String name = "";
49
    private String line1 = "";
50
    private String line2 = "";
51
    private String city = "";
52
    private String state = "";
53
    private String pincode = "";
54
    private String phone = "";
55
 
56
 
57
    private static final long serialVersionUID = 2079308723099307749L;
58
 
59
    private static Logger log = Logger.getLogger(Class.class);
60
 
61
    public String index() {
62
        return "index";
63
    }
64
 
65
    /******************************************************
66
     * 
67
     * 
68
     * 
69
     *****************************************************/
70
 
71
 
72
    public long getPaymentId() {
73
        return paymentId;
74
    }
75
 
76
    private String id;
77
    private long txnId = 0;
78
 
79
    private long paymentId;
80
 
81
    private String redirectURL;
82
    private RechargeOrder rechargeOrder;
83
 
84
    // GET /order/ orderid
85
    public String show() {
86
        log.info("id=" + id);
87
        htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
88
        htmlSnippets.put("ORDER_DETAILS", pageLoader.getOrderDetailsHtml(Long.parseLong(id), userinfo));
89
        return "show";
90
    }
91
 
92
    // POST /order/
93
    public String create(){
94
 
95
        if(rechargeOrderId == null){
96
            return "recharge-redirect";
97
        }
6091 anupam.sin 98
        UserClient uc;
99
        try {
100
            uc = new UserClient();
101
            TransactionClient tc = new TransactionClient();
102
            rechargeOrder = tc.getClient().getRechargeOrder(Long.parseLong(rechargeOrderId));
103
            if(!name.isEmpty()) {
104
                Address address = new Address();
105
                address.setName(name);
106
                address.setLine1(line1);
107
                address.setLine2(line2);
108
                address.setCity(city);
109
                address.setState(state);
110
                address.setCountry("India");
111
                address.setPin(pincode);
112
                address.setPhone(phone);
113
 
6050 anupam.sin 114
                uc.getClient().addAddressForUser(rechargeOrder.getUserId(), address, true);
115
            }
116
 
6091 anupam.sin 117
        } catch (TTransportException e) {
118
            // TODO Auto-generated catch block
119
            e.printStackTrace();
120
        } catch (NumberFormatException e) {
121
            // TODO Auto-generated catch block
122
            e.printStackTrace();
123
        } catch (TransactionServiceException e) {
124
            // TODO Auto-generated catch block
125
            e.printStackTrace();
126
        } catch (TException e) {
127
            // TODO Auto-generated catch block
128
            e.printStackTrace();
129
        } catch (UserContextException e) {
130
            // TODO Auto-generated catch block
131
            e.printStackTrace();
6050 anupam.sin 132
        }
6091 anupam.sin 133
 
134
 
6050 anupam.sin 135
        String paymentOption = request.getParameter("payment_option");
136
        log.info("Payment Option Selected: " + paymentOption);
137
        if(paymentOption == null || paymentOption.equals("")){
138
            addActionError("Please select a payment method to continue.");
139
            return "recharge-pay-options-redirect";
140
        }
141
 
142
 
143
        if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) || 
144
                paymentOption.equals(IPaymentService.HDFC_VISA) || paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON)) {
145
            // User has selected Visa or MasterCard
146
            HdfcPaymentService hdfcPaymentService = new HdfcPaymentService();
147
            paymentId = hdfcPaymentService.createPayment(rechargeOrder, paymentOption);
148
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
149
                log.error("Unable to process payment through HDFC. Falling through to EBS.");
150
            } else {
151
                this.redirectURL = hdfcPaymentService.getRedirectUrl();
152
                log.info(this.redirectURL);
153
                return "success";
154
            }
155
        }
156
 
157
        if(paymentOption.equals(IPaymentService.HDFC_VISA))
158
            paymentOption = IPaymentService.EBS_VISA;
159
        else if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT))
160
            paymentOption = IPaymentService.EBS_MASTERCARD;
161
        else if(paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON))
162
            paymentOption = null;           //Since we don't know the bank's name in this case, we'll let the user select the bank on the EBS page.
163
 
164
        EbsPaymentService ebsPaymentService = new EbsPaymentService();
165
        paymentId = ebsPaymentService.createPayment(rechargeOrder, paymentOption);
166
        if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
167
            addActionError("We are experiencing some problems. Please try later.");
168
            log.error("Unable to process payment through EBS.");
169
            return "proceed-to-pay-redirect";
170
        } else {
171
            log.info("Successfully created payment for EBS to process. Redirecting to /ebs-pay/" + paymentId);
172
            return "ebs-pay-redirect";
173
        }           
174
    }
175
 
176
    public String getMyaccountHeaderSnippet(){
177
        return htmlSnippets.get("MYACCOUNT_HEADER");
178
    }
179
 
180
    public String getOrderDetailsSnippet(){
181
        return htmlSnippets.get("ORDER_DETAILS");
182
    }
183
 
184
    public long getTxn(){
185
        return this.txnId;
186
    }
187
 
188
    public String getRedirectURL(){
189
        return this.redirectURL;
190
    }
191
 
192
    public void setRechargeOrderId(String rechargeOrderId) {
193
        this.rechargeOrderId = rechargeOrderId;
194
    }
195
 
196
    public String getRechargeOrderId() {
197
        return rechargeOrderId;
198
    }
199
 
200
    public String getName() {
201
        return name;
202
    }
203
 
204
    public void setName(String name) {
205
        this.name = name;
206
    }
207
 
208
    public String getLine1() {
209
        return line1;
210
    }
211
 
212
    public void setLine1(String line1) {
213
        this.line1 = line1;
214
    }
215
 
216
    public String getLine2() {
217
        return line2;
218
    }
219
 
220
    public void setLine2(String line2) {
221
        this.line2 = line2;
222
    }
223
 
224
    public String getCity() {
225
        return city;
226
    }
227
 
228
    public void setCity(String city) {
229
        this.city = city;
230
    }
231
 
232
    public String getPincode() {
233
        return pincode;
234
    }
235
 
236
    public void setPincode(String pincode) {
237
        this.pincode = pincode;
238
    }
239
 
240
    public String getPhone() {
241
        return phone;
242
    }
243
 
244
    public void setPhone(String phone) {
245
        this.phone = phone;
246
    }
247
 
248
    public void setState(String state) {
249
        this.state = state;
250
    }
251
 
252
    public String getState() {
253
        return state;
254
    }
255
}