Okay.
As discussed in the intro lesson, this is the point where we're going to be able to start taking payments
from our users for the products that they have put inside their shopping carts or their basket.
Now, this is not something that we do on our own servers.
For all of the good reasons that I specified in the introduction.
And we're going to be using a payment processor payment provider called stripe, which is going to handle
the receipt of payments from our users.
Now, this is a transaction that really happens directly between the client's browser and the stripe
servers.
And in order to meet the requirements for strong customer authentication, we need to set up on our
back end API side of things, the payment intents.
So our back end API is going to securely communicate with stripe.
So the idea of this system is so that we can implement secure customer authentication.
Is that our user, when they get to our checkout our client browser is going to send our API request
along with the contents of the baskets, what's in their basket?
And our back end API is going to securely communicate with stripe to express an intent to pay on behalf
of the customer.
Stripe will then send back the payment intent to our API, and we'll update our customer's shopping
cart or basket with that payment intent code.
And then the client can effectively communicate with stripe directly to pay for the contents of that
card.
So we're going to set up on the API side of things, the payment intent system first.
And then we're going to move on to our client to deal with the rest of the functionality.
But first we need a stripe account.
So please go to stripe.com.
This is the payment intent provider that we are going to be using.
So please do sign in.
And I've already got an account here.
So I'm going to sign in using my account and get to effectively the dashboard.
And once you're into the dashboard of this you should see something that looks like this.
Now we can have a number of different accounts with stripe.
I already have one or many different accounts that are available inside.
Here.
I'm going to create a new account for this specific course so that I have a clean dashboard and clean
transactions so that we can see clearly what's going on as we test our code.
Now we're going to operate in test mode.
We're not going to receive any live payments as part of this training course.
And then if you ever did want to enable this into live mode, then you turn off test mode, you would
need to complete a business profile with stripe.
There are some rules and regulations with receiving payments depending on where you are in the world.
Whatever you need to do to enable this, you'd need to go through their documentation and get them to
approve your account, I suspect, and all sorts of money laundering rules out there.
So we're just going to operate in test mode.
We're going to use test cards to get the functionality working.
And like I say, if you did want to enable this to receive live payments, then it would be something
that you would need to do outside of this training course.
So I'm going to create a new account.
So on the left hand side I'm going to use this create new account.
And I'm going to call this account restore V2.
And I'm going to pretend that the country of operation is United States.
We're just going to deal with dollars for our payments.
And I'm going to select create.
And once this has been created, then we've effectively got a new account to work with.
If I take a look at transactions we don't have anything.
And if we go to the home then what we do have inside the dashboard and this is not within my control
to ensure this always looks the same, but what you're looking for and it's available on the dashboard
here.
So this is the codes that I'm going to use.
We have a publishable key.
This is something that we use on our client side as well as our back end server side.
And we also have a secret key that's stored only on our server side.
So we're going to use those keys soon, but we're going to go back to VS code first of all.
And we're going to create what we need to on our back end API.
Now the first thing we'll do is we'll install a package from stripe.
So we're going to go to NuGet.
And we're just going to look for stripe inside NuGet because there's a package we need to install for
our.
Net application.
And it's this one it's called stripe dot net.
And we're going to install this into our API Csproj.
Don't worry about the version.
Just make sure you get the latest version available for your application.
And now that is installed we will supply our configuration keys in our settings.
Now for this example what I am going to use is the well I've got a choice of two the app settings development
JSON or the app Settings.json.
Now for convenience, and because I can easily change the account details that I'm using here and it's
only a test account, then I'm just going to put it inside the app settings development.
Jason, A bit later on when it comes to publishing, I'll use a different key for the published version
of this application.
It will still operate in test mode, so there's still going to be an element of fakery inside here.
But for this one I'm just going to add a configuration in App Settings development dot JSON.
And inside the quotes here I'm going to specify stripe settings as the configuration key.
Open curly brackets.
And we're going to use both of our keys inside here.
So I'm going to have a publishable key for stripe settings.
And I'm going to go across to the dashboard and copy the publishable key.
Go back to App Settings and paste that in there, a very long key that goes right off the edge of the
screen.
So I'm not going to worry about that and just keep it on the edge of the screen.
And we'll also have a secret key here.
And again I'm going to go back to the dashboard and copy the secret key and paste it in here.
Now, both of these are test keys, as we can clearly see, because this one is called PK underscore
test for the public key and for the secret key.
It's also underscore test.
When you do have a live active account that can actually receive payments, then they won't have the
word test here.
So whether or not these keys get out into the big bad world of the internet, what's the worst that
can happen in this scenario?
I can receive fake payments into my fake store and okay, but I will change the keys.
Not that I expect anybody's going to go through the tedium of copying these, but they will be visible
on my GitHub repo.
But they won't be valid for anything because I'll have changed the account before anybody gets to actually
use them.
So now we have that available.
The next thing we're going to take a look at is creating a payment service, which will be able to reach
out to stripe and create that payment intent I was referring to.