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