| 419 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 517 |
rajveer |
3 |
import in.shop2020.model.v1.order.Order;
|
| 693 |
rajveer |
4 |
import in.shop2020.payments.PaymentService.Client;
|
| 419 |
rajveer |
5 |
import in.shop2020.serving.controllers.BaseController;
|
| 693 |
rajveer |
6 |
import in.shop2020.serving.utils.Utils;
|
|
|
7 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
| 517 |
rajveer |
8 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
9 |
|
| 419 |
rajveer |
10 |
import java.util.*;
|
|
|
11 |
|
|
|
12 |
import org.apache.juli.logging.Log;
|
|
|
13 |
import org.apache.juli.logging.LogFactory;
|
|
|
14 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
15 |
import org.apache.struts2.convention.annotation.Results;
|
| 517 |
rajveer |
16 |
import org.apache.thrift.TException;
|
| 419 |
rajveer |
17 |
|
|
|
18 |
@Results({
|
| 681 |
rajveer |
19 |
@Result(name="redirect", type="redirectAction",
|
|
|
20 |
params = {"actionName" , "login"}),
|
| 693 |
rajveer |
21 |
@Result(name="payredirect", location="${url}", type="redirect", params = {"paymentid" , "${payment-id}"}),
|
|
|
22 |
@Result(name="shipping-redirect", type="redirectAction",
|
|
|
23 |
params = {"actionName" , "shipping"})
|
| 681 |
rajveer |
24 |
|
| 419 |
rajveer |
25 |
})
|
| 650 |
rajveer |
26 |
public class OrderController extends BaseController {
|
| 419 |
rajveer |
27 |
|
|
|
28 |
private static final long serialVersionUID = 1L;
|
|
|
29 |
|
|
|
30 |
private static Log log = LogFactory.getLog(OrderController.class);
|
| 507 |
rajveer |
31 |
private String id;
|
| 650 |
rajveer |
32 |
|
| 517 |
rajveer |
33 |
private String message;
|
| 419 |
rajveer |
34 |
|
| 693 |
rajveer |
35 |
//FIXME right now only one PG. Once we will have more, need to fix it.
|
| 681 |
rajveer |
36 |
private String paymentUrl="hdfc-pay";
|
| 693 |
rajveer |
37 |
private int gatewayId=1;
|
| 681 |
rajveer |
38 |
|
| 693 |
rajveer |
39 |
private long paymentId;
|
|
|
40 |
|
| 419 |
rajveer |
41 |
public OrderController(){
|
| 507 |
rajveer |
42 |
super();
|
| 419 |
rajveer |
43 |
}
|
|
|
44 |
|
| 507 |
rajveer |
45 |
// GET /order/ orderid
|
|
|
46 |
public String show() {
|
|
|
47 |
log.info("id=" + id);
|
| 424 |
rajveer |
48 |
if(!userinfo.isLoggedIn()){
|
| 650 |
rajveer |
49 |
setRedirectUrl();
|
| 507 |
rajveer |
50 |
return "redirect";
|
| 424 |
rajveer |
51 |
}
|
| 650 |
rajveer |
52 |
htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
|
|
|
53 |
htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getOrderDetailsHtml(Long.parseLong(id)));
|
| 507 |
rajveer |
54 |
return "show";
|
| 419 |
rajveer |
55 |
}
|
| 517 |
rajveer |
56 |
|
| 572 |
chandransh |
57 |
// POST /order/
|
|
|
58 |
public String create(){
|
| 650 |
rajveer |
59 |
if(!userinfo.isLoggedIn()){
|
|
|
60 |
setRedirectUrl();
|
|
|
61 |
return "redirect";
|
|
|
62 |
}
|
| 572 |
chandransh |
63 |
long addressId = Long.parseLong(this.request.getParameter("addressid"));
|
|
|
64 |
long currentCartId = userinfo.getCartId();
|
| 693 |
rajveer |
65 |
double amount;
|
|
|
66 |
try{
|
|
|
67 |
amount = Double.parseDouble(request.getParameter("amount"));
|
|
|
68 |
}catch(Exception e){
|
|
|
69 |
amount = Utils.getPaymentAmount(userinfo.getCartId());
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
|
| 572 |
chandransh |
73 |
List<Order> orders = null;
|
|
|
74 |
try {
|
|
|
75 |
UserContextServiceClient userServiceClient = new UserContextServiceClient();
|
|
|
76 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
|
|
|
77 |
|
|
|
78 |
userClient.addAddressToCart(currentCartId, addressId);
|
| 693 |
rajveer |
79 |
if(!userClient.validateCart(currentCartId)){
|
|
|
80 |
return "shipping-redirect";
|
|
|
81 |
}
|
|
|
82 |
Long txnId = userClient.createOrders(currentCartId);
|
| 572 |
chandransh |
83 |
|
| 693 |
rajveer |
84 |
PaymentServiceClient paymentServiceClient = new PaymentServiceClient();
|
|
|
85 |
Client paymentClient = paymentServiceClient.getClient();
|
|
|
86 |
|
|
|
87 |
this.paymentId = paymentClient.createPayment(userinfo.getUserId(), amount, gatewayId, txnId);
|
|
|
88 |
return "payredirect";
|
|
|
89 |
|
|
|
90 |
/*
|
| 572 |
chandransh |
91 |
TransactionServiceClient tsc = new TransactionServiceClient();
|
| 693 |
rajveer |
92 |
orders = tsc.getClient().getOrdersForTransaction(txnId);
|
| 572 |
chandransh |
93 |
|
|
|
94 |
long newCartId = userClient.getUserById(userinfo.getUserId()).getActiveCartId();
|
|
|
95 |
userinfo.setCartId(newCartId);
|
|
|
96 |
userinfo.setTotalItems(0);
|
| 693 |
rajveer |
97 |
|
|
|
98 |
011-46010946
|
|
|
99 |
*/
|
| 572 |
chandransh |
100 |
} catch (TException e) {
|
|
|
101 |
e.printStackTrace();
|
|
|
102 |
} catch (Exception e) {
|
|
|
103 |
e.printStackTrace();
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
this.message = "Your order numbers are as below:";
|
|
|
107 |
|
|
|
108 |
for(Order order: orders){
|
|
|
109 |
this.message = this.message + "<br> <a href=\"./order/" + order.getId() + "\">" + order.getId() + "</a>";
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
return "success";
|
|
|
113 |
}
|
|
|
114 |
|
| 507 |
rajveer |
115 |
public String getId(){
|
|
|
116 |
return id;
|
|
|
117 |
}
|
| 419 |
rajveer |
118 |
|
| 507 |
rajveer |
119 |
public void setId(String id){
|
|
|
120 |
this.id = id;
|
|
|
121 |
}
|
| 419 |
rajveer |
122 |
|
| 507 |
rajveer |
123 |
public String getMyaccountHeaderSnippet(){
|
|
|
124 |
return htmlSnippets.get("MYACCOUNT_HEADER");
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
public String getOrderDetailsSnippet(){
|
|
|
128 |
return htmlSnippets.get("ORDER_DETAILS");
|
|
|
129 |
}
|
|
|
130 |
|
| 681 |
rajveer |
131 |
public String getUrl(){
|
|
|
132 |
return this.paymentUrl;
|
|
|
133 |
}
|
| 507 |
rajveer |
134 |
|
| 693 |
rajveer |
135 |
public long getPaymentId(){
|
|
|
136 |
return this.paymentId;
|
|
|
137 |
}
|
|
|
138 |
|
| 517 |
rajveer |
139 |
public String getMessage(){
|
|
|
140 |
return this.message;
|
|
|
141 |
}
|
|
|
142 |
|
| 419 |
rajveer |
143 |
}
|