| 7343 |
anupam.sin |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.order.Order;
|
|
|
4 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
|
|
5 |
import in.shop2020.payments.PaymentException;
|
|
|
6 |
import in.shop2020.serving.utils.FormattingUtils;
|
|
|
7 |
import in.shop2020.thrift.clients.PaymentClient;
|
|
|
8 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
9 |
|
|
|
10 |
import java.text.SimpleDateFormat;
|
|
|
11 |
import java.util.ArrayList;
|
|
|
12 |
import java.util.Date;
|
|
|
13 |
import java.util.List;
|
|
|
14 |
|
|
|
15 |
import org.apache.thrift.TException;
|
|
|
16 |
|
|
|
17 |
public class OrderSuccessController extends BaseController{
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
*
|
|
|
21 |
*/
|
|
|
22 |
private static final long serialVersionUID = 1;
|
|
|
23 |
private long userId;
|
|
|
24 |
private long paymentId;
|
|
|
25 |
private long txnId;
|
|
|
26 |
private List<Order> orders = new ArrayList<Order>();
|
|
|
27 |
private FormattingUtils formattingUtils = new FormattingUtils();
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
public String index() {
|
|
|
31 |
|
|
|
32 |
PaymentClient paymentServiceClient = null;
|
|
|
33 |
TransactionClient transactionServiceClient = null;
|
|
|
34 |
|
|
|
35 |
try {
|
|
|
36 |
paymentServiceClient = new PaymentClient();
|
|
|
37 |
transactionServiceClient = new TransactionClient();
|
|
|
38 |
} catch (Exception e1) {
|
|
|
39 |
// TODO Nothing to worry
|
|
|
40 |
log.error("Unable to initialize the client for either payment or transaction or user service", e1);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
try {
|
|
|
44 |
txnId = paymentServiceClient.getClient().getPayment(paymentId).getMerchantTxnId();
|
|
|
45 |
setOrders(transactionServiceClient.getClient().getOrdersForTransaction(txnId, userId));
|
|
|
46 |
} catch (PaymentException e) {
|
|
|
47 |
log.error("Payment service not responding. Payment id is" + paymentId, e);
|
|
|
48 |
} catch (TException e) {
|
|
|
49 |
log.error("Thrift service exception. Payment id is" + paymentId, e);
|
|
|
50 |
} catch (TransactionServiceException e) {
|
|
|
51 |
log.error("Transaction service exception. Payment id is" + paymentId, e);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
return "index";
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
public long getPaymentId() {
|
|
|
59 |
return paymentId;
|
|
|
60 |
}
|
|
|
61 |
public void setPaymentId(long paymentId) {
|
|
|
62 |
this.paymentId = paymentId;
|
|
|
63 |
}
|
|
|
64 |
public long getUserId() {
|
|
|
65 |
return userId;
|
|
|
66 |
}
|
|
|
67 |
public void setUserId(long userId) {
|
|
|
68 |
this.userId = userId;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
public void setOrders(List<Order> orders) {
|
|
|
73 |
this.orders = orders;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
public List<Order> getOrders() {
|
|
|
78 |
return orders;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
public String formatPrice(double price) {
|
|
|
82 |
return formattingUtils.formatPrice(price);
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
public static String formatDate(long timestamp){
|
|
|
86 |
SimpleDateFormat dateformat = new SimpleDateFormat("dd MMMM yyyy");
|
|
|
87 |
return dateformat.format(new Date(timestamp));
|
|
|
88 |
}
|
|
|
89 |
}
|