Stripe Payment Integration In C#


In this article, we will learn how to implement a Stripe payment gateway in a .NET Web application using C#.

Let’s begin.

Go to

Click on the START NOW button to do the registration. After successful registration, the below page appears.

Click on Developers > API Keys, and get your Publishable key and Secret key

Now, Install “” SDK in your application

Go to Tools > NuGet Package Manager > Manage NuGet Packages For Solutions.

Click on Browse Tab and search for “”. Click on search NuGet and click to Install button.

After installation of SDK, Set Publishable key and Secret key in web.config.

C# Code Example

Open the HomeController.cs file and add the code in it.

public ActionResult Index()
    ViewBag.StripePublishKey = ConfigurationManager.AppSettings["stripePublishableKey"];
     return View();
public ActionResult Charge(string stripeToken, string stripeEmail)
   Stripe.StripeConfiguration.SetApiKey("your Publishable key");
    Stripe.StripeConfiguration.ApiKey = "your Secret key";
    var myCharge = new Stripe.ChargeCreateOptions();

    // always set these properties
    myCharge.Amount = 500;
    myCharge.Currency = "USD";

    myCharge.ReceiptEmail = stripeEmail;
    myCharge.Description = "Sample Charge";
    myCharge.Source = stripeToken;
    myCharge.Capture = true;

    var chargeService = new Stripe.ChargeService();
    Charge stripeCharge = chargeService.Create(myCharge);

    return View();

Open the Index.cshtml file and add the code in it.

<form action="/Home/Charge" method="POST">
        <label>Amount: $5.00</label>
    <script src="//"
            data-description="Sample Charge"

That’s it, you are ready to use the Stripe gateway.



  1. Sara Costa

    Not work with 3d secure, can you try make an example please?

  2. BM Gumbi

    Hi,Thank you for the code you have provided. Please help how can i add success return or cancel return link?

  3. Nuggets08

    Thank you!!!! You saved my miserable life lol!! Blessings from Mauritius 🙂

    1. My pleasure!

      1. osama

        have you done the 3d secure 2 ? on .net
        not in core
        i’m having so much trouble on making it 3d secure

        one time payment on server side

        1. Sara Costa

          me too..i dont understand the documentation of stripe

  4. William Best

    I couldn’t get this to work. I got the popup message and pressed the button to purchase but no record of the purchase in my stripe account.

  5. Freebies

    Wonderful goods from you, man. I have understand your stuff previous to and you’re just extremely magnificent. I actually like what you’ve acquired here, really like what you’re saying and the way in which you say it. You make it enjoyable and you still take care of to keep it wise. I can not wait to read far more from you. This is really a terrific web site.

    1. Thanks 🙂

      1. rahul patil

        hello sir which place to come stripeToken and can you give link for stripe for web form

        1. The Code Hubs

          Please review the “Index.cshtml” page code, when you submit that form you will get token, and in webforms its almost similar so you can use the same with some minor changes.


Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories