In my last post I wrote about how to setup your SSL certificate properly. It's a bit of an issue for PayPal and Microsoft, but there is an answer and that's a good thing.
Now we get to the good stuff- how do you use the dern thing! First you have to setup a PayPal Sandbox account (a merchant and a regular account that will pay the merchant). If you don't know what a Sandbox account is, head on over to http://developer.paypal.com and it will be explained.
Once you do that, upgrade the business account to use the API; also MAKE SURE you upgrade again to PaymentsPro! Most people forget about this part.
Get your certificate following my last post, and in addtion make sure you download both the WSDLs (and the ebay type XSDs) from the downloads area. This is very important- you can only use the Sandbox WSDL with the sandbox, and live with live.
If you haven't ever used a WSDL, you can think of it as a web service proxy. PayPal doesn't want just anyone snooping around their web services, especially us mischevious developers. So instead of pinging their API to figure out what it does, you have to use one of these WSDLs (Wizdells). Setting them up is simple: create 2 virtual directories on your machine - one for sandbox and one for live, and simply put the WSDL and the XSDs in the appropriate folder. I put mine in the PayPal/soap/sandbox and PayPal/Soap directories.
When that's done, you can now use Visual Studio's web reference tool to capture the WSDL. Right click on the References folder and “Add Web Reference“; a dialog will pop up and ask you for a URL - enter the URL of the sandbox WSDL file you just created (including the wsdl extension) - name the reference something meaningful and off you go. I called mine “PayPalSvc“ - to use the attached code you should to the same.
The API works off of a simple Request/Response and rather then go through it all, here is what I am calling the APIWrapper (which was actually published in the chapter I wrote for PayPal Hacks. You can use this wrapper to do all of your dirty work for you - I am actually using it in 4 separate projects right now, and it works great. Just spin it up with the proper settings (including an absolute reference to your cert file) and you're off and running.
Note: you can use this exact code with 2.0, and in fact avoid the headaches of cert files altogether. Using 2.0, you can attach a PFX file (an SSL cert with a key) and .NET won't have to access the machine store at all. I'll post that one in a few days.
