Hack 31 Create an Auction Payment Button

figs/moderate.gif figs/hack31.gif

Create payment buttons for auctions, such that the completed transaction updates the payment status on the auction web site automatically.

Merchants that sell using auction sites such as eBay often have to collect payment for their goods after the auction has ended. Sometimes, it can be confusing to the winning bidder how to complete payment, and you'll want to make it as easy as possible for your customers to send you money. Using some simple HTML, you can construct a payment button much like the payment buttons generated by PayPal for Shopping Cart and Web Accept purchases. You then present this button to the winning bidder in an email or on your web site to supplement the payment buttons already on the auction site.

4.5.1 The Easy Way

Since PayPal is an eBay company, it shouldn't be surprising that PayPal is well integrated with the eBay web site. For instance, if you indicate that you accept PayPal payments when constructing an eBay listing, a PayPal button will automatically appear for the winning bidder when the listing ends. Here's how to build the link between your eBay account and your PayPal account:

  1. Go to the eBay web site and log into your eBay account.

  2. Go to My eBay and click the eBay Preferences link under the My Account heading.

  3. Click the Change link next to the Payment Preferences heading, and turn on all the PayPal-related settings here.

  4. When you sell your next item, check the PayPal option in the "Seller-accepted payment methods" section and enter the email address of the PayPal account to which you'd like auction payments to be sent.

That's it! When your auction ends, a PayPal payment button will automatically appear at the top of the auction page, but for the winning bidder only.

Furthermore, you can configure PayPal to automatically insert a Pay Now button into each of your running auctions:

  1. Log into your PayPal account.

  2. Click the Profile tab and then click Auctions.

  3. If your eBay account isn't listed here, click Add, and then enter your eBay user ID and password.

  4. Otherwise, simply turn on the features you'd like to employ. The changes will take effect immediately.

The PayPal Auction options include the following:

Automatic Logo Insertion

PayPal automatically inserts a PayPal logo into the description of each of your running auctions (using eBay's Add to Description feature). This not only advertises the fact that you accept PayPal, it also gives your winning bidder a shortcut to the payment process.

Winning Buyer Notification

This instructs PayPal to automatically send an email to all your winning bidders, complete with payment instructions and a Pay Now button. This email is sent independently of eBay's "Congratulations! You are the buyer for..." email.

PayPal Preferred on eBay

This inserts the PayPal logo into the "Payment methods accepted" section of your auction page, as shown in Figure 4-3. The PayPal logo appears in addition to the logo that might already be there and suggests to your customers that you not only accept PayPal, but you whole-heartedly prefer it as a means of payment.

Figure 4-3. Buttons indicating that you prefer PayPal in an eBay listing

4.5.2 Making Your Own Button

Although eBay provides payment buttons for high bidders, you might want to supplement these buttons with your own. Plus, you might want to add eBay-like functionality to other auction sites, such as Yahoo!, uBid, Amazon.com, MSN, and Bidville auctions.

This code displays a simple Pay Now button that sends your customers to the PayPal web site and guides them through the payment process. The system automatically tracks the payment for this particular auction, so your customer will not have to enter any additional auction-related information. Plus, the auction site, provided that it's linked up with PayPal, will be notified automatically so that it can update the payment status of the auction for you and your bidder.

The goal of providing an extra payment button like this one is to reduce the chances that your customer (bidder) will use PayPal's Send Money function to pay for an auction; in that case, you would receive a payment not linked to its corresponding auction.

Among other difficulties, PayPal's Send Money tab makes it possible for your customer to "forget" to include the shipping charge or sales tax, you might have to process the order manually (or simply refund the payment), and the auction site might not reflect that the customer has paid. To automatically reject all payments sent this way, configure your PayPal account to "Block Payments from users who initiate payments from the Pay Anyone subtab of the Send Money tab," as described in Chapter 3.

Here is the HTML code for an auction payment button, linked to a particular auction:

<form method="get" action="https://www.paypal.com/cgi-bin/webscr">

<input type="hidden" name="cmd" value=_cart>

<input type="hidden" name="business" value="youremail@paypalhacks.com">

<input type="hidden" name="item_name_1" value="Widget">

<input type="hidden" name="amount_1" value="1.00">

<input type="hidden" name="quantity_1" value="1">

<input type="hidden" name="site_1" value="eBay">

<input type="hidden" name="ai_1" value="2540252652">

<input type="hidden" name="ab_1" value="your_ebay_id">

<input type="submit" name="upload" value="Pay Now">


This code is similar to the code used in [Hack #50], with the exception of a few new variables: site_n, ai_n, and ab_n, where n is a number representing the item in multiple item payments, starting with 1 (for example, include ab_1, ab_2, and ab_3 if you're requesting payment for three different auctions).

The site_n variable defines the site on which the auction was listed, and it should be set to eBay for eBay auctions or Yahoo for Yahoo! Auctions. This value is case sensitive, so for other auction sites, you'd type uBid, Amazon, MSN, or Bidville. The second variable, ai_n, should be set to the auction (or listing) number at the auction site. Finally, ab_n, is your user ID at the auction site (your_ebay_id in this example). Naturally, you'll need to replace all italicized text in the code with the details of your transaction.

The other variables, such as item_name_n and amount_n, can be modified as described in [Hack #28] .

4.5.3 Hacking the Hack

This hack demonstrates how you can create buttons that facilitate auction-specific payments. Naturally, creating a button for each auction manually would be a time-consuming process, but you can use the eBay API to automate this process. Start by sending a query to obtain the information for each of your completed auctions using a GetTransactionDetails call, and then assemble your buttons and email them to the high bidders. The technical procedures involved with implementing this type of system go beyond the scope of this book, but extensive information can be found in David A. Karp's eBay Hacks (O'Reilly).

If you use an off-site listing tool or a third-party listing service to build your auctions, you might be able to tie your application into the application's local database. However, you will also need a means of obtaining completed-item details (such as the final price and high-bidder contact information). For an example that shows how to build payment buttons dynamically, see [Hack #54] .