PHP and the PayPal API - from 10,000 feet..
i spent a good deal of time plodding through the documentation to get this thing set up, only to find that the documentation is spread all over the site, and you really have to pull pieces from everywhere.. and alot of them are not 100% correct.. and alot of them don’t fit together..
the biggest problem that the doco has is that there is no view from 10,000 feet. the views are all from the ground.. here are some hints to save you some aggravation..
this is not a comprehensive “how-to” doc.. but rather a gotcha doc.
- the first thing you do is create accounts in what is called a “sandbox.” you need a developer’s account to do this, but in essence, you are just creating a buyer and a seller account. that’s it. there is no juju here.
- while you are doing this, you also need to generate fake certs.. write down the passphrase you use. you will follow the codebases and doco to hell and back. by the time you have assembled a workable codebase, you will have forgotten the passphrase you use. i did. on a good note, it’s easy to generate a new one. when you generate a new one, the old one is IMMEDIATELY taken out of service. if you are working on a live cert, there is a risk of disaster on a high volume site..
- next, you need to install the pear files. for those of you who are not familiar with pear, it is alot like CPAN in the perl world. my guess is that if you are struggling with this, you are probably using this on a shared system. there are special rules for setting this up on a shared system. mostly, this involves setting up paths to the pear libraries. make SURE you install the libraries above your web root so that no one can abuse them..
- now that you have all that setup, there is a web console that you can use to test your api calls. although this looks interesting and fun, i spent a good amount of hours getting all the path dependencies worked out. after a good afternoon chasing these down, i nixed the whole idea. it would be easier to code bareback here.
- you will most luck at this point if you just TOTALLY dump the whole set of examples that paypal gives you and go here. there is a good codebase there, BUT keep in mind, there are some problems with it.. when you start running it, and it goes haywire, look for an xpm tag. remove it AND its mate. also, there is a whacked out form tag in there somewhere. move form and its twin OUTSIDE the whole form (they are embedded kinda weird. dreamweaver will bitch like mad about this). fix that first before you go insane.
- ditch ALL of the POST variable initializations. trust me on this one. there are a TON that don’t really do anything but make you go back and forth about a million times trying to figure out what gets used and what doesn’t. this is all stuff that should be done in javascript OR left completely out of a tutorial on the API.
- create session variables for your info. the data is passed twice. this is a typo minefield. i found a neat way to do this (after my eyes glazed over for the millionth time tracking down POST variables.) you can see how i did it (and will do it from now on) . let me know if anyone has any comments on this. on my way out he door today, i started wondering if mabye i had a switch on in PHP that allowed you to just call $_SESSION and $_POST variables at will. i remember hearing that you could do this under some configurations. this seems almost as dangerous as putting your weiner in a meat grinder.
- finally, run some fake transactions. go back to that link on pear. there is a bogus credit card number on there that you will have erased when you set your forms up. you need that because you will have forgotten the fake credit card number of your sandbox account. i spent about ten minutes trying to figure out how to get that back, but i gave up. that other credit card will do. by now, you will have made a bogus express transfer anyway, so you know your sandbox account works.
well, that’s about it. in retrospect, it wasn’t THAT bad.. but it was sort of like those little chinese finger cuffs. once you figure out how to get them off, it all makes sense.. but when you are jammed all up in there, it’s maddening.. let me know if this helps..