Creating your first Stripe Charge with Dotnet + C# in 5 minutes
In this short series, we are going to look at how to create a charge to Stripe in a number of their officially supported languages!
In this article, we are going to look at how to do so with C# and Dotnet.
The expectations are that you have both Dotnet installed and have your Stripe API keys setup and ready to go.
Adding the library
Assuming you have Dotnet setup, run the following:
Adding a Dotenv file
This file will be used to store our credentials to access Stripe.
Within the Dotenv file, we need to add your test keys from Stripe's website.
Updating your settings file
If you are going to use another method to fetch the variables (ie secrets etc), you could add the following to your
Make sure to check the docs on passing parameters to understand how this works.
Add Stripe config to Startup.cs
Create the Model
Create the Controller
Sending the request on HTTPie
Since we are sending back the response from the
Stripe.Charge object, it will be very verbose and not what you want to do in reality for the API.
In this example using HTTPie, call
http POST http://localhost:5000/api/charges amount:=1700 firstname.lastname@example.org and we will get back our charge results sent as JSON. Hooray!
I chose to use HTTPie because I feel it is a fun tool that more should know about! Alternative, you could do the above using
curl as well (or anything that can make a POST request for a matter of fact).
If you now go and check your Stripe dashboard, you will be able to see a charge.
Resources and Further Ready
- Setting up Stripe API for Dotnet
- Stripe Dotnet API Docs
- First Dotnet API
- Setting secrets for a Dotnet project
- Interfaces in C#
- ASP.NET Core API Service with Twilio, Stripe and Stormpath
- Process Payments with Dotnet
- Process Payments with Dotnet Github
- Stripe Development Docs
- Toptal ASP.NET WebAPI
- Dev.To tutorial
- HTTPie JSON
Image credit: Goran Ivos
1,200+ PEOPLE ALREADY JOINED ❤️️
Get fresh posts + news direct to your inbox.
No spam. We only send you relevant content.