OK.
Right back to it we're still working on our Strype API handler for making a POST request with the token
from the front end.
Now you might be thinking that doing all the striked stuff in here is going to be a bunch of really
nasty looking logic to actually build the credit card or exchange the token for an actual charge with
the stripe API.
But I've got good news is actually way more straightforward than you might think.
So let's see what it actually looks like.
We are going to install an MP module that is specifically for use on the server side of our application
to help us work with the stripe API.
So we've got one stripe module on the front end that's the check out at J.S. library.
That thing is all about just showing a credit card form to our users.
And then on the back end we are going to use a completely separate Strype library that's all about helping
us take the token that we got from the front end and exchanging it for an actual charge to the user's
credit card.
So rather than just installing it and diving right in I think this would be a pretty good place to look
through a little bit of documentation just to get some guidance on exactly how we're going to pull this
off.
So to look at the documentation I'm going to change over to my browser I'm going to open up a new tab
and go to NPM J person NPM J.S. dot com and there we go.
And then once here I'll search for a module called Strype so simply Strype like so we are looking for
the one called Strype API wrapper.
So a click on that and we'll see some documentation around the Strype library.
So this is a library specifically for working inside of node applications.
Now there is a little bit of documentation on this page right here but the full documentation is at
this link right here saying node API docs.
So we're going to go there and we're going to specifically attempt to find some documentation around
charging a user's credit card or debit card.
Now remember what we had said previously about Strype when we were looking out the stripe dashboard
stripe has a tremendous number of products inside of it.
You know they do credit card charges but they do a lot of other stuff as well.
So if you look at the documentation here on the left hand side you'll see all of these different things
going on all these different things.
A lot of stuff is going on.
So we want to look at one very specific area which is the core resources right here.
The charges section you look at.
So if you look at this very closely we want to charge a credit card or debit card.
Yup that's us.
OK we want to create a charge object and that gives us some documentation around the charge object.
Now to be clear this charge object right here.
This is something that is returned to us by the Strype API.
So they're kind of telling us hey when you use this API Here's what you get in response.
And we don't really you know that's kind of jumping the gun here.
We don't even know what to give them.
So to actually figure out what we have to provide to the Strype API in the first place we're going to
scroll down past this and find ways down here create a charge.
And of course you can always just click on the left and Nav. over here too OK.
So this is how we create an urge to me this is how we actually charge a credit card.
And when we charge it we create a charge object.
Now creating the object really straightforward again.
All we really do is essentially this block of code over here.
So we're going to require the Strype library we're going to pass in the secret key.
We then call Strype charges create and pass and configuration to do this to essentially say hey here's
what we're trying to charge the user for and that's pretty much it.
Now one last thing I want to point out in here is that when we create the charge and when we zoom in
on this you can see it very easily when we create the charge.
So here's the charge creation.
One of the properties required is source and that essentially is saying what credit card or what source
of payment we are using.
So this right here is the token that we got back from the check out at J.S. library.
Remember when we put out everything.
Or when we kicked our user into check out G-S or when they put in their credit card information that
returns us kind of like an authorization or something that says you are authorized to charge up to five
dollars on this card.
So we refer to that kind of as like a source of money or a source of credit.
So when you create the actual charge we specify Here's where to pull the money from.
OK.
So that's pretty much it.
Let's install the striped G-S library on the back end after we do so we'll make sure that we pass in
the secret key and then we'll start to set up the charge.
So let's first change over to our terminal or find my running server.
Here it is.
I'm going to kill the running server and then making sure that I'm still inside of the server project
because we want to install this module to the server side of our project.
I would run and install dash dash save and the name The library is simply Strype OK.
So it looks good.
Let's take a quick break and let this install and come back.
OK.
That was fast.
Well regardless.
Let's take a break come back in the next section in where this thing up so I'll see you in just a minute.