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