In the last section we use the Strype library to create a new charge.
Remember this will make a request over to the Strype API and tell it hey we want to finalize this transaction
we want to build a customer for 500 cents.
Now if you look carefully back at the documentation that we were looking at just a second ago you could
see right here there was a second argument of a callback function that we could pass into this Create
call.
So any time we reach out to another API Strype included Remember it's always a synchronous.
And so we have to deal with it either by using a callback function by using a promise or by using that
async await syntax.
So the documentation right here is clearly kind of pointing you towards using a callback function which
we could definitely do but if we go and look out the API documentation that we saw on NPM around Strype.
So here's A.I.M. we looked at this just a little bit ago.
The Strype library.
If you scroll down here a little bit you'll notice that right here it says using promises.
Every method returns a chain will provenance that can be used instead of a regular callback.
So for us we can use promises but remember we have already spoken about the async 08 syntax which we
can use in any place inside of our application that is using promises.
So because the Strype library returns a promise any time you create a charge like what we're doing right
now the returns of promise and to handle that promise we will use the async await syntax.
So let's give it a shot.
So the Create call right here is what returns a promise.
So let's keep that in mind as we do this little rock factor or I should say as we add in the syncopate
syntax at all.
So the first thing we're going to do is find a function that has some asynchronous requestion side of
it.
That's definitely the request handler right here.
So in front of that function that contains the asynchronous logic we will mark it with a keyword async.
Next we'll find the call that returns a promise.
Like I said it's this Create call right here.
We'll put the a weight keyword in front that and then whatever this promise resolves with we are going
to pass off to a new variable in this case oh we call it charge because that's what it really returns
or returns an object that represents the charge that just occurred.
Okay.
So this is looking good.
Now the very last thing I want to do what's canceling out that church.
We'll see what we're working with now and we'll get a better sense of what to do after we successfully
build the user.
So I'm going to go back to my counsel and make sure I don't have any heirs over here outside of those
really really really annoying deprecation warnings.
I know they are annoying.
Hopefully by the time you're watching this mongoose has this stuff all fixed up but as I'm ready right
now obviously it's not fixed.
OK.
We'll go back over to our browser.
We're going to Smithey credit card charge again and we'll see what happens.
And to clear up my request log on bring up my credit card form put in our fake e-mail for two for two.
And then the other stuff OK.
So this is definitely going to make the request off to our API.
Yes the request is still pending because we're not actually dealing with it appropriately.
But if we go over to our terminal we should now see a big huge object that describes the charge that
was just created.
Here we go.
OK.
So here's the idea.
Notice how the idea starts off with the C.H. That's short for as you might guess charge.
So we're dealing with a charged object.
We build them for five hundred cents and somewhere else in here is going to be currency.
Actually here it is right here.
U.S. dollars.
We got that description.
We got some transaction ID.
We got basically just a whole lot of information about the charge that was just created.
And that's pretty much it.
Cool.
So we're definitely making that charge successfully.
That is pretty much all we really have to do as far as Strype is concerned.
So we take Check out Jay.
Yes.
We received some information that identifies the user's credit card that they just entered.
That essentially authorizes us to bill a certain amount of money.
We then post it to the back end where we use the Strype module to create the actual charge and build
the user.
OK.
So let's take a break right here.
When we come back now that we are actually billing the user for some amount of money we'll talk about
what we want to do.
So remember we want to like a sign these are some amount of credits We'll talk about exactly how we
will take care of that.
So I'll see you in just a minute.