May
26
Written by:
Steve Gray
5/26/2011 12:44 PM
When you create a web site in ASP.NET the form tag is included for you. This issue is magnified if you use master pages (who doesn’t?).
The issue is that the code that you get from PayPal has a <form> tag in it, and you can’t nest form tags. So your code doesn’t post correctly when the user clicks ‘Buy Now’.
Here’s a real easy way around that. There are two ways you can do this, as a link from the <HTML> code, or as a Response.Redirect from the code behind. The link will be less work, but also less flexible.
From the HTML, code something like this:
- <a href="https://www.paypal.com/cgi-bin/webscr
- ?cmd=_xclick&business=YOUR-PAYPAL-EMAIL-HERE
- &item_name=Widget
- &amount=29.00
- &undefined_quantity=1
- ¤cy_code=USD">
- <img src="http://www.paypal.com/en_US/i/btn/x-click-but23.gif"
- border="0" alt="Buy Now Using PayPal" />
- </a>
If you’ll compare the above to the code that you got from PayPal, you’ll see that we converted the <input> tags to be parameters in the query string.
From the code behind it looks like this:
- Protected Sub btnSubscribeYear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubscribeYear.Click
- Dim dblAmount As Double
- dblAmount = Me.txtAmount.text
-
- https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amount=" & dblAmount & "&hosted_button_id=3IMNOTREAL3E3
- End Sub
Here’s a list of all the arguments (not guaranteed to be complete or correct, you’ll want to check with PayPal for complete information)
Argument Description
business Email address associated with seller's PayPal account
quantity Quantity of items being sold
undefined_quantity Allows user to edit quantity
item_name Name of item
item_number Optional item number
amount Price of each item (without currency symbol)
undefined_amount Allows user to edit the amount (good for donations)
shipping Price of shipping
currency_code Code for type of currency (Default appears to be USD)
first_name Customer's first name
last_name Customer's last name
address1 Customer's first address line
address2 Customer's second address line
city Customer's city
state Customer's state
zip Customer's zip code
email Customer's email address
night_phone_a Customers telephone area code
night_phone_b Customers telephone prefix
night_phone_c Remainder of customer's telephone number
As always, I welcome your comments!