stock update not working
Posted: Wed Mar 12, 2014 9:32 am
i have a cart set up that uses paypal as the merchant, i have a notify.php and a return.php
the return.php is meant to check to see if the transaction is fulfilled and if it is it redirect to a success.php (this works) then makes the stock up, what seems to be happening though is the notify.php isnt updating the database quick enough so the user is getting redirected to the failed page and therefor not updating the stock.
the notify.php is using the script papal shares.
the return.php is the page the user is returned to, i have added a sleep of (3) just to give it more time but this doesnt work
the return.php is meant to check to see if the transaction is fulfilled and if it is it redirect to a success.php (this works) then makes the stock up, what seems to be happening though is the notify.php isnt updating the database quick enough so the user is getting redirected to the failed page and therefor not updating the stock.
the notify.php is using the script papal shares.
Code: Select all
<?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 ('www.paypal.com', 80, $errno, $errstr, 30);
// assign posted variables to local variables
// note: additional IPN variables also available -- see IPN documentation
$itemNumber = $_POST['item_number'];
$paymentStatus = $_POST['payment_status'];
$payerStatus = $_POST['payer_status'];
$pendingReason = $_POST['pending_reason'];
$txnID = $_POST['txn_id'];
$receiverEmail = $_POST['receiver_email'];
mysql_select_db($database_beau, $beau); // find Txn ID
$query_rsTxnId = "SELECT TransactID FROM beauSS14_orders WHERE TransactID = '" . $txnID . "'";
$rsTxnId = mysql_query($query_rsTxnId, $beau) or die(mysql_error());
$row_rsTxnId = mysql_fetch_assoc($rsTxnId);
$totalRows_rsTxnId = mysql_num_rows($rsTxnId);
// Check notification validation
if (!$fp) {
$errmsg = "$errstr ($errno)";
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
if ($paymentStatus != "Completed") {
$errmsg = "Payment is " . $paymentStatus . " (" . $pendingReason . ")";
} else
{
$errmsg = "";
}
}
else if (strcmp ($res, "INVALID") == 0) {
$errmsg = "Request is INVALID";
}
}
fclose ($fp);
}
// last check
if ($errmsg != "") {
$status = 0;
} else {
$status = 1;
}
// update orders table
if ($itemNumber != "" && $txnID != "" && $paymentStatus != "") {
mysql_select_db($database_beau, $beau);
$IPN_upd = "UPDATE beauSS14_orders SET Fulfilled = " . $status . ", TransactID = '" . $txnID . "', TransactResult = '" . $paymentStatus . "', ResponseMsg = '" . $errmsg . "' WHERE OrderID = " . $itemNumber;
$IPN_rsId = mysql_query($IPN_upd, $beau) or die(mysql_error());
$IPN_rsId = null;
}
?>Code: Select all
session_start();
sleep(3);
$colname_rsReturn = "-1";
if (isset($_SESSION['OrderID'])) {
$colname_rsReturn = $_SESSION['OrderID'];
}
mysql_select_db($database_beau, $beau);
$query_rsReturn = sprintf("SELECT Fulfilled FROM beauSS14_orders WHERE beauSS14_orders.OrderID = %s", GetSQLValueString($colname_rsReturn, "int"));
$rsReturn = mysql_query($query_rsReturn, $beau) or die(mysql_error());
$row_rsReturn = mysql_fetch_assoc($rsReturn);
$totalRows_rsReturn = mysql_num_rows($rsReturn);
if ($row_rsReturn['Fulfilled'] == 1) {
header ("Location: success.php");
} else header ("Location: failed-order.php");