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
 
719 rajveer 51
	public String index() throws IOException, SecurityException, PaymentException, TException, TransactionServiceException{
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
 
66
 
67
		this.userinfo.setTotalItems(Utils.getNumberOfItemsInCart(userinfo.getCartId()));
693 rajveer 68
		return "index";
428 ashish 69
	}
70
 
719 rajveer 71
 
72
 
712 rajveer 73
	public List<Order> getOrders(){
74
		return this.orders;
485 rajveer 75
	}
76
 
77
	public String getMessage(){
78
		return this.message;
79
	}
80
 
81
}