Simple Checkout Express Using C# MVC Web API in PayPal | Best and cheap ASP.NET MVC Hosting. In this tutorial you will learn how easily you can implement a simple checkout express using C# MVC Web API. We will create a really simple shopping cart where customers can add and delete their cart items before proceed to payment.

Let’s start by creating an empty web application MVC project. In this example, we will use the Visual Studio Community 2015. Open the program and click the Menu > File > Project.

Select the Template for C# Language and choose the ASP.Net Web Application.


We are going to create this sample project as Web API Project.


The next step is to install the PayPal SDK. We can use Nuget Manager console to install this. It will basically will add the PayPal.dll and NewtonSoft.dll into the project. To install the component, simply type in the following code.

The next step is to create a PayPal app. You will need to go to the PayPal developer site.

If you do not have an account, you will need to create it first. Once create you can create a new app under Rest API apps.




Alternatively, if you are lazy to create an API account, you can use the following API credentials. They are from PayPal SDK sample. If it does not work, please use your own credential API Keys.

Once we have the API keys we can now add those information into our project web.config, you can save this information in the database if you prefer. Open your web.config and add the following line in your web.config file under configuration section.


And then add the following section setting under ConfigSections item. Make sure you add this one otherwise you will get an error saying related configuration data for the page is invalid.

The next step is to create a PayPal Configuration static class. This class will be used to return a PayPal API authentication object token against your credential api keys. On your solution explorer, create a new folder called Utilities. Add a new static class name PayPalConfiguration.cs


Edit the class file and copy the following code.

The request id is basically used to represent the order id, this must be unique and actually being presented to prevent any duplication same payment. In this example, I am using GUID for testing purpose only. But in real life, you should replace this with an invoice or order no.

We need to modify the home page index.html to the following code. Note: all the screens like View Cart, Order confirmation, View transactions history will be placed into one page. Feel free to separate them if you need to.

This will be the css style for styling our shopping cart.
And this is our main javascript logic that will perform the shopping cart payment.

Sample Card Images





I hope this article helpful for you. Happy Coding 🙂