简体   繁体   中英

PayPal IPN PHP API

So, no matter what I try to do, I seem to always get INVALID from my PayPal IPN process. I have found other pages that have similar issues, however either the solution has not worked for me or it was not solved.

Here is my current php code:

include_once($_SERVER['DOCUMENT_ROOT']."/api/static.php");
include_once($_SERVER['DOCUMENT_ROOT']."/api/api.php");

$req = 'cmd=_notify-validate';
foreach($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}

$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

$fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);

if(!$fp) {
    //There was an error.
    $mccubedConnection->query("replace into testing (result) values (-2);");
} else {
    fputs($fp, $header . $req);
    while(!feof($fp)) {
        $res = fgets($fp, 1024);
        if(strcmp($res, "VERIFIED") == 0) {
            //Valid
            $mccubedConnection->query("replace into testing (result) values (1);");
        } else if(strcmp($res, "INVALID") == 0) {
            //Invalid
            $mccubedConnection->query("replace into testing (result) values (-1);");
        }
    } fclose($fp);
}

$mccubedConnection->query("replace into testing (result) values (0);");
$mccubedConnection->close();

The MySQL queries are working fine, and in the database it's posting a -1 and a 0. Where my desire is for it to be posting a 1 and a 0 (This way is just temporary for my testing, I will be handling the transaction differently).

I am using the INP simulator here: https://developer.paypal.com/developer/ipnSimulator/

And supplying the correct url to where my php file is, as it is executing, but posting a -1 and 0 to the DB.

Thanks for your time!

So it appears to me that this is an issue with PayPal's simulator specifically. I have done even more research and found this post , where they mention that it works on live servers, but not within sandbox. I really hate to make assumptions and to just assume it works and to push it, but if anyone else can confirm this is true, please let me know! (btw this has been an issue on that github for almost 2 months now... quite incredible)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM