Subversion Repositories SmartDukaan

Rev

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