Integrate PayPal into your web site with a simple HTML form.
PayPal is more than a standalone auction payment service?it's an engine that you can use to power transactions on or off eBay. Any site that sells products can accept PayPal payments, and can do so without forcing customers to type an email address and an amount into their browser windows.
Somewhat like an API, PayPal provides an HTTP interface to their payment system that works just like the Pay Now button at the top of completed eBay auctions. This allows you, as the seller, to specify an amount, a product name, and any other bits of information you'd like to associate with the payment.
Any seller can accept PayPal payments through their HTTP interface; no special agreement or settings are necessary, other than a basic PayPal account. There are two ways to integrate PayPal into your site.
The simpler of the two methods involves nothing more than a link placed on your site. For instance, this URL:
specifies the email address (email@example.com), the product name (wicket), and the amount ($58.00). If you want to link the URL to an image (like the PayPal logo), use this code:
<a href="https://firstname.lastname@example.org&item_ name=wicket&amount=58.00&no_note=1"><img src="https://www.paypal.com/images/ x-click-but01.gif" border=0></a>
Other Pay Now button images are available at PayPal. When your customers click the link, they will see a window like the one in Figure 7-11.
When your customers click Continue, the only thing they'll be able to change on the next page is the funding source and the shipping address. If you want your customers to be able to enter a note or special instructions, remove the &no_note=1 parameter from the URL.
You can further customize your customers' experience by including additional fields in the URL, many of which are discussed in the next section.
The more robust approach requires a little more code:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="email@example.com"> <input type="hidden" name="return" value="http://www.ebayhacks.com/thankyou.html"> <input type="hidden" name="cancel_return" value="http://www.ebayhacks.com/cancelled.html"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="item_name" value="Extra-Strenth Wicket"> <input type="hidden" name="item_number" value="63123"> <input type="hidden" name="amount" value="$77.00"> <input type="hidden" name="on0" value="Name"> <input type="hidden" name="on1" value="Color"> Please type your name: <input name="os0" value="" maxlength=60 size=22> <p> Please choose a color <select name="os1"> <option>Mustard Yellow <option>Metallic Puce <option>Chartreuse <option>Clear <option>Candy Apple Gray </select> <p> <input type="submit" name="submit" value="Continue..."> </form>
The advantages of the form interface are clear: in addition to the standard fields (listed at the beginning in the hidden <input> tags), you can include up to two custom fields to be filled out by your customers. The names of the custom fields are specified in the hidden on0 and on1 fields, and their contents are specified in the os0 and os1 fields. In the example, the custom fields, name and color, are comprised of a standard text box and a drop-down list box, respectively.
Also new in this form are the return and cancel_return fields, which contain the URLs to which your customers will be sent when they complete (or cancel) the payment process, and the item_number field, which can be your stock number (SKU) or part number.
PayPal also supports a shopping cart interface in which customers can specify ? and pay for ? multiple items from your store. The code is nearly identical to the form in the previous section, except for two fields. First, change the contents of the cmd field to _cart (with the underscore), like this:
<input type="hidden" name="cmd" value="_cart">
Next, add the following new field:
<input type="hidden" name="add" value="1">
Finally, change the caption of the submit button like this:
<input type="submit" name="submit" value="Add to Cart...">
When your customers add items to their shopping carts, they'll see a page like the one in Figure 7-12.
You'll be notified of any completed sales with a payment notification email to your registered PayPal email address. To eliminate the human interaction required to process the emails and further integrate your business with PayPal, you can use Instant Payment Notification, as described in [Hack #80].
Also, see [Hack #49] for details on controlling the integration of PayPal with your completed auctions.