| 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 |
|
| 11896 |
amit.gupta |
50 |
private String storeAffiliate = "Saholic";
|
|
|
51 |
|
| 712 |
rajveer |
52 |
long merchantPaymentId;
|
| 6546 |
rajveer |
53 |
long txnId;
|
| 712 |
rajveer |
54 |
List<Order> orders = null;
|
| 719 |
rajveer |
55 |
String message = null;
|
| 6903 |
anupam.sin |
56 |
|
|
|
57 |
private boolean isAnyOrderInsured;
|
| 428 |
ashish |
58 |
|
| 719 |
rajveer |
59 |
public PaySuccessController(){
|
| 428 |
ashish |
60 |
super();
|
|
|
61 |
}
|
|
|
62 |
|
| 853 |
rajveer |
63 |
public String index() {
|
| 3121 |
chandransh |
64 |
|
| 3126 |
rajveer |
65 |
PaymentClient paymentServiceClient = null;
|
|
|
66 |
TransactionClient transactionServiceClient = null;
|
|
|
67 |
UserClient userServiceClient = null;
|
| 4453 |
varun.gupt |
68 |
|
| 894 |
rajveer |
69 |
try {
|
| 3126 |
rajveer |
70 |
paymentServiceClient = new PaymentClient();
|
|
|
71 |
transactionServiceClient = new TransactionClient();
|
|
|
72 |
userServiceClient = new UserClient();
|
| 894 |
rajveer |
73 |
} catch (Exception e1) {
|
|
|
74 |
// TODO Nothing to worry
|
| 2944 |
chandransh |
75 |
log.error("Unable to initialize the client for either payment or transaction or user service", e1);
|
| 894 |
rajveer |
76 |
}
|
|
|
77 |
|
|
|
78 |
|
| 719 |
rajveer |
79 |
merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));
|
|
|
80 |
|
| 6546 |
rajveer |
81 |
|
| 853 |
rajveer |
82 |
try {
|
| 894 |
rajveer |
83 |
txnId = paymentServiceClient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
|
| 1527 |
ankur.sing |
84 |
orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId, userinfo.getUserId());
|
| 11896 |
amit.gupta |
85 |
if(transactionServiceClient.getClient().isPrivateDealTransaction(txnId)){
|
|
|
86 |
setStoreAffiliate("Privatedeal");
|
|
|
87 |
}
|
| 6903 |
anupam.sin |
88 |
for(Order order : orders) {
|
|
|
89 |
if(order.getInsurer() > 0) {
|
|
|
90 |
setAnyOrderInsured(true);
|
|
|
91 |
break;
|
|
|
92 |
}
|
|
|
93 |
}
|
| 894 |
rajveer |
94 |
Cart cart = userServiceClient.getClient().getCart(userinfo.getCartId());
|
|
|
95 |
if(cart != null){
|
| 3830 |
chandransh |
96 |
userinfo.setTotalItems(cart.getLinesSize());
|
|
|
97 |
userinfo.setTotalAmount(cart.getTotalPrice());
|
|
|
98 |
}else{
|
|
|
99 |
userinfo.setTotalItems(0);
|
|
|
100 |
userinfo.setTotalAmount(0);
|
| 894 |
rajveer |
101 |
}
|
| 3830 |
chandransh |
102 |
|
|
|
103 |
String suffix = ITEM;
|
|
|
104 |
if(orders.size() > 1)
|
|
|
105 |
suffix = ITEMS;
|
|
|
106 |
|
| 3967 |
rajveer |
107 |
this.message = "You have successfully ordered <span class=\"orange\">" + orders.size() + " " + suffix + ".</span>";
|
|
|
108 |
|
| 4061 |
vikas |
109 |
if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
|
|
|
110 |
long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
|
|
|
111 |
userServiceClient.getClient().addTrackLog(affId, userinfo.getUserId(), TrackLogType.PAYMENT_SUCCESS, "",
|
|
|
112 |
Long.toString(merchantPaymentId), (new Date()).getTime());
|
|
|
113 |
Affiliate aff = userServiceClient.getClient().getAffiliateById(affId);
|
|
|
114 |
if (aff.getName().equals(SHOOGLOO_AFF_NAME)) {
|
|
|
115 |
isShooglooAff = true;
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
|
| 853 |
rajveer |
119 |
} catch (PaymentException e) {
|
| 2944 |
chandransh |
120 |
log.error("Payment service not responding. Payment id is" + merchantPaymentId, e);
|
| 853 |
rajveer |
121 |
} catch (TException e) {
|
| 2944 |
chandransh |
122 |
log.error("Thrift service exception. Payment id is" + merchantPaymentId, e);
|
| 853 |
rajveer |
123 |
} catch (TransactionServiceException e) {
|
| 2944 |
chandransh |
124 |
log.error("Transaction service exception. Payment id is" + merchantPaymentId, e);
|
| 853 |
rajveer |
125 |
} catch (ShoppingCartException e) {
|
| 2944 |
chandransh |
126 |
log.error("Shopping cart service exception. Payment id is" + merchantPaymentId, e);
|
| 1999 |
vikas |
127 |
} catch (UserAffiliateException e) {
|
| 2944 |
chandransh |
128 |
log.error("Affiliate service exception. Payment id is" + merchantPaymentId, e);
|
| 1999 |
vikas |
129 |
}
|
| 853 |
rajveer |
130 |
|
| 3209 |
vikas |
131 |
DataLogger.logData(EventType.PAYMENT_SUCCESS, getSessionId(), userinfo.getUserId(),
|
|
|
132 |
userinfo.getEmail(), Long.toString(merchantPaymentId), Utils.getItemIdStringFromOrders(orders));
|
| 2087 |
vikas |
133 |
|
| 693 |
rajveer |
134 |
return "index";
|
| 428 |
ashish |
135 |
}
|
|
|
136 |
|
| 2193 |
varun.gupt |
137 |
public String formatPrice(double price) {
|
|
|
138 |
return formattingUtils.formatPrice(price);
|
|
|
139 |
}
|
| 719 |
rajveer |
140 |
|
| 712 |
rajveer |
141 |
public List<Order> getOrders(){
|
|
|
142 |
return this.orders;
|
| 485 |
rajveer |
143 |
}
|
|
|
144 |
|
| 6475 |
rajveer |
145 |
public List<Order> getSuccessfulOrders(){
|
|
|
146 |
if((this.orders.get(0).getStatus() == OrderStatus.COD_VERIFICATION_PENDING
|
|
|
147 |
|| this.orders.get(0).getStatus() == OrderStatus.SUBMITTED_FOR_PROCESSING) && this.orders.get(0).getCreated_timestamp() + 10*60*1000 > Calendar.getInstance().getTimeInMillis()){
|
|
|
148 |
return this.orders;
|
|
|
149 |
}
|
|
|
150 |
return null;
|
|
|
151 |
}
|
|
|
152 |
|
| 485 |
rajveer |
153 |
public String getMessage(){
|
|
|
154 |
return this.message;
|
| 3903 |
varun.gupt |
155 |
}
|
|
|
156 |
|
| 4061 |
vikas |
157 |
public boolean getIsShooglooAff() {
|
|
|
158 |
return this.isShooglooAff;
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
public long getMerchantPaymentId() {
|
|
|
162 |
return merchantPaymentId;
|
|
|
163 |
}
|
|
|
164 |
|
| 6546 |
rajveer |
165 |
public long getTxnId() {
|
|
|
166 |
return txnId;
|
|
|
167 |
}
|
|
|
168 |
|
| 5880 |
rajveer |
169 |
public static String formatDate(long timestamp){
|
|
|
170 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd MMMM yyyy");
|
|
|
171 |
return dateformat.format(new Date(timestamp));
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
|
| 3903 |
varun.gupt |
175 |
@Override
|
|
|
176 |
public String getHeaderSnippet() {
|
|
|
177 |
String url = request.getQueryString();
|
|
|
178 |
if (url == null) {
|
|
|
179 |
url = "";
|
|
|
180 |
} else {
|
|
|
181 |
url = "?" + url;
|
|
|
182 |
}
|
|
|
183 |
url = request.getRequestURI() + url;
|
| 11829 |
amit.gupta |
184 |
return pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getEmail(), userinfo.getTotalItems(), url , 0, false, userinfo.isPrivateDealUser());
|
| 5880 |
rajveer |
185 |
}
|
| 6903 |
anupam.sin |
186 |
|
|
|
187 |
public void setAnyOrderInsured(boolean isAnyOrderInsured) {
|
|
|
188 |
this.isAnyOrderInsured = isAnyOrderInsured;
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
public boolean isAnyOrderInsured() {
|
|
|
192 |
return isAnyOrderInsured;
|
|
|
193 |
}
|
| 11896 |
amit.gupta |
194 |
|
|
|
195 |
public void setStoreAffiliate(String storeAffiliate) {
|
|
|
196 |
this.storeAffiliate = storeAffiliate;
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
public String getStoreAffiliate() {
|
|
|
200 |
return storeAffiliate;
|
|
|
201 |
}
|
| 3903 |
varun.gupt |
202 |
}
|