| 428 |
ashish |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 2263 |
vikas |
3 |
import in.shop2020.datalogger.EventType;
|
| 555 |
chandransh |
4 |
import in.shop2020.model.v1.order.Order;
|
| 6475 |
rajveer |
5 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 428 |
ashish |
6 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 4061 |
vikas |
7 |
import in.shop2020.model.v1.user.Affiliate;
|
| 894 |
rajveer |
8 |
import in.shop2020.model.v1.user.Cart;
|
| 712 |
rajveer |
9 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
| 3378 |
vikas |
10 |
import in.shop2020.model.v1.user.TrackLogType;
|
| 1999 |
vikas |
11 |
import in.shop2020.model.v1.user.UserAffiliateException;
|
| 428 |
ashish |
12 |
import in.shop2020.payments.PaymentException;
|
| 1999 |
vikas |
13 |
import in.shop2020.serving.interceptors.TrackingInterceptor;
|
| 2193 |
varun.gupt |
14 |
import in.shop2020.serving.utils.FormattingUtils;
|
| 3209 |
vikas |
15 |
import in.shop2020.serving.utils.Utils;
|
| 3126 |
rajveer |
16 |
import in.shop2020.thrift.clients.PaymentClient;
|
|
|
17 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
18 |
import in.shop2020.thrift.clients.UserClient;
|
| 2511 |
vikas |
19 |
import in.shop2020.utils.DataLogger;
|
| 428 |
ashish |
20 |
|
| 5880 |
rajveer |
21 |
import java.text.SimpleDateFormat;
|
| 6475 |
rajveer |
22 |
import java.util.Calendar;
|
| 2263 |
vikas |
23 |
import java.util.Date;
|
|
|
24 |
import java.util.List;
|
| 894 |
rajveer |
25 |
|
| 2263 |
vikas |
26 |
import org.apache.log4j.Logger;
|
|
|
27 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
28 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
29 |
import org.apache.thrift.TException;
|
|
|
30 |
|
|
|
31 |
|
| 822 |
vikas |
32 |
@InterceptorRefs({
|
|
|
33 |
@InterceptorRef("myDefault"),
|
|
|
34 |
@InterceptorRef("login")
|
| 712 |
rajveer |
35 |
})
|
| 693 |
rajveer |
36 |
|
| 719 |
rajveer |
37 |
public class PaySuccessController extends BaseController{
|
| 693 |
rajveer |
38 |
private static final long serialVersionUID = 1L;
|
| 3830 |
chandransh |
39 |
|
|
|
40 |
private static final String ITEM = "ITEM";
|
|
|
41 |
private static final String ITEMS = "ITEMS";
|
|
|
42 |
|
| 4061 |
vikas |
43 |
private static final String SHOOGLOO_AFF_NAME = "shoogloo";
|
|
|
44 |
|
| 1044 |
chandransh |
45 |
private static Logger log = Logger.getLogger(Class.class);
|
| 2193 |
varun.gupt |
46 |
private FormattingUtils formattingUtils = new FormattingUtils();
|
|
|
47 |
|
| 4061 |
vikas |
48 |
private boolean isShooglooAff = false;
|
| 1044 |
chandransh |
49 |
|
| 712 |
rajveer |
50 |
long merchantPaymentId;
|
| 6546 |
rajveer |
51 |
long txnId;
|
| 712 |
rajveer |
52 |
List<Order> orders = null;
|
| 719 |
rajveer |
53 |
String message = null;
|
| 6903 |
anupam.sin |
54 |
|
|
|
55 |
private boolean isAnyOrderInsured;
|
| 428 |
ashish |
56 |
|
| 719 |
rajveer |
57 |
public PaySuccessController(){
|
| 428 |
ashish |
58 |
super();
|
|
|
59 |
}
|
|
|
60 |
|
| 853 |
rajveer |
61 |
public String index() {
|
| 3121 |
chandransh |
62 |
|
| 3126 |
rajveer |
63 |
PaymentClient paymentServiceClient = null;
|
|
|
64 |
TransactionClient transactionServiceClient = null;
|
|
|
65 |
UserClient userServiceClient = null;
|
| 4453 |
varun.gupt |
66 |
|
| 894 |
rajveer |
67 |
try {
|
| 3126 |
rajveer |
68 |
paymentServiceClient = new PaymentClient();
|
|
|
69 |
transactionServiceClient = new TransactionClient();
|
|
|
70 |
userServiceClient = new UserClient();
|
| 894 |
rajveer |
71 |
} catch (Exception e1) {
|
|
|
72 |
// TODO Nothing to worry
|
| 2944 |
chandransh |
73 |
log.error("Unable to initialize the client for either payment or transaction or user service", e1);
|
| 894 |
rajveer |
74 |
}
|
|
|
75 |
|
|
|
76 |
|
| 719 |
rajveer |
77 |
merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));
|
|
|
78 |
|
| 6546 |
rajveer |
79 |
|
| 853 |
rajveer |
80 |
try {
|
| 894 |
rajveer |
81 |
txnId = paymentServiceClient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
|
| 1527 |
ankur.sing |
82 |
orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId, userinfo.getUserId());
|
| 6903 |
anupam.sin |
83 |
for(Order order : orders) {
|
|
|
84 |
if(order.getInsurer() > 0) {
|
|
|
85 |
setAnyOrderInsured(true);
|
|
|
86 |
break;
|
|
|
87 |
}
|
|
|
88 |
}
|
| 894 |
rajveer |
89 |
Cart cart = userServiceClient.getClient().getCart(userinfo.getCartId());
|
|
|
90 |
if(cart != null){
|
| 3830 |
chandransh |
91 |
userinfo.setTotalItems(cart.getLinesSize());
|
|
|
92 |
userinfo.setTotalAmount(cart.getTotalPrice());
|
|
|
93 |
}else{
|
|
|
94 |
userinfo.setTotalItems(0);
|
|
|
95 |
userinfo.setTotalAmount(0);
|
| 894 |
rajveer |
96 |
}
|
| 3830 |
chandransh |
97 |
|
|
|
98 |
String suffix = ITEM;
|
|
|
99 |
if(orders.size() > 1)
|
|
|
100 |
suffix = ITEMS;
|
|
|
101 |
|
| 3967 |
rajveer |
102 |
this.message = "You have successfully ordered <span class=\"orange\">" + orders.size() + " " + suffix + ".</span>";
|
|
|
103 |
|
| 4061 |
vikas |
104 |
if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
|
|
|
105 |
long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
|
|
|
106 |
userServiceClient.getClient().addTrackLog(affId, userinfo.getUserId(), TrackLogType.PAYMENT_SUCCESS, "",
|
|
|
107 |
Long.toString(merchantPaymentId), (new Date()).getTime());
|
|
|
108 |
Affiliate aff = userServiceClient.getClient().getAffiliateById(affId);
|
|
|
109 |
if (aff.getName().equals(SHOOGLOO_AFF_NAME)) {
|
|
|
110 |
isShooglooAff = true;
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
|
| 853 |
rajveer |
114 |
} catch (PaymentException e) {
|
| 2944 |
chandransh |
115 |
log.error("Payment service not responding. Payment id is" + merchantPaymentId, e);
|
| 853 |
rajveer |
116 |
} catch (TException e) {
|
| 2944 |
chandransh |
117 |
log.error("Thrift service exception. Payment id is" + merchantPaymentId, e);
|
| 853 |
rajveer |
118 |
} catch (TransactionServiceException e) {
|
| 2944 |
chandransh |
119 |
log.error("Transaction service exception. Payment id is" + merchantPaymentId, e);
|
| 853 |
rajveer |
120 |
} catch (ShoppingCartException e) {
|
| 2944 |
chandransh |
121 |
log.error("Shopping cart service exception. Payment id is" + merchantPaymentId, e);
|
| 1999 |
vikas |
122 |
} catch (UserAffiliateException e) {
|
| 2944 |
chandransh |
123 |
log.error("Affiliate service exception. Payment id is" + merchantPaymentId, e);
|
| 1999 |
vikas |
124 |
}
|
| 853 |
rajveer |
125 |
|
| 3209 |
vikas |
126 |
DataLogger.logData(EventType.PAYMENT_SUCCESS, getSessionId(), userinfo.getUserId(),
|
|
|
127 |
userinfo.getEmail(), Long.toString(merchantPaymentId), Utils.getItemIdStringFromOrders(orders));
|
| 2087 |
vikas |
128 |
|
| 693 |
rajveer |
129 |
return "index";
|
| 428 |
ashish |
130 |
}
|
|
|
131 |
|
| 2193 |
varun.gupt |
132 |
public String formatPrice(double price) {
|
|
|
133 |
return formattingUtils.formatPrice(price);
|
|
|
134 |
}
|
| 719 |
rajveer |
135 |
|
| 712 |
rajveer |
136 |
public List<Order> getOrders(){
|
|
|
137 |
return this.orders;
|
| 485 |
rajveer |
138 |
}
|
|
|
139 |
|
| 6475 |
rajveer |
140 |
public List<Order> getSuccessfulOrders(){
|
|
|
141 |
if((this.orders.get(0).getStatus() == OrderStatus.COD_VERIFICATION_PENDING
|
|
|
142 |
|| this.orders.get(0).getStatus() == OrderStatus.SUBMITTED_FOR_PROCESSING) && this.orders.get(0).getCreated_timestamp() + 10*60*1000 > Calendar.getInstance().getTimeInMillis()){
|
|
|
143 |
return this.orders;
|
|
|
144 |
}
|
|
|
145 |
return null;
|
|
|
146 |
}
|
|
|
147 |
|
| 485 |
rajveer |
148 |
public String getMessage(){
|
|
|
149 |
return this.message;
|
| 3903 |
varun.gupt |
150 |
}
|
|
|
151 |
|
| 4061 |
vikas |
152 |
public boolean getIsShooglooAff() {
|
|
|
153 |
return this.isShooglooAff;
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
public long getMerchantPaymentId() {
|
|
|
157 |
return merchantPaymentId;
|
|
|
158 |
}
|
|
|
159 |
|
| 6546 |
rajveer |
160 |
public long getTxnId() {
|
|
|
161 |
return txnId;
|
|
|
162 |
}
|
|
|
163 |
|
| 5880 |
rajveer |
164 |
public static String formatDate(long timestamp){
|
|
|
165 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd MMMM yyyy");
|
|
|
166 |
return dateformat.format(new Date(timestamp));
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
|
| 3903 |
varun.gupt |
170 |
@Override
|
|
|
171 |
public String getHeaderSnippet() {
|
|
|
172 |
String url = request.getQueryString();
|
|
|
173 |
if (url == null) {
|
|
|
174 |
url = "";
|
|
|
175 |
} else {
|
|
|
176 |
url = "?" + url;
|
|
|
177 |
}
|
|
|
178 |
url = request.getRequestURI() + url;
|
| 6152 |
amit.gupta |
179 |
return pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getEmail(), userinfo.getTotalItems(), url , 0, false);
|
| 5880 |
rajveer |
180 |
}
|
| 6903 |
anupam.sin |
181 |
|
|
|
182 |
public void setAnyOrderInsured(boolean isAnyOrderInsured) {
|
|
|
183 |
this.isAnyOrderInsured = isAnyOrderInsured;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
public boolean isAnyOrderInsured() {
|
|
|
187 |
return isAnyOrderInsured;
|
|
|
188 |
}
|
| 3903 |
varun.gupt |
189 |
}
|