Subversion Repositories SmartDukaan

Rev

Rev 6091 | Rev 6108 | Go to most recent revision | Details | Compare with Previous | 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;
6056 amit.gupta 5
import in.shop2020.model.v1.order.RechargeType;
6050 anupam.sin 6
import in.shop2020.model.v1.order.TransactionServiceException;
7
import in.shop2020.model.v1.user.Affiliate;
8
import in.shop2020.model.v1.user.TrackLogType;
9
import in.shop2020.model.v1.user.UserAffiliateException;
10
import in.shop2020.payments.PaymentException;
11
import in.shop2020.serving.interceptors.TrackingInterceptor;
12
import in.shop2020.serving.utils.FormattingUtils;
13
import in.shop2020.thrift.clients.PaymentClient;
14
import in.shop2020.thrift.clients.TransactionClient;
15
import in.shop2020.thrift.clients.UserClient;
16
 
17
import java.text.SimpleDateFormat;
18
import java.util.Date;
6056 amit.gupta 19
import java.util.HashMap;
20
import java.util.Map;
6050 anupam.sin 21
 
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;
6056 amit.gupta 26
import org.apache.thrift.transport.TTransportException;
6050 anupam.sin 27
 
28
public class RechargeResultController extends BaseController {
29
    private static final long serialVersionUID = 1L;
30
 
31
    private static final String SHOOGLOO_AFF_NAME = "shoogloo";
32
 
33
    private static Logger log = Logger.getLogger(Class.class);
34
    private FormattingUtils formattingUtils = new FormattingUtils();
35
 
36
    private boolean isShooglooAff  = false;
6056 amit.gupta 37
    private static Map<Long,String> allProviders;
38
    static {
39
    	try {
40
			allProviders = new TransactionClient().getClient().getServiceProviders(RechargeType.DTH);
41
			allProviders.putAll(new TransactionClient().getClient().getServiceProviders(RechargeType.MOBILE));
42
		} catch (TTransportException e) {
43
			// TODO Auto-generated catch block
44
			e.printStackTrace();
45
		} catch (TException e) {
46
			// TODO Auto-generated catch block
47
			e.printStackTrace();
48
		}
49
    }
6050 anupam.sin 50
    long merchantPaymentId;
51
    RechargeOrder rechargeOrder = null;
52
    String message = null;
53
 
54
    public RechargeResultController(){
55
        super();
56
    }
57
 
58
    public String index() {
59
        PaymentClient paymentServiceClient = null;
60
        TransactionClient transactionServiceClient = null;
61
        UserClient userServiceClient = null;
62
 
63
        try {
64
            paymentServiceClient = new PaymentClient();
65
            transactionServiceClient = new TransactionClient();
66
            userServiceClient = new UserClient();
67
        } catch (Exception e1) {
68
            // TODO Nothing to worry
69
            log.error("Unable to initialize the client for either payment or transaction or user service", e1);
70
        }
71
 
72
 
73
        merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));
6056 amit.gupta 74
        String operator = "";
6050 anupam.sin 75
        long txnId;
76
        try {
77
            txnId = paymentServiceClient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
78
            rechargeOrder = transactionServiceClient.getClient().getRechargeOrdersForTransaction(txnId);
79
 
80
            this.message = "You have successfully recharged your mobile.";
81
 
82
            if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
83
                long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
84
                userServiceClient.getClient().addTrackLog(affId, userinfo.getUserId(), TrackLogType.PAYMENT_SUCCESS, "",
85
                        Long.toString(merchantPaymentId), (new Date()).getTime());
86
                Affiliate aff = userServiceClient.getClient().getAffiliateById(affId);
87
                if (aff.getName().equals(SHOOGLOO_AFF_NAME)) {
88
                    isShooglooAff = true;
89
                }
90
            }
91
 
92
        } catch (PaymentException e) {
93
            log.error("Payment service not responding. Payment id is" + merchantPaymentId, e);
94
        } catch (TException e) {
95
            log.error("Thrift service exception. Payment id is" + merchantPaymentId, e);
96
        } catch (TransactionServiceException e) {
97
            log.error("Transaction service exception. Payment id is" + merchantPaymentId, e);
98
        } catch (UserAffiliateException e) {
99
            log.error("Affiliate service exception. Payment id is" + merchantPaymentId, e);
100
        }
101
 
102
//        DataLogger.logData(EventType.PAYMENT_SUCCESS, getSessionId(), userinfo.getUserId(), 
103
//                userinfo.getEmail(), Long.toString(merchantPaymentId), Utils.getItemIdStringFromOrders(orders));
104
 
105
        return "index";
106
    }
107
 
108
    public String formatPrice(double price)    {
109
        return formattingUtils.formatPrice(price);
110
    }
111
 
112
    public String getMessage(){
113
        return this.message;
114
    }
115
 
116
    public boolean getIsShooglooAff() {
117
        return this.isShooglooAff;
118
    }
119
 
120
    public long getMerchantPaymentId() {
121
        return merchantPaymentId;
122
    }
123
 
124
    public static String formatDate(long timestamp){
125
        SimpleDateFormat dateformat = new SimpleDateFormat("dd MMMM yyyy");
126
        return dateformat.format(new Date(timestamp));  
127
    }
128
 
129
 
130
    @Override
131
    public String getHeaderSnippet() {
132
        String url = request.getQueryString();
133
        if (url == null) {
134
            url = "";
135
        } else {
136
            url = "?" + url;
137
        }
138
        url = request.getRequestURI() + url;
139
        return pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getEmail(), url , 0, false);
140
    }
141
 
142
    public RechargeOrder getRechargeOrder() {
143
        return rechargeOrder;
144
    }
145
 
146
    public void setRechargeOrder(RechargeOrder rechargeOrder) {
147
        this.rechargeOrder = rechargeOrder;
148
    }
6056 amit.gupta 149
 
150
 
151
    public boolean isDTH() {
152
    	return rechargeOrder.getRechargeType().equals(RechargeType.DTH);
153
    }
154
 
155
    public String getProvider() {
156
    	return allProviders.get(rechargeOrder.getOperatorId());
157
    }
158
 
159
    public String[] getOrderStatus(){
160
    	RechargeOrderStatus status = rechargeOrder.getStatus();
161
    	if(status.equals(RechargeOrderStatus.PAYMENT_FAILED)||status.equals(RechargeOrderStatus.PAYMENT_PENDING)){
162
    		return new String[]{"red", "PAYMENT FAILED", "Payment failed. Try to <a href='/recharge'>recharge again</a>"};
163
    	}
164
    	else if(status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)||status.equals(RechargeOrderStatus.RECHARGE_FAILED)){
6106 rajveer 165
			return new String[]{"red", "RECHARGE FAILED", "Payment was successful and amount is transferred to your <a href='/my-wallet'>wallet</a>.<br> <a href='/recharge'>Recharge again</a> using wallet."};
6056 amit.gupta 166
    	} else {
167
    		return new String[] {"", "SUCCESS", "Congratulations your mobile is successfully recharged."};
168
    	}
169
    }
6050 anupam.sin 170
}