Subversion Repositories SmartDukaan

Rev

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

Rev 719 Rev 741
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
-
 
3
import java.util.ArrayList;
-
 
4
import java.util.HashMap;
-
 
5
import java.util.List;
3
import java.util.Map;
6
import java.util.Map;
-
 
7
import java.util.Random;
4
 
8
 
5
import javax.servlet.http.HttpServletResponse;
9
import javax.servlet.http.HttpServletResponse;
6
 
10
 
7
import org.apache.struts2.convention.annotation.Result;
11
import org.apache.struts2.convention.annotation.Result;
8
import org.apache.struts2.convention.annotation.Results;
12
import org.apache.struts2.convention.annotation.Results;
9
import org.apache.struts2.rest.DefaultHttpHeaders;
13
import org.apache.struts2.rest.DefaultHttpHeaders;
10
import org.apache.struts2.rest.HttpHeaders;
14
import org.apache.struts2.rest.HttpHeaders;
11
import org.apache.thrift.TException;
15
import org.apache.thrift.TException;
12
 
16
 
13
import in.shop2020.config.ConfigException;
17
import in.shop2020.config.ConfigException;
-
 
18
import in.shop2020.payments.Attribute;
14
import in.shop2020.payments.PaymentException;
19
import in.shop2020.payments.PaymentException;
-
 
20
import in.shop2020.payments.PaymentStatus;
15
import in.shop2020.serving.utils.Utils;
21
import in.shop2020.serving.utils.Utils;
16
import in.shop2020.thrift.clients.PaymentServiceClient;
22
import in.shop2020.thrift.clients.PaymentServiceClient;
17
import in.shop2020.thrift.clients.config.ConfigClient;
23
import in.shop2020.thrift.clients.config.ConfigClient;
18
 
24
 
19
 
25
 
Line 53... Line 59...
53
	
59
	
54
	public String getRedirectURL(){
60
	public String getRedirectURL(){
55
		return this.redirectURL;
61
		return this.redirectURL;
56
	}
62
	}
57
	
63
	
58
	public HttpHeaders show(){
-
 
59
		return new DefaultHttpHeaders("lfail");
-
 
60
 
-
 
61
	}
-
 
62
	
-
 
63
	public String index(){
64
	public String index(){
64
		String orderDetails = "";
65
		String orderDetails = "";
65
		String email = "";
66
		String email = "";
66
		String contactNumber = "";
67
		String contactNumber = "";
67
		String billingAddress = "";
68
		String billingAddress = "";
Line 84... Line 85...
84
		
85
		
85
		
86
		
86
//	    Random rnd = new Random(System.currentTimeMillis());
87
//	    Random rnd = new Random(System.currentTimeMillis());
87
//		String trackId = String.valueOf(Math.abs(rnd.nextLong()));	//Merchant must generate the Track Id
88
//		String trackId = String.valueOf(Math.abs(rnd.nextLong()));	//Merchant must generate the Track Id
88
		
89
		
89
		String paymentId = request.getParameter("paymentid");	
90
		String merchantPaymentId = request.getParameter("paymentid");	
90
		
91
		
91
		session.setAttribute("trackId",paymentId);
92
		session.setAttribute("trackId",merchantPaymentId);
92
//		String InstituteID=request.getParameter("InstituteID");	//Must be 1 for the merchant having only one bank(mandatory must be initilized)
93
//		String InstituteID=request.getParameter("InstituteID");	//Must be 1 for the merchant having only one bank(mandatory must be initilized)
93
	
94
	
94
		
95
		
95
		//Following is the code which initilize e24PaymentPipe with proper value
96
		//Following is the code which initilize e24PaymentPipe with proper value
96
		e24PaymentPipe pipe=new e24PaymentPipe();
97
		e24PaymentPipe pipe=new e24PaymentPipe();
Line 146... Line 147...
146
 
147
 
147
		pipe.setLanguage("USA");
148
		pipe.setLanguage("USA");
148
		String p=pipe.getLanguage();
149
		String p=pipe.getLanguage();
149
		System.out.println("Language="+p+ "<br>");
150
		System.out.println("Language="+p+ "<br>");
150
        
151
        
151
		pipe.setTrackId(paymentId);
152
		pipe.setTrackId(merchantPaymentId);
152
		
153
		
153
 
154
 
154
		orderDetails = Utils.getOrderDetails(userinfo.getCartId());
155
		orderDetails = Utils.getOrderDetails(txnId);
155
		email = Utils.getEmailId(userinfo.getUserId());
156
		email = Utils.getEmailId(userinfo.getUserId());
156
		contactNumber = Utils.getContactNumber(userinfo.getCartId());
157
		contactNumber = Utils.getContactNumber(txnId);
157
		billingAddress = Utils.getBillingAddress(userinfo.getCartId());
158
		billingAddress = Utils.getBillingAddress(txnId);
-
 
159
		
-
 
160
		String regex = "[^a-zA-Z0-9\\s\\-\\@\\/\\.]";
-
 
161
		String replacement = " ";
-
 
162
		
-
 
163
		orderDetails = orderDetails.replaceAll(regex, replacement);
-
 
164
		email = email.replaceAll(regex, replacement);
-
 
165
		contactNumber = replacement.replaceAll(regex, replacement);
-
 
166
		billingAddress = billingAddress.replaceAll(regex, replacement);
-
 
167
		if(orderDetails.length() > 250){
-
 
168
			orderDetails = orderDetails.substring(0, 249);
-
 
169
		}
-
 
170
		if(billingAddress.length() > 250){
-
 
171
			billingAddress = billingAddress.substring(0, 249);
-
 
172
		}
-
 
173
		Random random = new Random();
158
		merchantInfo = "Shop2020";
174
		merchantInfo = ""+random.nextLong(); 
159
		
175
		
160
		
176
		
161
//		UDF 1 - Order details
177
//		UDF 1 - Order details
162
//		UDF 2 - Email ID
178
//		UDF 2 - Email ID
163
//		UDF 3 - Contact Number. 
179
//		UDF 3 - Contact Number. 
164
//		UDF 4 - Billing Address
180
//		UDF 4 - Billing Address
165
//		UDF 5 - Merchant specific
181
//		UDF 5 - Merchant specific
-
 
182
		
166
		/*
183
		
-
 
184
        System.out.println("udf1:"  + orderDetails);
-
 
185
        System.out.println("udf2:"  + email);
-
 
186
        System.out.println("udf3:"  + contactNumber);
-
 
187
        System.out.println("udf4:"  + billingAddress);
-
 
188
        System.out.println("udf5:"  + merchantInfo);
-
 
189
        
-
 
190
        
167
		pipe.setUdf1(orderDetails);
191
		pipe.setUdf1(orderDetails);
168
		pipe.setUdf2(email);
192
		pipe.setUdf2(email);
169
		pipe.setUdf3(contactNumber);
193
		pipe.setUdf3(contactNumber);
170
		pipe.setUdf4(billingAddress);
194
		pipe.setUdf4(billingAddress);
171
        pipe.setUdf5(merchantInfo);
195
		pipe.setUdf5(merchantInfo);
172
		 */
196
		
-
 
197
		List<Attribute> attributes = new ArrayList<Attribute>();
-
 
198
		Attribute attribute1 = new Attribute();
-
 
199
		Attribute attribute2 = new Attribute();
-
 
200
		Attribute attribute3 = new Attribute();
-
 
201
		Attribute attribute4 = new Attribute();
-
 
202
		Attribute attribute5 = new Attribute();
-
 
203
		attribute1.setName("udf1");
-
 
204
		attribute1.setValue(orderDetails);
-
 
205
		attribute2.setName("udf2");
-
 
206
		attribute2.setValue(email);
-
 
207
		attribute3.setName("udf3");
-
 
208
		attribute3.setValue(contactNumber);
-
 
209
		attribute4.setName("udf4");
-
 
210
		attribute4.setValue(billingAddress);
-
 
211
		attribute5.setName("udf5");
-
 
212
		attribute5.setValue(merchantInfo);
-
 
213
		attributes.add(attribute1);
-
 
214
		attributes.add(attribute2);
-
 
215
		attributes.add(attribute3);
-
 
216
		attributes.add(attribute4);
-
 
217
		attributes.add(attribute5);
173
		
218
		
174
		try {
219
		try {
175
			if(pipe.performPaymentInitialization() != e24PaymentPipe.SUCCESS) 
220
			if(pipe.performPaymentInitialization() != e24PaymentPipe.SUCCESS) 
176
				{
221
				{
177
					System.out.println("Error sending Payment Initialization Request: ");
222
					System.out.println("Error sending Payment Initialization Request: ");
-
 
223
					paymentServiceClient.getClient().updatePaymentDetails(Long.parseLong(merchantPaymentId), null, "", "", pipe.getErrorMsg(), "", "", "", "", PaymentStatus.INIT, attributes);
178
					response.sendRedirect(response.encodeRedirectURL( errorURL + "?ErrorText="+pipe.getErrorMsg()+"&paymentId="+paymentId));
224
					response.sendRedirect(response.encodeRedirectURL( errorURL + "?ErrorText="+pipe.getErrorMsg()+"&paymentId="+merchantPaymentId));
179
					redirectURL = errorURL + "?ErrorText="+pipe.getErrorMsg();
225
					redirectURL = errorURL + "?ErrorText="+pipe.getErrorMsg();
180
					response.setHeader("Location", redirectURL);
226
					response.setHeader("Location", redirectURL);
181
					response.setStatus(HttpServletResponse.SC_FOUND);
227
					response.setStatus(HttpServletResponse.SC_FOUND);
182
				}
228
				}
183
			else
229
			else
184
				{
230
				{
185
					String PaymentID = pipe.getPaymentId();
231
					String paymentID = pipe.getPaymentId();
-
 
232
					// Update of payment information
-
 
233
					paymentServiceClient.getClient().updatePaymentDetails(Long.parseLong(merchantPaymentId), paymentID, "", "", "", "", "", "", "", PaymentStatus.INIT, attributes);
-
 
234
					
186
					String payURL = pipe.getPaymentPage();
235
					String payURL = pipe.getPaymentPage();
187
					redirectURL = payURL + "?PaymentID=" + PaymentID;
236
					redirectURL = payURL + "?PaymentID=" + paymentID;
188
					response.sendRedirect(response.encodeRedirectURL( redirectURL ));
237
					response.sendRedirect(response.encodeRedirectURL( redirectURL ));
189
					
238
					
190
					response.setHeader("Location", redirectURL);
239
					response.setHeader("Location", redirectURL);
191
					response.setStatus(HttpServletResponse.SC_FOUND);
240
					response.setStatus(HttpServletResponse.SC_FOUND);
192
				}
241
				}
Line 198... Line 247...
198
			// TODO Auto-generated catch block
247
			// TODO Auto-generated catch block
199
			e.printStackTrace();
248
			e.printStackTrace();
200
		}
249
		}
201
		
250
		
202
		//response.sendRedirect(response.encodeRedirectURL( "www.yahoo.com" ));
251
		//response.sendRedirect(response.encodeRedirectURL( "www.yahoo.com" ));
203
		
-
 
-
 
252
		redirectURL = errorURL + "?ErrorText=Error while initializing payment.";
204
		return "fail";
253
		return "success";
205
	}
254
	}
206
	
255
	
207
	String getUrl(){
256
	String getUrl(){
208
		return this.redirectURL;
257
		return this.redirectURL;
209
	}
258
	}