Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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.
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:
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…

770 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