| 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;
|
| 894 |
rajveer |
6 |
import in.shop2020.model.v1.user.Cart;
|
| 712 |
rajveer |
7 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
| 1999 |
vikas |
8 |
import in.shop2020.model.v1.user.UserAffiliateException;
|
| 428 |
ashish |
9 |
import in.shop2020.payments.PaymentException;
|
| 1999 |
vikas |
10 |
import in.shop2020.serving.interceptors.TrackingInterceptor;
|
| 2193 |
varun.gupt |
11 |
import in.shop2020.serving.utils.FormattingUtils;
|
| 3209 |
vikas |
12 |
import in.shop2020.serving.utils.Utils;
|
| 3126 |
rajveer |
13 |
import in.shop2020.thrift.clients.PaymentClient;
|
|
|
14 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
15 |
import in.shop2020.thrift.clients.UserClient;
|
| 2511 |
vikas |
16 |
import in.shop2020.utils.DataLogger;
|
| 428 |
ashish |
17 |
|
| 2263 |
vikas |
18 |
import java.util.Date;
|
|
|
19 |
import java.util.List;
|
| 894 |
rajveer |
20 |
|
| 2263 |
vikas |
21 |
import org.apache.log4j.Logger;
|
|
|
22 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
23 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
24 |
import org.apache.thrift.TException;
|
|
|
25 |
|
|
|
26 |
|
| 822 |
vikas |
27 |
@InterceptorRefs({
|
|
|
28 |
@InterceptorRef("myDefault"),
|
|
|
29 |
@InterceptorRef("login")
|
| 712 |
rajveer |
30 |
})
|
| 693 |
rajveer |
31 |
|
| 719 |
rajveer |
32 |
public class PaySuccessController extends BaseController{
|
| 693 |
rajveer |
33 |
private static final long serialVersionUID = 1L;
|
| 894 |
rajveer |
34 |
|
| 1044 |
chandransh |
35 |
private static Logger log = Logger.getLogger(Class.class);
|
| 2193 |
varun.gupt |
36 |
private FormattingUtils formattingUtils = new FormattingUtils();
|
|
|
37 |
|
| 1044 |
chandransh |
38 |
|
| 712 |
rajveer |
39 |
long merchantPaymentId;
|
|
|
40 |
List<Order> orders = null;
|
| 719 |
rajveer |
41 |
String message = null;
|
| 428 |
ashish |
42 |
|
| 719 |
rajveer |
43 |
public PaySuccessController(){
|
| 428 |
ashish |
44 |
super();
|
|
|
45 |
}
|
|
|
46 |
|
| 853 |
rajveer |
47 |
public String index() {
|
| 3121 |
chandransh |
48 |
|
| 3126 |
rajveer |
49 |
PaymentClient paymentServiceClient = null;
|
|
|
50 |
TransactionClient transactionServiceClient = null;
|
|
|
51 |
UserClient userServiceClient = null;
|
| 894 |
rajveer |
52 |
|
|
|
53 |
try {
|
| 3126 |
rajveer |
54 |
paymentServiceClient = new PaymentClient();
|
|
|
55 |
transactionServiceClient = new TransactionClient();
|
|
|
56 |
userServiceClient = new UserClient();
|
| 894 |
rajveer |
57 |
} catch (Exception e1) {
|
|
|
58 |
// TODO Nothing to worry
|
| 2944 |
chandransh |
59 |
log.error("Unable to initialize the client for either payment or transaction or user service", e1);
|
| 894 |
rajveer |
60 |
}
|
|
|
61 |
|
|
|
62 |
|
| 719 |
rajveer |
63 |
merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));
|
|
|
64 |
|
| 853 |
rajveer |
65 |
long txnId;
|
|
|
66 |
try {
|
| 894 |
rajveer |
67 |
txnId = paymentServiceClient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
|
| 1527 |
ankur.sing |
68 |
orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId, userinfo.getUserId());
|
| 894 |
rajveer |
69 |
Cart cart = userServiceClient.getClient().getCart(userinfo.getCartId());
|
|
|
70 |
int totalItems = 0;
|
|
|
71 |
if(cart != null){
|
|
|
72 |
totalItems = cart.getLinesSize();
|
|
|
73 |
}
|
| 890 |
chandransh |
74 |
userinfo.setTotalItems(totalItems);
|
| 1999 |
vikas |
75 |
if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
|
|
|
76 |
long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
|
|
|
77 |
userServiceClient.getClient().addTrackLog(affId, userinfo.getUserId(), "payment success", "",
|
|
|
78 |
Long.toString(merchantPaymentId), (new Date()).getTime());
|
|
|
79 |
}
|
| 3121 |
chandransh |
80 |
if(orders.get(0).isCod())
|
|
|
81 |
this.message = "Order placed successfully";
|
|
|
82 |
else
|
|
|
83 |
this.message = "Payment completed successfully.";
|
| 853 |
rajveer |
84 |
} catch (PaymentException e) {
|
| 2944 |
chandransh |
85 |
log.error("Payment service not responding. Payment id is" + merchantPaymentId, e);
|
| 853 |
rajveer |
86 |
} catch (TException e) {
|
| 2944 |
chandransh |
87 |
log.error("Thrift service exception. Payment id is" + merchantPaymentId, e);
|
| 853 |
rajveer |
88 |
} catch (TransactionServiceException e) {
|
| 2944 |
chandransh |
89 |
log.error("Transaction service exception. Payment id is" + merchantPaymentId, e);
|
| 853 |
rajveer |
90 |
} catch (ShoppingCartException e) {
|
| 2944 |
chandransh |
91 |
log.error("Shopping cart service exception. Payment id is" + merchantPaymentId, e);
|
| 1999 |
vikas |
92 |
} catch (UserAffiliateException e) {
|
| 2944 |
chandransh |
93 |
log.error("Affiliate service exception. Payment id is" + merchantPaymentId, e);
|
| 1999 |
vikas |
94 |
}
|
| 853 |
rajveer |
95 |
|
| 3209 |
vikas |
96 |
DataLogger.logData(EventType.PAYMENT_SUCCESS, getSessionId(), userinfo.getUserId(),
|
|
|
97 |
userinfo.getEmail(), Long.toString(merchantPaymentId), Utils.getItemIdStringFromOrders(orders));
|
| 2087 |
vikas |
98 |
|
| 693 |
rajveer |
99 |
return "index";
|
| 428 |
ashish |
100 |
}
|
|
|
101 |
|
| 2193 |
varun.gupt |
102 |
public String formatPrice(double price) {
|
|
|
103 |
return formattingUtils.formatPrice(price);
|
|
|
104 |
}
|
| 719 |
rajveer |
105 |
|
| 712 |
rajveer |
106 |
public List<Order> getOrders(){
|
|
|
107 |
return this.orders;
|
| 485 |
rajveer |
108 |
}
|
|
|
109 |
|
|
|
110 |
public String getMessage(){
|
|
|
111 |
return this.message;
|
| 2193 |
varun.gupt |
112 |
}
|
|
|
113 |
}
|