简体   繁体   English

PayPal IPN无法更新MySQL数据库

[英]PayPal IPN not updating MySQL database

please excuse my ignorance in advance, but i'm fairly new to php, and this one has been bugging me for a while. 请原谅我的无知,但是我对php还是很陌生,而且这个问题困扰了我一段时间。 i'm trying to write an IPN script for an online store that sells individual items. 我正在尝试为销售单个商品的在线商店编写IPN脚本。 once the payment is complete, the script will update the database and change the availability from "available" to "unavailable". 付款完成后,脚本将更新数据库并将可用性从“可用”更改为“不可用”。 the IPN seems to work fine apart from updating the database. IPN除了更新数据库外似乎还可以正常工作。 i'm at my wits end now as i can't see what is wrong with the script. 我现在不知所措,因为我看不到脚本出了什么问题。 here's what i have: 这是我所拥有的:

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);
}

Paypal IPN returned status have first character uppercase. Paypal IPN返回状态的首字符为大写。

So Completed is not equal to completed . 因此, Completed不等于completed Try this 尝试这个

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);
}

It is better to store the status in a variable and use php strtolower function to make them lower case. 最好将状态存储在变量中,并使用php strtolower函数使它们变为小写。

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

Than do the check like this 比做这样的检查

if($paypalStatus == 'pending')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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