Solved

PayPal IPN Messages - Getting Invalid Response 1 out of 10 times

Posted on 2010-09-13
6
1,254 Views
Last Modified: 2013-11-29
Hi,

We have a production IIS / aspx e-commerce system in place that processes PayPal payments and about 10% of the time when we try to confirm with PayPal the received IPN message, we get an INVALID response.

The cause is that we are receiving some russian, french or some other foriegn language characters in the body of the IPN message (i.e. first name), and when we try to send that received IPN message back to PayPal, the "encoding" is somehow not preserved and a strange character gets sent back thereby resulting in an INVALID response.

I read somewhere to verify what the character encoding is and to preserve it when the IPN message is sent back to PayPal for verifiation.

Question - How do I determine what the inbound character encoding is when the IPN message comes in and how to set it properly to send a response back to PayPal.

0
Comment
  • 2
  • 2
6 Comments
 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
0
 
LVL 22

Expert Comment

by:neeraj523
Comment Utility
Hello

I will suggest to handle IPN response in a better way.. try to ignore any special chars etc instead just ensure that u get payment status and the transaction id to update your database..

Try to dump all the raw response data being posted from paypal for review.

0
 

Author Comment

by:RobertFromSecretWeapons
Comment Utility
Hi MogulManic,

Yeah, we stumbled across that possible solution already and tried setting the encoding to UTF-8 on both ends, but problem still persists.  We do see a change in behavior in incoming data, but still, problem persists.

Neeraj - There is no "better way" to handle this issue, The reason you send the IPN message back to PayPal is to verify it came from PayPal in the first place.  You can't just assume the incoming data is from PayPal.  I don't think it's a perfect mechanism, but never the less, that's the protocol.

Thank-you both, but for now, problem remains..
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 250 total points
Comment Utility
What does your posting code look like?  Similar to the attached code snippit?

HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://www.paypal.com/cgi-bin/webscr");
httpWebRequest.Method = "POST";
// length plus 21 because &cmd=_notify-validate is 21 chars long
httpWebRequest.ContentLength = stringPost.Length + 21;
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
StreamWriter streamWriter = null;
streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());
stringPost = stringPost + "&cmd=_notify-validate";
streamWriter.Write(Encoding.UTF8.Encode(stringPost));
streamWriter.Close();
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
{
response = streamReader.ReadToEnd();
streamReader.Close();
}

Open in new window

0
 

Author Comment

by:RobertFromSecretWeapons
Comment Utility
Hi Mogal,

Yes, we are using similar code.  We had set UTF-8 encoding in both directions on the PayPal website for our IPN messages and tried UTF8 encoding in our programming example.  Didn't quite work.  Our developer changed the source code to use ASCII encoding and things started to work.  I can't explain it.  We will just have to see if it works over the long term.

If I were doing this, for the purposes of looping back the IPN message to PayPal, I would probably just read the stream in as a series of raw bytes without any regard to encoding and just send it back to PayPal as a series of raw bytes.  That way, we don't get engulfed in any mis matched encoding issues.

Thank-you for your help, but we may have hacked our own solution here.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now