Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
421 rajveer 1
package in.shop2020.serving.controllers;
2
 
3
import javax.servlet.http.HttpServletResponse;
4
import org.apache.struts2.rest.DefaultHttpHeaders;
5
import org.apache.struts2.rest.HttpHeaders;
6
import org.apache.thrift.TException;
7
 
8
import in.shop2020.config.ConfigException;
9
import in.shop2020.payments.PaymentException;
10
import in.shop2020.serving.utils.Utils;
11
import in.shop2020.thrift.clients.PaymentServiceClient;
12
import in.shop2020.thrift.clients.config.ConfigClient;
13
 
14
 
15
 
16
import com.aciworldwide.commerce.gateway.plugins.NotEnoughDataException;
17
import com.aciworldwide.commerce.gateway.plugins.e24PaymentPipe;
18
/*
19
@Results({
20
    @Result(name="success", type="redirectAction", params = {"actionName" , 
21
    		"pay"})
22
})
23
*/
682 rajveer 24
public class HdfcPayController extends BaseController {
421 rajveer 25
 
682 rajveer 26
	private static final long serialVersionUID = 1L;
27
 
421 rajveer 28
	PaymentServiceClient paymentServiceClient = null;
29
	private String redirectURL;
682 rajveer 30
	private enum ActionType{
31
		PURCHASE("1"),
32
		AUTH ("4");
33
		private String value;
34
		ActionType(String value) {
35
			this.value = value;
36
		}
37
		public String value(){
38
			return this.value;
39
		}
40
	}
421 rajveer 41
 
682 rajveer 42
	public HdfcPayController(){
421 rajveer 43
		try {
44
			paymentServiceClient = new PaymentServiceClient();
45
		} catch (Exception e) {
46
			e.printStackTrace();
47
		}
48
	}
49
 
50
	public String getRedirectURL(){
51
		return this.redirectURL;
52
	}
53
 
54
	public HttpHeaders show(){
55
		return new DefaultHttpHeaders("lfail");
56
 
57
	}
58
 
59
	public HttpHeaders create(){
60
		String orderDetails = "";
61
		String email = "";
62
		String contactNumber = "";
63
		String billingAddress = "";
64
		String merchantInfo = "";
424 rajveer 65
		String amount;
682 rajveer 66
 
424 rajveer 67
		try{
682 rajveer 68
			amount = request.getParameter("amount");
424 rajveer 69
		}catch(Exception e){
70
			amount = (new Double(Utils.getPaymentAmount(userinfo.getCartId()))).toString();
71
		}
682 rajveer 72
 
421 rajveer 73
		// May be we can use some utils function to get the prices in cart but it is better to get price from post form
74
 
75
		long paymentId = 0;
76
		in.shop2020.payments.PaymentService.Client client = paymentServiceClient.getClient();
77
 
78
 
79
		try {
80
			paymentId = client.createPayment(userinfo.getUserId(), userinfo.getCartId(), Double.parseDouble(amount), 1);
81
		} catch (NumberFormatException e1) {
82
			// TODO Auto-generated catch block
83
			e1.printStackTrace();
84
		} catch (PaymentException e1) {
85
			// TODO Auto-generated catch block
86
			e1.printStackTrace();
87
		} catch (TException e1) {
88
			// TODO Auto-generated catch block
89
			e1.printStackTrace();
90
		}
91
 
92
 
93
 
94
 
95
//	    Random rnd = new Random(System.currentTimeMillis());
96
//		String trackId = String.valueOf(Math.abs(rnd.nextLong()));	//Merchant must generate the Track Id
97
 
98
		String trackId = (new Long(paymentId)).toString();
99
 
100
 
101
		session.setAttribute("trackId",trackId);
102
//		String InstituteID=request.getParameter("InstituteID");	//Must be 1 for the merchant having only one bank(mandatory must be initilized)
103
 
104
 
105
		//Following is the code which initilize e24PaymentPipe with proper value
106
		e24PaymentPipe pipe=new e24PaymentPipe();
107
		String resourceFilePath = "";
108
		String aliasName = "";
109
		String responseURL = "";
110
		String errorURL = "";
111
		try {
112
			resourceFilePath = ConfigClient.getClient().get("payment_resource_file_path");
113
			aliasName  = ConfigClient.getClient().get("payment_alias_name");
114
			responseURL = ConfigClient.getClient().get("payment_response_url");
115
			errorURL = ConfigClient.getClient().get("payment_error_url");
116
		} catch (ConfigException e1) {
117
			// TODO Auto-generated catch block
118
			resourceFilePath = "/home/rajveer/shop2020/payments/resource/";
119
			aliasName = "90001194";
120
 
517 rajveer 121
			responseURL = "http://74.207.248.175:8080/JSP-Pages/HRedirect.jsp";
122
			errorURL = "http://74.207.248.175:8080/JSP-Pages/HError.jsp";
421 rajveer 123
//			responseURL = "http://securemtp.fssnet.co.in/MerchantDemo/viren/TESTTEST/HRedirect.jsp";
124
//			errorURL = "http://securemtp.fssnet.co.in/MerchantDemo/viren/TESTTEST/HError.jsp";
125
			e1.printStackTrace();
126
		}
127
 
128
		pipe.setResourcePath(resourceFilePath);	//mandatory 
129
		String as = pipe.getResourcePath();
130
		System.out.println("Resource="+as+ "<br>");
131
 
132
		pipe.setAlias(aliasName);			//mandatory 
133
		String ab=pipe.getAlias();
134
		System.out.println("Alias="+ab+ "<br>");
135
 
682 rajveer 136
		pipe.setAction(ActionType.PURCHASE.value());			//mandatory 
421 rajveer 137
		String ac=pipe.getAction();
138
		System.out.println("Action="+ac+ "<br>");
139
 
140
		pipe.setResponseURL( responseURL );	//mandatory
141
		String at=pipe.getResponseURL();
142
		System.out.println("ResponseURL="+at+ "<br>");
143
 
144
		pipe.setErrorURL( errorURL );		//mandatory 
145
        String ak=pipe.getErrorURL();
146
        System.out.println("ErrorURL="+ak+ "<br>");
147
 
148
 
149
		pipe.setAmt(amount);		
150
		String ap=pipe.getAmt();
151
		System.out.println("Amt="+ap);
152
 
153
		pipe.setCurrency("356");
154
		String a=pipe.getCurrency();
155
		System.out.println("Currency="+a+ "<br>");
156
 
157
		pipe.setLanguage("USA");
158
		String p=pipe.getLanguage();
159
		System.out.println("Language="+p+ "<br>");
160
 
161
		pipe.setTrackId(trackId);
162
 
163
 
164
		orderDetails = Utils.getOrderDetails(userinfo.getCartId());
165
		email = Utils.getEmailId(userinfo.getUserId());
166
		contactNumber = Utils.getContactNumber(userinfo.getCartId());
167
		billingAddress = Utils.getBillingAddress(userinfo.getCartId());
168
		merchantInfo = "Shop2020";
169
 
170
 
171
//		UDF 1 - Order details
172
//		UDF 2 - Email ID
173
//		UDF 3 - Contact Number. 
174
//		UDF 4 - Billing Address
175
//		UDF 5 - Merchant specific
517 rajveer 176
		/*
421 rajveer 177
		pipe.setUdf1(orderDetails);
178
		pipe.setUdf2(email);
179
		pipe.setUdf3(contactNumber);
180
		pipe.setUdf4(billingAddress);
181
        pipe.setUdf5(merchantInfo);
517 rajveer 182
		 */
183
 
421 rajveer 184
		try {
185
			if(pipe.performPaymentInitialization() != e24PaymentPipe.SUCCESS) 
186
				{
187
					System.out.println("Error sending Payment Initialization Request: ");
188
					response.sendRedirect(response.encodeRedirectURL( errorURL + "?ErrorText="+pipe.getErrorMsg()));
189
					redirectURL = errorURL + "?ErrorText="+pipe.getErrorMsg();
190
					response.setHeader("Location", redirectURL);
191
					response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
192
				}
193
			else
194
				{
195
					String PaymentID = pipe.getPaymentId();
196
					String payURL = pipe.getPaymentPage();
197
					response.sendRedirect(response.encodeRedirectURL( payURL + "?PaymentID=" + PaymentID ));
198
 
199
					redirectURL = payURL + "?PaymentID=" + PaymentID;
200
					response.setHeader("Location", redirectURL);
201
					response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
202
				}
203
			return new DefaultHttpHeaders("success");
204
		} catch (NotEnoughDataException e) {
205
			// TODO Auto-generated catch block
206
			e.printStackTrace();
207
		}catch (Exception e) {
208
			// TODO Auto-generated catch block
209
			e.printStackTrace();
210
		}
211
 
212
		//response.sendRedirect(response.encodeRedirectURL( "www.yahoo.com" ));
213
 
214
		return new DefaultHttpHeaders("fail");
215
	}
216
 
217
}
218