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
 
712 rajveer 8
import org.apache.struts2.convention.annotation.Result;
9
import org.apache.struts2.convention.annotation.Results;
428 ashish 10
import org.apache.thrift.TException;
11
 
712 rajveer 12
import in.shop2020.model.v1.order.LineItem;
555 chandransh 13
import in.shop2020.model.v1.order.Order;
428 ashish 14
import in.shop2020.model.v1.order.TransactionServiceException;
712 rajveer 15
import in.shop2020.model.v1.order.TransactionStatus;
16
import in.shop2020.model.v1.user.ShoppingCartException;
428 ashish 17
import in.shop2020.payments.PaymentException;
693 rajveer 18
import in.shop2020.payments.PaymentStatus;
712 rajveer 19
import in.shop2020.serving.utils.Utils;
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
import in.shop2020.utils.Logger;
24
 
712 rajveer 25
@Results({
26
    @Result(name="redirect", type="redirectAction", 
719 rajveer 27
    		params = {"actionName" , "login"})
712 rajveer 28
})
693 rajveer 29
 
719 rajveer 30
public class PaySuccessController extends BaseController{
693 rajveer 31
	private static final long serialVersionUID = 1L;
428 ashish 32
	PaymentServiceClient pclient = null;
33
	TransactionServiceClient tsc = null;
712 rajveer 34
	UserContextServiceClient usc = null;
428 ashish 35
 
712 rajveer 36
	long merchantPaymentId;
37
	List<Order> orders = null;
719 rajveer 38
	String message = null;
428 ashish 39
 
719 rajveer 40
	public PaySuccessController(){
428 ashish 41
		super();
42
		try {
43
			pclient = new PaymentServiceClient();
44
			tsc = new TransactionServiceClient();
712 rajveer 45
			usc = new UserContextServiceClient();
428 ashish 46
		} catch (Exception e) {
47
			Logger.log("Could not initialize the paymentservice client", this);
48
		}
49
	}
50
 
762 rajveer 51
	public String index() throws IOException, SecurityException, PaymentException, TException, TransactionServiceException, ShoppingCartException{
719 rajveer 52
		this.message = "Payment completed successfully.";
53
		System.out.println("Inside the index method of pay response");
712 rajveer 54
    	if(!userinfo.isLoggedIn()){
719 rajveer 55
    		System.out.println("Inside user is not logged in");
712 rajveer 56
    		setRedirectUrl();
57
    		return "redirect";
58
    	}
719 rajveer 59
 
60
		merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));
61
 
62
		long txnId = pclient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
712 rajveer 63
 
719 rajveer 64
		orders = tsc.getClient().getOrdersForTransaction(txnId);
65
 
762 rajveer 66
		int totalItems = usc.getClient().getCart(userinfo.getCartId()).getLinesSize();
67
		userinfo.setTotalItems(totalItems);
68
 
693 rajveer 69
		return "index";
428 ashish 70
	}
71
 
719 rajveer 72
 
73
 
712 rajveer 74
	public List<Order> getOrders(){
75
		return this.orders;
485 rajveer 76
	}
77
 
78
	public String getMessage(){
79
		return this.message;
80
	}
81
 
82
}