marcodalzotto
asked on
Paypal IPN: INVALID
Hi experts, I'm trying to use the IPN Paypal system.
I've tryed different code... but always the same answer: INVALID.
The strange thing is that the PayPal manual say that Paypal pass the parameters in POST... but I get anything in POST, I get data only in GET.
Here is my code:
<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_GET as $key => $value) {
$value = urlencode(stripslashes($va lue));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n"; //<<<<<<<<<<<< ADD THIS LINE
$header .= "Referer: ".$_SERVER['HTTP_HOST'].$_ SERVER['PH P_SELF'].@ $_SERVER[' QUERY_STRI NG']."\r\n ";
$header .= "Server: ".$_SERVER['SERVER_SOFTWAR E']."\r\n" ;
$header .= "Content-Type: application/x-www-form-url encoded\r\ n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Accept: */*\r\n\r\n";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
if (!$fp) {
echo "PHP fsockopen() error: " . $errstr;
}
else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
echo "RECEIVED: ".$res."<BR>"; // for debug
if (strcmp ($res, "VERIFIED") == 0) {
echo "VERIFIED";
}
else if (strcmp ($res, "INVALID") == 0) {
echo "INVALID";
}
}
}
?>
Here the answer:
cmd=_notify-validate&tx=9B L62873GK24 3402G&st=C ompleted&a mt=100.00& cc=EUR&cm= &sig=rD%2f vVjLNDwD3d Am9sv9GPPi TyAvtYm4fc qJBqXhwWoV 0Y1nyEkWDR suJg2102Np BwPjDp0sAR hPOF446Z6h fW8xzv3S%2 f1ILdF1v96 4dm0M%2fCX ItrhJI2RsD 7d63EgMeVP Rn8TZ4ndlr mEtCBvtLT8 QOlViCPOoP CwgGhXd9I% 2bM8%3dREC EIVED: HTTP/1.0 200 OK
RECEIVED: Date: Mon, 19 Jun 2006 16:53:49 GMT
RECEIVED: Server: Apache/1.3.27 (Unix) mod_ssl/2.8.12 OpenSSL/0.9.7a PHP/4.3.2
RECEIVED: Set-Cookie: cookie_check=yes; expires=Thu, 16-Jun-2016 16:53:49 GMT; path=/; domain=.paypal.com
RECEIVED: Set-Cookie: Apache=64.202.165.201.1536 0115073602 9465; path=/; expires=Wed, 11-Jun-36 16:53:49 GMT
RECEIVED: Content-Type: text/html; charset=UTF-8
RECEIVED: X-Cache: MISS from wc04.inet.mesa1.secureserv er.net
RECEIVED: Connection: close
RECEIVED:
RECEIVED: INVALID
Thanks
I've tryed different code... but always the same answer: INVALID.
The strange thing is that the PayPal manual say that Paypal pass the parameters in POST... but I get anything in POST, I get data only in GET.
Here is my code:
<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_GET as $key => $value) {
$value = urlencode(stripslashes($va
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n"; //<<<<<<<<<<<< ADD THIS LINE
$header .= "Referer: ".$_SERVER['HTTP_HOST'].$_
$header .= "Server: ".$_SERVER['SERVER_SOFTWAR
$header .= "Content-Type: application/x-www-form-url
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Accept: */*\r\n\r\n";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
if (!$fp) {
echo "PHP fsockopen() error: " . $errstr;
}
else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
echo "RECEIVED: ".$res."<BR>"; // for debug
if (strcmp ($res, "VERIFIED") == 0) {
echo "VERIFIED";
}
else if (strcmp ($res, "INVALID") == 0) {
echo "INVALID";
}
}
}
?>
Here the answer:
cmd=_notify-validate&tx=9B
RECEIVED: Date: Mon, 19 Jun 2006 16:53:49 GMT
RECEIVED: Server: Apache/1.3.27 (Unix) mod_ssl/2.8.12 OpenSSL/0.9.7a PHP/4.3.2
RECEIVED: Set-Cookie: cookie_check=yes; expires=Thu, 16-Jun-2016 16:53:49 GMT; path=/; domain=.paypal.com
RECEIVED: Set-Cookie: Apache=64.202.165.201.1536
RECEIVED: Content-Type: text/html; charset=UTF-8
RECEIVED: X-Cache: MISS from wc04.inet.mesa1.secureserv
RECEIVED: Connection: close
RECEIVED:
RECEIVED: INVALID
Thanks
ASKER
The answer I've posted is a paramateter passed by Paypal to my ok.php when the payment transaction is completed.
The code I've posted connects to Paypal and repeat the parameters as received, adding 'cmd=_notify-validate'.
As a result I shoud get VERIFIED.
Yes I want to get a confirmation by paypal that the transaction really occured so I can permit the downalod of my product.
The code I've posted connects to Paypal and repeat the parameters as received, adding 'cmd=_notify-validate'.
As a result I shoud get VERIFIED.
Yes I want to get a confirmation by paypal that the transaction really occured so I can permit the downalod of my product.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well done, DataSmarts.
I'm going to accept your answer, and I'm going to give you a grade of 'A' if you tel me the difference between:
$req = 'cmd=_notify-validate';
and
$req = 'cmd=_notify-synch';
And why I couldn't use 'cmd=_notify-validate' that is present in a lot of example about how to receive IPN notification from Paypal?
Thanks
I'm going to accept your answer, and I'm going to give you a grade of 'A' if you tel me the difference between:
$req = 'cmd=_notify-validate';
and
$req = 'cmd=_notify-synch';
And why I couldn't use 'cmd=_notify-validate' that is present in a lot of example about how to receive IPN notification from Paypal?
Thanks
Well to be technical, I used the PDT instead of IPN as IPN has routinely had problems with the way they are sending the transaction confirmations.
As you may be aware, IPN provides a means where the user could, feasibly, close the browser and still receive the confirmation required to download your product. PDT requires the user to got hrough the process of completing their transaction and then auto_return would direct them back to your site. You also need a Cancel_return to be set so they are directed to your site where they can determine IF they want to continue or not...
As you may be aware, IPN provides a means where the user could, feasibly, close the browser and still receive the confirmation required to download your product. PDT requires the user to got hrough the process of completing their transaction and then auto_return would direct them back to your site. You also need a Cancel_return to be set so they are directed to your site where they can determine IF they want to continue or not...
Are you wanting to get the confirmation id from Paypal and add that to your own database?