George
asked on
Perl: PayPal IPN Response is Invalid -- returns HTTP::Response=HASH(....
I'm integrating PayPal into our web store.
We send people to PayPal where they pay.
Then PayPal Sends us an IPN (Instant Payment Notification), that contains data about the payment.
We have a 'Listerner' program that receives the IPN.
When we receive the IPN, we are supposed to POST the data back to PayPal for validation.
PayPal Provided some code in Perl for this.
I used the code provided by PayPal, and integrated it into my page.
Here is some of the code in the 'Listener' program:
--------------------------
use LWP::Protocol::http;
use LWP::UserAgent;
$payPalTestMode = 1;
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
$query = $buffer;
&writePayPalIpnLog("IPN RECEIVED: ".$query);
$query .= '&cmd=_notify-validate';
# post back to PayPal system to validate
$ua = new LWP::UserAgent;
if ($payPalTestMode){
$req = new HTTP::Request 'POST','https://www.sandbox.paypal.com/cgi-bin/webscr';
}else{
$req = new HTTP::Request 'POST','https://www.paypal.com/cgi-bin/webscr';
}
$req->content_type('applic
$req->content($query);
$res = $ua->request($req);
&writePayPalIpnLog("Valida
--------------------------
From my log file, I can see that I received the IPN from PayPal.
And I also log the response I get back from the POST that is sent.
The response I get back is like: HTTP::Response=HASH(0x9251de4)
(It should be VERIFIED or INVALID.)
I used PayPal's IPN simulator to send an IPN to my Listener program.
If I Post the response back to PayPal, then the following message is displayed by the IPN simulator:
"IPN delivery failed. HTTP error code 502: Bad Gateway"
If I do not POST back to PayPal, then the IPN simulator displays:
"IPN successfully sent."
So it appears that something about the POST is not working right. But I don't know what it could be.
I'll appreciate any help in this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did it work using HTTP?
ASKER
It did not work using HTTP. I get the same response. Darn.
( Sorry for delay - had to complete an important deadline.)
Could it be an SSL issue or a Firewall issue?
( Sorry for delay - had to complete an important deadline.)
Could it be an SSL issue or a Firewall issue?
To help debug, you are welcome to change the destination URL of the POSTfrom PayPal site to http://www.sjklein.com/dumpParms.pl to see what you are really sending.
If you'd like the sources to dumpParms.pl see:
https://www.experts-exchange.com/questions/26823069/perl-how-to-print-out-all-the-cgi-fom-values.html
If you'd like the sources to dumpParms.pl see:
https://www.experts-exchange.com/questions/26823069/perl-how-to-print-out-all-the-cgi-fom-values.html
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
clockwatcher,
I think you got it.
I think you got it.
ASKER
I appreciate your help!
ASKER
First, I tried changing the post-back method from https to http. I still got a response of HASH(...).
So I changed the method back to https.
Then I changed:
&writePayPalIpnLog("Valida tion Response ".$res);
TO: &writePayPalIpnLog("Valida tion Response ".$res->content);
Now I could see the response, which was that https was not supported.
So I changed to http, and received a 'VERIFIED' response. (Yea!)
However, PayPal is still sending me IPN messages. I looked at their IPN History page, and they state that they received a 502 bad gateway response from my original IPN -- even though they verified the post-back. It appears that the program that receives the post-back does not update their database that the IPN was received. So now I need to solve that problem. I'll try working with PayPal first, and if cannot get it resolved, I'll open another ticket.
Thanks for your help!
So I changed the method back to https.
Then I changed:
&writePayPalIpnLog("Valida
TO: &writePayPalIpnLog("Valida
Now I could see the response, which was that https was not supported.
So I changed to http, and received a 'VERIFIED' response. (Yea!)
However, PayPal is still sending me IPN messages. I looked at their IPN History page, and they state that they received a 502 bad gateway response from my original IPN -- even though they verified the post-back. It appears that the program that receives the post-back does not update their database that the IPN was received. So now I need to solve that problem. I'll try working with PayPal first, and if cannot get it resolved, I'll open another ticket.
Thanks for your help!
ASKER