0

请提前原谅我的无知,但我对 php 还很陌生,这个问题一直困扰着我一段时间。我正在尝试为销售单个商品的在线商店编写 IPN 脚本。付款完成后,脚本将更新数据库并将可用性从“可用”更改为“不可用”。除了更新数据库外,IPN 似乎工作正常。我现在不知所措,因为我看不出脚本有什么问题。这就是我所拥有的:

curl_close($ch);

if (strcmp ($res, "VERIFIED") == 0) {

$token = $_POST['invoice'];
$item= $_POST['invoice'];

$conn=new PDO("mysql:host=SERVER;dbname=MYDATABASE","NAME","PASS");
if ($_POST['payment_status'] == 'completed')
{
   $sql="UPDATE `tbl_products` SET `id_status` = 3 WHERE `id_product`=:idproduct";
   $stmt=$conn->prepare($sql);
   $stmt->bindParam(':idproduct',$item);
   $stmt->execute();
}
if ($_POST['payment_status'] == 'pending')
{
    $sql="UPDATE `tbl_products` SET `id_status` = 2 WHERE `id_product`=:idproduct";
    $stmt=$conn->prepare($sql);
    $stmt->bindValue(':idproduct',$item);
    $stmt->execute();
}
foreach ($_POST as $key => $value)
{
    $emailtext .= $key . " = " .$value ."\n\n";
}
mail("MYEMAIL", "Live-VALID IPN", $emailtext . "\n\n" . $req);
}
else if (strcmp ($res, "INVALID") == 0)
{
// log for manual investigation
foreach ($_POST as $key => $value)
{
    $emailtext .= $key . " = " .$value ."\n\n";
}
mail("MYEMAIL", "Live-INVALID IPN", $emailtext . "\n\n" . $req);
}
4

1 回答 1

0

Paypal IPN 返回状态的第一个字符大写。

所以Completed不等于completed。尝试这个

curl_close($ch);

if (strcmp ($res, "VERIFIED") == 0) {

$token = $_POST['invoice'];
$item= $_POST['invoice'];

$conn=new PDO("mysql:host=SERVER;dbname=MYDATABASE","NAME","PASS");
if ($_POST['payment_status'] == 'Completed')
{
   $sql="UPDATE `tbl_products` SET `id_status` = 3 WHERE `id_product`=:idproduct";
   $stmt=$conn->prepare($sql);
   $stmt->bindParam(':idproduct',$item);
   $stmt->execute();
}
if ($_POST['payment_status'] == 'Pending')
{
    $sql="UPDATE `tbl_products` SET `id_status` = 2 WHERE `id_product`=:idproduct";
    $stmt=$conn->prepare($sql);
    $stmt->bindValue(':idproduct',$item);
    $stmt->execute();
}
foreach ($_POST as $key => $value)
{
    $emailtext .= $key . " = " .$value ."\n\n";
}
mail("MYEMAIL", "Live-VALID IPN", $emailtext . "\n\n" . $req);
}
else if (strcmp ($res, "INVALID") == 0)
{
// log for manual investigation
foreach ($_POST as $key => $value)
{
    $emailtext .= $key . " = " .$value ."\n\n";
}
mail("MYEMAIL", "Live-INVALID IPN", $emailtext . "\n\n" . $req);
}

最好将状态存储在变量中并使用 phpstrtolower函数将它们变为小写。

$paypalStatus = strtolower($_POST['payment_status']);

比做这样的检查

if($paypalStatus == 'pending')
于 2013-06-18T11:56:16.443 回答