Saturday, January 15, 2011

Simple Shopping Cart with Alertpay™

Many of you must be thinking about putting a shopping cart on your site, blog to earn some cash, sell your HTML templates or images or scripts. But shopping cart takes a little effort to run. I mean My SQL or a flat file database. Also many free scripts use a .cgi file, if you have paid hosting then no problem, but if you have free hosting (like my www.designinline.elementfx.com ) then you are not given access to any .cgi file on the server.
So after fiddling around with PHP, I made a script that uses neither a database (My SQL or flat file) nor .cgi file. It is a simple PHP file that calls the variable from the link to load data and sends the user to your AlertPay page to buy your file. So all you have to do is upload the screenshot image file, flash files (if any) and the zip file to be downloaded and using only three files you can sell all your files. I have used AlertPay because I have an account there also I tried to open a PayPal™ account but I didn't succeed. So here is my script.
You might remember earlier I had posted a tutorial I modified to make PHP Templates. The script is more or less the same but I modified it more so that instead of calling a php file. It calls .jpg preview of the template and inserts all the data from the link into itself. Sample.
To start just copy and paste this code in the body tag and save it as say cart.php.
// Simple PHP Shopping Page Script
// © Copyright, Design InLine.com
// Script created by Tanmay Das
<?php
$default1 = 'test';
$furl = isset($_GET['id']) ? $_GET['id'] : $default1;
$furl = basename($furl);
$default2 = 'Name of the Template';
$fname = isset($_GET['name']) ? $_GET['name'] : $default2;
$fname = basename($fname);
$default3 = 'Tanmay Das';
$author = isset($_GET['aut']) ? $_GET['aut'] : $default3;
$author = basename($author);
$default4 = '0';
$price1 = isset($_GET['r1']) ? $_GET['r1'] : $default4;
$price1 = basename($price1);
$default5 = '0';
$price2 = isset($_GET['r2']) ? $_GET['r2'] : $default5;
$price2 = basename($price2);
if (file_exists('download/'.$furl.'.zip'))    {
echo('<table width="1000" border="0" cellspacing="0" cellpadding="0">');
echo('<tr><td width="75%"><img src="preview/'.$furl.'.jpg" /></td>');
echo('<td width="25%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">');
echo('<tr><td>'.$fname.'</td></tr><tr><td>&nbsp;</td></tr>');
echo('<tr><td>Author : '.$author.'</td></tr><tr><td>&nbsp;</td></tr>');
echo('<tr><td>Commercial Licence (Price : $'.$price1.')</td></tr><tr><td align="center">');
echo('<form method="post" action="https://www.alertpay.com/checkout" >');
echo('<input type="hidden" name="ap_purchasetype" value="item-goods"/>');
echo('<input type="hidden" name="ap_merchant" value="yourmail@yoursite.com"/>');
echo('<input type="hidden" name="ap_itemname" value="'.$fname.' (Commercial Licence)"/>');
echo('<input type="hidden" name="ap_currency" value="USD"/>');
echo('<input type="hidden" name="ap_returnurl" value="http://www.yoursite.com/c_download.php?id='.$furl.'"/>');
echo('<input type="hidden" name="ap_itemcode" value="'.$furl.'"/>');
echo('<input type="hidden" name="ap_quantity" value="1"/>');
echo('<input type="hidden" name="ap_amount" value="'.$price1.'"/>');
echo('<input type="hidden" name="ap_cancelurl" value="http://www.yoursite.com/c_cancel.php?id='.$furl.'"/>');
echo('<input type="image" name="ap_image" src="buy.gif"/>');
echo('</form></td></tr><tr><td>&nbsp;</td></tr>');
echo('<tr><td>Developer&acute;s Licence (Price : $'.$price2.')</td></tr>');
echo('<tr><td align="center"><form method="post" action="https://www.alertpay.com/checkout" >');
echo('<input type="hidden" name="ap_purchasetype" value="item-goods"/>');
echo('<input type="hidden" name="ap_merchant" value="yourmail@yoursite.com"/>');
echo('<input type="hidden" name="ap_itemname" value="'.$fname.' (Developer&acute;s Licence)"/>');
echo('<input type="hidden" name="ap_currency" value="USD"/>');
echo('<input type="hidden" name="ap_returnurl" value="http://www.yoursite.com/d_download.php?id='.$furl.'"/>');
echo('<input type="hidden" name="ap_itemcode" value="'.$furl.'"/>');
echo('<input type="hidden" name="ap_quantity" value="1"/>');
echo('<input type="hidden" name="ap_amount" value="'.$price2.'"/>');
echo('<input type="hidden" name="ap_cancelurl" value="http://www.yoursite.com/d_cancel.php?id='.$furl.'"/>');
echo('<input type="image" name="ap_image" src="buy.gif"/>');
echo('</form></td></tr></table></td></tr></table>');
}
else
{
echo('The template you are looking for was not found');
}
?>

Now for the link.
http://www.yoursite.com/cart.php?id=12345&name=Name of the Template&aut=Author's Name&r1=10&r2=20
OK the "id" is the name of your screenshot file (the image file that you'll give for preview) which should be in the "preview" folder also the name of the .zip/.rar file (the one that others will download) which should be in the "download" folder. You can change the folders by changing their paths.
The "name" in the link is the name you want to give to the template or script to download to make it look fancy. The "aut" is the name of the author of the file and "r1" and "r2" are the variables carrying the price to Alertpay™.

The download file is also very simple. Just copy and paste this code in download .php.

<?php
$default = 'home';
$furl = isset($_GET['id']) ? $_GET['id'] : $default;
$furl = basename($furl);
header('Location: http://www.yoursite.com/download/'.$furl.'.zip');
?>
<div align="center"><b>Download is in progress</b><br />
<img src="load.gif" width="32" height="32" /><br />
If the download doesn't starts in 5 sec then <a href="<?php echo('http://www.yoursite.com/download/'.$furl.'.zip'); ?>">Click Here</a> to download manually.</div>

It is a simple script right just make the files, upload them and test them out. You'll figure it out very easily.

P.S.- The script is still a work in progress. I have still some work to do on it to make it secure. It is basically for those who want to earn some cash, if you really want to earn your living of selling the I suggest you look for a more secure shopping cart.

No comments:

Post a Comment