| 419 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 894 |
rajveer |
3 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
| 419 |
rajveer |
4 |
import in.shop2020.serving.controllers.BaseController;
|
| 1905 |
chandransh |
5 |
import in.shop2020.serving.services.EbsPaymentService;
|
| 1318 |
rajveer |
6 |
import in.shop2020.serving.services.HdfcPaymentService;
|
| 1905 |
chandransh |
7 |
import in.shop2020.serving.services.IPaymentService;
|
| 517 |
rajveer |
8 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
9 |
|
| 832 |
rajveer |
10 |
import org.apache.log4j.Logger;
|
| 822 |
vikas |
11 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
12 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 419 |
rajveer |
13 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
14 |
import org.apache.struts2.convention.annotation.Results;
|
| 517 |
rajveer |
15 |
import org.apache.thrift.TException;
|
| 419 |
rajveer |
16 |
|
| 822 |
vikas |
17 |
@InterceptorRefs({
|
|
|
18 |
@InterceptorRef("myDefault"),
|
|
|
19 |
@InterceptorRef("login")
|
|
|
20 |
})
|
|
|
21 |
|
| 419 |
rajveer |
22 |
@Results({
|
| 693 |
rajveer |
23 |
@Result(name="shipping-redirect", type="redirectAction",
|
| 1905 |
chandransh |
24 |
params = {"actionName" , "shipping"}),
|
|
|
25 |
@Result(name="ebs-pay-redirect", type="redirect", location="/ebs-pay/${paymentId}")
|
| 419 |
rajveer |
26 |
})
|
| 650 |
rajveer |
27 |
public class OrderController extends BaseController {
|
| 419 |
rajveer |
28 |
|
| 1905 |
chandransh |
29 |
public long getPaymentId() {
|
|
|
30 |
return paymentId;
|
|
|
31 |
}
|
|
|
32 |
|
| 419 |
rajveer |
33 |
private static final long serialVersionUID = 1L;
|
|
|
34 |
|
| 832 |
rajveer |
35 |
private static Logger log = Logger.getLogger(Class.class);
|
| 507 |
rajveer |
36 |
private String id;
|
| 712 |
rajveer |
37 |
private long txnId = 0;
|
| 650 |
rajveer |
38 |
|
| 1905 |
chandransh |
39 |
private long paymentId;
|
|
|
40 |
|
| 1318 |
rajveer |
41 |
private String redirectURL;
|
| 681 |
rajveer |
42 |
|
| 419 |
rajveer |
43 |
public OrderController(){
|
| 507 |
rajveer |
44 |
super();
|
| 419 |
rajveer |
45 |
}
|
|
|
46 |
|
| 507 |
rajveer |
47 |
// GET /order/ orderid
|
|
|
48 |
public String show() {
|
|
|
49 |
log.info("id=" + id);
|
| 822 |
vikas |
50 |
htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
|
| 1527 |
ankur.sing |
51 |
htmlSnippets.put("ORDER_DETAILS", pageLoader.getOrderDetailsHtml(Long.parseLong(id), userinfo.getUserId()));
|
| 507 |
rajveer |
52 |
return "show";
|
| 419 |
rajveer |
53 |
}
|
| 517 |
rajveer |
54 |
|
| 572 |
chandransh |
55 |
// POST /order/
|
|
|
56 |
public String create(){
|
| 786 |
rajveer |
57 |
String addressIdString = this.request.getParameter("addressid");
|
|
|
58 |
if(addressIdString == null){
|
| 894 |
rajveer |
59 |
addActionError("Please specify shipping address to continue.");
|
| 786 |
rajveer |
60 |
return "shipping-redirect";
|
|
|
61 |
}
|
|
|
62 |
long addressId = Long.parseLong(addressIdString);
|
| 572 |
chandransh |
63 |
long currentCartId = userinfo.getCartId();
|
| 894 |
rajveer |
64 |
try{
|
| 1318 |
rajveer |
65 |
if(!createOrders(addressId, currentCartId)){
|
| 1128 |
rajveer |
66 |
addActionError("We are experiencing some problems. Please try later.");
|
| 894 |
rajveer |
67 |
return "shipping-redirect";
|
|
|
68 |
}
|
|
|
69 |
}catch (Exception e) {
|
| 1128 |
rajveer |
70 |
addActionError("We are experiencing some problems. Please try later.");
|
| 894 |
rajveer |
71 |
log.error("Exception in createOrders function. Something want wrong.");
|
|
|
72 |
e.printStackTrace();
|
|
|
73 |
return "shipping-redirect";
|
| 693 |
rajveer |
74 |
}
|
| 894 |
rajveer |
75 |
|
| 1905 |
chandransh |
76 |
boolean paymode = Boolean.parseBoolean(request.getParameter("paymode"));
|
|
|
77 |
if (paymode) {
|
|
|
78 |
HdfcPaymentService hdfcPaymentService = new HdfcPaymentService();
|
|
|
79 |
paymentId = hdfcPaymentService.createPayment(userinfo.getCartId(), userinfo.getUserId(), txnId);
|
|
|
80 |
if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
|
|
|
81 |
addActionError("We are experiencing some problems. Please try later.");
|
|
|
82 |
return "shipping-redirect";
|
|
|
83 |
} else {
|
|
|
84 |
this.redirectURL = hdfcPaymentService.getRedirectUrl();
|
|
|
85 |
log.info(this.redirectURL);
|
|
|
86 |
return "success";
|
|
|
87 |
}
|
|
|
88 |
} else {
|
|
|
89 |
EbsPaymentService ebsPaymentService = new EbsPaymentService();
|
|
|
90 |
paymentId = ebsPaymentService.createPayment(userinfo.getCartId(), userinfo.getUserId(), txnId);
|
|
|
91 |
if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
|
|
|
92 |
addActionError("We are experiencing some problems. Please try later.");
|
|
|
93 |
return "shipping-redirect";
|
|
|
94 |
}else{
|
|
|
95 |
log.info("Successfully created payment for EBS to process. Redirecting to: ");
|
|
|
96 |
return "ebs-pay-redirect";
|
|
|
97 |
}
|
|
|
98 |
}
|
| 572 |
chandransh |
99 |
}
|
|
|
100 |
|
| 507 |
rajveer |
101 |
public String getId(){
|
|
|
102 |
return id;
|
|
|
103 |
}
|
| 419 |
rajveer |
104 |
|
| 507 |
rajveer |
105 |
public void setId(String id){
|
|
|
106 |
this.id = id;
|
|
|
107 |
}
|
| 419 |
rajveer |
108 |
|
| 507 |
rajveer |
109 |
public String getMyaccountHeaderSnippet(){
|
|
|
110 |
return htmlSnippets.get("MYACCOUNT_HEADER");
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
public String getOrderDetailsSnippet(){
|
|
|
114 |
return htmlSnippets.get("ORDER_DETAILS");
|
|
|
115 |
}
|
|
|
116 |
|
| 712 |
rajveer |
117 |
public long getTxn(){
|
|
|
118 |
return this.txnId;
|
| 517 |
rajveer |
119 |
}
|
| 894 |
rajveer |
120 |
|
|
|
121 |
/**
|
|
|
122 |
*
|
|
|
123 |
* @param addressId
|
|
|
124 |
* @param currentCartId
|
|
|
125 |
* @return
|
|
|
126 |
*/
|
| 1318 |
rajveer |
127 |
private boolean createOrders(long addressId, long currentCartId){
|
| 894 |
rajveer |
128 |
UserContextServiceClient userServiceClient = null;
|
|
|
129 |
try {
|
|
|
130 |
userServiceClient = new UserContextServiceClient();
|
|
|
131 |
} catch (Exception e) {
|
|
|
132 |
e.printStackTrace();
|
|
|
133 |
return false;
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
|
|
|
137 |
try {
|
|
|
138 |
userClient.addAddressToCart(currentCartId, addressId);
|
|
|
139 |
} catch (ShoppingCartException e1) {
|
|
|
140 |
log.error("Not able to set address in the cart." + e1.getId() + e1.getMessage());
|
|
|
141 |
e1.printStackTrace();
|
|
|
142 |
return false;
|
|
|
143 |
} catch (TException e1) {
|
|
|
144 |
log.error("Thrift exception while setting address in cart." + e1.getMessage());
|
|
|
145 |
e1.printStackTrace();
|
|
|
146 |
return false;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
try {
|
| 1466 |
ankur.sing |
151 |
String errorMsg = userClient.validateCart(currentCartId);
|
|
|
152 |
if(!errorMsg.isEmpty()){
|
|
|
153 |
addActionError(errorMsg);
|
| 894 |
rajveer |
154 |
return false;
|
|
|
155 |
}
|
|
|
156 |
} catch (ShoppingCartException e1) {
|
|
|
157 |
log.error("Error while validating shopping cart." + e1.getId() + e1.getMessage());
|
|
|
158 |
e1.printStackTrace();
|
|
|
159 |
return false;
|
|
|
160 |
} catch (TException e) {
|
|
|
161 |
log.error("Thrift exception while validating cart." + e.getMessage());
|
|
|
162 |
e.printStackTrace();
|
|
|
163 |
return false;
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
try {
|
|
|
168 |
txnId = userClient.createOrders(currentCartId);
|
|
|
169 |
} catch (ShoppingCartException e1) {
|
|
|
170 |
log.error("Error while creating orders from cart." + e1.getId() + e1.getMessage());
|
|
|
171 |
e1.printStackTrace();
|
|
|
172 |
return false;
|
|
|
173 |
} catch (TException e) {
|
|
|
174 |
log.error("Thrift exception while creating orders from cart." + e.getMessage());
|
|
|
175 |
e.printStackTrace();
|
|
|
176 |
return false;
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
return true;
|
|
|
182 |
}
|
| 1318 |
rajveer |
183 |
|
|
|
184 |
public String getRedirectURL(){
|
|
|
185 |
return this.redirectURL;
|
|
|
186 |
}
|
| 419 |
rajveer |
187 |
}
|