0

因此,我正在努力获得经常性付款以在我正在开发的网站上工作(在 PHP 中)。我在我的 Paypal 帐户上启用了 IPN,并设置了我的按钮等。

当我点击我网站上的按钮时,它会将我带到 Paypal 并完成注册过程。然后它将我转发回正确的 url,带有大的“auth”get 变量。交易历史可在我的卖家和买家账户中查看。

问题在于更新我的数据库(mysql)。我尝试了几种不同的 IPN 脚本,并将来自 Google、Stackoverflow 和各种教程的不同脚本拼凑在一起。我试过的都没有更新我的数据库,这让我相信我的方法出了问题。

这是我的 ipn.php 脚本:

<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}
// post back to PayPal system to validate
$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";

// If testing on Sandbox use:
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

$notify_email =  "xxx"; //email address to which debug emails are sent to
$DB_Server = "xxx"; //your MySQL Server
$DB_Username = "xxx"; //your MySQL User Name
$DB_Password = "xxx"; //your MySQL Password
$DB_DBName = "xxx"; //your MySQL Database Name


if (!$fp) 
{
    // HTTP ERROR
} 
else 
{
mail($notify_email, "IPN Triggered 1", "IPN Triggered 1");  

fputs ($fp, $header . $req);

while (!feof($fp)) 
{
    //Already used this
    //$res = fgets ($fp, 1024);

    //Using this to see if it sends response
    $res = stream_get_contents($fp, 1024);


    if (strcmp ($res, "VERIFIED") == 0) 
    {   
        mail($notify_email, "VERIFIED 1", "VERIFIED 1");

        //create MySQL connection
        $Connect = mysql_connect($DB_Server, $DB_Username, $DB_Password)
        or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());


        //select database
        $Db = @mysql_select_db($DB_DBName, $Connect)
        or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno());


        $fecha = date("m")."/".date("d")."/".date("Y");
        $fecha = date("Y").date("m").date("d");

        //check if transaction ID has been processed before
        $checkquery = "SELECT txn_id FROM payments WHERE txn_id='".$txn_id."'";
        $sihay = mysql_query($checkquery) or die("Duplicate txn id check query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
        $nm = mysql_num_rows($sihay);

        if ($nm == 0)
        {
            //execute query
            if ($txn_type == "subscr_signup")
            {
                $strQuery = "INSERT INTO payments SET txn_id='".$txn_id."', user_id='$custom'";

                 $result = mysql_query($strQuery) or die("Cart - paypal_payment_info, Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
            }
        // send an email in any case
         //echo "Verified";
            mail($notify_email, "VERIFIED IPN", "$res\n $req\n $strQuery\n $struery\n  $strQuery2");
        }
        else 
        {
            // send an email
            mail($notify_email, "VERIFIED DUPLICATED TRANSACTION", "$res\n $req \n $strQuery\n $struery\n  $strQuery2");
        }
    }

    // if the IPN POST was 'INVALID'...do this
    else if (strcmp ($res, "INVALID") == 0) 
    {
        // log for manual investigation
        mail($notify_email, "INVALID IPN", "$res\n $req");
    }
}

fclose ($fp);
}
?>
4

1 回答 1

0

出于某种原因,在 Paypal 上禁用然后重新启用我的 IPN 似乎可以解决问题。

于 2013-11-12T15:59:55.417 回答