Solved

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

Posted on 2010-09-13
6
1,268 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 250 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Every business owner understands the significance of online customer reviews and the impact it can have on sales and revenues. With technology advancing at such a rapid pace, getting online reviews has never been easier, especially when many regions…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
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.
Suggested Courses

739 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