Subversion Repositories SmartDukaan

Rev

Rev 3721 | Rev 3903 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
428 ashish 1
package in.shop2020.serving.controllers;
2
 
2263 vikas 3
import in.shop2020.datalogger.EventType;
555 chandransh 4
import in.shop2020.model.v1.order.Order;
428 ashish 5
import in.shop2020.model.v1.order.TransactionServiceException;
894 rajveer 6
import in.shop2020.model.v1.user.Cart;
712 rajveer 7
import in.shop2020.model.v1.user.ShoppingCartException;
3378 vikas 8
import in.shop2020.model.v1.user.TrackLogType;
1999 vikas 9
import in.shop2020.model.v1.user.UserAffiliateException;
428 ashish 10
import in.shop2020.payments.PaymentException;
1999 vikas 11
import in.shop2020.serving.interceptors.TrackingInterceptor;
2193 varun.gupt 12
import in.shop2020.serving.utils.FormattingUtils;
3209 vikas 13
import in.shop2020.serving.utils.Utils;
3126 rajveer 14
import in.shop2020.thrift.clients.PaymentClient;
15
import in.shop2020.thrift.clients.TransactionClient;
16
import in.shop2020.thrift.clients.UserClient;
2511 vikas 17
import in.shop2020.utils.DataLogger;
428 ashish 18
 
2263 vikas 19
import java.util.Date;
20
import java.util.List;
894 rajveer 21
 
2263 vikas 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;
26
 
27
 
822 vikas 28
@InterceptorRefs({
29
    @InterceptorRef("myDefault"),
30
    @InterceptorRef("login")
712 rajveer 31
})
693 rajveer 32
 
719 rajveer 33
public class PaySuccessController extends BaseController{
693 rajveer 34
	private static final long serialVersionUID = 1L;
3830 chandransh 35
 
36
	private static final String ITEM = "ITEM";
37
	private static final String ITEMS = "ITEMS";
38
 
1044 chandransh 39
	private static Logger log = Logger.getLogger(Class.class);
2193 varun.gupt 40
	private FormattingUtils formattingUtils = new FormattingUtils();
41
 
1044 chandransh 42
 
712 rajveer 43
	long merchantPaymentId;
44
	List<Order> orders = null;
719 rajveer 45
	String message = null;
428 ashish 46
 
719 rajveer 47
	public PaySuccessController(){
428 ashish 48
		super();
49
	}
50
 
853 rajveer 51
	public String index() {
3121 chandransh 52
 
3126 rajveer 53
		PaymentClient paymentServiceClient = null;
54
		TransactionClient transactionServiceClient = null;
55
		UserClient userServiceClient = null;
894 rajveer 56
 
57
		try {
3126 rajveer 58
			paymentServiceClient = new PaymentClient();
59
			transactionServiceClient = new TransactionClient();
60
			userServiceClient = new UserClient();
894 rajveer 61
		} catch (Exception e1) {
62
			// TODO Nothing to worry
2944 chandransh 63
			log.error("Unable to initialize the client for either payment or transaction or user service", e1);
894 rajveer 64
		}
65
 
66
 
719 rajveer 67
		merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));
68
 
853 rajveer 69
		long txnId;
70
		try {
894 rajveer 71
			txnId = paymentServiceClient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
1527 ankur.sing 72
			orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId, userinfo.getUserId());
894 rajveer 73
			Cart cart = userServiceClient.getClient().getCart(userinfo.getCartId());
74
			if(cart != null){
3830 chandransh 75
				userinfo.setTotalItems(cart.getLinesSize());
76
				userinfo.setTotalAmount(cart.getTotalPrice());
77
			}else{
78
				userinfo.setTotalItems(0);
79
				userinfo.setTotalAmount(0);
894 rajveer 80
			}
3830 chandransh 81
 
1999 vikas 82
			if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
83
	            long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
3378 vikas 84
	            userServiceClient.getClient().addTrackLog(affId, userinfo.getUserId(), TrackLogType.PAYMENT_SUCCESS, "",
1999 vikas 85
                        Long.toString(merchantPaymentId), (new Date()).getTime());
86
	        }
3830 chandransh 87
 
88
			String suffix = ITEM;
89
			if(orders.size() > 1)
90
			    suffix = ITEMS;
91
 
3121 chandransh 92
			if(orders.get(0).isCod())
3830 chandransh 93
			    this.message = "You have successfully ordered <span class=\"orange\">" + orders.size() + " " + suffix + ".</span>";
3121 chandransh 94
			else
3830 chandransh 95
				this.message = "You have successfully ordered <span class=\"orange\">" + orders.size() + " " + suffix + ".</span>" + 
96
				" <br/> Congratulations! Your order qualifies for the 100% Cashback Offer. <br/>" +
97
				"We will get in touch with you if you are the lucky winner. <br/>" +
98
				"Meanwhile you can check out all our winners on our <a href='http://www.facebook.com/mysaholic'>Facebook Page</a> .";
853 rajveer 99
		} catch (PaymentException e) {
2944 chandransh 100
			log.error("Payment service not responding. Payment id is" + merchantPaymentId, e);
853 rajveer 101
		} catch (TException e) {
2944 chandransh 102
			log.error("Thrift service exception. Payment id is" + merchantPaymentId, e);
853 rajveer 103
		} catch (TransactionServiceException e) {
2944 chandransh 104
			log.error("Transaction service exception. Payment id is" + merchantPaymentId, e);
853 rajveer 105
		} catch (ShoppingCartException e) {
2944 chandransh 106
			log.error("Shopping cart service exception. Payment id is" + merchantPaymentId, e);
1999 vikas 107
		} catch (UserAffiliateException e) {
2944 chandransh 108
		    log.error("Affiliate service exception. Payment id is" + merchantPaymentId, e);
1999 vikas 109
        }
853 rajveer 110
 
3209 vikas 111
		DataLogger.logData(EventType.PAYMENT_SUCCESS, getSessionId(), userinfo.getUserId(), 
112
		        userinfo.getEmail(), Long.toString(merchantPaymentId), Utils.getItemIdStringFromOrders(orders));
2087 vikas 113
 
693 rajveer 114
		return "index";
428 ashish 115
	}
116
 
2193 varun.gupt 117
	public String formatPrice(double price)    {
118
	    return formattingUtils.formatPrice(price);
119
	}
719 rajveer 120
 
712 rajveer 121
	public List<Order> getOrders(){
122
		return this.orders;
485 rajveer 123
	}
124
 
125
	public String getMessage(){
126
		return this.message;
2193 varun.gupt 127
	}	
3830 chandransh 128
}