Jump to content
Sign in to follow this  
joshlittlewood

help with php ipn for digital goods.

Recommended Posts

hello, so i've been developing this website ( http://www.ultimate-dimension.co.uk/NewRAL/store1.php ) for a while now, and the owner wanted a  shopping cart implemented. However another coder began the coding of this shopping cart. The cart works perfectly besides that fact that after the Paypal payment as been made I cannot make the system redirect the user to a page where they can download the files that they have ordered.

 

Here is the shopping cart code...

<?php

session_start();

$page = 'store1.php';

if (isset($_GET['add'])) {
	$quantity = mysql_query('SELECT id, quantity FROM filesTable WHERE id='.mysql_real_escape_string((int)$_GET['add']));
		while ($quantity_row = mysql_fetch_assoc($quantity)) {
			if ($quantity_row['quantity']!=$_SESSION['cart_'.(int)$_GET['add']]) {
				$_SESSION['cart_'.(int)$_GET['add']]+='1';	
			}	
	}
	header('location:'.$page);
}

if (isset($_GET['remove'])) {
	$_SESSION['cart_'.(int)$_GET['remove']]--;
	header('location:'.$page);
}
	
if (isset($_GET['delete'])) {
	$_SESSION['cart_'.(int)$_GET['delete']]='0';
	header('location:'.$page);
}

function products() {
	$get = mysql_query('SELECT id, name, description, price, shipping FROM filesTable WHERE quantity > 0 ORDER BY id DESC');
	if (mysql_num_rows($get)==0) {
		echo "There are no products to display :/";
	}
	else {
		while ($get_row = mysql_fetch_assoc($get)) {
			echo '<p>'.$get_row['name'].'<br />'.$get_row['description'].'<br /> &pound'.number_format($get_row['price'], 2).' <br /> <a href="cart.php?add='.$get_row['id'].'">ADD</a></p> <br /><hr><br />';
		}
	}
}
 
function paypal_items() {
	$num==0;
	foreach ($_SESSION as $name => $value) {
		if ($value!=0) {
			if (substr($name, 0, 5)=='cart_') {
				$id = substr($name, 5, strlen($name)-5);
				$get = mysql_query('SELECT id, name, price, shipping FROM filesTable WHERE id='.mysql_real_escape_string((int)$id));
				while ($get_row = mysql_fetch_assoc($get)) {
					$num++;
					echo '<input type="hidden" name="item_number_'.$num.'" value="'.$id.'">';
					echo '<input type="hidden" name="item_name_'.$num.'" value="'.$get_row['name'].'">';
					echo '<input type="hidden" name="amount_'.$num.'" value="'.$get_row['price'].'">';
					echo '<input type="hidden" name="shipping_'.$num.'" value="'.$get_row['shipping'].'">';
					echo '<input type="hidden" name="shipping2_'.$num.'" value="'.$get_row['shipping'].'">';
					echo '<input type="hidden" name="quantity_'.$num.'" value="'.$value.'">';
				}
			}
		}
	}
}

function cart() {
	foreach ($_SESSION as $name => $value) {
		if ($value>0) {
			if (substr($name, 0, 5)=='cart_') {
				$id = substr($name, 5, (strlen($name)-5));
				$get = mysql_query('SELECT id, name, description, price, shipping FROM filesTable WHERE id='.mysql_real_escape_string((int)$id));
				while ($get_row = mysql_fetch_assoc($get)) {
					$sub = $get_row['price']*$value;
					echo $get_row['name'].' x '.$value.' @ &pound'.number_format($get_row['price'], 2).' = &pound'.number_format($sub, 2).' <a href="cart.php?remove='.$id.'">[ - ]</a> <a href="cart.php?add='.$id.'">[ + ]</a> <a href="cart.php?delete='.$id.'">[ DELETE ]</a> <br><br>';
				}
			}
	
			$total += $sub;

		}
	}

	if ($total==0) {
		echo "Your cart is empty :/";
	}
	else {
		echo '<br><p class="rightAlignCart">Total: £'.number_format($total, 2).'</p>';

	?>	
	<p>
		<form  class="rightAlignCart" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
		<input type="hidden" name="cmd" value="_cart">
		<input type="hidden" name="upload" value="1">
		<input type="hidden" name="business" value="joshlittlewood@ultimate-dimension.co.uk">
		<?php paypal_items(); ?>
		<input type="hidden" name="currency_code" value="GBP">
		<input type="hidden" name="amount" value="<?php echo $total; ?>">
		<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but06.gif" name="submit" alt="Make payments with PayPal - it's fast,                 free and secure!">
		</form>
	</p>
	<?php
	}		

}

?>

By the way the store is running in sandbox mode, for anyone who wants to try it.

 

I believe that Paypal's IPN is the way to do it, but I just can't get it to work with the current shopping cart system. Any help on how do do this would be greatly appreciated! 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.