Subversion Repositories SmartDukaan

Rev

Rev 1999 | Rev 2157 | 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
 
1999 vikas 3
import java.util.Date;
428 ashish 4
import java.util.List;
5
 
2087 vikas 6
import org.apache.commons.lang.StringUtils;
1044 chandransh 7
import org.apache.log4j.Logger;
822 vikas 8
import org.apache.struts2.convention.annotation.InterceptorRef;
9
import org.apache.struts2.convention.annotation.InterceptorRefs;
428 ashish 10
import org.apache.thrift.TException;
11
 
555 chandransh 12
import in.shop2020.model.v1.order.Order;
428 ashish 13
import in.shop2020.model.v1.order.TransactionServiceException;
894 rajveer 14
import in.shop2020.model.v1.user.Cart;
712 rajveer 15
import in.shop2020.model.v1.user.ShoppingCartException;
1999 vikas 16
import in.shop2020.model.v1.user.UserAffiliateException;
428 ashish 17
import in.shop2020.payments.PaymentException;
1999 vikas 18
import in.shop2020.serving.interceptors.TrackingInterceptor;
2087 vikas 19
import in.shop2020.serving.utils.DataLogger;
20
import in.shop2020.serving.utils.DataLogger.Event;
428 ashish 21
import in.shop2020.thrift.clients.PaymentServiceClient;
22
import in.shop2020.thrift.clients.TransactionServiceClient;
712 rajveer 23
import in.shop2020.thrift.clients.UserContextServiceClient;
428 ashish 24
 
894 rajveer 25
 
822 vikas 26
@InterceptorRefs({
27
    @InterceptorRef("myDefault"),
28
    @InterceptorRef("login")
712 rajveer 29
})
693 rajveer 30
 
719 rajveer 31
public class PaySuccessController extends BaseController{
693 rajveer 32
	private static final long serialVersionUID = 1L;
894 rajveer 33
 
1044 chandransh 34
	private static Logger log = Logger.getLogger(Class.class);
2087 vikas 35
	private static Logger dataLog = DataLogger.getLogger();
1044 chandransh 36
 
712 rajveer 37
	long merchantPaymentId;
38
	List<Order> orders = null;
719 rajveer 39
	String message = null;
428 ashish 40
 
719 rajveer 41
	public PaySuccessController(){
428 ashish 42
		super();
43
	}
44
 
853 rajveer 45
	public String index() {
719 rajveer 46
		this.message = "Payment completed successfully.";
894 rajveer 47
		PaymentServiceClient paymentServiceClient = null;
48
		TransactionServiceClient transactionServiceClient = null;
49
		UserContextServiceClient userServiceClient = null;
50
 
51
		try {
52
			paymentServiceClient = new PaymentServiceClient();
53
			transactionServiceClient = new TransactionServiceClient();
54
			userServiceClient = new UserContextServiceClient();
55
		} catch (Exception e1) {
56
			// TODO Nothing to worry
57
			e1.printStackTrace();
58
		}
59
 
60
 
719 rajveer 61
		merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));
62
 
853 rajveer 63
		long txnId;
64
		try {
894 rajveer 65
			txnId = paymentServiceClient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
1527 ankur.sing 66
			orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId, userinfo.getUserId());
894 rajveer 67
			Cart cart = userServiceClient.getClient().getCart(userinfo.getCartId());
68
			int totalItems = 0;
69
			if(cart != null){
70
				totalItems = cart.getLinesSize();
71
			}
890 chandransh 72
			userinfo.setTotalItems(totalItems);
1999 vikas 73
			if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
74
	            long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
75
	            userServiceClient.getClient().addTrackLog(affId, userinfo.getUserId(), "payment success", "",
76
                        Long.toString(merchantPaymentId), (new Date()).getTime());
77
	        }
853 rajveer 78
		} catch (PaymentException e) {
79
			log.error("Payment service not responding. Payment id is" + merchantPaymentId);
80
			e.printStackTrace();
81
		} catch (TException e) {
82
			log.error("Thrift service exception. Payment id is" + merchantPaymentId);
83
			e.printStackTrace();
84
		} catch (TransactionServiceException e) {
85
			log.error("Transaction service exception. Payment id is" + merchantPaymentId);
86
			e.printStackTrace();
87
		} catch (ShoppingCartException e) {
88
			log.error("Shopping cart service exception. Payment id is" + merchantPaymentId + " message id and name are " + e.getId() + e.getMessage());
89
			e.printStackTrace();
1999 vikas 90
		} catch (UserAffiliateException e) {
91
		    log.error("Affiliate service exception. Payment id is" + merchantPaymentId + " message id and name are " + e.getId() + e.getMessage());
92
            e.printStackTrace();
93
        }
853 rajveer 94
 
2087 vikas 95
		dataLog.info(StringUtils.join(new String[] { Event.PAYMENT_SUCCESS.name(), 
96
                userinfo.getEmail(), Long.toString(merchantPaymentId)}, ", "));
97
 
693 rajveer 98
		return "index";
428 ashish 99
	}
100
 
719 rajveer 101
 
102
 
712 rajveer 103
	public List<Order> getOrders(){
104
		return this.orders;
485 rajveer 105
	}
106
 
107
	public String getMessage(){
108
		return this.message;
109
	}
110
 
111
}