Home MVC Storefront

Using PayPal PaymentsPro and Standard with ASP.NET 1.1 (C#)

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.

 

APIWrapper.zip (5.74 KB)
misa avatar
misa says:
Wednesday, June 06, 2007
Hi, I've been trying for two days now to make a successfull call to any paypal api method. I followed the instructions from your article on installing the paypal certificate step by step and when I call any method I always get the 10002 error code with the message Security header is not valid. Do you have any idea why this might be? Any help would be greatly appeciated.

manoj avatar
manoj says:
Wednesday, July 18, 2007
Hi, I've been trying for two days to make a successfull call to paypal api method. I followed the instructions from your article on installing the paypal certificate step by step and when I call method I and set the value in
public APIWrapper(String apiUserName, string apiPassword, string certLocation)
always get the

"System.Security.Cryptography.CryptographicException: Cannot find the requested object"

[CryptographicException: Cannot find the requested object.
]

at line number 74

X509Certificate cert = new X509Certificate(buffer);


Do you have any idea why this might be? Any help would be greatly appeciated.

developerk2 avatar
developerk2 says:
Friday, July 20, 2007
i develop an application while using pay pal Dot.net sdk it worked fine on my local server. but when i upload it on my hosting provider it got the following error.
SecurityException: That asembly does not allow partially trusted callers. can anyone help me out

fwse avatar
fwse says:
Monday, August 06, 2007
rwrwer


Search Me
Subscribe

Index Of MVC Screencasts

You can watch all of the MVC Screencasts up at ASP.NET, and even leave comments if you like.

Popular Posts
 
My Tweets
  • @jasonbock Kittens are having a really, really rough go of it then - Oxite is #2 on Codeplex downloads: http://www.codeplex.com/
  • Ergodynamic urinals. Awesome. http://twitpic.com/102dz
  • @paulsterling went to Laurelwood yesterday - absolutely stellar
  • At Hopwerks in Portland; awesome beer, outstanding grub, and a play area for the girls. Portland rocks.
  • I seem to have found @shanselman's otter... With "carrot"and all
  About Me



Hi! My name is Rob Conery and I work at Microsoft. I am the Creator of SubSonic and was the Chief Architect of the Commerce Starter Kit (a free, Open Source eCommerce platform for .NET)

I live in Kauai, HI with my family, and when my clients aren't looking, I sometimes write things on my blog (giving away secrets of incalculable value).