Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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