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