Click here to Skip to main content
16,005,121 members
Articles / PayPal

Quick-and-Dirty, Buy-Now Buttons in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.75/5 (3 votes)
16 Feb 2010CPOL3 min read 13.8K   7   1
For quick and dirty Buy Now buttons, there is a far simpler approach. You can simply use an anchor link and provide parameters as query arguments.

I posted previously about an issue when incorporating PayPal Buy-Now buttons on an ASP.NET web form. Basically, after presenting a few hacks, I pointed out that you could simply place the form items directly within your ASP.NET form. (See that post for more info.)

However, for quick and dirty Buy Now buttons, there is a far simpler approach. You can simply use an anchor link and provide parameters as query arguments. Listing 1 demonstrates this technique:

ASP.NET
<a href="https://www.paypal.com/cgi-bin/webscr
  ?cmd=_xclick&business=MyEmail
  &item_name=Widget
  &amount=29.00
  &undefined_quantity
  &currency_code=USD">
<img src="http://www.paypal.com/en_US/i/btn/x-click-but23.gif"
  border="0" alt="Buy Now Using PayPal" />
</a>

Listing 1: Simple Implementation of PayPal Buy Now Button

Note that the href value of the a tag should all go on a single line. I wrapped the text here only so it would fit within the page. MyEmail should be replaced with the email address associated with your PayPal account.

As you can see, we provided several bits of information. After our account email, we provide an item name, the price (amount), and I included the optional currency code.

The undefined_quantity parameter allows the user to enter the quantity, and PayPal will calculate the total based on the price you specified and the quantity entered by the user. Alternatively, you can instead say quantity=5 to fix the quantity so that the user cannot edit it.

Although that should be all you need for a simple Buy-Now button, Table 1 lists some additional arguments you can include.

ArgumentDescription
businessEmail address associated with seller’s PayPal account
quantityQuantity of items being sold
undefined_quantityAllows user to edit quantity
item_nameName of item
item_numberOptional item number
amountPrice of each item (without currency symbol)
undefined_amountAllows user to edit the amount (good for donations)
shippingPrice of shipping
currency_codeCode for type of currency (Default appears to be USD)
first_nameCustomer’s first name
last_nameCustomer’s last name
address1Customer’s first address line
address2Customer’s second address line
cityCustomer’s city
stateCustomer’s state
zipCustomer’s zip code
emailCustomer’s email address
night_phone_aCustomers telephone area code
night_phone_bCustomers telephone prefix
night_phone_cRemainder of customer’s telephone number
Table 1: Additional Query Arguments

The arguments listed in Table 1 are not exhaustive. Other arguments are available as well. For the simple task I'm describing, this list should be more than enough.

Of course, you also have the option of programmatically forming this link and then using code to redirect to it. This allows you, for example, to set the quantity based on a value entered by the user on your own site.

Note that there are some potential downsides to this technique. For starters, the link is fully visible for anyone to see. Of course, it won't include your PayPal password so that type of information is not exposed. But your account email is visible.

Users can also save your web page to their computer, and then edit the link. So, for example, they could change the price, load the edited page, and click the link. So you need to verify the correct amount was paid when processing orders.

Nonetheless, for a simply Buy-Now button, this technique works great and couldn't be simpler to implement.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
GeneralMy vote of 5 Pin
Tahir Shah9-Aug-12 1:25
Tahir Shah9-Aug-12 1:25 
Excellent

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.