<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NGCoders - Next Generation Coders &#187; paypal php</title>
	<atom:link href="http://www.ngcoders.com/tag/paypal-php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ngcoders.com</link>
	<description>Personal Blog of Vikas Patial.</description>
	<lastBuildDate>Sun, 25 Jul 2010 08:01:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Selling Digital Goods/Ebooks With Paypal IPN and PHP</title>
		<link>http://www.ngcoders.com/php/selling-digital-goods-with-paypal-ipn-and-php</link>
		<comments>http://www.ngcoders.com/php/selling-digital-goods-with-paypal-ipn-and-php#comments</comments>
		<pubDate>Thu, 14 Aug 2008 18:11:08 +0000</pubDate>
		<dc:creator>Vikas Patial</dc:creator>
				<category><![CDATA[Downloads]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[paypal ipn]]></category>
		<category><![CDATA[paypal php]]></category>
		<category><![CDATA[sell ebooks]]></category>

		<guid isPermaLink="false">http://ngcoders.com/?p=12</guid>
		<description><![CDATA[Recently I wanted to sell a small script for which I was getting some requests.I wanted the procedure to be as efficient as possible where the user was delivered the script though a secret link once the payment was made. After some thorough searching around the net , I found that though the Idea and [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I wanted to sell a small script for which I was getting some requests.I wanted the procedure to be as efficient as possible where the user was delivered the script though a secret link once the payment was made. After some thorough searching around the net , I found that though the Idea and procedure is so simple there exist No Free scripts<br />
to do so ( Weired ). So in this tutorial we build a small script which can be used anywhere to sell digital goods online using Paypal IPN.They can be ebooks, shareware , software, images anything Bits and Bytes.</p>
<p>The script has the following features</p>
<ul>
<li>Complete automation of your online orders.</li>
<li>Automatically emails your customers and provides them with a unique download link to your digital product.</li>
<li>Automatically expiring links as required by the user.</li>
<li>File Attachments in Email.</li>
<li>Easy to test and debug.</li>
<li>Easy to integrate into any existing website.</li>
<li>Easy to install and configure. Only one settings file.</li>
</ul>
Note: There is a file embedded within this post, please visit this post to download the file.
<p><a id="more-42"></a></p>
<p>IPN is what this system is designed around.Instant Payment<br />
Notification (IPN) allows you to integrate PayPal payments with your<br />
website’s back-end operations. IPN provides immediate notification and<br />
confirmation of PayPal payments you receive. Here is how IPN works</p>
<p><img src="/images/guides/ipn.jpg" alt="How IPN Works" /></p>
<ul>
<li>A customer payment or a refund triggers IPN. This payment can be<br />
via Website Payments Standard FORMs or via the PayPal Web Services<br />
API’s for Express Checkout, Mass Pay, or Refund Transaction. If the<br />
payment has a “Pending” status, you receive another IPN when the<br />
payment clears, fails, or is denied.</li>
<li>PayPal posts HTML FORM variables to a program at a URL you specify.<br />
You can specify this URL either in your Profile or with the notify_url<br />
variable on each transaction. This post is the heart of IPN. Included<br />
in the notification is the customer’s payment information (such as<br />
customer name, payment amount). All possible variables in IPN posts are<br />
detailed in this guide. When your server receives a notification, it<br />
must process the incoming data.</li>
<li>Your server must then validate the notification to ensure that it<br />
is legitimate.Once this is verified you can go ahead and deliver the<br />
goods with a link which expires after sometime to the payer.</li>
</ul>
<p>To activate IPN, you can either change a setting in your PayPal<br />
Profile or include the notify_url variable in the payment FORMs on your<br />
website. We will us the notify_url method.</p>
<p>Also as we will not be using any encryption in the buttons we will<br />
verify all the IPN details during the verification procedure.</p>
<p>Before you begin this tutorial please download the source and refer to it side by side for better understanding.</p>
<p><strong>Step 1</strong> : Setting up to receive and validate IPN<br />
request . We are going to use one of the many Paypal Classes available<br />
freely, I have taken one from <a href="http://www.micahcarrick.com/04-19-2005/php-paypal-ipn-integration-class.html">micah  carrick</a><br />
.This class handles the request which Paypal send back to us.So the<br />
validation code which will be called once the Paypal invokes our IPN.<br />
validate_ipn() is the function which handles this part.</p>
<p><strong>Step 2 </strong>: Now we want do define the products which<br />
we want to sell , As my aim was to sell 1 &#8211; 2 odd scripts there was no<br />
use of building a shopping cart. Also as i planned to skip the database<br />
, and keep things simple as possible. So my products listing is a<br />
simple array defined in the settings.php file. The array item index is<br />
the item number which is used when creating a button.</p>
<div class="code">
<p>// product[number] = array(’Name’ ,’Price’ , ‘Download Link’);</p>
<p>$products[2] = array(’My Script’,&#8217;32′,’downloads/myscript.zip’);</p></div>
<p><strong>Step 3 </strong>: As we will be using non encrypted buttons<br />
, users might try to fool the script by sending in fake IPN requests or<br />
paying different amount and invoking the IPN script. To prevent such<br />
kind of things from happening we put in a validation function which<br />
checks various parameters according to our defined products. This<br />
function is validate_product().</p>
<p><strong>Step 4</strong> : Now we need a Buy now button for our<br />
product which defines our IPN callback, Item number , price etc. This<br />
button is simple HTML and can be placed anywhere and all the user is<br />
required is to click it and pay up , rest the script will take care of.</p>
<div class="code">
<p>&lt;form action=”https://www.sandbox.paypal.com/cgi-bin/webscr” method=”post”&gt;</p>
<p>&lt;input type=”hidden” name=”cmd” value=”_xclick”&gt;<br />
&lt;input type=”hidden” name=”business” value=”mail@mybusiness.com”&gt;</p>
<p>&lt;input type=”hidden” name=”item_name” value=”My Ebook”&gt;<br />
&lt;input type=”hidden” name=”item_number” value=”2″&gt;<br />
&lt;input type=”hidden” name=”amount” value=”32.00″&gt;<br />
&lt;input type=”hidden” name=”rm” value=”2″&gt;</p>
<p>&lt;input type=”hidden” name=”return” value=”http://www.mybusiness.com/thankyou.html”&gt;<br />
&lt;input type=”hidden” name=”cancel_return” value=”http://www.mybusiness.com/”&gt;<br />
&lt;input type=”hidden” name=”notify_url” value=”http://www.mybusiness.com/paypal/paypal.php”&gt;</p>
<p>&lt;input type=”image” src=”https://www.paypal.com/en_US/i/btn/x-click-but23.gif” border=”0″ name=”submit” alt=”Make<br />
payments with PayPal &#8211; it’s fast, free and secure!”&gt;<br />
&lt;img alt=”&#8221; border=”0″ src=”https://www.paypal.com/en_US/i/scr/pixel.gif” width=”1″ height=”1″&gt;<br />
&lt;/form&gt;</p></div>
<p><strong>Step 5</strong> : Now if everything goes fine and user pays<br />
up we need to send him a secret link which expires at our pre decided<br />
time( say 24 hours ). Now this procedure will only takes place if the<br />
IPN return a verified value. The secret link just contains a timestamp<br />
and a product ID which is encrypted using RC4 encryption and then base<br />
64 Encoded so that it can be used in a URL. Then a email is sent to the<br />
user with the Download link.</p>
<div class="code">
<p>// Client has successfully paid for the product</p>
<p>$product_id = $p-&gt;ipn_data[’item_number’];</p>
<p>$download = $product_id.’|’.time();</p>
<p>$download_link = $script_location.’download.php?file=’.base64_encode(RC4Crypt::encrypt($secret,$download));</p></div>
<p><strong>Step 6 </strong>: Now we need a script which takes this link<br />
and validates it and gives the user the download if everything goes<br />
fine. download.php is the file which does this.</p>
<p>That’s it , you have a set of 2 scripts which will allow you to sell downloads online.</p>
<p>The package also includes a <strong>check.php</strong> which helps you check if Digisell is functioning properly. Run it after you have editing the settings file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ngcoders.com/php/selling-digital-goods-with-paypal-ipn-and-php/feed</wfw:commentRss>
		<slash:comments>310</slash:comments>
		</item>
	</channel>
</rss>
