Subversion Repositories SmartDukaan

Rev

Rev 6091 | Rev 6228 | 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}"}),
6215 anupam.sin 37
    @Result(name="ebs-pay-redirect", type="redirect", location="/ebs-pay/${paymentId}/edit", params = {"phone", "${phone}"}),
6050 anupam.sin 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 phone = "";
49
 
50
 
51
    private static final long serialVersionUID = 2079308723099307749L;
52
 
53
    private static Logger log = Logger.getLogger(Class.class);
54
 
55
    public String index() {
56
        return "index";
57
    }
58
 
59
    /******************************************************
60
     * 
61
     * 
62
     * 
63
     *****************************************************/
64
 
65
 
66
    public long getPaymentId() {
67
        return paymentId;
68
    }
69
 
70
    private String id;
71
    private long txnId = 0;
72
 
73
    private long paymentId;
74
 
75
    private String redirectURL;
76
    private RechargeOrder rechargeOrder;
77
 
78
    // GET /order/ orderid
79
    public String show() {
80
        log.info("id=" + id);
81
        htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
82
        htmlSnippets.put("ORDER_DETAILS", pageLoader.getOrderDetailsHtml(Long.parseLong(id), userinfo));
83
        return "show";
84
    }
85
 
86
    // POST /order/
87
    public String create(){
88
 
89
        if(rechargeOrderId == null){
90
            return "recharge-redirect";
91
        }
6215 anupam.sin 92
 
93
        /* Dont delete this code fragment. It will be reused.
6091 anupam.sin 94
        UserClient uc;
95
        try {
96
            uc = new UserClient();
97
            TransactionClient tc = new TransactionClient();
98
            rechargeOrder = tc.getClient().getRechargeOrder(Long.parseLong(rechargeOrderId));
99
            if(!name.isEmpty()) {
100
                Address address = new Address();
101
                address.setName(name);
102
                address.setLine1(line1);
103
                address.setLine2(line2);
104
                address.setCity(city);
105
                address.setState(state);
106
                address.setCountry("India");
107
                address.setPin(pincode);
108
                address.setPhone(phone);
109
 
6050 anupam.sin 110
                uc.getClient().addAddressForUser(rechargeOrder.getUserId(), address, true);
111
            }
112
 
6091 anupam.sin 113
        } catch (TTransportException e) {
114
            // TODO Auto-generated catch block
115
            e.printStackTrace();
116
        } catch (NumberFormatException e) {
117
            // TODO Auto-generated catch block
118
            e.printStackTrace();
119
        } catch (TransactionServiceException e) {
120
            // TODO Auto-generated catch block
121
            e.printStackTrace();
122
        } catch (TException e) {
123
            // TODO Auto-generated catch block
124
            e.printStackTrace();
125
        } catch (UserContextException e) {
126
            // TODO Auto-generated catch block
127
            e.printStackTrace();
6050 anupam.sin 128
        }
6215 anupam.sin 129
        */
6091 anupam.sin 130
 
6050 anupam.sin 131
        String paymentOption = request.getParameter("payment_option");
132
        log.info("Payment Option Selected: " + paymentOption);
133
        if(paymentOption == null || paymentOption.equals("")){
134
            addActionError("Please select a payment method to continue.");
135
            return "recharge-pay-options-redirect";
136
        }
137
 
138
 
139
        if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) || 
140
                paymentOption.equals(IPaymentService.HDFC_VISA) || paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON)) {
141
            // User has selected Visa or MasterCard
142
            HdfcPaymentService hdfcPaymentService = new HdfcPaymentService();
143
            paymentId = hdfcPaymentService.createPayment(rechargeOrder, paymentOption);
144
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
145
                log.error("Unable to process payment through HDFC. Falling through to EBS.");
146
            } else {
147
                this.redirectURL = hdfcPaymentService.getRedirectUrl();
148
                log.info(this.redirectURL);
149
                return "success";
150
            }
151
        }
152
 
153
        if(paymentOption.equals(IPaymentService.HDFC_VISA))
154
            paymentOption = IPaymentService.EBS_VISA;
155
        else if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT))
156
            paymentOption = IPaymentService.EBS_MASTERCARD;
157
        else if(paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON))
158
            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.
159
 
160
        EbsPaymentService ebsPaymentService = new EbsPaymentService();
161
        paymentId = ebsPaymentService.createPayment(rechargeOrder, paymentOption);
162
        if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
163
            addActionError("We are experiencing some problems. Please try later.");
164
            log.error("Unable to process payment through EBS.");
6215 anupam.sin 165
            return "recharge-redirect";
6050 anupam.sin 166
        } else {
167
            log.info("Successfully created payment for EBS to process. Redirecting to /ebs-pay/" + paymentId);
168
            return "ebs-pay-redirect";
169
        }           
170
    }
171
 
172
    public String getMyaccountHeaderSnippet(){
173
        return htmlSnippets.get("MYACCOUNT_HEADER");
174
    }
175
 
176
    public String getOrderDetailsSnippet(){
177
        return htmlSnippets.get("ORDER_DETAILS");
178
    }
179
 
180
    public long getTxn(){
181
        return this.txnId;
182
    }
183
 
184
    public String getRedirectURL(){
185
        return this.redirectURL;
186
    }
187
 
188
    public void setRechargeOrderId(String rechargeOrderId) {
189
        this.rechargeOrderId = rechargeOrderId;
190
    }
191
 
192
    public String getRechargeOrderId() {
193
        return rechargeOrderId;
194
    }
195
 
196
    public String getPhone() {
197
        return phone;
198
    }
199
 
200
    public void setPhone(String phone) {
201
        this.phone = phone;
202
    }
203
}