FreelanceSwitch
The Blog Job Board Freelance Book Forums Podcasts Resource Directory

Making a PayPal Form Tutorial

Collis Ta'eed

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="accounts@freelanceswitch.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:

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">

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!)

Currency Code
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.

Return URL
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.

Item Name
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.

Amount
The amount field is pretty self explanatory. The only thing to note is that if the user types anything other than a number in here PayPal will return an error, so you might want to use some Javascript to do validation on this field and ensure it’s a number - though that’s not necessary. The main problem is your users might be tempted to write in a dollar sign - e.g. “$450″ which results in an error. Another solution would be to write a $ sign before the form field.

Step 3 - Test!

OK and that’s it really! Here is the example form that i just made, you can write in some values and test out how it appears in PayPal, heck you can even donate some money if you like ;-)

Item Details:

Amount:


Collis Ta'eed

Click here to view a bio plus other posts


Leave a Comment
  1. Thanks. Nice tutorial ! I’m twice the happier now that my country (RO) can also receive money from PayPal, not only send :D

  2. Oh this is great guys! I can’t wait to crack my knuckles and sit down to make this work!

    A+!

  3. Nifty little idea this, thanks.

    BTW: The RSS feed for the blog is hosed. Try visiting http://feeds.feedburner.com/FreelanceSwitch in Firefox for some angry red error text.

  4. Sweet, i was actually looking for such an article, off to make my form now :)

  5. Does anybody know how to do the exact same thing but using Google Checkout? I’ve heard many horrible stories about PayPal stealing thousands of dollars from peoples accounts and people being out of luck to get it back. I trust Google much more.

  6. Should one be hosting their website on a secure server (https:// vs http://) to use this securely?

  7. This is a grea tutorial guys thanks for sharing! Very useful for those that want to make their own form ;)

  8. a sneaky way to raise funds. very sneaky. ;)

  9. Great and very useful tutorial! Thanks! :D

  10. Needed this, thanks!

  11. great tuto .. thanks a lot …! :0)

    greetings!

  12. Thankyou this is great!

  13. @Nathan: Thanks for the heads up, I think i must have broken that last week and not realised, argh! I’ll fix it today, it’s an extra line we put in for the podcast :-|

    @Matt: Regular http:// is OK actually, nothing secure happens on your site, because the only information they are transferring is that invoice number and an amount. Once they get to PayPal, they will be in a secure environment and that’s when they actually put in their payment/credit card/bank details. The neat thing about PayPal is that if someone gets your PayPal email address the only thing they can do is pay money to you - actually I suppose if they knew you well they could maybe try guessing your password, but that just means you should have a hard password for things like PayPal - I use long strings of random characters which are troublesome to remember but safe :-)

    Anyhow so you can place the form on anything and you’ll be fine!

  14. Do payments made this way still attract the same Paypal fees? If so, how do you allow for the fact that an invoice paid via Paypal will actually return you less funds than if they pay by some other method, e.g. direct bank deposit?

  15. Researching all eCommerce means, just about everyone will charge you per sale, per month, etc. PayPal and Google checkout have very great deals on pricing. You could always ask for a check or direct deposit, but then it isn’t anonymous nor convenient. Thanks for the great tutorial! Do one for Google checkout now please!!! :D

  16. Maybe not convenient, but if you’re asking your clients to pay their invoices (as demonstrated in the first example in this article), anonymity doesn’t really come into it. You aleady know who they are and they already know who you are. My question doesn’t really relate to ecommerce - I’m not talking about selling anything, I’m talking about offering different payment options to clients.

  17. @Collis Well, yeah, duh. That makes sense, of course. Thanks!

  18. Great little tutorial!

  19. I like it a lot :D

    will defiantly have to use this, already have three or four websites I could use this for

  20. Hey nice Tutorial,
    We implemented a paypal integration into one of our sites lately using Ruby on Rails.

    http://www.fortytwo.gr/blog/14/Using-Paypal-with-Rails

    Hope it is useful to someone.

    Regards
    Vasilis

  21. Cool tutorial,

    Will be very useful! And complements on the site in general; nice slick design and some excellent content!

  22. Great tutorial. Thanks!

  23. A really useful tutorial - this is exactly what I need for my site. PayPal’s own documentation makes it sound so complicated and I had no idea it was so simple. Thank you! :)

  24. So all I need to do is view source and find the return url to get the stuff/ebook/scirpt/software for free?

    Um.. time to grow up eh?

  25. Good tutorial.
    Paypals documentation is way too complicated. This is what i need to see how it works and build it from there. Too bad you didn’t finish the tutorial with testing against paypal’s servers. ;)
    Thanks

  26. Good One….. thanks a lot

  27. If concerns of people viewing source are ripping your URL a quick google search returned this:

    http://www.1-hit.com/online-payment-systems/html-encryption.htm

  28. Nice tutorial thanks for the share.

  29. Great tutorial!!! Thanks Magic to you too!

    A very useful post. Unfortunately for my mates in Argentina Paypal doesn’t seem to work very well.

  30. I have a personal paypal account how can i claim donations..its saying wrong paypal id.plz reply to my mail

  31. i have implemented the code and it does seem to work but……
    is there a way to have the text of your product and the price embedded in the form

    what is worrying me is if a user input $5.00 instead of the price e.g $7.00 would the transaction go through where-as the consumer could input $0.01 and still get away with the product????

  32. Awesome lil tut

  33. you did not mention something very important.
    how does paypal know which vender is sending a customer ?
    https://www.paypal.com/cgi-bin/webscr only sends the form to the login page in paypal
    I know there must be that hidden field related to the vendor ,you could’ve insert it as well with a value of :)
    Also,how about using a link that embeds all that stuff and its advantages vs disadvantages ?
    nice tutorial,keep up the good work

  34. Is there a way to adapt this for a Registration Form? For Example:

    Customer fills out RegForm > they click a Next button (info goes to us) > they finish paying with PayPal (we get a confirmation of payment).

    A tutorial like that would save the day! Thanks.

  35. What happens if someone edits the HTML code, inserts a lower number in the “amount” field, but leaves everything else the same.

    Then they would automatically get access to the product being sold.

    I guess this could be combated by performing form validation before the data gets sent to paypal and/or when IPN sends it back. Could store the form values and only allow access to the website once the IPN values that come back match the values that were originally sent from the website.

    The (dollar amount) value would need to be checked before the form was submitted.

    Hmm… seems a bit confusing, and still not water-tight. But i guess that’s the cost of using a cheap service?

  36. Even if they were to visit the “payment complete” URL, it is very easy to check PayPal for the correct payment amount from the client or whether they paid at all. Worst case scenario just don’t use a custom page, but either way, it is very easy to tell if they have paid by checking your PayPal account.

    If it is being used for another method such as a registration where it is a specific amount that is required, just require that amount and don’t give them a field to enter it. I have seen many retailers use PayPal, where after paying, it takes you back to their checkout process with the funds now processed.. obviously if someone was to hack the URL by visiting the “payment complete” page for this type of checkout, it will still say it needs more funds, because the checkout process on the retailer’s site makes sure that the paypal payment processed first. I am sure PayPal provides ways of doing this to make sure no one’s customers or clients are getting anything for free.

  37. nice post, btw my client do not even know about it, so we must make them understand how it could work…

  38. hi

    I am new to paypal and I would like to display the shipping cost for the transaction in the paypal site. I’m displaying tax per each item by using the following code.

    This works fine and the total tax value is displayed below the subtotal in the paypal site. However i cant pass shipping cost for individual items like

    because the total shipping cost is not displayed in paypal. Can some one tell me the correct way to do this so the total shipping cost will be calculated by paypal and displayed like it happens with tax.

    Thanks

  39. hi

    I am new to paypal and I would like to display the shipping cost for the transaction in the paypal site. I’m displaying tax per each item by using the following code.

    input type=”hidden” name=”amount_1″ value=”26.99″
    input type=”hidden” name=”tax_1″ value=”2.00″

    input type=”hidden” name=”amount_2″ value=”25.99″
    input type=”hidden” name=”tax_2″ value=”8.00″

    This works fine and the total tax value is displayed below the subtotal in the paypal site. However i cant pass shipping cost for individual items like

    input type=”hidden” name=”shipping_1″ value=”8.00″
    input type=”hidden” name=”shipping_2″ value=”18.00″

    because the total shipping cost is not displayed in paypal. Can some one tell me the correct way to do this so the total shipping cost will be calculated by paypal and displayed like it happens with tax.

    Thanks

  40. Hey!
    Some of the links in the tutorial seem to have gotten broken over time, might want to look into that.

  41. This is easy tutorial for new commers

  42. Why waste time juggling with HTML.. I prefer using a invoicing software like CurdBee to get the job done.

  43. You might want to check your “Here is an example” and “http://freelanceswitch.com/payment-complete/” links, they are not working… would be nice to be able to see those examples… anyway, nice tutorial :)

  44. Hi All,

    Here is an example of how to make this better:
    http://www.appointmentsbook.com/appointmentsbook/shopping.aspx

    1. view the html source and see the Javascript in the tags.

    functions:
    autocheck
    ddlCopies_Change
    getCheckedValue
    GetSelectedCurrency
    GetSelectedCurrencyStandardEdition

    2. Put this line of code in to tick one of the currency radio buttons

    <body onload=”javascript:autocheck(1);

    Tip: the above line hides dropdownlists with other currencies on page load

    3. Then put in the dropdownlists with the prices

    Note: I have prevented users typing there own figures and remove and foreign dollar sign. It seems PayPal has a regular expression that only validates currencies with “$” type of dollar sign, pounds and euros it doesn’t like.

  45. also e-junkie.com is a valuable partner when you need PayPal APIs but dont have the time

  46. Wow that’s a superb idea…

    I will try it soon. Thanks man :)
    http://www.fadzuli.com

Leave a Trackback