Integrate Stripe.NET Payment Processing Library With Your ASP.NET 4.5 C# Application
The Benefits of Stripe
Accepting payment cards online has never been easier than it is now. Companies like Stripe have made it easy for developers like ourselves to include advanced payment methods into our web applications without having to worry about the security compliance and audits that are usually associated with payment card data storage.
Stripe enables you to save customers’ information securely, create custom payment structures, and even create custom payment plans for multiple or single customers.
Stripe.NET is an open source library for the Microsoft .NET Framework that allows easy integration into your .NET projects. Today we will only be covering the integration of Stripe.NET into an ASP.NET project, but you can read the documentation and learn more about how to use the Stripe.NET library at the Stripe.NET Github repository.
For the purpose of this tutorial, we will be creating a new ASP.NET web application. If you already have an application that you wish to integrate Stripe.NET with, that’s awesome! If not, or if you have never created an ASP.NET web application, follow these first step to get up and running.
First, we need to create the project. We can do this by opening up Microsoft Visual Studio, and selecting
Visual C# > Web > ASP.NET Web Forms Application. Notice that we are using the .NET 4.5 Framework at the top of the window, feel free to change the framework version to your liking. Press OK.
You can get a free copy of Visual Studio Express for Web here.
Referencing the Stripe.NET Library
Once you have your application open in Visual Studio, you’re going to need to install the Stripe.NET library to use it’s classes and methods in your program.
By reading the Stripe.NET Github page, we’ve learned that the library is available as a NuGet package in Visual Studio, that’s the optimal way to integrate the library, so that’s how we’re going to do it.
In your solution explorer find the
References directory and right click on it. You will see an option labelled “Manage NuGet Packages…”, click that option in the dropdown menu.
You will be prompted with the Manage NuGet Packages window. Navigate down the left menu and click on
Online. Now you can type Stripe.NET into the search bar in the top left corner of the window, and (if you are connected to the internet) you will see the Stripe.NET library appear in the center of the window. Install the package and you will notice that it installs the json.NET and Stripe.NET package in the references directory. The reason this happens, is that the Stripe.NET library is dependent upon the json.NET library, so you must include it into your references directory in order for Stripe.NET to work.
The last step of integration in this process, is verifying your account with Stripe. The designated authentication method that Stripe has provided for us is their developer API Key. This key is unique to each Stripe user and verifies your account so Stripe knows which user account all of your transactions belong to.
We only need to place this API Key into our application once by opening up the Web.config file and placing the following code before the
<add key="StripeApiKey" value="[your API Key]"/>
Now you’re all set to use the Stripe.NET library in your application! Just remember to reference the json.NET and Stripe.NET libraries in any files you are using Stripe.NET functionality. Don’t forget to read the documentation at the Stripe.NET Github repository.