Subversion Repositories SmartDukaan

Rev

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

Rev 693 Rev 712
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
-
 
3
import java.util.Map;
-
 
4
 
3
import javax.servlet.http.HttpServletResponse;
5
import javax.servlet.http.HttpServletResponse;
-
 
6
 
-
 
7
import org.apache.struts2.convention.annotation.Result;
-
 
8
import org.apache.struts2.convention.annotation.Results;
4
import org.apache.struts2.rest.DefaultHttpHeaders;
9
import org.apache.struts2.rest.DefaultHttpHeaders;
5
import org.apache.struts2.rest.HttpHeaders;
10
import org.apache.struts2.rest.HttpHeaders;
6
import org.apache.thrift.TException;
11
import org.apache.thrift.TException;
7
 
12
 
8
import in.shop2020.config.ConfigException;
13
import in.shop2020.config.ConfigException;
Line 13... Line 18...
13
 
18
 
14
 
19
 
15
 
20
 
16
import com.aciworldwide.commerce.gateway.plugins.NotEnoughDataException;
21
import com.aciworldwide.commerce.gateway.plugins.NotEnoughDataException;
17
import com.aciworldwide.commerce.gateway.plugins.e24PaymentPipe;
22
import com.aciworldwide.commerce.gateway.plugins.e24PaymentPipe;
18
/*
-
 
19
@Results({
23
@Results({
20
    @Result(name="success", type="redirectAction", params = {"actionName" , 
24
	@Result(name="redirect", type="redirectAction", 
21
    		"pay"})
25
			params = {"actionName" , "${url}"})
22
})
26
})
23
*/
27
 
24
public class HdfcPayController extends BaseController {
28
public class HdfcPayController extends BaseController {
25
	
29
	
26
	private static final long serialVersionUID = 1L;
30
	private static final long serialVersionUID = 1L;
27
	
31
	
28
	PaymentServiceClient paymentServiceClient = null;
32
	PaymentServiceClient paymentServiceClient = null;
Line 54... Line 58...
54
	public HttpHeaders show(){
58
	public HttpHeaders show(){
55
		return new DefaultHttpHeaders("lfail");
59
		return new DefaultHttpHeaders("lfail");
56
 
60
 
57
	}
61
	}
58
	
62
	
59
	public HttpHeaders create(){
63
	public String index(){
60
		String orderDetails = "";
64
		String orderDetails = "";
61
		String email = "";
65
		String email = "";
62
		String contactNumber = "";
66
		String contactNumber = "";
63
		String billingAddress = "";
67
		String billingAddress = "";
64
		String merchantInfo = "";
68
		String merchantInfo = "";
65
		String amount;
69
		String amount;
66
		long txnId;
70
		long txnId;
-
 
71
		
-
 
72
		
-
 
73
		System.out.println("amount:" + request.getParameter("amount"));
-
 
74
		System.out.println("amount:" + request.getParameter("txnid"));
-
 
75
		System.out.println("amount:" + request.getParameter("paymentid"));
-
 
76
		
67
		try{
77
		try{
68
			amount = request.getParameter("amount");
78
			amount = request.getParameter("amount");
69
		}catch(Exception e){
79
		}catch(Exception e){
70
			amount = (new Double(Utils.getPaymentAmount(userinfo.getCartId()))).toString();
80
			amount = (new Double(Utils.getPaymentAmount(userinfo.getCartId()))).toString();
71
		}
81
		}
72
		txnId = Long.parseLong(request.getParameter("tranid"));
82
		txnId = Long.parseLong(request.getParameter("txnid"));
73
		
-
 
74
		// May be we can use some utils function to get the prices in cart but it is better to get price from post form
-
 
75
		
-
 
76
		long paymentId = 0;
-
 
77
		in.shop2020.payments.PaymentService.Client client = paymentServiceClient.getClient();
-
 
78
	
-
 
79
		
-
 
80
		try {
-
 
81
			
83
			
82
			paymentId = client.createPayment(userinfo.getUserId(), Double.parseDouble(amount), 1, txnId);
-
 
83
		} catch (NumberFormatException e1) {
-
 
84
			// TODO Auto-generated catch block
-
 
85
			e1.printStackTrace();
-
 
86
		} catch (PaymentException e1) {
-
 
87
			// TODO Auto-generated catch block
-
 
88
			e1.printStackTrace();
-
 
89
		} catch (TException e1) {
-
 
90
			// TODO Auto-generated catch block
-
 
91
			e1.printStackTrace();
-
 
92
		}
-
 
93
		
-
 
94
		
-
 
95
		
84
		
96
		
85
		
97
//	    Random rnd = new Random(System.currentTimeMillis());
86
//	    Random rnd = new Random(System.currentTimeMillis());
98
//		String trackId = String.valueOf(Math.abs(rnd.nextLong()));	//Merchant must generate the Track Id
87
//		String trackId = String.valueOf(Math.abs(rnd.nextLong()));	//Merchant must generate the Track Id
99
		
88
		
100
		String trackId = (new Long(paymentId)).toString();
89
		String paymentId = request.getParameter("paymentid");	
101
			
-
 
102
		
90
		
103
		session.setAttribute("trackId",trackId);
91
		session.setAttribute("trackId",paymentId);
104
//		String InstituteID=request.getParameter("InstituteID");	//Must be 1 for the merchant having only one bank(mandatory must be initilized)
92
//		String InstituteID=request.getParameter("InstituteID");	//Must be 1 for the merchant having only one bank(mandatory must be initilized)
105
	
93
	
106
		
94
		
107
		//Following is the code which initilize e24PaymentPipe with proper value
95
		//Following is the code which initilize e24PaymentPipe with proper value
108
		e24PaymentPipe pipe=new e24PaymentPipe();
96
		e24PaymentPipe pipe=new e24PaymentPipe();
Line 158... Line 146...
158
 
146
 
159
		pipe.setLanguage("USA");
147
		pipe.setLanguage("USA");
160
		String p=pipe.getLanguage();
148
		String p=pipe.getLanguage();
161
		System.out.println("Language="+p+ "<br>");
149
		System.out.println("Language="+p+ "<br>");
162
        
150
        
163
		pipe.setTrackId(trackId);
151
		pipe.setTrackId(paymentId);
164
		
152
		
165
 
153
 
166
		orderDetails = Utils.getOrderDetails(userinfo.getCartId());
154
		orderDetails = Utils.getOrderDetails(userinfo.getCartId());
167
		email = Utils.getEmailId(userinfo.getUserId());
155
		email = Utils.getEmailId(userinfo.getUserId());
168
		contactNumber = Utils.getContactNumber(userinfo.getCartId());
156
		contactNumber = Utils.getContactNumber(userinfo.getCartId());
Line 200... Line 188...
200
					
188
					
201
					redirectURL = payURL + "?PaymentID=" + PaymentID;
189
					redirectURL = payURL + "?PaymentID=" + PaymentID;
202
					response.setHeader("Location", redirectURL);
190
					response.setHeader("Location", redirectURL);
203
					response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
191
					response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
204
				}
192
				}
205
			return new DefaultHttpHeaders("success");
193
			return "success";
206
		} catch (NotEnoughDataException e) {
194
		} catch (NotEnoughDataException e) {
207
			// TODO Auto-generated catch block
195
			// TODO Auto-generated catch block
208
			e.printStackTrace();
196
			e.printStackTrace();
209
		}catch (Exception e) {
197
		}catch (Exception e) {
210
			// TODO Auto-generated catch block
198
			// TODO Auto-generated catch block
211
			e.printStackTrace();
199
			e.printStackTrace();
212
		}
200
		}
213
		
201
		
214
		//response.sendRedirect(response.encodeRedirectURL( "www.yahoo.com" ));
202
		//response.sendRedirect(response.encodeRedirectURL( "www.yahoo.com" ));
215
		
203
		
-
 
204
		return "fail";
-
 
205
	}
-
 
206
	
-
 
207
	String getUrl(){
216
		return new DefaultHttpHeaders("fail");
208
		return this.redirectURL;
217
	}
209
	}
218
 
210
 
219
}
211
}
220
 
212