YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

PDT works on Sandbox but not Live Options
paypal@jthink.net
#1 Posted : Thursday, January 13, 2005 7:16:53 AM
Rank: Starting Member

Groups: Registered

Joined: 1/13/2005
Posts: 6
Location: ,
I have Java code runnning against Sandbox fine but it fails on Live. It returns a FAIL response when verifying the PDT. Is there any difference between these two environments, (I think I tried Live in the past and it worked a few months ago). Below I have posted my Java code could anyone take a look and see why isnt working public class VerifyPayment extends AbstractAction { private static String PAYPALUSER; private static int PAYPALITEMNO; private static final String PAGE_SUCCESS = "/jsp/buy/success.jsp"; private static final String PAGE_FAILURE = "/jsp/buy/failure.jsp"; private static final String PAGE_CANCEL = "/jsp/buy/cancel.jsp"; private static String URL_PAYPAL_VALIDATE; //PDT 1st Response Variables private static final String PARAM_TX = "tx"; private static final String PARAM_CMD = "cmd"; private static final String PARAM_CMD_VALUE = "_notify-synch"; private static final String PARAM_AT = "at"; private static String PARAM_AT_VALUE; private static final String PARAM_ITEM_NAME = "item_name"; private static final String PARAM_ITEM_NUMBER = "item_number"; private static final String PARAM_PAYMENT_STATUS = "payment_status"; private static final String PARAM_MC_GROSS = "mc_gross"; private static final String PARAM_MC_CURRENCY = "mc_currency"; private static final String PARAM_TXN_ID = "txn_id"; private static final String PARAM_RECEIVER_EMAIL = "receiver_email"; private static final String PARAM_PAYER_EMAIL = "payer_email"; private static final String RESPONSE_SUCCESS = "SUCCESS"; private static final String RESPONSE_FAIL = "FAIL"; private static final String PARAM_PAYPALEMAILADDRESS = "paypalemailaddress"; static { URL_PAYPAL_VALIDATE = (String) wb.getValue(Prefs.PATH_FULL_LICENSE, Prefs.EL_PAYPALVALIDATE); PARAM_AT_VALUE = (String) wb.getValue(Prefs.PATH_FULL_LICENSE, Prefs.EL_PAYPALPDT); PAYPALUSER = (String) wb.getValue(Prefs.PATH_FULL_LICENSE, Prefs.EL_PAYPALUSER); PAYPALITEMNO = ((Integer) wb.getValue(Prefs.PATH_FULL_LICENSE, Prefs.EL_PAYPALITEMNO)).intValue(); } public String handleRequest(Session session, HttpServletRequest request, HttpServletResponse response, String page) { try { // Read Get from PayPal and create encoded response to get full txn details String txn = request.getParameter(PARAM_TX); //Cancelled if (txn == null) { session.getUserFeedback().addMsgInfo(Messages.getMsg(Messages.BUY_CANCEL)); return PAGE_CANCEL; } //Display get from PayPal and decode it. Enumeration en = request.getParameterNames(); String readString = ""; while (en.hasMoreElements()) { String paramName = (String) en.nextElement(); String paramValue = request.getParameter(paramName); readString = readString + "&" + paramName + "=" + URLDecoder.decode(paramValue, "UTF-8"); } Controller.logger.finer("Received PDT from PayPal:" + readString); //Construct String String str = PARAM_CMD + "=" + PARAM_CMD_VALUE; en = request.getParameterNames(); while (en.hasMoreElements()) { String paramName = (String) en.nextElement(); String paramValue = request.getParameter(paramName); str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue, "UTF-8"); } str = str + "&" + PARAM_AT + "=" + PARAM_AT_VALUE; Controller.logger.finer("Sending PDT to PayPal:" + str); // Send back to PayPal system to validate using POST URL u = new URL(URL_PAYPAL_VALIDATE); HttpURLConnection uc = (HttpURLConnection) 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(); if (res.equals(RESPONSE_SUCCESS)) { String[] temp; HashMap vars = new HashMap(); while ((res = in.readLine()) != null) { temp = res.split("="); if (temp.length == 2) { vars.put(temp[0], URLDecoder.decode(temp[1], "UTF-8")); } else { vars.put(temp[0], ""); } } // Assign posted variables to local variables String itemName = (String) vars.get(PARAM_ITEM_NAME); int itemNumber = Integer.parseInt((String) vars.get(PARAM_ITEM_NUMBER)); String paymentStatus = (String) vars.get(PARAM_PAYMENT_STATUS); String paymentAmount = (String) vars.get(PARAM_MC_GROSS); String paymentCurrency = (String) vars.get(PARAM_MC_CURRENCY); String txnId = (String) vars.get(PARAM_TXN_ID); String receiverEmail = (String) vars.get(PARAM_RECEIVER_EMAIL); String payerEmail = (String) vars.get(PARAM_PAYER_EMAIL); if(confirmTransaction(session,txnId,receiverEmail,itemNumber)==true) { Controller.logger.finer("Transaction OK"); session.getUserData().setValue(PARAM_PAYPALEMAILADDRESS, payerEmail); session.getUserFeedback().addMsgConfirm(Messages.getMsg(Messages.BUY_SUCCESS)); return PAGE_SUCCESS; } else { Controller.logger.finer("Transaction FAILED"); session.getUserFeedback().addMsgError(Messages.getMsg(Messages.BUY_ERROR)); return PAGE_FAILURE; } } else if (res.equals(RESPONSE_FAIL)) { Controller.logger.finer("Response FAILED"); // log for investigation session.getUserFeedback().addMsgError(Messages.getMsg(Messages.BUY_ERROR)); return PAGE_FAILURE; } else { Controller.logger.finer("Response CANCELLED"); session.getUserFeedback().addMsgInfo(Messages.getMsg(Messages.BUY_CANCEL)); return PAGE_FAILURE; } } catch (Exception e) { e.printStackTrace(); session.getUserFeedback().addMsgError(Messages.getMsg(Messages.BUY_ERROR)); return PAGE_FAILURE; } } /** * PayPal has verified the transaction, now need to a few more checks to confirm */ private boolean confirmTransaction(Session session, String txnId, String receiverEmail, int itemNumber) { Controller.logger.finer("Double Checking transaction"); //Check txnId to make sure not reprocessing //Check ReceiverEmail address is my address. if (!receiverEmail.equals(PAYPALUSER)) { Controller.logger.warning("Invalid Email" + receiverEmail); session.getUserFeedback().addMsgError("Invalid Email Address provided"); return false; } //Check Item No is correct if (itemNumber != PAYPALITEMNO) { Controller.logger.warning("Invalid Item Number" + receiverEmail + ":" + itemNumber); session.getUserFeedback().addMsgError("Invalid Item Number provided"); return false; } //Check Correct amount has been paid. Controller.logger.finer("Transaction checked ok"); return true; } }
Sponsor  
 
paypal@jthink.net
#2 Posted : Thursday, January 13, 2005 11:29:42 AM
Rank: Starting Member

Groups: Registered

Joined: 1/13/2005
Posts: 6
Location: ,
Despite the fact that the posted works n the Sandbox Ive reread the manual and it seems to be indicating I only need to post back tx,at and cmd so Ive simplified the code and tried it again but still fails with the same error.

So code below and example output(Formatted to make it easier to read)

To anyone at Paypal I think it would be a good idea if you post some Java examples in your sample code it would make things much easier. (Java not JSP to avoid confusion).
//Display get from PayPal and decode it.
Enumeration en = request.getParameterNames();
String readString = "";
while (en.hasMoreElements())
{
String paramName = (String) en.nextElement();
String paramValue = request.getParameter(paramName);
readString = readString + "&" + paramName + "=" + URLDecoder.decode(paramValue, "UTF-8");
}
Controller.logger.finer("Received PDT from PayPal:" + readString);

//Construct String to Post Back
String transValue = request.getParameter(PARAM_TX);
String str = PARAM_TX + "=" + URLDecoder.decode(transValue,"UTF-8");
str = str + "&" + PARAM_AT + "=" + URLDecoder.decode(PARAM_AT_VALUE,"UTF-8");
str = str + "&" + PARAM_CMD + "=" + URLDecoder.decode(PARAM_CMD_VALUE,"UTF-8");
Controller.logger.finer("Sending PDT to PayPal:" + str);

// Send back to PayPal system to validate using POST
URL u = new URL(URL_PAYPAL_VALIDATE);
HttpURLConnection uc = (HttpURLConnection) 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();
if (res.equals(RESPONSE_SUCCESS))
{
Controller.logger.finer("Response SUCCESS");
}
else if (res.equals(RESPONSE_FAILED))
{
Controller.logger.finer("Response FAILED");
}
else
{
Controller.logger.finer("Response INVALID");
}

VerifyPayment:handleRequest:FINER: Received PDT from PayPal:
&cm=
&tx=3C860370XJ139983J
&st=Completed
&action=VerifyPayment
&sig=lxcifnPp00P R BMVXlYyIR VryPtOK4mF1gQN1h4Aud6TAtoyzv1QK8OKNc6uGmyxwgAIVJh/FP/WLuW0SJ8fBz6nG mWX6z5ZmHcpFHrM0bxl/P8k3gazMvrPomaGSSSecGCca6fXylKAQh4RelPWZviHOGm7lXoBnuNsD9/M=
&cc=GBP
&amt=10.00
VerifyPayment:handleRequest:FINER: Sending PDT to PayPal:
tx=3C860370XJ139983J&at=IMPK5zLghaFS8IzfKgfNbxMmaxF5zUXsxiUoqTqdjHisnuco6AR5o3XdH08&cmd=_notify-synch
VerifyPayment:handleRequest:FINER: Response FAILED

paypal@jthink.net
#3 Posted : Thursday, January 13, 2005 2:04:57 PM
Rank: Starting Member

Groups: Registered

Joined: 1/13/2005
Posts: 6
Location: ,
On dear the problem was the PDT String, I think I deleted the first character from the PDT Entry and when I added it in I thought it was a '1' when in fact it was a 'l'.

FYI infor this Java code now orks fine
shahzadsadiq
#4 Posted : Tuesday, May 27, 2008 12:44:11 PM
Rank: Starting Member

Groups: Registered

Joined: 5/27/2008
Posts: 3
Location: ,
Hi, I am new to paypal.I am getting exactly the same response. I am always getting FAIL response. Can anybody please tell me how to implement PDT in sandbox environment. Is this a token issue?
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAFVision Theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.3 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.380 seconds.