Hack 28 Create a Buy Now Button 
Accept payments on your web site with a simple
button that sends the customer, along with all necessary payment
information, to PayPal.
The most basic
way to accept payments on your web site is to deploy a Buy Now
button, which essentially consists of an HTML form.
In order to use the Buy Now system, you need to have a Business or
Premier account at PayPal.
Use the Merchant Tools section of the PayPal web site to generate the
necessary code to sell goods from your web site. Once you have the
code for one item, you can modify that code for any of your other
products by changing a few variable values.
4.2.1 The Code
To generate a simple block of button code, follow these steps:
Go to http://www.paypal.com, log
into your account, and click the Merchant Tools tab. Click the Buy Now link under the Website Payments section to open the
PayPal
Button Factory, as shown in Figure 4-1.

Create a basic button by entering the item name and item number.
Leave the Buyer Country as is, and enter 1 for the
amount. Skip the rest of the settings, but make sure to change the
Encrypt Button option to No. When you're done, click Create Button Now to
generate the code.
The resulting code should look like this:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="sales@payloadz.com">
1. <input type="hidden" name="item_name" value="Widget">
2. <input type="hidden" name="item_number" value="Wid-001">
3. <input type="hidden" name="amount" value="1.00">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="image" src=
"https://www.paypal.com/en_US/i/btn/x-click-but23.gif" border="0"
name="submit">
</form>
Most of the variables will not change, regardless of
the item you're selling. The variables on lines
1 ,2 , and 3 are the only ones you'll need
to customize for each particular product.
Modifications to the variables are straightforward and can be done
directly in the HTML. For instance, to specify a price, replace
1.00 with the
price of your item, in dollars and cents (but no dollar sign).
Likewise, set the item_name variable
to the name of the product, and set the
item_number variable
to a unique product number or SKU code that makes sense for your
store.
4.2.2 Hacking the Hack
In addition to the aforementioned variables, there are also other
PayPal-supported options you can add to your purchase buttons. For
example, the return and
cancel_return
variables define the addresses of web pages to which the user should
be taken after the payment process has been completed or if the
process is cancelled, respectively:
<input type="hidden" name="return" value="http://yoursite.com/thankyou.html">
<input type="hidden" name="cancel_return" value=
"http://yoursite.com/cancel.html">
Simply insert additional variables anywhere in your button code, so
long as they appear between the opening
<form> and closing
</form> tags. Other variables include:
- cn
-
The text label
to appear above the note field (maximum of 40 characters).
- cs
-
Sets the
background color of your payment pages to black
(1); the default is white (0).
- currency_code
-
The
three-digit code indicating the currency in which the payment is to
be made.
- custom and invoice
-
Both
custom and invoice are
pass-through variables, never shown to customers, to be returned to
you when the payment process is complete.
- handling
-
The
shipping surcharge, applied regardless of the number of items
ordered.
- image_url
-
The
address (URL) of your company logo. The image can be up to 150x50
pixels. If this variable is omitted, the customer will see your
business name if you have a Business account or your email address if
you have a Premier account.
- no_note
-
If this
variable is set to 1, the customer will not be
allowed to include a note. It's probably best to
specify the no_note option (as in the example
earlier in this hack) if you'll be automating your
operation and are unlikely to see any notes your customers would
enter here.
- no_shipping
-
See
[Hack #34] for more information on
this setting.
- on0, on1, os0, and os1
-
See [Hack #33]
for more information on these four settings.
- page_style
-
Sets the
Custom Payment Page style for payment pages. This variable should be
the name of one of the styles listed on the Custom Payment Page
Styles page. To add or edit custom payment pages, click the My
Account tab, click Profile, and click the Custom Payment Pages link.
See [Hack #51] for further
details.
- return
-
The URL of
the page on your web site to which the customer will be sent when the
transaction is complete.
- rm
-
Specifies the
behavior of the return URL (see the return
option). If this variable is set to 1, the buyer
will be sent back to the return URL using a GET method, and no
transaction variables will be submitted. If rm is
set to 2, the buyer will be sent back to the
return URL using a POST method, to which all
available transaction variables will also be posted. If
rm is omitted or set to 0,
GET methods will be used for all Shopping Cart
transactions in which IPN is not enabled and POST
methods with variables will be used for the rest.
- shipping, shipping2
-
The
amount to charge the customer for shipping, per item. If you specify
an amount for shipping2, the
shipping amount will be charged only for the first
item ordered and shipping2 amount will be charged
for each additional item (all of which applies only if the customer
orders a quantity of more than one).
- tax
-
If this
variable is omitted, the sales tax specified in your account
preferences will take effect. Otherwise, use tax
to specify a flat tax (in dollars and cents, rather than a
percentage) to apply to the order.
|
Main Menu
|