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