I am looking for a way to use PHP and MySQL to keep track of a few products and sell them on my website. I have found the following code online and wish to edit it to make it for recurring payments (paypal subscriptions) instead of single payments. I am not sure what to change for recurring payments. I have read over the PayPal Developer site but there it doesn't show code for what I need. Can anyone help?
Here is the SQL for products:
--
-- Table structure for table `products`
--
CREATE TABLE IF NOT EXISTS `products` (
`id` int(11) NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`price` float(10,2) NOT NULL,
`status` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `products`
--
INSERT INTO `products` (`id`, `name`, `price`, `status`) VALUES
(1, 'LavaBasic', 1.99, 1),
(2, 'LavaStarter', 2.99, 1),
(3, 'LavaAdvanced', 4.99, 1),
(4, 'LavaFlow', 5.99, 1);
And here is the PHP on the page where I am displaying products:
<body>
<?php
//fetch products from the database
$results = $db->query("SELECT * FROM products");
while($row = $results->fetch_assoc())
{
?>
<br/>Name: <?php echo $row['name']; ?>
<br/>Price: <?php echo $row['price']; ?>
<form action="<?php echo $paypal_url; ?>" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="Lavastack" value="<?php echo $paypal_id; ?>">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">
<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="<?php echo $row['name']; ?>">
<input type="hidden" name="item_number" value="<?php echo $row['id']; ?>">
<input type="hidden" name="amount" value="<?php echo $row['price']; ?>">
<input type="hidden" name="currency_code" value="USD">
<!-- Specify URLs -->
<input type='hidden' name='cancel_return' value='http://localhost/nitya/paypal_integration_php/cancel.php'>
<input type='hidden' name='return' value='http://localhost/nitya/paypal_integration_php/success.php'>
<!-- Display the payment button. -->
<input type="image" name="submit" border="0"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
<?php } ?>
</body>
I am trying to find what to make changes to so that the prices I have listed on the SQL will be recurring for that amount instead of a one time payment. Any suggestions would be greatly appreciated! Thank everyone in advance.