Thursday, April 3, 2014

Working with the PayPal API using ASP.NET

If you need to work with the PayPal API, you have 2 choices to choose from:

  • Classic API
As you can probably guess, the REST API is newer and therefore the preferred method of integration.

However, if you need work with the Classic API and you need to use Express Checkout, PayPal makes it quite easy for you to integrate your code with the language of your choice using the PayPal Integration Wizard:

Unfortunately, the PayPal Integration Wizard does not support code samples for integrating with ASP.NET MVC, therefore, you are stuck with ASP.NET Web Forms if you are planning on using the Wizard.

The PayPal Integration Wizard simply asks you a series of questions and then provides you with necessary integration code to include in your ASP.NET Web Forms files.  The main point to note is that you will need to create a Session variable called "payment_amt" in order to store the PayPal payment amount to submit to the PayPal site.

If you are planning on using the PayPal REST API, you can download code samples from here:

From the right hand lower corner, simply click on the link to "Download ZIP".  Once you extract the .zip file, you should be able to see the "Samples" folder containing the code samples for various versions of Visual Studio up to Visual Studio 2012.

Unfortunately, as with the PayPal Integration Wizard, the code samples are provided only for ASP.NET Web Forms.

When you open the Visual Studio 2012 Solution initially in Visual Studio 2013, you will notice that the RestAPISDK reference is missing.

Fortunately, since this package is managed through NuGet, this can be easily rectified!

You can simply go to "Manage NuGet Packages" and search for "PayPal REST API SDK".  This should return the appropriate search result and allow you to install the package for  your solution.

Once the NuGet package has been updated, you should be ready to work with the PayPal REST API code samples!

No comments:

Post a Comment