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