| 6050 |
anupam.sin |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 8733 |
anupam.sin |
3 |
import java.util.List;
|
|
|
4 |
|
| 13373 |
amit.gupta |
5 |
import in.shop2020.serving.services.PayuPaymentService;
|
| 6050 |
anupam.sin |
6 |
import in.shop2020.model.v1.order.RechargeOrder;
|
|
|
7 |
import in.shop2020.model.v1.user.Address;
|
| 8733 |
anupam.sin |
8 |
import in.shop2020.payments.Payment;
|
|
|
9 |
import in.shop2020.payments.PaymentException;
|
| 6050 |
anupam.sin |
10 |
import in.shop2020.serving.services.EbsPaymentService;
|
|
|
11 |
import in.shop2020.serving.services.HdfcPaymentService;
|
|
|
12 |
import in.shop2020.serving.services.IPaymentService;
|
| 20278 |
aman.kumar |
13 |
import in.shop2020.serving.utils.PaymentUtils;
|
| 13425 |
amit.gupta |
14 |
import in.shop2020.serving.utils.Utils;
|
| 8733 |
anupam.sin |
15 |
import in.shop2020.thrift.clients.PaymentClient;
|
| 6050 |
anupam.sin |
16 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
17 |
import in.shop2020.thrift.clients.UserClient;
|
|
|
18 |
|
|
|
19 |
import org.apache.log4j.Logger;
|
|
|
20 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
21 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
@Results({
|
| 8733 |
anupam.sin |
25 |
@Result(name="recharge-redirect", type="redirectAction", params = {"actionName" , "recharge", "error", "${errorMessage}"}),
|
| 6050 |
anupam.sin |
26 |
@Result(name="recharge-pay-options-redirect", type="redirectAction", params = {"actionName" , "recharge-pay-options", "rechargeOrderId", "${rechargeOrderId}"}),
|
| 18937 |
kshitij.so |
27 |
@Result(name="ebs-pay-redirect", type="redirect", location="/ebs-pay!edit?id=${paymentId}&phone=${phone}"),
|
| 6050 |
anupam.sin |
28 |
@Result(name="cod-redirect", type="redirect", location="/pay-success?paymentId=${paymentId}")
|
|
|
29 |
})
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
public class RechargePaymentController extends BaseController {
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
*
|
|
|
36 |
*/
|
|
|
37 |
private String rechargeOrderId = "";
|
| 6228 |
anupam.sin |
38 |
private String name = "";
|
|
|
39 |
private String line1 = "";
|
|
|
40 |
private String line2 = "";
|
|
|
41 |
private String city = "";
|
|
|
42 |
private String state = "";
|
|
|
43 |
private String pincode = "";
|
| 6050 |
anupam.sin |
44 |
private String phone = "";
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
private static final long serialVersionUID = 2079308723099307749L;
|
|
|
48 |
|
|
|
49 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
50 |
|
|
|
51 |
public String index() {
|
|
|
52 |
return "index";
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
/******************************************************
|
|
|
56 |
*
|
|
|
57 |
*
|
|
|
58 |
*
|
|
|
59 |
*****************************************************/
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
public long getPaymentId() {
|
|
|
63 |
return paymentId;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
private String id;
|
|
|
67 |
private long txnId = 0;
|
|
|
68 |
|
|
|
69 |
private long paymentId;
|
| 8733 |
anupam.sin |
70 |
private String errorMessage;
|
| 6050 |
anupam.sin |
71 |
|
|
|
72 |
private String redirectURL;
|
|
|
73 |
private RechargeOrder rechargeOrder;
|
|
|
74 |
|
|
|
75 |
// GET /order/ orderid
|
|
|
76 |
public String show() {
|
|
|
77 |
log.info("id=" + id);
|
|
|
78 |
htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
|
|
|
79 |
htmlSnippets.put("ORDER_DETAILS", pageLoader.getOrderDetailsHtml(Long.parseLong(id), userinfo));
|
|
|
80 |
return "show";
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
// POST /order/
|
|
|
84 |
public String create(){
|
| 6228 |
anupam.sin |
85 |
|
| 6050 |
anupam.sin |
86 |
if(rechargeOrderId == null){
|
| 8733 |
anupam.sin |
87 |
setErrorMessage("There was some problem. Please try again.");
|
| 6050 |
anupam.sin |
88 |
return "recharge-redirect";
|
|
|
89 |
}
|
| 6091 |
anupam.sin |
90 |
try {
|
|
|
91 |
TransactionClient tc = new TransactionClient();
|
|
|
92 |
rechargeOrder = tc.getClient().getRechargeOrder(Long.parseLong(rechargeOrderId));
|
| 6228 |
anupam.sin |
93 |
} catch (Exception ee) {
|
|
|
94 |
log.error("problem fetching rechargeOrder : " + rechargeOrderId);
|
| 8733 |
anupam.sin |
95 |
setErrorMessage("There was some problem. Please try again.");
|
| 6228 |
anupam.sin |
96 |
return "recharge-redirect";
|
|
|
97 |
}
|
| 8733 |
anupam.sin |
98 |
|
| 6228 |
anupam.sin |
99 |
try {
|
| 8733 |
anupam.sin |
100 |
PaymentClient paymentServiceClient = new PaymentClient();
|
|
|
101 |
List<Payment> payments = paymentServiceClient.getClient().getPaymentForRechargeTxnId(rechargeOrder.getTransactionId());
|
|
|
102 |
if(payments.size() > 0) {
|
|
|
103 |
setErrorMessage("There was some problem. Please try again.");
|
|
|
104 |
return "recharge-redirect";
|
|
|
105 |
}
|
|
|
106 |
} catch (Exception ee) {
|
|
|
107 |
log.error("problem fetching payment for rechargeId : " + rechargeOrderId);
|
|
|
108 |
setErrorMessage("There was some problem. Please try again.");
|
|
|
109 |
return "recharge-redirect";
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
try {
|
| 6228 |
anupam.sin |
113 |
UserClient uc = new UserClient();
|
|
|
114 |
if(!name.isEmpty() && !phone.isEmpty()) {
|
| 6091 |
anupam.sin |
115 |
Address address = new Address();
|
|
|
116 |
address.setName(name);
|
|
|
117 |
address.setLine1(line1);
|
|
|
118 |
address.setLine2(line2);
|
|
|
119 |
address.setCity(city);
|
|
|
120 |
address.setState(state);
|
|
|
121 |
address.setCountry("India");
|
|
|
122 |
address.setPin(pincode);
|
|
|
123 |
address.setPhone(phone);
|
| 6228 |
anupam.sin |
124 |
|
| 6050 |
anupam.sin |
125 |
uc.getClient().addAddressForUser(rechargeOrder.getUserId(), address, true);
|
|
|
126 |
}
|
| 6228 |
anupam.sin |
127 |
|
|
|
128 |
} catch (Exception e) {
|
|
|
129 |
log.error("Problem saving the address", e);
|
|
|
130 |
return "recharge-pay-options-redirect";
|
| 6050 |
anupam.sin |
131 |
}
|
| 6091 |
anupam.sin |
132 |
|
| 6050 |
anupam.sin |
133 |
String paymentOption = request.getParameter("payment_option");
|
| 20278 |
aman.kumar |
134 |
String paymentType="";
|
| 6050 |
anupam.sin |
135 |
log.info("Payment Option Selected: " + paymentOption);
|
|
|
136 |
if(paymentOption == null || paymentOption.equals("")){
|
|
|
137 |
addActionError("Please select a payment method to continue.");
|
|
|
138 |
return "recharge-pay-options-redirect";
|
|
|
139 |
}
|
| 20278 |
aman.kumar |
140 |
if(paymentOption.contains("~")){
|
|
|
141 |
paymentType = paymentOption.split("~")[0];
|
|
|
142 |
paymentOption = paymentOption.split("~")[1];
|
|
|
143 |
}
|
| 6050 |
anupam.sin |
144 |
|
| 6228 |
anupam.sin |
145 |
if (name.isEmpty() && !phone.isEmpty()) {
|
|
|
146 |
//This means we only got the phone from UI.
|
|
|
147 |
//Lets keep it.
|
|
|
148 |
} else {
|
|
|
149 |
//For all other cases make it empty.
|
|
|
150 |
phone = "";
|
|
|
151 |
}
|
| 6050 |
anupam.sin |
152 |
|
| 20278 |
aman.kumar |
153 |
long gatewayId = PaymentUtils.getGatewayId(paymentType+paymentOption);
|
|
|
154 |
|
|
|
155 |
/* if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) ||
|
| 6050 |
anupam.sin |
156 |
paymentOption.equals(IPaymentService.HDFC_VISA) || paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON)) {
|
|
|
157 |
// User has selected Visa or MasterCard
|
|
|
158 |
HdfcPaymentService hdfcPaymentService = new HdfcPaymentService();
|
| 6228 |
anupam.sin |
159 |
paymentId = hdfcPaymentService.createPayment(rechargeOrder, paymentOption, phone);
|
| 6050 |
anupam.sin |
160 |
if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
|
|
|
161 |
log.error("Unable to process payment through HDFC. Falling through to EBS.");
|
|
|
162 |
} else {
|
|
|
163 |
this.redirectURL = hdfcPaymentService.getRedirectUrl();
|
|
|
164 |
log.info(this.redirectURL);
|
|
|
165 |
return "success";
|
|
|
166 |
}
|
|
|
167 |
}
|
| 20278 |
aman.kumar |
168 |
|
|
|
169 |
|
| 6050 |
anupam.sin |
170 |
|
|
|
171 |
if(paymentOption.equals(IPaymentService.HDFC_VISA))
|
|
|
172 |
paymentOption = IPaymentService.EBS_VISA;
|
|
|
173 |
else if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT))
|
|
|
174 |
paymentOption = IPaymentService.EBS_MASTERCARD;
|
|
|
175 |
else if(paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON))
|
|
|
176 |
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.
|
| 20278 |
aman.kumar |
177 |
*/
|
|
|
178 |
// if(paymentOption.equals(IPaymentService.PAYU_CC) || PaymentUtils.PAYU_NET_BANKING_CODES_MAP.containsKey(paymentOption)){
|
|
|
179 |
if(gatewayId==5){
|
| 13373 |
amit.gupta |
180 |
PayuPaymentService payuPaymentService = new PayuPaymentService();
|
| 20278 |
aman.kumar |
181 |
paymentId = payuPaymentService.createPayment(rechargeOrder, paymentOption,paymentType);
|
|
|
182 |
if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
|
|
|
183 |
addActionError("We are experiencing some problems. Please try later.");
|
|
|
184 |
log.error("Unable to process payment through PAYU.");
|
|
|
185 |
setErrorMessage("There was some problem. Please try again.");
|
|
|
186 |
return "recharge-redirect";
|
|
|
187 |
} else {
|
|
|
188 |
log.info("Successfully created payment for Payu to process. Redirecting to /payu-pay/" + paymentId);
|
|
|
189 |
|
|
|
190 |
this.redirectURL = "payu-pay/" + paymentId + "/edit?phone=" + phone;
|
|
|
191 |
return "success";
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
}else{
|
|
|
195 |
addActionError("We are experiencing some problems. Please try later.");
|
|
|
196 |
log.error("Unable to process payment through PAYU.");
|
|
|
197 |
setErrorMessage("There was some problem. Please try again.");
|
|
|
198 |
return "recharge-redirect";
|
| 13373 |
amit.gupta |
199 |
}
|
| 6050 |
anupam.sin |
200 |
|
| 20278 |
aman.kumar |
201 |
/* EbsPaymentService ebsPaymentService = new EbsPaymentService();
|
| 6050 |
anupam.sin |
202 |
paymentId = ebsPaymentService.createPayment(rechargeOrder, paymentOption);
|
|
|
203 |
if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
|
|
|
204 |
addActionError("We are experiencing some problems. Please try later.");
|
|
|
205 |
log.error("Unable to process payment through EBS.");
|
| 8733 |
anupam.sin |
206 |
setErrorMessage("There was some problem. Please try again.");
|
| 6215 |
anupam.sin |
207 |
return "recharge-redirect";
|
| 6050 |
anupam.sin |
208 |
} else {
|
|
|
209 |
log.info("Successfully created payment for EBS to process. Redirecting to /ebs-pay/" + paymentId);
|
|
|
210 |
return "ebs-pay-redirect";
|
| 20278 |
aman.kumar |
211 |
} */
|
| 6050 |
anupam.sin |
212 |
}
|
|
|
213 |
|
|
|
214 |
public String getMyaccountHeaderSnippet(){
|
|
|
215 |
return htmlSnippets.get("MYACCOUNT_HEADER");
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
public String getOrderDetailsSnippet(){
|
|
|
219 |
return htmlSnippets.get("ORDER_DETAILS");
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
public long getTxn(){
|
|
|
223 |
return this.txnId;
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
public String getRedirectURL(){
|
|
|
227 |
return this.redirectURL;
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
public void setRechargeOrderId(String rechargeOrderId) {
|
|
|
231 |
this.rechargeOrderId = rechargeOrderId;
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
public String getRechargeOrderId() {
|
|
|
235 |
return rechargeOrderId;
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
public String getPhone() {
|
|
|
239 |
return phone;
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
public void setPhone(String phone) {
|
| 10968 |
amit.gupta |
243 |
log.info("phone---- " + phone);
|
| 6050 |
anupam.sin |
244 |
this.phone = phone;
|
|
|
245 |
}
|
| 6228 |
anupam.sin |
246 |
|
|
|
247 |
public String getName() {
|
|
|
248 |
return name;
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
public void setName(String name) {
|
| 10968 |
amit.gupta |
252 |
log.info("name---- " + name);
|
| 6228 |
anupam.sin |
253 |
this.name = name;
|
|
|
254 |
}
|
|
|
255 |
|
|
|
256 |
public String getLine1() {
|
|
|
257 |
return line1;
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
public void setLine1(String line1) {
|
|
|
261 |
this.line1 = line1;
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
public String getLine2() {
|
|
|
265 |
return line2;
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
public void setLine2(String line2) {
|
|
|
269 |
this.line2 = line2;
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
public String getCity() {
|
|
|
273 |
return city;
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
public void setCity(String city) {
|
|
|
277 |
this.city = city;
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
public String getState() {
|
|
|
281 |
return state;
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
public void setState(String state) {
|
|
|
285 |
this.state = state;
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
public String getPincode() {
|
|
|
289 |
return pincode;
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
public void setPincode(String pincode) {
|
|
|
293 |
this.pincode = pincode;
|
|
|
294 |
}
|
| 8733 |
anupam.sin |
295 |
|
|
|
296 |
public void setErrorMessage(String errorMessage) {
|
|
|
297 |
this.errorMessage = errorMessage;
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
public String getErrorMessage() {
|
|
|
301 |
return errorMessage;
|
|
|
302 |
}
|
| 6050 |
anupam.sin |
303 |
}
|