There are many Payment Gateways in the market that offer secure and easy implementation. And Stripe is one of them.
There are several steps to integrate Stripe.
Basically, there are two ways to implement it.
- Client Side: You can use Stripe.js and load the Stripe controls to enter Credit card details and make the payment.
- Server Side: If you already have a full-fledged Checkout page and everything is in place, then you can use the library (DLL) to make the payment.
Today, we are going to see the Server-Side implementation of Stripe.
If you follow each and every step, you can easily integrate Stripe Payment Gateway.
Step 1. Register on https://dashboard.stripe.com/register with your Email, Name, and Password.
Step 2. Install the Stripe library in your Visual Project using Install-Package Stripe.net. It will download Stripe.net.dll and add a reference to your project.
Step 3. Add Namespace (using Stripe.Infrastructure;) to the Class where you want to implement the payment gateway.
Step 4. To implement, you need to play with several classes. Please follow each step to make the payment.
Step 5. To connect with Stripe, you need KEY - “Publishable key”. You can get it from https://dashboard.stripe.com/account/apikeys.

Step 6. Set the API key with the below function.
Stripe.StripeConfiguration.SetApiKey(“pk_test_FyPZYPyqf8jU6IdG2DONgudS”);
Step 7. Create an Object of a Credit Card to generate a Token. That Token will be set to Customer object at the time of Creation of Customer.
//Create Card Object to create Token
Stripe.CreditCardOptions card = new Stripe.CreditCardOptions();
card.Name = tParams.CardOwnerFirstName + " " + tParams.CardOwnerLastName;
card.Number = tParams.CardNumber;
card.ExpYear = tParams.ExpirationYear;
card.ExpMonth = tParams.ExpirationMonth;
card.Cvc = tParams.CVV2;
//Assign Card to Token Object and create Token
Stripe.TokenCreateOptions token = new Stripe.TokenCreateOptions();
token.Card = card;
Stripe.TokenService serviceToken = new Stripe.TokenService();
Stripe.Token newToken = serviceToken.Create(token);
Step 8. Assign TokenID to the Customer Object so the at the time of customer creation, a card gets created and linked to the Customer.
//Create Customer Object and Register it on Stripe
Stripe.CustomerCreateOptions myCustomer = new Stripe.CustomerCreateOptions();
myCustomer.Email = tParams.Buyer_Email;
myCustomer.SourceToken = newToken.Id;
var customerService = new Stripe.CustomerService();
Stripe.Customer stripeCustomer = customerService.Create(myCustomer);
Step 9. Create Charge Object. Charge object is the actual object which will do the payment.
//Create Charge Object with details of Charge
var options = new Stripe.ChargeCreateOptions {
Amount = Convert.ToInt32(tParams.Amount),
Currency = tParams.CurrencyId == 1 ? "ILS" : "USD",
ReceiptEmail = tParams.Buyer_Email,
CustomerId = stripeCustomer.Id,
Description = Convert.ToString(tParams.TransactionId), //Optional
};
//and Create Method of this object is doing the payment execution.
var service = new Stripe.ChargeService();
Stripe.Charge charge = service.Create(options); // This will do the Payment
Step 10. Charge.Status will return the status.
Step 11. Now you can check Created Customer from https://dashboard.stripe.com/test/customers.

And Payment using this link - https://dashboard.stripe.com/test/payments.

-- Happy Coding --

SIDDHARTHA ZEDIAPosted Jun 21, 2022, 8:32 PM
CustomerId property doesn't exitsts
Pankaj KalePosted Oct 11, 2021, 1:14 PM
I want payment gateway website in mvc.net with source code with DB and stored procedure can you please help me please ping me on [email protected]
TechtoliaPosted Dec 25, 2020, 5:05 PM
If you are looking the latest solution of Stripe checkout integration in ASP.NET Web Forms or ASP.NET Core MVC, check out the demo ==> techtolia.com/Stripe/ Receive payments from credit or debit cards, Alipay, WeChat Pay, Bancontact, EPS, giropay, iDEAL, Multibanco, Przelewy24, SOFORT, Secure Remote Commerce and Payment Request Button (Apple Pay, Google Pay, Microsoft Pay, and the browser Payment Request API) via Stripe.
Fawaz AlmogademPosted Dec 7, 2020, 3:17 AM
Can u inbox source code
Furqan ShaheenPosted Nov 23, 2020, 4:11 AM
Hello i am facing error here ......card.Name = tParams.CardOwnerFirstName + " " + tParams.CardOwnerLastName; card.Number = tParams.CardNumber; card.ExpYear = tParams.ExpirationYear; card.ExpMonth = tParams.ExpirationMonth; also i key where can i store these values in my project
riz bhatiPosted Oct 27, 2020, 4:27 AM
Stepl 6 to 9 ... where can we use???
Aliya khanPosted Sep 2, 2020, 11:34 AM
Where have to add API key?
Suresh RautPosted May 19, 2020, 9:35 AM
Hi Dinesh, I am getting two errors in the code you provided above. Line no. 4 in step no. 8: 'CustomerCreateOptions' does not contain a definition for 'SourceToken'. And another error on line no. 6 in step no. 9: 'ChargeCreateOptions' does not contain a definition for 'CustomerId'. Can you please help me fix these two issues? I am using latest version of Stripe.Net 37.1.0
Jass WaliaPosted May 9, 2020, 3:09 PM
Sir, when we create a charge then amount will deduct from that account associated with customerid entered in createcharge
nazir aliPosted Oct 8, 2019, 10:37 PM
Where should i add Stripe.StripeConfiguration.SetApiKey(“pk_test_FyPZYPyqf8jU6IdG2DONgudS”); ??
akram khanPosted Aug 24, 2019, 2:35 AM
This will work only for credit card?
Hitesh KumarPosted Jul 31, 2019, 2:35 AM
Hi Can you please share 3d concept for stripe payment gateway.
Vinod KamblePosted May 28, 2019, 7:06 AM
This API call cannot be made with a publishable API key. Please use a secret API key. You can find a list of your API keys at https://dashboard.stripe.com/account/apikeys
jubula samalPosted May 21, 2019, 7:54 AM
Nice article
Amar YadavPosted Jan 24, 2019, 1:09 AM
I am getting an error like The type initializer for 'Stripe.Infrastructure.StripeTypeRegistry' threw an exception. why? please check and let me know when it comes?
Laxmidhar SahooPosted Nov 15, 2018, 4:10 AM
This will be help full thanks