Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
428 ashish 1
package in.shop2020.serving.controllers;
2
 
3
import java.util.List;
4
 
853 rajveer 5
import org.apache.juli.logging.Log;
6
import org.apache.juli.logging.LogFactory;
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;
712 rajveer 13
import in.shop2020.model.v1.user.ShoppingCartException;
428 ashish 14
import in.shop2020.payments.PaymentException;
15
import in.shop2020.thrift.clients.PaymentServiceClient;
16
import in.shop2020.thrift.clients.TransactionServiceClient;
712 rajveer 17
import in.shop2020.thrift.clients.UserContextServiceClient;
428 ashish 18
import in.shop2020.utils.Logger;
19
 
822 vikas 20
@InterceptorRefs({
21
    @InterceptorRef("myDefault"),
22
    @InterceptorRef("login")
712 rajveer 23
})
693 rajveer 24
 
719 rajveer 25
public class PaySuccessController extends BaseController{
693 rajveer 26
	private static final long serialVersionUID = 1L;
428 ashish 27
	PaymentServiceClient pclient = null;
28
	TransactionServiceClient tsc = null;
712 rajveer 29
	UserContextServiceClient usc = null;
428 ashish 30
 
853 rajveer 31
	private static Log log = LogFactory.getLog(Class.class);
712 rajveer 32
	long merchantPaymentId;
33
	List<Order> orders = null;
719 rajveer 34
	String message = null;
428 ashish 35
 
719 rajveer 36
	public PaySuccessController(){
428 ashish 37
		super();
38
		try {
39
			pclient = new PaymentServiceClient();
40
			tsc = new TransactionServiceClient();
712 rajveer 41
			usc = new UserContextServiceClient();
428 ashish 42
		} catch (Exception e) {
43
			Logger.log("Could not initialize the paymentservice client", this);
44
		}
45
	}
46
 
853 rajveer 47
	public String index() {
719 rajveer 48
		this.message = "Payment completed successfully.";
49
		System.out.println("Inside the index method of pay response");
50
 
51
		merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));
52
 
853 rajveer 53
		long txnId;
54
		try {
55
			txnId = pclient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
712 rajveer 56
 
890 chandransh 57
			orders = tsc.getClient().getOrdersForTransaction(txnId);
58
 
59
			int totalItems = usc.getClient().getCart(userinfo.getCartId()).getLinesSize();
60
			userinfo.setTotalItems(totalItems);
853 rajveer 61
		} catch (PaymentException e) {
62
			log.error("Payment service not responding. Payment id is" + merchantPaymentId);
63
			e.printStackTrace();
64
		} catch (TException e) {
65
			log.error("Thrift service exception. Payment id is" + merchantPaymentId);
66
			e.printStackTrace();
67
		} catch (TransactionServiceException e) {
68
			log.error("Transaction service exception. Payment id is" + merchantPaymentId);
69
			e.printStackTrace();
70
		} catch (ShoppingCartException e) {
71
			log.error("Shopping cart service exception. Payment id is" + merchantPaymentId + " message id and name are " + e.getId() + e.getMessage());
72
			e.printStackTrace();
73
		}
74
 
693 rajveer 75
		return "index";
428 ashish 76
	}
77
 
719 rajveer 78
 
79
 
712 rajveer 80
	public List<Order> getOrders(){
81
		return this.orders;
485 rajveer 82
	}
83
 
84
	public String getMessage(){
85
		return this.message;
86
	}
87
 
88
}