问题描述
请提前原谅我的无知,但我对php是相当新的,这个一直在欺骗我一段时间。
我试图为销售单个项目的在线商店写一个IPN脚本。一旦付款完成,脚本将更新数据库并将可用性从可用更改为不可用。
除了更新数据库外,IPN似乎工作得很好。我在我的智慧结束现在,因为我看不出有什么问题的脚本。这里是我有:
please excuse my ignorance in advance, but i'm fairly new to php, and this one has been bugging me for a while.i'm trying to write an IPN script for an online store that sells individual items. 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. 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字符大写。
Paypal IPN returned status have first character uppercase.
因此已完成
不等于完成
。尝试此
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);
}
最好将状态存储在变量中,并使用php strtolower
函数使它们小写。
It is better to store the status in a variable and use php strtolower
function to make them lower case.
$paypalStatus = strtolower($_POST['payment_status']);
比这样检查
if($paypalStatus == 'pending')
这篇关于PayPal IPN不更新MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!