Subversion Repositories SmartDukaan

Rev

Rev 7343 | Details | Compare with Previous | Last modification | View Log | RSS feed

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