Subversion Repositories SmartDukaan

Rev

Rev 6056 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6050 anupam.sin 1
package in.shop2020.serving.controllers;
2
 
3
import in.shop2020.model.v1.order.RechargeOrder;
4
import in.shop2020.model.v1.order.RechargeOrderStatus;
5
import in.shop2020.model.v1.order.TransactionServiceException;
6
import in.shop2020.model.v1.user.Affiliate;
7
import in.shop2020.model.v1.user.TrackLogType;
8
import in.shop2020.model.v1.user.UserAffiliateException;
9
import in.shop2020.payments.PaymentException;
10
import in.shop2020.serving.interceptors.TrackingInterceptor;
11
import in.shop2020.serving.utils.FormattingUtils;
12
import in.shop2020.thrift.clients.PaymentClient;
13
import in.shop2020.thrift.clients.TransactionClient;
14
import in.shop2020.thrift.clients.UserClient;
15
 
16
import java.text.SimpleDateFormat;
17
import java.util.Date;
18
 
19
import org.apache.log4j.Logger;
20
import org.apache.struts2.convention.annotation.InterceptorRef;
21
import org.apache.struts2.convention.annotation.InterceptorRefs;
22
import org.apache.thrift.TException;
23
 
24
@InterceptorRefs({
25
    @InterceptorRef("myDefault"),
26
    @InterceptorRef("login")
27
})
28
 
29
public class RechargeResultController extends BaseController {
30
    private static final long serialVersionUID = 1L;
31
 
32
    private static final String SHOOGLOO_AFF_NAME = "shoogloo";
33
 
34
    private static Logger log = Logger.getLogger(Class.class);
35
    private FormattingUtils formattingUtils = new FormattingUtils();
36
 
37
    private boolean isShooglooAff  = false;
38
 
39
    long merchantPaymentId;
40
    RechargeOrder rechargeOrder = null;
41
    String message = null;
42
 
43
    public RechargeResultController(){
44
        super();
45
    }
46
 
47
    public String index() {
48
        long i = 2;
49
        if (i == 2) {
50
            return "index";
51
        }
52
        PaymentClient paymentServiceClient = null;
53
        TransactionClient transactionServiceClient = null;
54
        UserClient userServiceClient = null;
55
 
56
        try {
57
            paymentServiceClient = new PaymentClient();
58
            transactionServiceClient = new TransactionClient();
59
            userServiceClient = new UserClient();
60
        } catch (Exception e1) {
61
            // TODO Nothing to worry
62
            log.error("Unable to initialize the client for either payment or transaction or user service", e1);
63
        }
64
 
65
 
66
        merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));
67
 
68
        long txnId;
69
        try {
70
            txnId = paymentServiceClient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
71
            rechargeOrder = transactionServiceClient.getClient().getRechargeOrdersForTransaction(txnId);
72
 
73
            this.message = "You have successfully recharged your mobile.";
74
 
75
            if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
76
                long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
77
                userServiceClient.getClient().addTrackLog(affId, userinfo.getUserId(), TrackLogType.PAYMENT_SUCCESS, "",
78
                        Long.toString(merchantPaymentId), (new Date()).getTime());
79
                Affiliate aff = userServiceClient.getClient().getAffiliateById(affId);
80
                if (aff.getName().equals(SHOOGLOO_AFF_NAME)) {
81
                    isShooglooAff = true;
82
                }
83
            }
84
 
85
        } catch (PaymentException e) {
86
            log.error("Payment service not responding. Payment id is" + merchantPaymentId, e);
87
        } catch (TException e) {
88
            log.error("Thrift service exception. Payment id is" + merchantPaymentId, e);
89
        } catch (TransactionServiceException e) {
90
            log.error("Transaction service exception. Payment id is" + merchantPaymentId, e);
91
        } catch (UserAffiliateException e) {
92
            log.error("Affiliate service exception. Payment id is" + merchantPaymentId, e);
93
        }
94
 
95
//        DataLogger.logData(EventType.PAYMENT_SUCCESS, getSessionId(), userinfo.getUserId(), 
96
//                userinfo.getEmail(), Long.toString(merchantPaymentId), Utils.getItemIdStringFromOrders(orders));
97
 
98
        return "index";
99
    }
100
 
101
    public String formatPrice(double price)    {
102
        return formattingUtils.formatPrice(price);
103
    }
104
 
105
    public String getMessage(){
106
        return this.message;
107
    }
108
 
109
    public boolean getIsShooglooAff() {
110
        return this.isShooglooAff;
111
    }
112
 
113
    public long getMerchantPaymentId() {
114
        return merchantPaymentId;
115
    }
116
 
117
    public static String formatDate(long timestamp){
118
        SimpleDateFormat dateformat = new SimpleDateFormat("dd MMMM yyyy");
119
        return dateformat.format(new Date(timestamp));  
120
    }
121
 
122
 
123
    @Override
124
    public String getHeaderSnippet() {
125
        String url = request.getQueryString();
126
        if (url == null) {
127
            url = "";
128
        } else {
129
            url = "?" + url;
130
        }
131
        url = request.getRequestURI() + url;
132
        return pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getEmail(), url , 0, false);
133
    }
134
 
135
    public RechargeOrder getRechargeOrder() {
136
        return rechargeOrder;
137
    }
138
 
139
    public void setRechargeOrder(RechargeOrder rechargeOrder) {
140
        this.rechargeOrder = rechargeOrder;
141
    }
142
}