12Jun
PHP Class: Paypal Button Generator
Ever tried to make a Paypal button using their Button Creator, or even by getting the information from their Help pages? It’s not easy or dynamic. I’ve made many sites that use Paypal for their payment of both single items and multi item shopping carts. I’ve created this class to make my job easier. I have not come upon something like this in my search on the internet, so I’m sharing it to the world.
This class supports:
- CSS Styles
- Custom IPN, Return, and Cancel pages
- Postage, handling and tax amounts per item
- Custom pass-through variable
NEW – Version 1.1 now supports PayPal Subscriptions!
Sites using this class:
Download
- Download Version 1.1 (30-11-2005) (Zip file)

Trying to get this to work – the images link in the code is broken — and for ex: just wood toys looks like a complete cart system (to me) The Planet source code area states there was an “example file as well” I figure this is the example.php page – I’m stuck here
Yes you’re right, the example file that was included is quite outdated. I’ve re-written the examples, and they’ll give you a much clearer picture now. The zip file has been updated with this new file (and the downloads here work now, yay!). If you’re still having trouble, let me know.
Hi – Great class. I was going to write one myself but yours works perfectly!! My site is an online website builder and one of my products is a 4 page dynamic site with a paypal driven shopping cart. As the customers build their own pages, your class worked perfectly to do all of the redirections etc. Thanks and great work!! You wont be able to see it in working for a few days as i still need to get the products pages built but the product is online.
I will try your this great class.
Thank you.
Sounds great! I’ll try it out!
first be indulgent about my english (i’m french) i’am looking for a php code that might be very easy for you, i’ve built a website with a shopping cart but now i want to integrate paypal to give my customer another way to pay.So when the customer is checking out he is asked to choose and option to pay his cart.when he click on “pay with paypal or credit cartd” i would like to find a way to dynamically build this button in function of the customer’s shopping cart button so that he would be using a single button to send informations about a multiple-items-shopping-cart to paypal
This is working great for our application, I have a few websites that will benefit from this. Right now it’s being used at a college frat website that accepts donations…
cool stuff… thanks
My problem is – I want to build a cart which will prevent visitors to view private pages until they PAY thru paypal. How to do it ? Will this CLASS help me
No. The class will create a Button that they can use to pay with, that is all. What you are looking for is Paypal IPN. It’s a secure way of checking whether the visitor has just come from paypal, and if the payment was a success or failure.
This class has an option for an IPN url, which you will need to use as part of the process. Searching paypals site for IPN will help you find out more.
Thanks JC, But what is the effectiveness of your class, PAYPAL buttons u generate dynamically ?I also need a list of buttons with an ID for each of the button , (ID from Database).. I also need this, but also a payment security – I mean IPN type should be incorporated in my system, I mean- the payment was a success or failure.
Yes exactly. Dynamic generation of buttons with hidden custom fields and the like.
There is a less secure way of getting the success or failure to a page, known as the passthrough URL. But, because it is simply a POST request it is open to vulnerability.
I should mention that I wrote this class over 2 years ago, I don’t even know if paypal supports it’s features anymore.
Hi, anyone know if its possible with this class, to include the logo of my site, in the paypal banner, when a user is bying a product.
i’ve tryed to use the attribute $image, but it dosen’t work. i used an image with 150×50.
am i doing somthig wrong? is that the attribute?
I have been looking for something like this for ages.
Assuming PayPal haven’t changed the way they work, I look forward to putting this to good use.
Thanks.
A teeny little suggestion, if I may : modify the constructor
thusly :
function PayPalButton($paypal_url=’https://www.paypal.com/cgi-bin/webscr’)
and make the code use that string : makes it heaps easier to do testing via the paypal sandbox. Otherwise – Lovely Stuff!
Cheers,
Martin
Exactly what I was looking for!
This class php4? php5?
Both :)
Hi –
I’m trying to implement this class to add multiple items to a shopping cart — passing the ” $button ” varibles to the class from flash.. basically what I need to know if anyone knows is how to directly run the class without embedding an html button first – or making the button default “clicked” and immediately navigate to paypal -
cause I’m not very PHP savy yet I’m not sure how to go about it, anyone?
hi,
i need a pay now an d subscribe buttopn in turkish. I cant find any on paypals website. does anyone know where to find non english paypal buttons?
this is exactly what I was looking for, and its still working. however, i cant seem to get a custom ‘add to cart’ image working. anyone have suggestions?
i dont want my email address on PAYPAL page. How can you write “Almost Anything Desktop Publishing” instead of your email???
Simply fantastic. Used alle night trying to find something like this … and here it was. Thanks man!!
thanks
Thanks for sharing
Yes, you are very much right, you cannot open a PayPal account for Charity, if your charity is registered in India, same thing happened with me also, I applied a Charity account for my client and after completing all the formalities they just denied for the account.
I have a suggestion for you, apply for a normal account with some other website and then use it for your Charity website, I have list of websites who are doing the same thing.
You can also try some other Payment Gateways like CCavenue, but in case you are using Vbulletin script, I don’t think so that it may help you. The first suggestion may work for you.
BEAUTIFUL SCRIPT!!! Got it fully integrated and working gracefully in under an hour, customizing was a breeze. I’ve implemented it into my CMS, which before i had the whole PayPal API setup, but now I can give my clients the easy choice of full integration or simple, thanks to this class. And I’ve made sure you got full credit in the source code of my CMS. Great, great job and thank you so much for making it free, that’s the best part of it all. You’re a great dude!
Hi,
Love the script, just implemented it as part of purchasing tickets for shows on our website. There is only one thing which i would question and that is when the transaction is set up with paypal I see “Cancel and return to my-email@domain.com” rather than what i would expect is “Cancel and return to http://www.website.com“. Is that just my expectation that is wrong or is that something that can be passed to paypal?
Thanks.
Simon