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