Приглашаем посетить
Чарушин (charushin.lit-info.ru)

Using a PayPal Buy Now Button

Previous Page
Table of Contents
Next Page

Using a PayPal Buy Now Button

One of the most common usages of forms is to carry out e-commerce, which typically involves a form that serves as a web-based shopping cart. Full-blown shopping cart forms can be very complex, but there is a simple alternative if you don't want to tackle developing a shopping cart of your own.

I'm referring to a PayPal Buy Now button, which takes advantage of the popular PayPal electronic payment service to provide a "buy now" link for your own products and services. If you haven't heard of or used PayPal before, take a moment to visit the PayPal site (http://www.paypal.com/) and take a look around.

By the Way

PayPal was purchased by eBay a couple of years ago, and is now the preferred payment method for eBay auctions. Needless to say, PayPal is here to stay as an online method of payment.


PayPal makes use of forms in somewhat of an unconventional wayyou use a form to create a customized button that appears simply as an image on a page. When the user clicks the image, the form data is passed along to PayPal to provide specifics about the item being purchased. By using a form to submit purchase data, a PayPal Buy Now button allows PayPal to offer a customized shopping experience without much technical mess. More important, PayPal Buy Now buttons make it very easy for web page developers to sell products and services without having to spend lots of money on expensive shopping cart applications and credit processing services.

To get started using PayPal Buy Now buttons, you first need a PayPal account. If you don't already have a PayPal account, you can create one by clicking Sign Up in the upper-left corner of the main PayPal web page (http://www.paypal.com/).

After you have an account created, log in and visit the Buy Now Buttons web page at https://www.paypal.com/us/cgi-bin/webscr?cmd=p/xcl/rec/singleitem-intro. Click the Get Started! link to start creating a PayPal Buy Now button. Figure 18.4 shows the next page that appears, which prompts you to enter information about the product or service you intend to offer for sale.

Figure 18.4. The PayPal Buy Now Button tool prompts you for details about the item you want to sell.

Using a PayPal Buy Now Button


In this example, I've entered information pertaining to a trivia game that I created for my company, Stalefish Labs. As you can see in the figure, I had to enter the name of the product, an item number, and a price; the item number can be anything you want it to be. You must also set the currency for the transaction, as in U.S. Dollars, Canadian Dollars, and so forth. You can also set the country for the buyer, which I don't recommend doing unless you have very specific requirements for the location of buyers.

Click Choose a Different Button to change the appearance of the PayPal button that will appear on your page. In the example, I opted to use a larger button that will be more prominent on the page. You can also use your own button image if you so choose.

The last option you must enter, which isn't visible in Figure 18.4, is whether you want the HTML code for the PayPal button to be encrypted for security purposes. This ensures that if someone hacks your site they'll have a much more difficult time attempting to change the price or other details of your item that is for sale. Whether to use this setting is entirely up to youI opted not to in order to keep the code simpler for this example.

Did you Know?

Click the Add More Options button to set additional options for the Buy Now buttoncustom option fields, multiple item purchase, and an optional buyer note, to name a few. Using an encrypted Buy Now button limits some of these advanced options you can set for the button.


Figure 18.5 shows the page that is displayed after the Create Button Now button is clicked.

Figure 18.5. When you're finished describing the item, PayPal automatically generates HTML form code that you can cut and paste into your page.

Using a PayPal Buy Now Button


The figure reveals that the PayPal Buy Now Button page generates the code for a complete HTML form that you can cut and paste directly into your own pages. Just highlight the code in the first edit box, copy it, and then paste it into your page. Listing 18.3 shows an example of a web page that includes the automatically generated PayPal Buy Now button form code.

Listing 18.3. The Tall Tales Sample Page Now Includes a PayPal Buy Now Button for Buying a Copy of the Game Through PayPal
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <title>Tall Tales - The Game of Legends and Creative One-Upmanship</title>
    <style type="text/css">
    ...
    </style>
  </head>

  <body>
    ...
    <p>
      To learn more about Tall Tales, visit the Tall Tales Web site at <a
      href="http://www.talltalesgame.com/">www.talltalesgame.com</a>. Or to buy
      the game just click the button below:
    </p>
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
      <p style="text-align:center">
        <input type="hidden" name="cmd" value="_xclick" />
        <input type="hidden" name="business" value="michael@stalefishlabs.com" />
        <input type="hidden" name="item_name" value="Tall Tales Pocket Edition" />
        <input type="hidden" name="item_number" value="TTPE" />
        <input type="hidden" name="amount" value="14.95" />
        <input type="hidden" name="no_note" value="1" />
        <input type="hidden" name="currency_code" value="USD" />
        <input type="hidden" name="bn" value="PP-BuyNowBF" />
        <input type="image"
        src="https://www.paypal.com/en_US/i/btn/x-click-but5.gif"
        style="border-style:none" name="submit" alt="Make payments with
        PayPal - it's fast, free and secure!" />
      </p>
    </form>
  </body>
</html>

You may recognize this page from earlier in the book. In this example, an otherwise interesting promotional page is made considerably more valuable by becoming a simplified shopping cart of sorts. In other words, now visitors to the Tall Tales page can not only learn about the game, but also buy a copy by clicking the Buy Now button and paying through PayPal (see Figure 18.6).

Figure 18.6. The PayPal form code in Listing 18.3 produces this form, which is really just a button that links to a PayPal purchase page.

Using a PayPal Buy Now Button


By the Way

It's worth mentioning that I had to make some slight changes to the code generated by PayPal. Unfortunately, PayPal doesn't crank out XHTML-compatible code. I had to place the <input /> tags within a parent <p> tag, as well as altering the border code for the button image so that it uses CSS instead of the deprecated border attribute.


Clicking the Buy Now button near the bottom of the screen shown in Figure 18.6 links you to a Checkout page on the PayPal web site, where the item details are presented before the purchase is confirmed (see Figure 18.7).

Figure 18.7. When the user clicks the Buy Now button, the form takes you to a PayPal purchase page where the purchase is carried out.

Using a PayPal Buy Now Button


From here on, the transaction is purely in the hands of PayPal. The funds for purchases through a PayPal Buy Now button are automatically deposited into your PayPal account, and you receive a notification of the purchase to the email address associated with your PayPal account. Don't forget that it's still up to you to deliver the product or service to the customerPayPal just handles the payment side of the equation.


Previous Page
Table of Contents
Next Page