Making a PayPal Form to accept a payment on our site

PayPal makes doing this very easy by providing those “Buy-It-Now” buttons you’ve probably seen around the place. Basically when you see one of those buttons, it is really the submit button on an HTML form with all the form fields set to hidden. This is fine for when you have a set price and set item, but in our situation we want the client to be able to fill out what it is they are paying for (e.g. an invoice number) and also to set how much they are paying.

This is easily done by changing the <input> fields from hidden to text and stripping away the defaults so that the user can fill them in. So let’s get started.

Step 1 – Make a Payment Confirmation Page

First of all you should make a page to send the user to after payment has been processed. For the example form that I am making – one for FreelanceSwitch – I created this page http://sumitbansal.com/payment-complete/. On this page you should be placing a simple confirmation message so that your client doesn’t feel like they just sent money off into the ether. Next upload the confirmation page so it’s accessible over the web and you have a URL for it.

Step 2 – Create the Form

Next we create the form. When I first made this form I used the Buy-It-Now button form generator on PayPal and then modified accordingly, but you can just use the code below and make the changes I’ve described further on:

<form action=”https://www.paypal.com/cgi-bin/webscr” method=”post” id=”payPalForm”>

<input type=”hidden” name=”item_number” value=”01 – General Payment to SumitBansal.com”>
<input type=”hidden” name=”cmd” value=”_xclick”>
<input type=”hidden” name=”no_note” value=”1″>
<input type=”hidden” name=”business” value=”your@paypalaccount.com”>
<input type=”hidden” name=”currency_code” value=”USD”>
<input type=”hidden” name=”return” value=”http://sumitbansal.com/payment-complete/”>
<input type=”hidden” name=”cancel_ return” value=”http://sumitbansal.com/payment-complete-error/”>

Item Details:<br /><input name=”item_name” type=”text” id=”item_name”  size=”45″>
<br /><br />
Amount: <br /><input name=”amount” type=”text” id=”amount” size=”45″>
<br /><br />
<input type=”submit” name=”Submit” value=”Submit”>

</form>

The parts that need modification are as follows:

Item Number
The item number field is this one:

<input type="hidden" name="item_number" value="01 - General Payment to FreelanceSwitch.com">

The value you place in this field appears when the user goes to PayPal and clicks the down arrow for more details on their purchase (you can see it by entering some information in the test form below). I’ve used the value “01 – General Payment to FreelanceSwitch.com” and theoretically if I had some other forms for say donation I might write “02 – Donation” and so on.

Business
The business field is this one:

<input type="hidden" name="business" value="accounts@freelanceswitch.com">

Your PayPal ID or an email address associated with your PayPal account. Email addresses must be confirmed.

Currency Code

The currency of prices for trial periods and the subscription. The default is USD.

For allowable values, see Currency Codes.

Return URL

<input type="hidden" name="return" value="http://freelanceswitch.com/payment-complete/">

The URL to which the payer’s browser is redirected after completing the payment; for example, a URL on your site that displays a “Thank you for your payment” page.

Default – The browser is redirected to a PayPal web page.

Item Name

Description of item being sold (maximum 127 characters). If you are collecting aggregate payments, this can include a summary of all items purchased, tracking numbers, or generic terms such as “subscription.” If omitted, customer will see a field in which they have the option of entering an Item Name

Amount

The price or amount of the product, service, or contribution, not including shipping, handling, or tax. If omitted from Buy Now or Donate buttons, payers enter their own amount at the time of payment.

  • Required for Add to Cart buttons
  • Optional for Buy Now and Donate buttons
  • Not used with Subscribe or Buy Gift Certificate buttons

cancel_ return

A URL to which the payer’s browser is redirected if payment is cancelled; for example, a URL on your website that displays a “Payment Canceled” page.

Default – The browser is redirected to a PayPal web page.

For More PayPal HTML Variables Click Here

Share This Post

Post Comment