The front end of our application is now taking the Strype token and attempting to send it to our express
API.
However our express API does not yet have a route handler set up to watch for post requests to the route
API slash.
And that's why we get this 404 not found error.
So we're now going to transition over to our backend over to the Express side of the app.
We are going to first create a new route handler for watch to watch two or four post requests to the
API slash Strype route after we do that.
We'll then add in some additional logic to handle all this Strype charging stuff.
So let's get to it.
I'm going to change over to my code editor and remember how we defined routes inside of our application.
We had previously been creating a file inside of our route's directory We had called it all routes and
inside of a year we put a bunch of handlers associated with authentication.
Now when we think about billing not terribly closely related to authentication really billing and authentication
are two separate tasks.
So I'm thinking that maybe we should make a new file to handle all the different billing related handlers
inside of our application.
So let's do that inside the route's directory.
I'm going to make a new file called billing routes.
Yes.
And then inside of here remember the kind of boiler plate that we set up with inside the author house
file we had created an arrow function that gets called with our express app object and then inside of
that function body we set up the different route handlers that we wanted to create then immediately
exported that function and then we made use of it inside of our top level index G-S file.
So we're going to do the exact same thing this time around as well.
So I'm going to change over to the billing round Scott Jacobs file and we will create an arrow function
and immediately export it.
So we'll say module.
Exports equals app like so OK.
That's pretty much it for the set up.
Now we can do some different route handlers inside of here but before we do I want to make sure that
we require this into our index not G-S file and hook it up with our express app object.
So let's do that right now.
I'm going to save this file.
I'll change over to the index file and I'll scroll on down towards the bottom right where we had required
in the previous auth routes helper right underneath that will add in an additional required statement
for routes slash billing routes.
And then we'll pass in the app with a second set of parentheses.
So remember both of these files the author routes and billing routes files they return a function they
export a function.
So this requires statement right here is going to turn into a function which we then immediately call
with the express object.
So having the two sets of parentheses right here completely valid javascript.
OK so this looks good.
Let's save this and change back over to our billing routes file.
So here's billing routes.
So I want to start off by not really thinking about any of the special Strypes stuff or what we're doing
with a token.
I want to just focus on putting together the route handler first.
So for this row handler we want to watch for post requests that are made to the API slash stripe route.
So to set up that row handler will say don't post API slash stripe and then as a second argument we
pass in the response handler where the request handler which is our arrow function that gets called
with the request and rez objects.
OK.
So it's looking pretty good.
We definitely are off to a good start.
So now we've got the row handlers setup and if we ran the front end application and sent off the token
again it would get redirected or I should say redirected but that token would end up inside of this
request handler right here.
So this right here is where we are going to want to put some logic to handle the token somehow reach
out to the Strype API and finalize the actual charge.
And then after we finalize the charge we'll make sure that we update the users number of credits.
Let's take a quick break right now.
When we come back in the next section we're going to start to do the actual Strype integration into
the server side of our application so I'll see you in just a second.