Can anybody help?
I made an IPN request to a page called inventory.php where I'm running the script (part found on a thread posted by CraigR) and it looks to me not updating the inventory. can anybody give the light so I can find my way out of this problem.
Thanks
Carlos
Script below:
<?php require_once('Connections/sdconn.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";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>
<?php
// initialize flag
$OK = false;
$conn_sdconn = mysql_connect($hostname_sdconn, $username_sdconn, $password_sdconn);
// Now update stock level in tblitem
for ($i = 1; $i <= $num_cart_items; $i++) {
$itemnumber = "item_number".$i;
$quantity = "quantity".$i;
$sqlstock = 'UPDATE inventory_inv SET quantity_inv = quantity_inv - ? WHERE idprd_inv = ?' ;
// initialize prepared statement
$stmt = $conn_sdconn->stmt_init();
if ($stmt->prepare($sqlstock)) {
// bind parameters and execute statment
//$var1 = 'StockQty - '.$_POST[$quantity];
//$var2 = $_POST[$itemnumber];
$var1= $_POST[$quantity];
$var2 = $_POST[$itemnumber];
$stmt->bind_param('ii', $var1, $var2);
$OK = $stmt->execute();
}
}
// redirect if successful or display error
if ($OK) {
$result = ' Stock Level Updated ';
$result = nl2br($result);
}
else {
$result = $stmt->error;
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
This script should be posted on the success payment page? Should I send the IPN to a different page?
I'M CONFUSED AND NO SOLUTION