Subversion Repositories SmartDukaan

Rev

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