Subversion Repositories SmartDukaan

Rev

Rev 6336 | Rev 6341 | 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
 
6108 amar.kumar 3
import in.shop2020.datalogger.EventType;
6050 anupam.sin 4
import in.shop2020.model.v1.order.RechargeOrder;
5
import in.shop2020.model.v1.order.RechargeOrderStatus;
6056 amit.gupta 6
import in.shop2020.model.v1.order.RechargeType;
6050 anupam.sin 7
import in.shop2020.model.v1.order.TransactionServiceException;
8
import in.shop2020.payments.PaymentException;
9
import in.shop2020.serving.utils.FormattingUtils;
10
import in.shop2020.thrift.clients.PaymentClient;
11
import in.shop2020.thrift.clients.TransactionClient;
6108 amar.kumar 12
import in.shop2020.utils.DataLogger;
6050 anupam.sin 13
 
14
import java.text.SimpleDateFormat;
15
import java.util.Date;
6266 anupam.sin 16
import java.util.HashMap;
6056 amit.gupta 17
import java.util.Map;
6050 anupam.sin 18
 
19
import org.apache.log4j.Logger;
20
import org.apache.thrift.TException;
6056 amit.gupta 21
import org.apache.thrift.transport.TTransportException;
6050 anupam.sin 22
 
23
public class RechargeResultController extends BaseController {
24
    private static final long serialVersionUID = 1L;
25
 
6266 anupam.sin 26
//    private static final String SHOOGLOO_AFF_NAME = "shoogloo";
6050 anupam.sin 27
 
28
    private static Logger log = Logger.getLogger(Class.class);
29
    private FormattingUtils formattingUtils = new FormattingUtils();
30
 
6266 anupam.sin 31
    //private boolean isShooglooAff  = false;
32
 
6056 amit.gupta 33
    private static Map<Long,String> allProviders;
34
    static {
35
    	try {
6206 rajveer 36
			allProviders = new TransactionClient().getClient().getServiceProviders(RechargeType.DTH, true);
37
			allProviders.putAll(new TransactionClient().getClient().getServiceProviders(RechargeType.MOBILE, true));
6056 amit.gupta 38
		} catch (TTransportException e) {
39
			// TODO Auto-generated catch block
40
			e.printStackTrace();
41
		} catch (TException e) {
42
			// TODO Auto-generated catch block
43
			e.printStackTrace();
44
		}
45
    }
6266 anupam.sin 46
 
47
    private static Map<String, String> FailureReasonMap;
48
    static {
49
        FailureReasonMap = new HashMap<String, String>();
50
        FailureReasonMap.put("Invalid Amount", "the amount you tried seems to be invalid. Please try another amount.");
51
        FailureReasonMap.put("Customer Exceeded Daily Limit", "you have exceeded daily recharge limit for this number. Please try after 12 hours.");
52
        FailureReasonMap.put("Invalid Mobile Number", "it seems that your mobile number is not being recognized by selected operator. Please make sure the number you tried is correct.");
53
    }
54
 
6050 anupam.sin 55
    long merchantPaymentId;
56
    RechargeOrder rechargeOrder = null;
57
    String message = null;
58
 
59
    public RechargeResultController(){
60
        super();
61
    }
62
 
63
    public String index() {
64
        PaymentClient paymentServiceClient = null;
65
        TransactionClient transactionServiceClient = null;
6266 anupam.sin 66
        //UserClient userServiceClient = null;
6050 anupam.sin 67
 
68
        try {
69
            paymentServiceClient = new PaymentClient();
70
            transactionServiceClient = new TransactionClient();
6266 anupam.sin 71
          //  userServiceClient = new UserClient();
6050 anupam.sin 72
        } catch (Exception e1) {
73
            // TODO Nothing to worry
74
            log.error("Unable to initialize the client for either payment or transaction or user service", e1);
75
        }
76
 
6123 anupam.sin 77
        String returningPayIdString = this.request.getParameter("paymentId");
78
        if (returningPayIdString == null || returningPayIdString.isEmpty()) {
79
            this.message = "Payment Failed at payment gateway. Please try again.";
80
            return "index";
81
        }
6050 anupam.sin 82
        merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));
83
        long txnId;
84
        try {
85
            txnId = paymentServiceClient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
86
            rechargeOrder = transactionServiceClient.getClient().getRechargeOrdersForTransaction(txnId);
87
 
88
            this.message = "You have successfully recharged your mobile.";
89
 
6266 anupam.sin 90
            /*if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
6050 anupam.sin 91
                long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
92
                userServiceClient.getClient().addTrackLog(affId, userinfo.getUserId(), TrackLogType.PAYMENT_SUCCESS, "",
93
                        Long.toString(merchantPaymentId), (new Date()).getTime());
94
                Affiliate aff = userServiceClient.getClient().getAffiliateById(affId);
95
                if (aff.getName().equals(SHOOGLOO_AFF_NAME)) {
96
                    isShooglooAff = true;
97
                }
6266 anupam.sin 98
            }*/
6050 anupam.sin 99
 
100
        } catch (PaymentException e) {
101
            log.error("Payment service not responding. Payment id is" + merchantPaymentId, e);
102
        } catch (TException e) {
103
            log.error("Thrift service exception. Payment id is" + merchantPaymentId, e);
104
        } catch (TransactionServiceException e) {
105
            log.error("Transaction service exception. Payment id is" + merchantPaymentId, e);
106
        }
6266 anupam.sin 107
 
108
//        catch (UserAffiliateException e) {
109
//            log.error("Affiliate service exception. Payment id is" + merchantPaymentId, e);
110
//        }
6050 anupam.sin 111
 
112
        return "index";
113
    }
114
 
115
    public String formatPrice(double price)    {
116
        return formattingUtils.formatPrice(price);
117
    }
118
 
119
    public String getMessage(){
120
        return this.message;
121
    }
122
 
6266 anupam.sin 123
//    public boolean getIsShooglooAff() {
124
//        return this.isShooglooAff;
125
//    }
6050 anupam.sin 126
 
127
    public long getMerchantPaymentId() {
128
        return merchantPaymentId;
129
    }
130
 
131
    public static String formatDate(long timestamp){
132
        SimpleDateFormat dateformat = new SimpleDateFormat("dd MMMM yyyy");
133
        return dateformat.format(new Date(timestamp));  
134
    }
135
 
136
 
137
    @Override
138
    public String getHeaderSnippet() {
139
        String url = request.getQueryString();
140
        if (url == null) {
141
            url = "";
142
        } else {
143
            url = "?" + url;
144
        }
145
        url = request.getRequestURI() + url;
6152 amit.gupta 146
        return pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getEmail(), userinfo.getTotalItems(), url , 0, false);
6050 anupam.sin 147
    }
148
 
149
    public RechargeOrder getRechargeOrder() {
150
        return rechargeOrder;
151
    }
152
 
153
    public void setRechargeOrder(RechargeOrder rechargeOrder) {
154
        this.rechargeOrder = rechargeOrder;
155
    }
6056 amit.gupta 156
 
157
 
158
    public boolean isDTH() {
159
    	return rechargeOrder.getRechargeType().equals(RechargeType.DTH);
160
    }
161
 
162
    public String getProvider() {
163
    	return allProviders.get(rechargeOrder.getOperatorId());
164
    }
165
 
166
    public String[] getOrderStatus(){
167
    	RechargeOrderStatus status = rechargeOrder.getStatus();
168
    	if(status.equals(RechargeOrderStatus.PAYMENT_FAILED)||status.equals(RechargeOrderStatus.PAYMENT_PENDING)){
6108 amar.kumar 169
    		DataLogger.logData(EventType.RECHARGE_PAYMENT_FAILED, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
170
    				Long.toString(rechargeOrder.getOperatorId()), Long.toString(rechargeOrder.getTotalAmount()), Long.toString(rechargeOrder.getWalletAmount()),
171
                    rechargeOrder.getRechargeType().toString());
6145 anupam.sin 172
    		return new String[]{"red", "PAYMENT FAILED", "Payment failed at the payment gateway. Try to <a href='/recharge'>recharge again</a>"};
6056 amit.gupta 173
    	}
6215 anupam.sin 174
    	else if(status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)) {
175
    	    DataLogger.logData(EventType.RECHARGE_PAYMENT_SUCCESSFUL, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
176
                    Long.toString(rechargeOrder.getOperatorId()), Long.toString(rechargeOrder.getTotalAmount()), Long.toString(rechargeOrder.getWalletAmount()),
177
                    rechargeOrder.getRechargeType().toString());
178
    	    return new String[]{"red", "RECHARGE IN PROCESS", "Your Payment was successful but due to some internal error with the operator's system we are not sure if the recharge was successful.<br>" +
179
                    "We have put your recharge under process. As soon as we get a confirmation on this transaction, we will notify you.<br>" +
180
                    "In case of recharge failure your entire amount will be credited to your " +
181
                    "<a href='/my-wallet'>recharge wallet</a>.<br><br> You " +
182
                    "will need to <a href='/login?redirectUrl=/recharge'>login</a> to use your Wallet.<br> If you are registered on" + 
183
                    " Saholic.com please use your username and password to Login.<br> In case you are " +
184
                    "a first time user, we have sent your login details on the emailId you gave us. " +
185
                    "<br>For more information <a href='/static/recharge-faq'>click here</a>"};
186
    	}
187
    	else if (status.equals(RechargeOrderStatus.RECHARGE_FAILED)){
6108 amar.kumar 188
    		DataLogger.logData(EventType.RECHARGE_PAYMENT_SUCCESSFUL, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
189
    				Long.toString(rechargeOrder.getOperatorId()), Long.toString(rechargeOrder.getTotalAmount()), Long.toString(rechargeOrder.getWalletAmount()),
190
    				rechargeOrder.getRechargeType().toString());
6266 anupam.sin 191
    		String displayReason = FailureReasonMap.get(rechargeOrder.getDescription());
192
    		if (!(displayReason == null || displayReason.isEmpty())) {
193
    		    displayReason = "Your Payment was successful but unfortunately the recharge failed because " + displayReason + "<br>";
194
    		} else {
195
    		    displayReason = "Your Payment was successful but unfortunately the recharge failed.<br>";
196
    		}
197
			return new String[]{"red", "RECHARGE FAILED", displayReason +
6145 anupam.sin 198
					"Don't worry your payment is safe with us. The entire Amount has been refunded to your " +
199
					"<a href='/my-wallet'>recharge wallet</a>.<br><br> You " +
200
					"will need to <a href='/login?redirectUrl=/recharge'>login</a> to use your Wallet.<br> If you are registered on" + 
201
					" Saholic.com please use your username and password to Login.<br> In case you are " +
202
					"a first time user, we have sent your login details on the emailId you gave us. " +
6146 anupam.sin 203
					"<br>For more information <a href='/static/recharge-faq'>click here</a>"};
6056 amit.gupta 204
    	} else {
6108 amar.kumar 205
    		DataLogger.logData(EventType.RECHARGE_SUCCESSFUL, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
206
    				Long.toString(rechargeOrder.getOperatorId()), Long.toString(rechargeOrder.getTotalAmount()), Long.toString(rechargeOrder.getWalletAmount()),
207
    				rechargeOrder.getRechargeType().toString());
6323 rajveer 208
 
6336 anupam.sin 209
    		String operator = "";
210
    		if(isDTH()) {
211
    		    operator = getProvider();
212
    		} else {
213
    		    operator = getProvider() + " mobile";
214
    		}
215
 
216
    		String original_referer = "http://www.saholic.com/recharge-result?paymentId=" + this.request.getParameter("paymentId");
6323 rajveer 217
    		String fbUrl = "";
6336 anupam.sin 218
    		String twitterUrl = "";
219
    		String shareMsg = "";
6323 rajveer 220
    		String giftMessage = "Congratulations! Your device is successfully recharged.";
221
    		if(rechargeOrder.getTotalAmount()>=100){
222
    			if(rechargeOrder.getTotalAmount()>=500){
6336 anupam.sin 223
    			    shareMsg = "I just recharged my " + operator + " at Saholic.com and got Rs.500 cashback";
224
    				fbUrl = "http://www.facebook.com/dialog/feed?app_id=291830044248933&link=www.saholic.com/recharge?afid=61&picture=http://i1074.photobucket.com/albums/w407/amathur2k/logo_saholic.png&name=" + shareMsg + "&caption=Win Assured Gift Coupons worth upto Rs.500 on every Mobile or DTH Recharge&description=One Click Hassle Free Recharges&redirect_uri=http://saholic.com/?shared=1";
225
    				twitterUrl = "https://twitter.com/intent/tweet?hashtags=saholic&original_referer=" + original_referer + "&related=saholic&source=saholic.com&text=" + shareMsg + "&url=http://www.saholic.com/recharge/afid?64&via=saholic";
226
    				giftMessage = "Congratulations! Your device is successfully recharged and you have " +
227
    						"won Gift Coupons worth Rs.500 which you can use to shop for Mobiles, Laptops, Cameras, Accessories.<br><br>" +
228
    						"Voucher details have been sent to your email.<a target='_blank' href='/static/giftvoucher-offer'> Learn more.</a>" +
229
                            "<br><br>Please help us spread the word." +
230
    						"<div style=\"margin-top: 40px;text-align: center;\">" +
231
    						"<a target='_blank' href='" + twitterUrl + "'>" + 
6339 anupam.sin 232
    								"<input type='button' onclick=\"trackEventWithGA('Recharge', 'Twitter Share', '')\" style=\"background: url('/images/tweet-about-us.png') 0px 1px;width: 160px;height: 40px;margin-right: 40px;\"></a>" +
6336 anupam.sin 233
    						"<a target='_blank' href='" + fbUrl + "'>" +
6339 anupam.sin 234
    								"<input type=\"button\" onclick=\"trackEventWithGA('Recharge', 'Facebook Share', '');\" style=\"background:url('/images/Post-On-Facebook.jpg');width: 160px;height: 40px;\">" +
6336 anupam.sin 235
    								"</a></div>";
6323 rajveer 236
    			}else{
6339 anupam.sin 237
 
238
 
239
 
240
 
6336 anupam.sin 241
    			    shareMsg = "I just recharged my " + operator + " at Saholic.com and got full cashback";
242
    				fbUrl = "http://www.facebook.com/dialog/feed?app_id=291830044248933&link=www.saholic.com/recharge?afid=61&picture=http://i1074.photobucket.com/albums/w407/amathur2k/logo_saholic.png&name=" + shareMsg + "&caption=Win Assured Gift Coupons worth upto Rs.500 on every Mobile or DTH Recharge&description=One Click Hassle Free Recharges&redirect_uri=http://saholic.com/?shared=1";
243
    				twitterUrl = "https://twitter.com/intent/tweet?hashtags=saholic&original_referer=" + original_referer + "&related=saholic&source=saholic.com&text=" + shareMsg + "&url=http://www.saholic.com/recharge?afid=64&via=saholic";
244
    				giftMessage = "Congratulations! Your device is successfully recharged and you have " +
245
    						"won Gift Coupons worth Rs." + rechargeOrder.getTotalAmount() + " which you can use to shop for Mobiles, Laptops, Cameras, Accessories.<br><br>" +
246
    						"Voucher details have been sent to your email.<a target='_blank' href='/static/giftvoucher-offer'> Learn more.</a>" +
247
    						"<br><br>Please help us spread the word." +
248
    						"<div style=\"margin-top: 40px;text-align: center;\">" +
249
    						"<a target='_blank' href='" + twitterUrl + "'>" +
6339 anupam.sin 250
                            "<input type='button' onclick=\"trackEventWithGA('Recharge', 'Twitter Share', '')\" style=\"background: url('/images/tweet-about-us.png') 0px 1px;width: 160px;height: 40px;margin-right: 40px;\"></a>" + 
6336 anupam.sin 251
                            "<a target='_blank' href='" + fbUrl + "'>" +
6339 anupam.sin 252
                                    "<input type=\"button\" onclick=\"trackEventWithGA('Recharge', 'Facebook Share', '');\" style=\"background:url('/images/Post-On-Facebook.jpg');width: 160px;height: 40px;\">" +
6336 anupam.sin 253
                                    "</a></div>";
6323 rajveer 254
    			}
255
    		}
6325 rajveer 256
    		return new String[] {"", "SUCCESS", giftMessage};
6056 amit.gupta 257
    	}
258
    }
6050 anupam.sin 259
}