Web DevCenter
oreilly.comSafari Books Online.Conferences.
MySQL Conference and Expo April 14-17, 2008, Santa Clara, CA

Sponsored Developer Resources

Web Columns
Adobe GoLive
Essential JavaScript

Web Topics
All Articles
Scripting Languages

Atom 1.0 Feed RSS 1.0 Feed RSS 2.0 Feed

Learning Lab

O'Reilly Book Excerpts: PayPal Hacks

Hacking PayPal, Part 2

by Shannon Sofield, Dave Nielsen, Dave Burchell

Last week, in Part 1 of this two-part excerpt from PayPal Hacks, the authors offered three hacks to ensure PayPal's convenience and effectiveness. This week they present two more hacks to help make you and your customers happy. The first hack highlights using IPN to effortlessly deliver digital goods to your customers, and the second shows how to set up phony Sandbox accounts to test your code.

Hack #71

Deliver Digital Goods with IPN

Use IPN to have your server automatically send digital goods to customers as soon as they purchase them from your web site.

The Internet revolution allows instant gratification when purchasing an item. Customers can purchase digital goods--eBooks, digital music, video files, software, and anything else that can be delivered over the Internet--from the comfort of home and use them almost instantly.

This hack shows you how to leverage PayPal's ease of use, security, and brand name to sell digital goods with large margins and low overhead. PayPal's IPN system [Hack #65] lets you deliver those goods without any interaction as a seller.

The Code

The code in this hack uses Microsoft VBScript, but the same process can be implemented with any web scripting language.

WARNING: Because this solution employs IPN to deliver a product without any action on your part, you should take steps to ensure that the payment is legitimate (for example, no price tampering has taken place) [Hack #73].

This script, when used in conjunction with the IPN script from [Hack #73], sends your customer an email with your digital product as an attachment:

'Declare and populate email address for delivery
Dim payer_email
Payer_email = Request.Form("payer_email")

'Create file variable and set path to file
Dim file_location
1.  file_location = "C:\InetPub\wwwroot\yoursite\filestore\file.zip"

'Send an email to customer and attach file
Dim objCDO
Set objCDO = Server.CreateObject("CDOSYS.NewMail")
2.  objCDO.From = "sales@paypalhacks.com"
'Add customer email address
objCDO.To = payer_email
'Add file attachement
3.  objCDO.Subject = "PayPal Hacks Software Exo"
4.  objCDO.Body = "Thank you for your order. Your file is attached to this email."
objCDO.Send( )
Set objCDO = Nothing

Place your digital product in a file (presumably zipped) on your server, and specify the full path and filename in the file_location variable (line 1). Include your email address as the return (line 2); in most cases it will be the same as the email address your PayPal account uses. Finally, you'll want to customize the subject and message body text (lines 3 and 4, respectively) to suit your needs.

WARNING: When delivering files by email, be sure to keep the file size relatively small (less than 500K). Otherwise, you run the risk of overfilling your customer's email in-box or having the message rejected by the customer's ISP.

See Also

This hack shows the most simplistic way to implement digital goods sales for your site. For an improved method, see [Hack #72].

PayPal Hacks

Related Reading

PayPal Hacks
100 Industrial-Strength Tips & Tools
By Shannon Sofield, Dave Nielsen, Dave Burchell

Pages: 1, 2

Next Pagearrow