Setting up Stripe
In this lesson, we're going to set up Stripe
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo set up the project on your local machine, please follow the directions provided in the README.md
file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.
This lesson preview is part of the The newline Guide to Fullstack ASP.NET Core and React course and can be unlocked immediately with a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to The newline Guide to Fullstack ASP.NET Core and React with a single-time purchase.

[00:00 - 00:08] In this section, we are going to set up the payments for our courses. Although there are plenty of options when it comes to take online payments.
[00:09 - 00:20] But considering the popularity and the setup process, Stripe comes out as the best option. Here, we will simply focus on how to take customers credit card information and make the payment.
[00:21 - 00:30] Open Stripe.com and sign up or if you have an account login as a user. Once you login as a user, you will see a dashboard like this.
[00:31 - 00:41] With this, our root account has been created and here we can create multiple business accounts. So if you click on new account and we can give it the same name as our application.
[00:42 - 01:01] So let me write "learnify" and let's choose the country to be United States and click on create account. Now on top, you will see a new account with name "learnify" and all the payments related to this business will be shown here.
[01:02 - 01:13] This application is huge and going through all the features of Stripe is not the intention of this course. We will simply see the features which are required by us as developers.
[01:14 - 01:16] So let's do one thing. Let's open the developer tab.
[01:17 - 01:34] Here we will find the information to integrate this to our application. We want to get the API keys, so let's click on API keys and we are going to make payments in the test mode or the development mode because we really don't want to spend our money to test this application.
[01:35 - 01:46] And as you can see, we are currently inside test mode. To use it for production, we will have to use activate payments which requires a lot of information such as the bank account details or some proofs.
[01:47 - 01:57] We will simply focus on making this application work inside test mode. If you want to take that application to live mode, you can simply read the instructions and activate your account.
[01:58 - 02:06] Now to set up Stripe in our application, firstly we need to mention the keys in our application. We have two keys here, publishable key and a secret key.
[02:07 - 02:17] It won't matter if you share the publishable key but make sure you never reveal the secret key. We can open the seat because they are for test and they are not going to be used for production.
[02:18 - 02:25] We get different keys for testing purpose and for production purpose. So let's go back to the code and let's copy it one by one.
[02:26 - 02:32] So I will copy the publishable key first. Inside the code, we need to open app settings dot development dot JSON file.
[02:33 - 02:39] So let's search for app settings dot development dot JSON. And here we can create a new property.
[02:40 - 02:46] Let's call it Stripe. And inside we can create two more properties.
[02:47 - 02:59] One is the publishable key. So I will write public shable key and we can paste the key inside the quotations.
[03:00 - 03:07] Same goes for the client secret. So let me use a comma here and add another property.
[03:08 - 03:16] Let's call it client secret. Now we can go back to stripe and copy this client secret.
[03:17 - 03:23] Let's copy it. Go back to the code and paste it.
[03:24 - 03:29] To make Stripe work, we also need it as a dependency. So what we can do is we can use nougat gallery.
[03:30 - 03:39] So let's open nougat gallery and search for stripe. And we need stripe dot net.
[03:40 - 03:47] Let's use the latest version and we need to install it inside the infrastructure project. So let me click on install.
[03:48 - 03:52] And this has installed stripe in our infrastructure project. Let's close this now.
[03:53 - 03:58] Now we can go to the basket model. So let's search for basket.
[03:59 - 04:19] And here we need to add two more properties which are required by stripe, one of which is called payment intent ID. So let's write string and it is called payment intent ID.
[04:20 - 04:25] We also need another property which is called client secret. And again, it has type string.
[04:26 - 04:34] So let me write string and let's call it client secret. These two properties will be sent to the client.
[04:35 - 04:51] So that client can use this to make a payment directly without going through the API, which is used by our server. Since we have added two new properties, we will have to drop the current migration and create a new one to see these two properties.
[04:52 - 04:58] Let's go back to the terminal. And let's shut the server.
[04:59 - 05:22] And we need to go to our root location and now we can type dot net EF migr ations add and let's call it payment intent added. And we need to mention our startup project, which is API and the project, which is infrastructure.
[05:23 - 05:35] Let's run it now. This has successfully created a new migration for us and it gives us a warning which says an operation was scaffolded that may result in the loss of data.
[05:36 - 05:46] Please review the migration for accuracy. This is because the basket table currently does not have any payment intent ID property and the client secret property, which is fine.
[05:47 - 05:51] And we can safely ignore this. Also we can open migration.
[05:52 - 06:06] So let's go to infrastructure and migrations and this one is the payment intent added migration. And as you can see, we have added client secret and payment intent ID as a column.
[06:07 - 06:18] Now we can again go to the API project and run the server to make those changes . And this works fine as well.
[06:19 - 06:23] In the next lesson, let's create a payment service class to take care of the payments.