In continuation of my last blog post on handling PayPal IPN callbacks in Drupal, I would like to acknowledge one mistake I made while writing that code to handle IPN callbacks from PayPal.
As should be obvious, I was using the PayPal’s sandbox environment while writing and testing code for PayPal integration. Most of the process was working fine, which started with clicking the PayPal button on our site, going to PayPal sandbox and making a payment there, user being redirected back to our site and receival of IPN callback from PayPal.
But somehow the postback of the IPN information back to PayPal for transaction validation was always failing and PayPal was always returning the “INVALID” code they send back when transaction validation failed.
I had checked the entire code as well as manually verified the headers and post information sent to PayPal for validation and everything seemed perfect. But PayPal was just not happy and always returned “INVALID” code.
It was actually after I had made many payments on the sandbox that I realized what should have been a no-brainer, I was testing out code on the sandbox, but payment validation requests were being sent out to the production PayPal environment.
So all you guys out there who are wondering why PayPal is not successfully validating your IPN information, make sure if you are making payments through PayPal’s sandbox environment, then validation requests should also goto their sanbbox server: ssl://www.sandbox.paypal.com
So if you are using the code from the previous blog post for handling IPN callbacks for payments made in PayPal sandbox, then please ensure to change line “20” from the php code in that blog post to the following:
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
I would say I was caught off-guard by PayPal 🙂
I am working on paypal and using it through paypal.ini.
I got some variables return from paypal and the script return it back on paypal .
here i got tha negative response.Pls help me.
The code i am using is:–
$fp= @ fsockopen($this->paypalurl,80,$errno,$errstr,30);
$this->error=”fsockopen error no. $errno: $errstr”;
@ fputs($fp, “POST /cgi-bin/webscr HTTP/1.1\r\n”);
@ fputs($fp, “Host: “.$this->paypalurl.”\r\n”);
@ fputs($fp, “Content-type: application/x-www-form-urlencoded\r\n”);
@ fputs($fp, “Content-length: “.strlen($postvars).”\r\n”);
@ fputs($fp, “Connection: close\r\n\r\n”);
@ fputs($fp, $postvars . “\r\n\r\n”);
$string=”insert into Paypal_test (payment_code,iten_name) values(‘”.$postvars.”‘,’postvar’)”;