Stripe is one of the most popular gateways to implement credit card payment processing in web applications. Stripe provides an API that is used in a Web application. In this blog, we will see how to use the Stripe API to integrate credit card payment processing in an ASP.NET Web app using C#.
Here are the steps. Keep in mind I'm using a test account.
Step 1. Go to https://stripe.com/ to create an account and get API keys.
Step 2. Download the attached project, get Sripe.dll and Newtonsoft.Json.dll from the Bin Foder, and add references to your project.
Step 3. Create a simple ASP.NET Website and create a simple page with a button.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
On the button click event handler, we will execute Stripe API code.
Step 4. Add code to .cs file.
Here is the code-behind looks like.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Stripe;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Page Load logic goes here
}
protected void Button1_Click(object sender, EventArgs e)
{
StripeCustomer current = GetCustomer();
// Uncomment the following lines if you have a method getaTraildays()
// int? days = getaTraildays();
// if (days != null)
// {
int chargetotal = 100; // Convert.ToInt32((3.33 * Convert.ToInt32(days) * 100));
var mycharge = new StripeChargeCreateOptions();
mycharge.AmountInCents = chargetotal;
mycharge.Currency = "USD";
mycharge.CustomerId = current.Id;
string key = "sk_test_Uvk2cHkpYRTC2Rl4ZUfs4Fvs";
var chargeservice = new StripeChargeService(key);
StripeCharge currentcharge = chargeservice.Create(mycharge);
// }
}
private StripeCustomer GetCustomer()
{
var mycust = new StripeCustomerCreateOptions();
mycust.Email = "[email protected]";
mycust.Description = "Rahul Pandey([email protected])";
mycust.CardNumber = "4242424242424242";
mycust.CardExpirationMonth = "10";
mycust.CardExpirationYear = "2014";
// mycust.PlanId = "100";
mycust.CardName = "Rahul Pandey";
mycust.CardAddressCity = "ABC";
mycust.CardAddressCountry = "USA";
mycust.CardAddressLine1 = "asbcd";
// mycust.TrialEnd = getrialend();
var customerservice = new StripeCustomerService("sk_test_Uvk2cHkpYRTC2Rl4ZUfs4Fvs");
return customerservice.Create(mycust);
}
}
In the above code, we create a Customer and provide customer details, including credit card details. StripeCharge is the object responsible for charging.
Step 5. Build and run, and you should be able to execute a test payment transaction.
For more, please download the code.
Here is a detailed tutorial: Implement Stripe Payment Gateway In ASP.NET MVC

-------Posted Sep 7, 2020, 8:59 AM
Can you update your code please?
manish sharmaPosted Apr 12, 2017, 4:31 AM
Error Messages "Stripe no longer supports API requests made with TLS 1.0. Please initiate HTTPS connections with TLS 1.2 or later" Please help me
arvind baldaniyaPosted Mar 7, 2017, 8:08 AM
I am trying to Stripe payment Getway in xamarin android but i have no idea How to creat Looking for help in this site https://github.com/jaymedavis/stripe.net
Nauna ReviewsPosted Nov 10, 2016, 6:41 AM
Hi, your stripe.com dll has expired since stripe.com has make some changes in it can you please update your stripe.dll and share with us thanks
Nitin DhimanPosted Oct 5, 2015, 8:04 AM
How to apply Discount or Coupon any idea..?
rakesh sahooPosted Jun 12, 2015, 3:13 AM
from where will i download this project brother help me
sandya sPosted Oct 28, 2014, 1:31 AM
It's really looking good for the beginners..But Can we have example coding for making payment via stripe payment gateway integration?
Abhay AndhariyaPosted Jan 16, 2014, 9:08 AM
Hey Pankaj, Thanks for your help. But I am facing one problem with this code i.e. in GetCustomer(). It does not allow me to pass any parameter in var customerservice = new StripeCustomerService("sk_test_Uvk2cHkpYRTC2Rl4ZUfs4Fvs"); statement. If I use var customerservice = new StripeCustomerService(), then it works fine. But when I try to get data back from Stripe it gives me an error like INVALID API KEY PROVIDED. Do you have any idea why it gives me an error like this?
NBBPosted Oct 23, 2013, 6:55 PM
Thanks for this post and associate files. How would one go about catching & testing for exceptions such as listed here: https://stripe.com/docs/testing#cards ?
Eric WillisPosted Sep 11, 2013, 1:48 AM
Very nice blog and i am really agree with you. Please.... keep more and more sharing. sites like fiverr
RichaPosted Jun 18, 2013, 5:06 AM
nice blog sir