?
Solved

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

Posted on 2010-09-13
6
Medium Priority
?
1,284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 21

Expert Comment

by:MogalManic
ID: 33671083
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 33672085
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
ID: 33683899
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 1000 total points
ID: 33690712
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
ID: 33702739
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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

719 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