close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Payment Standard w/ Inventory update

Thread began 5/14/2011 8:27 pm by ccdantas101117 | Last modified 5/31/2011 4:12 pm by ccdantas101117 | 719 views | 1 replies

ccdantas101117

Can anybody help?

Originally Said By: ccdantas101117
  Hello all

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

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...