So let me save let me open up the sidebar and then we're going to head over to a submit order and then
like I said there's gonna be a lot of repetition within the subpoena order to die honestly.
The only difference is going to be fact is we're going to pass in our token we're going to start by
getting the axioms.
So let me close the sidebar.
We're going gonna import axioms from axioms.
You guessed it zeros.
Then we're also going to import the URL which is important because eventually of course we're going
to deploy our application from.
And then it comes from you tools.
So let's look in the UTAS folder and then we're looking for the URL.
Then the function is going to be a synchronous since we already set up our await.
So we're going to go with function as then submit order.
Or however you want to name it.
And then I am passing in of course the object and remember the parameters that I was looking for was
a name.
Then the total then the items as well as stripe stripe token token I.D. And then lastly we have a user
token so use their token.
Those are the parameters that I'm going to be passing and then we're gonna set up again our await and
we're gonna wait for the promise that obviously is provided by axioms.
So first we're gonna set up some kind of variable response is equal to await because of course we have
a synchronous and since axioms again post request returns a promise we can just wait when the promise
is settled Let's type in here CEOs POST request.
First we need to set up our you URL and remember in this case your URL is not getting the items so it's
not like we have a URL and then forward slash product we're gonna use a template string we're going
to access the URL the proper you URL is forward slash orders because that is the name of course of our
content type if you named your account type differently and make sure that you also type in the correct
your URL then we're gonna pass in our data so we're gonna have an object with our data and then before
we do that we're gonna set up our headers so there's gonna be another object and it's gonna have a property
of headers and it is going to be equal to another object so it's gonna be an object itself and then
the property we're gonna have is gonna be authorization also res Asian and that is of course a colon
and then we're looking for bearer so B E A R E R online we're looking for our user token so our user
token parameter and let's access it since I have the template strings can just use user token that is
the parameter and then of course I would want to pass in my data as well.
So this is gonna be the data that we're gonna be adding to our API however we need to make sure that
we have our token otherwise again we're not going to have permissions to do that.
And then one by one I'm going to pass in all my parameters and in this case I am going to use the S6
shorthand where I'm gonna say name total.
Then I'm going to have items as well as stripe token I.D. And lastly it does return a promise so I can
just change that catch Mark.
So again we're just in the console log the error so error and then we're gonna go the console log remove
the semicolon and let's just say error.
And similarly to our previous functions we're just gonna return the response.
So I'm gonna go with the return and then I'm always always returning the response.
And once we have our function ready We just need to make sure that we export it as a default.
So that just type export default and then of course we're exporting our submit order.
We're gonna save it and let's test it out.
So let's passing some kind of name let's say some random order and then let's enter the correct card
values.
So we're going to just copy and paste correct card values then whatever the month.
So let's say again January 20 22.
Then let's add some kind of security code and some old Zip code so let's go with this one and then let's
submit.
And now we have our order is complete and we navigated to a homepage and let's check it out whether
within the strappy we have a correct info.
So we're gonna head over back to strappy design we're going to refresh and I have my word.
You can see that I have some random order I have in fact the correct value as well as I have my items.
Now one thing that is missing is the user.
So again we haven't set up the functionality where we can get the user and we also haven't set up anything
as far as stripe is concerned because if you're going to head over back to your dashboard you're going
to see that there's no transactions.
Again you can refresh and you're still going to have an empty values.
So of course this is something that we're going to do in the next video.
But since it is such an important topic I would want to head over back and just talk about one more
time.
So I have all these parameters name total items stripe token I.D. as well as user token.
And as always you can call your parameters.
However you'd like.
Just make sure that you passing the correct values.
Now name parameters looking for the name input then total is looking for the card total that we're importing
from card context items is gonna be the card itself.
So the card away and then stripe token I.D. We're getting back from the stripe token.
So we do structure it and we get back our token.
And lastly we'll have the user token because we import the user context and then of course we access
our token property.
Once we have these values then we have our submit function.
And then within the submit or we again have these parameters we passed in of course our values.
And then we set up a post request.
So the post request is to your URL or current you URL and then forward slash orders.
Then we need to set up an object where are we passing the data.
So the data that we're looking for and make sure that in this case the properties match whatever you
have on your back end.
Because if I named my input as a name items and total essentially my fields then of course make sure
that you also have named total and items stripe token and is a bit different because we're going to
handle it differently.
I'm not going to handle in our admin but in general make sure if you're named your fields name total
and items then you're also passing in as your data.
And in my case I also named my parameters the same way.
So that's why we can do the six shorthand.
And lastly we're not going to be able to complete the order if we don't include our headers.
So make sure you have a headers that you have authorization and there is gonna be a user token.
And since our actual post method is going to return a promise we can just change that catch.
And always always just return a response and just jog your memory if we're going to head over to strappy
docs.
So let's type strappy audio and then we're going to look for documentation then we look for plugins
and users permissions.
You're going to see that the first thing they show is this is how we can set up a request if let's say
our content type has been restricted only to authorized users.
So this just show you how they do it in our case of course we just use a post request.
But the idea is was exactly the same.
We have the URL.
We're gonna have some kind of data since we are in fact adding something to a server.
In this case they're just using and get and then you need to have your headers.
That's where we're getting our submit order function setup.