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

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.

RobertFromSecretWeaponsAsked:
Who is Participating?
 
MogalManicCommented:
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
 
MogalManicCommented:
0
 
neeraj523Commented:
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
 
RobertFromSecretWeaponsAuthor Commented:
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
 
RobertFromSecretWeaponsAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.