Subversion Repositories SmartDukaan

Rev

Rev 712 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 712 Rev 719
Line 22... Line 22...
22
import in.shop2020.thrift.clients.UserContextServiceClient;
22
import in.shop2020.thrift.clients.UserContextServiceClient;
23
import in.shop2020.utils.Logger;
23
import in.shop2020.utils.Logger;
24
 
24
 
25
@Results({
25
@Results({
26
    @Result(name="redirect", type="redirectAction", 
26
    @Result(name="redirect", type="redirectAction", 
27
    		params = {"actionName" , "login"}),
27
    		params = {"actionName" , "login"})
28
    @Result(name="shipping-redirect", type="redirectAction", 
-
 
29
    		params = {"actionName" , "shipping"})
-
 
30
		
-
 
31
})
28
})
32
 
29
 
33
public class PayResponseController extends BaseController{
30
public class PaySuccessController extends BaseController{
34
	private static final long serialVersionUID = 1L;
31
	private static final long serialVersionUID = 1L;
35
 
-
 
36
	private enum PaymentReturnStatus{
-
 
37
		CAPTURED("CAPTURED"),
-
 
38
		NOT_CAPTURED ("NOT CAPTURED"),
-
 
39
		CANCELLED ("CANCELLED"),
-
 
40
		DENIED_BY_RISK("DENIED BY RISK"),
-
 
41
		HOST_TIMEOUT("HOST TIMEOUT");
-
 
42
		private String value;
-
 
43
		PaymentReturnStatus(String value) {
-
 
44
			this.value = value;
-
 
45
		}
-
 
46
		public String value(){
-
 
47
			return this.value;
-
 
48
		}
-
 
49
	}
-
 
50
 
-
 
51
	public static String AMOUNT = "amt";
-
 
52
	public static String TRACKID = "trackid";
-
 
53
	public static String TRACKID_CANCELLED = "trackId";
-
 
54
	public static String RESULT = "result";
-
 
55
	public static String AUTH = "auth";
-
 
56
	public static String TRANID = "tranid";
-
 
57
	public static String PAYMENTID = "paymentid";
-
 
58
	public static String REF = "ref";
-
 
59
	public static String POSTDATE = "postdate";
-
 
60
	public static String ERROR = "Error";
-
 
61
	public static String ERRORTEXT = "ErrorText";
-
 
62
	
-
 
63
	PaymentServiceClient pclient = null;
32
	PaymentServiceClient pclient = null;
64
	TransactionServiceClient tsc = null;
33
	TransactionServiceClient tsc = null;
65
	UserContextServiceClient usc = null;
34
	UserContextServiceClient usc = null;
66
	
35
	
67
	String amount;
-
 
68
	String trackId;
-
 
69
	String result;
-
 
70
	String postdate;
-
 
71
	String auth;
-
 
72
	String ref;
-
 
73
	String tranId;
-
 
74
	String paymentId;
-
 
75
	String sessionId;
-
 
76
	String errorText;
-
 
77
	String errorNo;
-
 
78
	long txnId;
-
 
79
	long merchantPaymentId;
36
	long merchantPaymentId;
80
	List<Order> orders = null;
37
	List<Order> orders = null;
81
 
-
 
82
	/*
-
 
83
	 * 	pw.println("RESULT="+result);
-
 
84
			pw.println("PDATE="+postdate);
-
 
85
			pw.println("TXNID="+tranid);
-
 
86
			pw.println("AUTH="+auth);
38
	String message = null;
87
			pw.println("TRACKID="+trackid);
-
 
88
			pw.println("REF="+ref);
-
 
89
			pw.println("AMT="+amount);
-
 
90
			
-
 
91
			pw.flush();
-
 
92
		*/	
-
 
93
			
-
 
94
	String message = "Unable to process the payment. PLease try Again.";
-
 
95
	
39
	
96
	public PayResponseController(){
40
	public PaySuccessController(){
97
		super();
41
		super();
98
		try {
42
		try {
99
			pclient = new PaymentServiceClient();
43
			pclient = new PaymentServiceClient();
100
			tsc = new TransactionServiceClient();
44
			tsc = new TransactionServiceClient();
101
			usc = new UserContextServiceClient();
45
			usc = new UserContextServiceClient();
102
		} catch (Exception e) {
46
		} catch (Exception e) {
103
			Logger.log("Could not initialize the paymentservice client", this);
47
			Logger.log("Could not initialize the paymentservice client", this);
104
		}
48
		}
105
	}
49
	}
106
	
50
	
107
	public String index() throws IOException, SecurityException{
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");
108
    	if(!userinfo.isLoggedIn()){
54
    	if(!userinfo.isLoggedIn()){
-
 
55
    		System.out.println("Inside user is not logged in");
109
    		setRedirectUrl();
56
    		setRedirectUrl();
110
    		return "redirect";
57
    		return "redirect";
111
    	}
58
    	}
112
 
-
 
113
    	result = this.request.getParameter(RESULT);
-
 
114
		postdate = this.request.getParameter(POSTDATE);
-
 
115
		tranId = this.request.getParameter(TRANID);
-
 
116
		auth = this.request.getParameter(AUTH);
-
 
117
		ref = this.request.getParameter(REF);
-
 
118
		amount = this.request.getParameter(AMOUNT);
-
 
119
		paymentId = this.request.getParameter(PAYMENTID);
-
 
120
		if (result.equalsIgnoreCase(PaymentReturnStatus.CANCELLED.value())){
-
 
121
			trackId = this.request.getParameter(TRACKID_CANCELLED);
-
 
122
		}else{
-
 
123
			trackId = this.request.getParameter(TRACKID);
-
 
124
		}
-
 
125
		merchantPaymentId = Long.parseLong(trackId);
-
 
126
		sessionId = this.request.getSession().getId();
-
 
127
		errorNo = request.getParameter(ERROR);
-
 
128
		errorText = request.getParameter(ERRORTEXT);
-
 
129
		/*
-
 
130
		String udf1=request.getParameter("udf1");
-
 
131
		String udf2=request.getParameter("udf2");
-
 
132
		String udf3=request.getParameter("udf3");
-
 
133
		String udf4=request.getParameter("udf4");
-
 
134
		String udf5=request.getParameter("udf5");
-
 
135
		*/
-
 
136
		//update the payment info object
-
 
137
		try {
-
 
138
			if(result.trim().equals(PaymentReturnStatus.CAPTURED.value())){
-
 
139
				String message = "Payment successful";
-
 
140
				pclient.getClient().updatePaymentDetails(merchantPaymentId, paymentId, sessionId, result, message, tranId, auth, ref, errorNo, PaymentStatus.SUCCESS, null);
-
 
141
				txnId = pclient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
-
 
142
				
-
 
143
				tsc.getClient().changeTransactionStatus(txnId, TransactionStatus.IN_PROCESS, "Payment received for the order");
-
 
144
				
-
 
145
		    	orders = tsc.getClient().getOrdersForTransaction(txnId);
-
 
146
		    	Map<Long,Double> items = new HashMap<Long, Double>();
-
 
147
		    	
59
    	
148
				for(Order order: orders){
-
 
149
					for(LineItem lineitem: order.getLineitems()){
-
 
150
						items.put(lineitem.getItem_id(),lineitem.getQuantity());
-
 
151
					}
-
 
152
				}
-
 
153
				usc.getClient().resetCart(userinfo.getCartId(), items);
-
 
154
				//TODO Optimize the function to send less number of data over network
-
 
155
				userinfo.setTotalItems(Utils.getNumberOfItemsInCart(userinfo.getCartId()));
-
 
156
 
-
 
157
				return "index";
-
 
158
			}else{
-
 
159
				String message = "Unable to process the payment.";
60
		merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));
160
				addActionError("Previous payment failed. Try again.");
-
 
161
				
61
		
162
				txnId = pclient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
62
		long txnId = pclient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();
163
				tsc.getClient().changeTransactionStatus(txnId, TransactionStatus.FAILED, "Payment failed for the transaction.");
-
 
164
				
63
				
165
				pclient.getClient().updatePaymentDetails(merchantPaymentId, paymentId, sessionId, result, errorText, tranId, auth, ref, errorNo, PaymentStatus.FAILED, null);
-
 
166
				return "shipping-redirect";
64
		orders = tsc.getClient().getOrdersForTransaction(txnId);
167
			}
-
 
168
			
65
		
169
		}
66
		
170
		catch (NumberFormatException e) {
-
 
171
			Logger.log(e.toString(), this);
-
 
172
		} catch (PaymentException e) {
-
 
173
			Logger.log(e.toString(), this);
-
 
174
		} catch (TException e) {
-
 
175
			Logger.log(e.toString(), this);
-
 
176
		} catch (TransactionServiceException e) {
67
		this.userinfo.setTotalItems(Utils.getNumberOfItemsInCart(userinfo.getCartId()));
177
			Logger.log(e.toString(), this);
-
 
178
		} catch (ShoppingCartException e) {
-
 
179
			// TODO Auto-generated catch block
-
 
180
			e.printStackTrace();
-
 
181
		}
-
 
182
		return "index";
68
		return "index";
183
	}
69
	}
184
	
70
	
-
 
71
	
-
 
72
	
185
	public List<Order> getOrders(){
73
	public List<Order> getOrders(){
186
		return this.orders;
74
		return this.orders;
187
	}
75
	}
188
	
76
	
189
	public String getMessage(){
77
	public String getMessage(){