| 428 |
ashish |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import java.util.List;
|
|
|
4 |
|
| 853 |
rajveer |
5 |
import org.apache.juli.logging.Log;
|
|
|
6 |
import org.apache.juli.logging.LogFactory;
|
| 822 |
vikas |
7 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
8 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 428 |
ashish |
9 |
import org.apache.thrift.TException;
|
|
|
10 |
|
| 555 |
chandransh |
11 |
import in.shop2020.model.v1.order.Order;
|
| 428 |
ashish |
12 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 894 |
rajveer |
13 |
import in.shop2020.model.v1.user.Cart;
|
| 712 |
rajveer |
14 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
| 428 |
ashish |
15 |
import in.shop2020.payments.PaymentException;
|
|
|
16 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
|
|
17 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
| 712 |
rajveer |
18 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
| 428 |
ashish |
19 |
|
| 894 |
rajveer |
20 |
|
| 822 |
vikas |
21 |
@InterceptorRefs({
|
|
|
22 |
@InterceptorRef("myDefault"),
|
|
|
23 |
@InterceptorRef("login")
|
| 712 |
rajveer |
24 |
})
|
| 693 |
rajveer |
25 |
|
| 719 |
rajveer |
26 |
public class PaySuccessController extends BaseController{
|
| 693 |
rajveer |
27 |
private static final long serialVersionUID = 1L;
|
| 894 |
rajveer |
28 |
|
| 853 |
rajveer |
29 |
private static Log log = LogFactory.getLog(Class.class);
|
| 712 |
rajveer |
30 |
long merchantPaymentId;
|
|
|
31 |
List<Order> orders = null;
|
| 719 |
rajveer |
32 |
String message = null;
|
| 428 |
ashish |
33 |
|
| 719 |
rajveer |
34 |
public PaySuccessController(){
|
| 428 |
ashish |
35 |
super();
|
|
|
36 |
}
|
|
|
37 |
|
| 853 |
rajveer |
38 |
public String index() {
|
| 719 |
rajveer |
39 |
this.message = "Payment completed successfully.";
|
| 894 |
rajveer |
40 |
PaymentServiceClient paymentServiceClient = null;
|
|
|
41 |
TransactionServiceClient transactionServiceClient = null;
|
|
|
42 |
UserContextServiceClient userServiceClient = null;
|
|
|
43 |
|
|
|
44 |
try {
|
|
|
45 |
paymentServiceClient = new PaymentServiceClient();
|
|
|
46 |
transactionServiceClient = new TransactionServiceClient();
|
|
|
47 |
userServiceClient = new UserContextServiceClient();
|
|
|
48 |
} catch (Exception e1) {
|
|
|
49 |
// TODO Nothing to worry
|
|
|
50 |
e1.printStackTrace();
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
|
| 719 |
rajveer |
54 |
merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));
|
|
|
55 |
|
| 853 |
rajveer |
56 |
long txnId;
|
|
|
57 |
try {
|
| 894 |
rajveer |
58 |
txnId = paymentServiceClient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
|
|
|
59 |
orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId);
|
|
|
60 |
Cart cart = userServiceClient.getClient().getCart(userinfo.getCartId());
|
|
|
61 |
int totalItems = 0;
|
|
|
62 |
if(cart != null){
|
|
|
63 |
totalItems = cart.getLinesSize();
|
|
|
64 |
}
|
| 890 |
chandransh |
65 |
userinfo.setTotalItems(totalItems);
|
| 853 |
rajveer |
66 |
} catch (PaymentException e) {
|
|
|
67 |
log.error("Payment service not responding. Payment id is" + merchantPaymentId);
|
|
|
68 |
e.printStackTrace();
|
|
|
69 |
} catch (TException e) {
|
|
|
70 |
log.error("Thrift service exception. Payment id is" + merchantPaymentId);
|
|
|
71 |
e.printStackTrace();
|
|
|
72 |
} catch (TransactionServiceException e) {
|
|
|
73 |
log.error("Transaction service exception. Payment id is" + merchantPaymentId);
|
|
|
74 |
e.printStackTrace();
|
|
|
75 |
} catch (ShoppingCartException e) {
|
|
|
76 |
log.error("Shopping cart service exception. Payment id is" + merchantPaymentId + " message id and name are " + e.getId() + e.getMessage());
|
|
|
77 |
e.printStackTrace();
|
|
|
78 |
}
|
|
|
79 |
|
| 693 |
rajveer |
80 |
return "index";
|
| 428 |
ashish |
81 |
}
|
|
|
82 |
|
| 719 |
rajveer |
83 |
|
|
|
84 |
|
| 712 |
rajveer |
85 |
public List<Order> getOrders(){
|
|
|
86 |
return this.orders;
|
| 485 |
rajveer |
87 |
}
|
|
|
88 |
|
|
|
89 |
public String getMessage(){
|
|
|
90 |
return this.message;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
}
|