Le statut renvoyé par Paypal IPN a le premier caractère en majuscule.
Donc Completed
n'est pas égal à completed
. Essayez ceci
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);
}
Il est préférable de stocker le statut dans une variable et d'utiliser php strtolower
fonction pour les rendre minuscules.
$paypalStatus = strtolower($_POST['payment_status']);
Ensuite, faites la vérification comme ceci
if($paypalStatus == 'pending')