Preface

PayPal wasn’t the first company to build an online payment system, but it might as well be the last. With over 50 million registered accounts, PayPal is rapidly becoming a household name. But, as indicated, there have been others; PayPal’s predecessors attempted to capitalize on the Internet boom by building new forms of money. But whether this new currency was called Flooz, Beanz, or eCash, it didn’t matter, because people didn’t buy it. PayPal based its system on plain old dollar bills (not to mention yen, euros, and pounds sterling), which, in the end, turned out to be more valuable than Internet gold.

PayPal’s next brilliant move was to identify each account by an email address. That way, anyone with an email account could send money to anyone else just by knowing the recipient’s email address. The email proclaiming “You’ve got cash” turned out to be extremely motivating.

From its beginning, PayPal empowered the little guy to compete in the big world. It made doing business over the Internet easy for individuals, who could attach their bank accounts to their PayPal accounts without requiring a CFO’s signature. And the little guy returned the favor. After all, it was the little guys who paved the way for PayPal to become the number one payment system on eBay.

PayPal also removed the technical challenges. PayPal made it possible for an HTML developer to accept online credit card payments from any web page without requiring the years of programming skills necessary to install credit card processing software on a web server. A simple Pay Now button in an eBay auction page became as empowering as the most expensive eCommerce site on the Internet.

For developers, it didn’t stop there. Buy Now, Donate, Add to Cart, and Subscription buttons make Internet commerce in all flavors possible. And with innovations such as Website Payments, Instant Payment Notification, and PayPal Web Services, all the power of this eCommerce giant is only a few lines of code away. It’s not surprising that PayPal is being touted as the payment platform of the future. But for those who learn what it can already do, it may mean making profits today!

Why PayPal Hacks?

The term hacking has a bad reputation in the press. They use it to refer to someone who breaks into systems or wreaks havoc with computers as their weapon. Among people who write code, though, the term hack refers to a “quick-and-dirty” solution to a problem, or a clever way to get something done. And the term hacker is taken very much as a compliment, referring to someone as being creative and having the technical chops to get things done. The Hacks series is an attempt to reclaim the word, document the good ways people are hacking, and pass the hacker ethic of creative participation on to the uninitiated. Seeing how others approach systems and problems is often the quickest way to learn about a new technology.

As any experienced merchant will tell you, there are plenty of tasks involved in accepting payments on the Internet, and anything that can be done to make those tasks easier, faster, or more effective will improve your profits and give you more time to grow your business. But despite the title PayPal Hacks, this book is also not about “hacking into a system” or anything so nefarious—quite the contrary. In fact, you’ll find in this book a very real emphasis on trading responsibly and ethically, as well as extensive tools and tips for protecting yourself as both a buyer and a seller.

PayPal, on the surface, seems like a simple system allowing you to send and receive payments. But there’s a whole lot more under the hood; there are many tips and tricks you can use to save time and improve sales with PayPal. The hacks in this book address the technological and diplomatic challenges faced by all PayPal members, and are written from the perspectives of both PayPal insiders and experienced solution providers. Essentially, you’ll find the tools to help you buy and sell smarter and safer, make more money, and have fun doing it.

Getting Started with the Code in This Book

The sample code in this book should serve as a good jumping-off point for however you want to use each hack in the real world. To that end, PayPal Hacks provides real code you can type in and run yourself.

PayPal’s home is the Web, a heterogeneous place governed by well-defined standards. The concepts presented in this book work with any programming language or platform you might be using with your web site. However, the example code is primarily kept to three language and platform combinations, each inhabiting its own niche of the Internet ecology: server-side scripting, client-side (browser) scripting, and desktop applications.

Server-Side Scripting

Server-side scripts are installed on a web server. When a user requests a web page that contains a server-side script, the script is processed on the web server and its output is converted to HTML and delivered to the end user’s web browser.

Most of the hacks in this book that involve server-side scripting are written in VBScript (Visual Basic Script), which runs on a web server with support for Microsoft Active Server Pages (ASP). The ASP/VBScript combination is one of the most popular platforms among webmasters and developers using Microsoft systems. Microsoft’s newest web platform, ASP.NET, is growing rapidly; it is backward-compatible and will also run ASP/VBScript code.

You can host the VBScript examples using a modern Microsoft operating system, such as Microsoft Windows XP Professional, Microsoft Windows 2000 Professional, or Microsoft Windows 2003 Server. Each of these products comes with Microsoft’s Internet Information Server (IIS), an ASP-capable web server. In practice, you might not have (or desire to set up) your own web server; many ISPs offer affordable (or free) space on preconfigured web servers that are capable of hosting ASP/VBScript.

To create ASP/VBScript pages, simply type them into your favorite text editor, whether you’re using Microsoft’s default Notepad or the powerful Vim editor, which is popular amongst Unix jocks. If you’re already using an ASP-compatible web site editor, such as Dreamweaver or Microsoft Visual Studio, you can use that instead. Once you have created your ASP/VBScript pages, upload them to your web server (typically via FTP) and view them with your web browser. (The steps to do this vary; check with your ISP for specific instructions.)

To browse ASP/VBScript pages, you (or your customers) need only an ordinary web browser, such as Internet Explorer, Netscape Navigator, Mozilla, Opera, or even Lynx. You will, however, need to know the URLs of your ASP/VBScript pages (e.g., http://www.yourdomain.com/pagename.asp). If you host the pages on the same computer as your web browser, the URL will likely start with http://localhost/. Because the VBScript is processed on the web server that turns it into HTML, your (or your customer’s) web browser does not need any VBScript capabilities.

Tip

Although many of the hacks in this book are written in ASP/VBScript, Perl, Python, PHP, Java, and Cold Fusion are all good choices for developing eCommerce web pages that use PayPal as a payment method. No exotic features unique to VBScript are used, so the concepts and examples should readily translate to your favorite platform.

Client-Side (Browser) Scripting

Browser, or client-side, scripts are embedded in the HTML of the web page and are executed by the browser. The first and still most popular browser scripting technology is JavaScript. Since its introduction, JavaScript has been cloned by Microsoft (their offering is called JScript) and standardized by an international standards organization (resulting in ECMAScript). The bland flavor of JavaScript/JScript/ECMAScript used in the examples should be palatable to all modern JavaScript-capable browsers.

To try the JavaScript examples, you need only a text editor, such as Microsoft Notepad or VIM, or some other HTML authoring tool, such as Microsoft FrontPage, Macromedia Dreamweaver, NetObjects Fusion, or Adobe GoLive. Save your JavaScript-laden HTML pages to your computer’s hard drive and view them in any modern browser with JavaScript support enabled.

Desktop Applications

The examples provided with PayPal’s API hacks involve the building of desktop applications. Although they use the Internet and HTTP to access the PayPal API, these are standalone applications designed to work on your Windows desktop (as opposed to working from within a web browser).

While you can access the PayPal API from within any programming language that supports SOAP (.NET, Java, Perl, PHP), the examples in this book are all written in C# and require the Microsoft .NET Framework. To try these examples yourself, you need to first compile them with a C# development environment, such as Microsoft Visual Studio .NET or Borland C#Builder. (You can’t use an older version of Visual Studio, because it won’t support SOAP or .NET). To run the examples, you (and your employees or customers) need Microsoft’s .NET Framework 1.1 installed on each computer on which your application is to run. The .NET framework is installed by default on Microsoft Windows XP and is freely available for previous versions of Windows, such as Windows 2000, from http://windowsupdate.microsoft.com.

Database Coding and Platform Choices

Many of the hacks in this book rely on your ability to set up a database and connect to it with code. A database table looks something like an Excel spreadsheet, with rows (records) and columns (fields). Table P-1 shows a simple products database table.

Table P-1. An extremely simple table with three fields (columns) and as many records (products) as you wish to store in it

ID

Description

Price

0001

Acme Widget

$37.94

0002

Industrial, Co. Wicket

$12.88

0003

Krusty Brand Tongue Depressor

$0.40

Here, each record corresponds to a single product. The data is divided into three fields: a unique numeric ID (ID), a product description (Description), and the unit price (Price). You’ll not only need to choose a database application with which to create your tables and manage your data, you’ll need to include code (specific to the platform you choose) to connect to your database.

Most of the database-enabled hacks in this book cite a Structured Query Language (SQL) query to retrieve data from a database or store data back into it. In order to put these hacks to use, you’ll have to customize the code for use with your server and database platform.

There are two general platforms commonly used to host web sites: Windows and Unix/Linux. These two systems can provide similar functionality, but they do so in completely different ways. The problem is that some of the more advanced code, especially code that accesses databases, might work on one platform but not the other. For instance, Windows servers have a built-in web server capable of interpreting VBScript or JavaScript that is executed in Active Server Pages (ASP). On the other hand, Unix/Linux platforms typically use the Apache web server, which can understand Hypertext Preprocessor (PHP) code (i.e., code with a .php extension). Of course, you can run ASP pages on Unix/Linux platforms using ChiliSoft ASP, and you can run PHP scripted pages on a Windows machine by installing the Windows version of the Apache web server.

Once you’ve chosen a server platform, you’ll need to choose a database technology that works with that system. For instance, Windows servers will likely be integrated with a Microsoft Access, MSDE, or Microsoft SQL database, whereas Unix/Linux servers will likely be using MySQL, Postgres, or Oracle.

Tip

It almost goes without saying that a dynamic web site (dynamic in that the content is created on the fly) will be much more powerful with the benefit of a relational database management system (RDBMS). The examples that require a database were tested against Microsoft’s SQL Server 2000 or better, but with some small modifications the examples will work with any popular RDBMS, such as MySQL or Oracle.

Many of the advanced hacks in this book reference a recordset in their instructions, so you’ll need to do something like the following to deploy those hacks. This code creates a recordset named rsProducts using VBScript for ASP:

1. connStore="DRIVER={Microsoft Access Driver (*.mdb)};DBQ="C:/InetPub/wwwroot/
database/dbPayPal.mdb")
2. set rsProducts = Server.CreateObject("ADODB.Recordset")
3. rsProducts.ActiveConnection = connStore
4. rsProducts.Source = "SELECT item_name FROM tblProducts"
5. rsProducts.Open( )
6. Response.Write(rsProducts.Fields.Item("item_name").Value)

Line 1 defines the location of the database and specifies the database driver. Line 2 initiates a new recordset named rsProducts. Line 5 actually executes the database query, and line 6 sends the contents of a field to the output (in this case, the item_name column returned from the database is displayed).

To put this code to use, replace the SQL statement on line 4 with the SQL query shown in the hack you wish to use.

Further Study

To learn more about some of the aforementioned technologies used in this book, check out the following O’Reilly books:

ASP

Programming ASP.NET by Jesse Liberty and Dan Hurwitz

Access (Database)

Access Database Design & Programming by Steven Roman, Ph.D.

JavaScript

JavaScript: The Definitive Guide by David Flanagan

MySQL (Database)

Managing & Using MySQL by George Reese, Randy Jay Yarger, and Tim King

PHP

PHP Cookbook by David Sklar and Adam Trachtenberg

SQL

SQL Pocket Guide by Jonathan Gennick

VB.NET

VB.NET Language in a Nutshell by Steven Roman, Ph.D., Ron Petrusha, and Paul Lomax

How to Use This Book

You can read this book from cover to cover if you like, but you’ll probably be better off picking an interesting item from the table of contents and just diving in. Each hack stands on its own, so feel free to browse and jump to the different sections that interest you most. If there’s a prerequisite you need to know about, a cross-reference will guide you to the right hack.

How This Book Is Organized

Each hack has been designed to show you how to complete a specific task, streamline a common practice, or overcome a PayPal limitation. Some hacks point to obscure features on the web site, while others present code to solve problems or unlock hidden features.

The 100 hacks in this book are distributed into eight chapters:

Chapter 1, Account Management

Use the hacks in this chapter to set up a PayPal account and keep it in good standing. If you’re new to PayPal, make sure to verify your account [Hack #2] and confirm your address [Hack #3] .

Chapter 2, Making Payments

PayPal’s all about sending payments. This chapter covers the basics of buying with PayPal and protecting yourself when you do.

Chapter 3, Selling with PayPal

The real fun of PayPal starts when you begin accepting payments. Upgrade to a Business or Premier account and then hook up your PayPal account with your eBay auctions or eCommerce web site and watch the money roll in. Make sure you take steps to protect yourself from buyer fraud [Hack #24] and chargebacks [Hack #25] .

Chapter 4, Payment Buttons

Integrate PayPal with your web site and begin accepting PayPal payments for goods and services in minutes. Although adding the most basic PayPal Buy Now button [Hack #28] to your site involves little more than copying and pasting a simple HTML form onto a web page, there are dozens of ways to extend and customize your online storefront and fine-tune your customer’s purchase experience.

Chapter 5, Storefronts and Shopping Carts

Take payment buttons a step further and allow customers to purchase multiple items in a single transaction. PayPal provides everything you need to set up a simple shopping cart interface with your web site; just add a few buttons [Hack #45] to your pages to get started.

Chapter 6, Managing Subscriptions

Accept recurring payments from other PayPal members and provide paid access to online content and other membership-based products.

Chapter 7, IPN & PDT

Automate your business by setting up PayPal to notify your server whenever you receive a payment, allowing you to automatically record all transactions into a local database, offer instant fulfillment of digital goods, and provide instant access to online content.

Chapter 8, The PayPal Web Services API

Leave the PayPal web site behind and build applications and web sites using the PayPal Web Services API as a development platform.

Conventions Used in This Book

The following is a list of the typographical conventions used in this book:

Italics

Used to indicate URLs, filenames, filename extensions, and directory/folder names. For example, a path in the filesystem appears as /Developer/Applications.

Constant width

Used to show code examples, the contents of files, and console output, as well as the names of variables, commands, and other code excerpts.

Constant width bold

Used to highlight portions of code, typically new additions to old code.

Constant width italic

Used in code examples and tables to show sample text to be replaced with your own values.

You should pay special attention to notes set apart from the text with the following icons:

Tip

This is a tip, suggestion, or general note. It contains useful supplementary information about the topic at hand.

Warning

This is a warning or note of caution, often indicating that your money or your privacy might be at risk.

The thermometer icons, found next to each hack, indicate the relative complexity of the hack:

beginner
moderate
expert

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "PayPal Hacks by Shannon Sofield, Dave Nielsen, and Dave Burchell. Copyright 2004 O’Reilly Media, Inc., 0-596-00751-5.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

How to Contact Us

We have tested and verified the information in this book to the best of our ability, but you may find that features have changed (or even that we have made mistakes!). As a reader of this book, you can help us to improve future editions by sending us your feedback. Please let us know about any errors, inaccuracies, bugs, misleading or confusing statements, and typos that you find anywhere in this book.

Please also let us know what we can do to make this book more useful to you. We take your comments seriously and will try to incorporate reasonable suggestions into future editions. You can write to us at:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the U.S. or Canada)
(707) 829-0515 (international/local)
(707) 829-0104 (fax)

To ask technical questions or to comment on the book, send email to:

The web site for PayPal Hacks lists examples, errata, and plans for future editions. You can find this page at:

http://www.oreilly.com/catalog/payhks/

Download sample code from:

http://www.paypalhacks.com

For more information about this book and others, see the O’Reilly web site:

http://www.oreilly.com

Got a Hack?

To explore Hacks books online or to contribute a hack for future titles, visit:

http://hacks.oreilly.com

Get PayPal Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.