Making a PayPal Form Tutorial
Some time ago I put up a post here on the ‘Switch about Taking Payment with PayPal, Escrow and other Online Options in which I mentioned that it was relatively easy to create a form on your regular website that allows you to accept credit card payments. Here is an example that Cyan and I used to use on our portfolio/agency site.
This is a pretty neat thing to do because it’s both very simple and it’s kinda nice to be able to say “Oh yes you can pay by credit card on our website” which to most offline people sounds rather like “I am an uber-freelancer and I should be charging you six squillion dollars an hour, but you’re getting me for a steal”. In actual fact when Cyan and I had the form on our site, we only actually took payment through it maybe a dozen times, but just having it on the site made us look that much more professional.
How it Works
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://freelanceswitch.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 FreelanceSwitch.com"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="business" value="email@example.com"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="return" value="http://freelanceswitch.com/payment-complete/"> 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:
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.
The business field is this one:
<input type="hidden" name="business" value="firstname.lastname@example.org">
This is the most important field to modify as it is the one that determines where your customer is paying to. You need to substitute in your PayPal email address. So for FreelanceSwitch, our PayPal address is accounts [@] freelanceswitch.com, but obviously you’ll want to change that (though please feel free to send payment our way if you want to!)
The currency code value in my example form is set to USD, you could change this to your own currency (Cyan and I used to use AUD for Australian Dollars). If you want a list of the different currencies available through PayPal you should log in to your account, click on Merchant Tools then click on Buy Now Buttons and in the form there is a drop down box which lists them.
The return URL (or payment confirmation page) is set by this field:
<input type="hidden" name="return" value="http://freelanceswitch.com/payment-complete/">
Simply swap in the URL you created in Step 1.
The item_name field is the one where your user describes what they are paying for. When billing clients I set up my form to have “Invoice Number” and in the invoices we sent out under “How to Pay” it explained that you had to get the invoice number from the top right of the bill and type it into the form. In my example form below, I’ve written simply Item Details, so theoretically you could write anything in there – e.g. “Payment for Providing Amazing Freelancing Website, Thanks” and that will appear in PayPal when you go to purchase.
Note that if this were a Buy-Now button form, then the item_name would be a Hidden field with a default value, but we’ve changed it to a text field so the user can decide what they are paying for.
Step 3 – Test!
OK and that’s it really! Here is the example form that i just made…
Update: I had to put in a fake email address into the form below as a few people accidentally tested it with rather large amounts of money