1 00:00:00,510 --> 00:00:07,200 So let me save let me open up the sidebar and then we're going to head over to a submit order and then 2 00:00:07,200 --> 00:00:11,640 like I said there's gonna be a lot of repetition within the subpoena order to die honestly. 3 00:00:11,640 --> 00:00:16,800 The only difference is going to be fact is we're going to pass in our token we're going to start by 4 00:00:16,800 --> 00:00:18,270 getting the axioms. 5 00:00:18,300 --> 00:00:20,580 So let me close the sidebar. 6 00:00:20,900 --> 00:00:25,050 We're going gonna import axioms from axioms. 7 00:00:25,080 --> 00:00:27,250 You guessed it zeros. 8 00:00:27,390 --> 00:00:31,980 Then we're also going to import the URL which is important because eventually of course we're going 9 00:00:31,980 --> 00:00:34,300 to deploy our application from. 10 00:00:34,530 --> 00:00:37,050 And then it comes from you tools. 11 00:00:37,050 --> 00:00:41,330 So let's look in the UTAS folder and then we're looking for the URL. 12 00:00:41,370 --> 00:00:46,080 Then the function is going to be a synchronous since we already set up our await. 13 00:00:46,110 --> 00:00:49,820 So we're going to go with function as then submit order. 14 00:00:50,010 --> 00:00:52,130 Or however you want to name it. 15 00:00:52,260 --> 00:00:58,380 And then I am passing in of course the object and remember the parameters that I was looking for was 16 00:00:58,420 --> 00:00:59,520 a name. 17 00:00:59,520 --> 00:01:10,650 Then the total then the items as well as stripe stripe token token I.D. And then lastly we have a user 18 00:01:10,650 --> 00:01:13,750 token so use their token. 19 00:01:13,860 --> 00:01:19,920 Those are the parameters that I'm going to be passing and then we're gonna set up again our await and 20 00:01:19,920 --> 00:01:24,480 we're gonna wait for the promise that obviously is provided by axioms. 21 00:01:24,510 --> 00:01:31,380 So first we're gonna set up some kind of variable response is equal to await because of course we have 22 00:01:31,470 --> 00:01:38,550 a synchronous and since axioms again post request returns a promise we can just wait when the promise 23 00:01:38,550 --> 00:01:43,700 is settled Let's type in here CEOs POST request. 24 00:01:43,920 --> 00:01:51,840 First we need to set up our you URL and remember in this case your URL is not getting the items so it's 25 00:01:51,840 --> 00:01:57,600 not like we have a URL and then forward slash product we're gonna use a template string we're going 26 00:01:57,600 --> 00:02:05,790 to access the URL the proper you URL is forward slash orders because that is the name of course of our 27 00:02:05,790 --> 00:02:11,520 content type if you named your account type differently and make sure that you also type in the correct 28 00:02:11,520 --> 00:02:17,940 your URL then we're gonna pass in our data so we're gonna have an object with our data and then before 29 00:02:17,940 --> 00:02:23,670 we do that we're gonna set up our headers so there's gonna be another object and it's gonna have a property 30 00:02:23,760 --> 00:02:30,990 of headers and it is going to be equal to another object so it's gonna be an object itself and then 31 00:02:30,990 --> 00:02:39,360 the property we're gonna have is gonna be authorization also res Asian and that is of course a colon 32 00:02:39,690 --> 00:02:50,910 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 33 00:02:50,910 --> 00:02:57,840 token parameter and let's access it since I have the template strings can just use user token that is 34 00:02:57,840 --> 00:03:02,640 the parameter and then of course I would want to pass in my data as well. 35 00:03:02,640 --> 00:03:09,270 So this is gonna be the data that we're gonna be adding to our API however we need to make sure that 36 00:03:09,270 --> 00:03:13,800 we have our token otherwise again we're not going to have permissions to do that. 37 00:03:14,220 --> 00:03:19,680 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 38 00:03:19,740 --> 00:03:22,400 shorthand where I'm gonna say name total. 39 00:03:23,040 --> 00:03:31,260 Then I'm going to have items as well as stripe token I.D. And lastly it does return a promise so I can 40 00:03:31,260 --> 00:03:33,550 just change that catch Mark. 41 00:03:33,570 --> 00:03:40,140 So again we're just in the console log the error so error and then we're gonna go the console log remove 42 00:03:40,200 --> 00:03:43,230 the semicolon and let's just say error. 43 00:03:43,230 --> 00:03:47,700 And similarly to our previous functions we're just gonna return the response. 44 00:03:47,850 --> 00:03:53,890 So I'm gonna go with the return and then I'm always always returning the response. 45 00:03:53,890 --> 00:03:58,560 And once we have our function ready We just need to make sure that we export it as a default. 46 00:03:59,040 --> 00:04:04,740 So that just type export default and then of course we're exporting our submit order. 47 00:04:04,950 --> 00:04:07,320 We're gonna save it and let's test it out. 48 00:04:07,530 --> 00:04:15,630 So let's passing some kind of name let's say some random order and then let's enter the correct card 49 00:04:15,630 --> 00:04:16,890 values. 50 00:04:16,890 --> 00:04:22,290 So we're going to just copy and paste correct card values then whatever the month. 51 00:04:22,290 --> 00:04:25,020 So let's say again January 20 22. 52 00:04:25,200 --> 00:04:32,910 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 53 00:04:32,910 --> 00:04:33,530 submit. 54 00:04:33,600 --> 00:04:39,840 And now we have our order is complete and we navigated to a homepage and let's check it out whether 55 00:04:39,900 --> 00:04:42,830 within the strappy we have a correct info. 56 00:04:42,960 --> 00:04:47,850 So we're gonna head over back to strappy design we're going to refresh and I have my word. 57 00:04:47,970 --> 00:04:54,560 You can see that I have some random order I have in fact the correct value as well as I have my items. 58 00:04:54,570 --> 00:04:57,250 Now one thing that is missing is the user. 59 00:04:57,270 --> 00:05:03,020 So again we haven't set up the functionality where we can get the user and we also haven't set up anything 60 00:05:03,290 --> 00:05:07,760 as far as stripe is concerned because if you're going to head over back to your dashboard you're going 61 00:05:07,760 --> 00:05:09,360 to see that there's no transactions. 62 00:05:09,370 --> 00:05:13,480 Again you can refresh and you're still going to have an empty values. 63 00:05:13,490 --> 00:05:16,340 So of course this is something that we're going to do in the next video. 64 00:05:16,490 --> 00:05:23,150 But since it is such an important topic I would want to head over back and just talk about one more 65 00:05:23,150 --> 00:05:23,850 time. 66 00:05:23,930 --> 00:05:30,910 So I have all these parameters name total items stripe token I.D. as well as user token. 67 00:05:30,980 --> 00:05:33,010 And as always you can call your parameters. 68 00:05:33,260 --> 00:05:34,510 However you'd like. 69 00:05:34,610 --> 00:05:37,010 Just make sure that you passing the correct values. 70 00:05:37,160 --> 00:05:44,570 Now name parameters looking for the name input then total is looking for the card total that we're importing 71 00:05:44,570 --> 00:05:48,290 from card context items is gonna be the card itself. 72 00:05:48,320 --> 00:05:53,430 So the card away and then stripe token I.D. We're getting back from the stripe token. 73 00:05:53,450 --> 00:05:56,290 So we do structure it and we get back our token. 74 00:05:56,360 --> 00:06:03,080 And lastly we'll have the user token because we import the user context and then of course we access 75 00:06:03,380 --> 00:06:04,940 our token property. 76 00:06:04,940 --> 00:06:08,850 Once we have these values then we have our submit function. 77 00:06:09,080 --> 00:06:16,040 And then within the submit or we again have these parameters we passed in of course our values. 78 00:06:16,040 --> 00:06:17,850 And then we set up a post request. 79 00:06:18,140 --> 00:06:23,880 So the post request is to your URL or current you URL and then forward slash orders. 80 00:06:23,960 --> 00:06:27,210 Then we need to set up an object where are we passing the data. 81 00:06:27,410 --> 00:06:33,710 So the data that we're looking for and make sure that in this case the properties match whatever you 82 00:06:33,710 --> 00:06:34,810 have on your back end. 83 00:06:35,150 --> 00:06:42,830 Because if I named my input as a name items and total essentially my fields then of course make sure 84 00:06:42,830 --> 00:06:48,230 that you also have named total and items stripe token and is a bit different because we're going to 85 00:06:48,230 --> 00:06:49,440 handle it differently. 86 00:06:49,470 --> 00:06:55,290 I'm not going to handle in our admin but in general make sure if you're named your fields name total 87 00:06:55,290 --> 00:06:58,760 and items then you're also passing in as your data. 88 00:06:58,760 --> 00:07:01,620 And in my case I also named my parameters the same way. 89 00:07:01,640 --> 00:07:04,370 So that's why we can do the six shorthand. 90 00:07:04,370 --> 00:07:10,110 And lastly we're not going to be able to complete the order if we don't include our headers. 91 00:07:10,220 --> 00:07:17,230 So make sure you have a headers that you have authorization and there is gonna be a user token. 92 00:07:17,340 --> 00:07:22,880 And since our actual post method is going to return a promise we can just change that catch. 93 00:07:22,880 --> 00:07:29,930 And always always just return a response and just jog your memory if we're going to head over to strappy 94 00:07:29,930 --> 00:07:30,750 docs. 95 00:07:30,860 --> 00:07:39,140 So let's type strappy audio and then we're going to look for documentation then we look for plugins 96 00:07:39,470 --> 00:07:41,110 and users permissions. 97 00:07:41,270 --> 00:07:47,300 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 98 00:07:47,300 --> 00:07:51,980 our content type has been restricted only to authorized users. 99 00:07:51,980 --> 00:07:57,030 So this just show you how they do it in our case of course we just use a post request. 100 00:07:57,080 --> 00:07:59,230 But the idea is was exactly the same. 101 00:07:59,360 --> 00:08:00,740 We have the URL. 102 00:08:00,740 --> 00:08:05,400 We're gonna have some kind of data since we are in fact adding something to a server. 103 00:08:05,510 --> 00:08:09,280 In this case they're just using and get and then you need to have your headers. 104 00:08:09,320 --> 00:08:12,050 That's where we're getting our submit order function setup.