Subversion Repositories SmartDukaan

Rev

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