Login Register
Code2night
  • Home
  • Blog Archive
  • Learn
    • Tutorials
    • Videos
  • Interview Q&A
  • Languages
    • Angular Angular js ASP.NET Asp.net Core ASP.NET Core, C# C C# C#, ASP.NET Core, Dapper
      C#, ASP.NET Core, Dapper, Entity Framework DotNet HTML/CSS Java JavaScript Node.js Python Python 3.11, Pandas, SQL
      Python 3.11, SQL Python 3.11, SQLAlchemy Python 3.11, SQLAlchemy, SQL Python 3.11, SQLite React Security SQL Server TypeScript
  • Post Blog
  • Tools
    • Beautifiers
      JSON Beautifier HTML Beautifier XML Beautifier CSS Beautifier JS Beautifier SQL Formatter
      Dev Utilities
      JWT Decoder Regex Tester Diff Checker Cron Explainer String Escape Hash Generator Password Generator
      Converters
      Base64 Encode/Decode URL Encoder/Decoder JSON to CSV CSV to JSON JSON to TypeScript Markdown to HTML Number Base Converter Timestamp Converter Case Converter
      Generators
      UUID / GUID Generator Lorem Ipsum QR Code Generator Meta Tag Generator
      Image Tools
      Image Converter Image Resizer Image Compressor Image to Base64 PNG to ICO Background Remover Color Picker
      Text & Content
      Word Counter PDF Editor
      SEO & Web
      SEO Analyzer URL Checker World Clock
  1. Home
  2. Blog
  3. ASP.NET Core
  4. Implement Stripe Payment Gateway In ASP.NET Core

Implement Stripe Payment Gateway In ASP.NET Core

Date- Jul 01,2023

Updated Feb 2026

16767

Free Download Pay & Download
Stripe Payment Gateway AspNet

Stripe Payment Gateway.

In today's digital world, businesses of all sizes are moving towards online payments. However, implementing a secure and reliable payment gateway can be a daunting task, especially for those who are new to the process. This is where Stripe comes in as a popular payment gateway solution that allows businesses to accept online payments with ease. In this tutorial, we will demonstrate how to implement Stripe Payment Gateway in an ASP.NET Core application built with C# and WebForms. We will be using the latest version of Stripe.Net API to integrate the Stripe Checkout feature. So, welcome to Code2Night, and let's get started and learn how to accept payments with Stripe Checkout in our ASP.NET Core application. Join us in this step-by-step guide and learn how to implement Stripe Payment Gateway in ASP.NET Core today!

Step 1: Create the project 


create your new stripe application in the MVC application

1.) Open Visual Studio 2022 and Click on Create a new Project.

Stripe Payment Gateway

2.) Search for MVC and select ASP.NET Core Web App(Model-View-Controller) as shown in the below image.

Implement Stripe Payment Gateway In ASPNET Core



Step 2: Add the Stripe.net package to your project from NuGet


In this, we will use the Stripe.net package's latest version for implementing the Stripe payment gateway in your project. So you have to go to Manage Nuget Packages and add Stripe.Net to your project.


Implement Stripe Payment Gateway In ASPNET Core 2


Step 3: Add the Stripe secret and publishable key in the  appsettings.json file

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "StripeSettings": {
    "SecretKey": "sk_test_51LEw9tSDgbzoG4N8KacRZQddaFfp0S41InGviyOyDoBbrA3Q8cz1G9iZ2wePhcW0BP5365NZw5TZa87Fvz4tts8Q00f1KLhbj3",
    "PublicKey": "pk_test_51LEw9tSDgbzoG4N8Fx534MJg07PbUcvLhzG6slO8Wk0pkkxkity5uQV81M0vkFU4b3ejQBAuGVJwLVMSxlzHU2AD002bHsYXEC"
  }
}

In this step, you have to go to your appseting.json and add an app setting section with your Stripe secret key and publishable key as we have shown below


Stripe Publishable key, Secret key


Implement Stripe Payment Gateway In ASPNET Core 3


Step 4: Create one class file to store StripeSettings:

  public class StripeSettings
    {
        public string SecretKey { get; set; }
        public string PublicKey { get; set; }
    }

Now you have to go to startup.cs file and add following code

  public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.Configure<StripeSettings>(Configuration.GetSection("StripeSettings"));
            
        }

Step 5: Create the payment Web page

Create a new Web page called Index.cshtml. In the file, add the following HTML markup inside of the <form> tag. Here we are adding one input box for getting the transaction amount and a button for checkout.

<form method="post" action="/Home/CreateCheckoutSession">
    <!-- Form fields -->
    <div>
        <label for="name">Amount:</label>
        <input type="text" id="amount" name="amount" value="" />
    </div>


    <!-- Submit button -->
    <button type="submit">Checkout</button>
</form>

Step 6: Go to Home Controller create new action method CreateCheckoutSession add the following code to the CreateCheckoutSession method:


         public class HomeController : Controller
    {

        private readonly StripeSettings _stripeSettings;

        public string SessionId { get; set; }
        public HomeController(IOptions<StripeSettings> stripeSettings)
        {
            _stripeSettings = stripeSettings.Value;
         
        }
        public IActionResult Index()
        {
            return View();
        }

        

        public IActionResult CreateCheckoutSession(string amount)
        {
           
            var currency = "usd"; // Currency code
            var successUrl = "https://localhost:44342/Home/success";
            var cancelUrl = "https://localhost:44342/Home/cancel";
            StripeConfiguration.ApiKey = _stripeSettings.SecretKey;

            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List<string>
                {
                    "card"
                },
                LineItems = new List<SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        PriceData = new SessionLineItemPriceDataOptions
                        {
                            Currency = currency,
                            UnitAmount = Convert.ToInt32(amount) * 100,  // Amount in smallest currency unit (e.g., cents)
                            ProductData = new SessionLineItemPriceDataProductDataOptions
                            {
                                Name = "Product Name",
                                Description = "Product Description"
                            }
                        },
                        Quantity = 1
                    }
                },
                Mode = "payment",
                SuccessUrl = successUrl,
                CancelUrl = cancelUrl
            };

            var service = new SessionService();
            var session = service.Create(options);
            SessionId = session.Id;
            
            return Redirect(session.Url);
        }

        public async Task <IActionResult> success()
        {
           
            return View("Index");
        }

        public IActionResult cancel()
        {
            return View("Index");
        }
    }
}

That’s it, a complete Stripe and ASP.NET Core integration built with C#.

Step 7: Run the application

Now run the application and enter amount and submit

In the web browser, click the button to launch the payment form. If you’re using Stripe test keys, you can test it with some dummy data. Enter the test number 4242 4242 4242 4242, a three-digit 123, and a future expiry date. Submit the form and see if the application correctly displays the successful charge page.

Implement Stripe Payment Gateway In ASPNET Core 4Implement Stripe Payment Gateway In ASPNET Core 5Implement Stripe Payment Gateway In ASPNET Core 6Implement Stripe Payment Gateway In ASPNET Core 7Implement Stripe Payment Gateway In ASPNET Core 8

So you can see the payment has been completed successfully. So this is how we can implement stripe payment gateway in asp.net core.

S
Shubham Batra
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Related Articles

Implement Stripe Payment Gateway In ASP.NET MVC
Jun 26, 2022
Implement Stripe Payment Gateway In ASP.NET
Sep 10, 2020
Integrate Stripe Payment Gateway In ASP.NET Core 8.0
Nov 23, 2023
Integrate Stripe Payment Gateway In ASP.NET Core 7.0
Jul 22, 2023
Previous in ASP.NET Core
App Trim in .NET Core
Next in ASP.NET Core
Integrate Stripe Payment Gateway In ASP.NET Core 7.0

Comments

On this page

🎯

Interview Prep

Ace your ASP.NET Core interview with curated Q&As for all levels.

View ASP.NET Core Interview Q&As

More in ASP.NET Core

  • How to Encrypt and Decrypt Password in Asp.Net 25981 views
  • Exception Handling Asp.Net Core 20741 views
  • HTTP Error 500.31 Failed to load ASP NET Core runtime 20225 views
  • How to implement Paypal in Asp.Net Core 19626 views
  • Task Scheduler in Asp.Net core 17527 views
View all ASP.NET Core posts →

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1770
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • SQL Formatter
  • Diff Checker
  • Regex Tester
  • Markdown to HTML
  • Word Counter
More Tools
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Base64 Encoder
  • JWT Decoder
  • UUID Generator
  • Image Converter
  • PNG to ICO
  • SEO Analyzer
By Language
  • Angular
  • Angular js
  • ASP.NET
  • Asp.net Core
  • ASP.NET Core, C#
  • C
  • C#
  • C#, ASP.NET Core, Dapper
  • C#, ASP.NET Core, Dapper, Entity Framework
  • DotNet
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • Python 3.11, Pandas, SQL
  • Python 3.11, SQL
  • Python 3.11, SQLAlchemy
  • Python 3.11, SQLAlchemy, SQL
  • Python 3.11, SQLite
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ·  Terms
Translate Page
We use cookies to improve your experience and analyze site traffic. By clicking Accept, you consent to our use of cookies. Privacy Policy
Accessibility
Text size
High contrast
Grayscale
Dyslexia font
Highlight links
Pause animations
Large cursor