|
Rank: Starting Member
Groups: Registered
Joined: 3/30/2006 Posts: 2 Location: ,
|
Hi,
I am trying to integrate my application with paypal to create user subscriptions. I have enabled PDT and IPN and the PDT return url redirects to a struts action class. I need to get the subscription id, and subscription amount to display in the success page. But, when I try to get the 'tx' parameter from the request, it is null, so when I post the notification validation url to Paypal, I get FAIL as the response. Could someone please tell me what could be the issue?
Below is the code of in the action class.
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
HttpSession session = request.getSession(false);
ActionErrors errors = new ActionErrors();
ActionForward forward = mapping.findForward("self_registration_success");
logger.info("In PDTNotification.execute() ");
String txId = request.getParameter("tx");
String authToken = "yC4XUx5hm_8t0Ca3SoGysCg5D5lPi5-ACBS2_lh0OaNn8RWGcdtDKg0pfbm";
String str = "cmd=_notify-synch";
Enumeration en = request.getParameterNames();
while(en.hasMoreElements()){
String paramName = (String)en.nextElement();
String paramValue = request.getParameter(paramName);
str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue);
}
str = str + "&at=" + authToken;
try {
URL u = new URL("http://www.sandbox.paypal.com/cgi-bin/webscr");
URLConnection uc = u.openConnection();
uc.setDoOutput(true);
uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
PrintWriter pw = new PrintWriter(uc.getOutputStream());
pw.println(str);
pw.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(uc.getInputStream()));
String res = in.readLine();
in.close();
if(res.equals("SUCCESS")) {
logger.info("Paypal PDT Notification Response : "+res);
activateNewUser(user, errors);
} else if(res.equals("FAIL")) {
logger.info("Paypal PDT Notification Response : "+res);
errors.add("error.paypal.registration", new ActionError("error.paypal.registration"));
saveErrors(request , errors);
forward = mapping.findForward("self_registration_success");
return forward;
}
String line = null;
String key = "";
String value = "";
while(( line = in.readLine()) != null) {
logger.info(line);
if(!res.equals("SUCCESS")) {
StringTokenizer st = new StringTokenizer(line, "=");
while(st.hasMoreTokens()) {
key = st.nextToken();
value = st.nextToken();
}
}
}
} catch(Exception e) {
logger.error("Exception in execute() ", e);
}
return forward;
}
Thanks,
Harini
|