1 00:00:00,480 --> 00:00:08,760 With our new content type by the name of order created we can just narrow act to our content and setup 2 00:00:08,850 --> 00:00:14,850 our submit order function and we're going to start by in fact running the function just so you can see 3 00:00:14,850 --> 00:00:16,920 what kind of values we're gonna be passing in. 4 00:00:17,250 --> 00:00:24,600 So again we are submit order and since we already set up a few post request using the ax heroes and 5 00:00:24,600 --> 00:00:30,150 all that then of course I would want first to start well what kind of hours we're gonna be passing because 6 00:00:30,150 --> 00:00:34,730 the actual functionality is gonna be almost exactly the same like we had before. 7 00:00:34,740 --> 00:00:39,830 The difference is of course we're gonna pass on the token on I would want you to be aware of where we 8 00:00:39,830 --> 00:00:45,310 are grabbing all the tokens whether that's user token or whether that is a strike token. 9 00:00:45,450 --> 00:00:49,490 So first of all we need to decide Well when are we gonna call this function. 10 00:00:49,480 --> 00:00:55,860 Well I think it would make the most sense if we would call the function or submit or when we have our 11 00:00:55,860 --> 00:00:56,820 token correct. 12 00:00:56,820 --> 00:00:59,610 Because there's no point to do that if we have some kind of error. 13 00:00:59,670 --> 00:01:04,710 So instead of console logging the response I am going to remove it and I'm going to say first of all 14 00:01:04,710 --> 00:01:10,410 that I would want to set error to an empty string because that way I know that everything one successful 15 00:01:10,770 --> 00:01:15,270 someone would set error and I'm gonna send it back to an empty string. 16 00:01:15,540 --> 00:01:22,120 Then we're going to the structure the I.D. from the token because we have the token. 17 00:01:22,290 --> 00:01:26,700 And then what we're looking for is this I.D. That's the property we're looking for. 18 00:01:26,700 --> 00:01:32,160 So right away we're going to the structure not seven seconds and we're looking for the I.D. It is coming 19 00:01:32,580 --> 00:01:38,300 from the token and now we're going to have our submit order it is going to be a synchronous function. 20 00:01:38,340 --> 00:01:46,110 So again we're gonna set up some kind of variable left order is gonna be equal to a wait and then we're 21 00:01:46,110 --> 00:01:52,050 gonna have our submit order so submit order and then within the submit order function we're going to 22 00:01:52,050 --> 00:01:56,520 pass in the object with these particular values. 23 00:01:56,520 --> 00:02:02,670 So first of all going to have the name and again name is just name input that we have within our form. 24 00:02:02,670 --> 00:02:04,410 Next we're gonna have a total. 25 00:02:04,540 --> 00:02:08,970 And in this case you know what I'm just gonna type in property with a value because I think is just 26 00:02:08,970 --> 00:02:10,190 gonna make a bit more sense. 27 00:02:10,590 --> 00:02:14,760 So I'm gonna have name is equal to name even though we can use a shorthand. 28 00:02:14,760 --> 00:02:20,640 In this case I think it is a little bit easier if we write it out everything the long way because that 29 00:02:20,640 --> 00:02:26,700 way you for sure know which one is the actual property that we're gonna have in the function more essentially 30 00:02:26,730 --> 00:02:30,500 a parameter and which one is the value that we're passing in. 31 00:02:30,720 --> 00:02:36,990 So we're going to have a parameter by the name of total and that is going to be equal to our card total. 32 00:02:36,990 --> 00:02:39,720 So in that case of course it is exactly the same. 33 00:02:39,750 --> 00:02:43,320 So we can just pass in the total that I would want to set up. 34 00:02:43,320 --> 00:02:50,130 Of course my items remember within the orders we also have the items where we dumped our Jason there. 35 00:02:50,130 --> 00:02:53,640 So I'm going to call this as a parameter of items. 36 00:02:53,640 --> 00:02:55,320 And then the value is gonna be my card. 37 00:02:55,800 --> 00:03:03,960 So remember we do structured out the card so whatever the card actual array was not the total but actual 38 00:03:03,960 --> 00:03:04,580 items. 39 00:03:04,710 --> 00:03:10,110 And then we're gonna set it equal to an items and then also we're gonna have a stripe token I.D. parameter 40 00:03:10,410 --> 00:03:12,470 and user token parameter. 41 00:03:12,570 --> 00:03:20,430 So we're gonna have a stripe token token I.D. and that is gonna be equal to I.D. that we're getting 42 00:03:20,430 --> 00:03:21,090 back. 43 00:03:21,090 --> 00:03:27,990 So we have our token and then I would want to get of course my stripe token I.D. so I'm gonna passing 44 00:03:27,990 --> 00:03:28,640 the entry. 45 00:03:28,710 --> 00:03:34,770 And lastly we have the user token because of course when we're communicating with our backend we need 46 00:03:34,770 --> 00:03:39,500 to let strappy know of which is the user that is submitting the order. 47 00:03:39,960 --> 00:03:44,610 So there's gonna be a parameter by the name of user token. 48 00:03:44,940 --> 00:03:51,480 And we're gonna have here the value of user token where we're getting the user. 49 00:03:51,480 --> 00:03:54,030 We do structured it from the user context. 50 00:03:54,210 --> 00:04:00,200 So we have our user user has the token property and we're just getting that token. 51 00:04:00,300 --> 00:04:07,440 Now once we have set up everything we're gonna have two options either are or is going to return an 52 00:04:07,440 --> 00:04:10,430 error or it's going to be a success. 53 00:04:10,440 --> 00:04:16,060 So again we're going to do one more if statement and I'm going to say if we order in that case of course 54 00:04:16,090 --> 00:04:19,390 it was a success because they're fun checking if it is true. 55 00:04:19,390 --> 00:04:21,930 And then of course we're also going to have else. 56 00:04:21,990 --> 00:04:25,550 So that way we're just going to display that there's some kind of error. 57 00:04:25,600 --> 00:04:30,880 Now we're gonna start I guess with a else because that way we're just going to show a different alert 58 00:04:31,330 --> 00:04:36,120 so we can go to show alert then we're gonna pass in again the message. 59 00:04:36,130 --> 00:04:44,990 So we're going to go with the message and we're going to say there was an error with your order with 60 00:04:44,990 --> 00:04:48,950 your order and then we're gonna have a dot. 61 00:04:49,130 --> 00:04:52,670 So please try again. 62 00:04:52,840 --> 00:04:54,410 Online exclamation mark. 63 00:04:54,470 --> 00:05:01,070 And for the type we need to have it as a danger because of course we would want it in the red color. 64 00:05:01,070 --> 00:05:03,370 So we're gonna go with danger. 65 00:05:04,220 --> 00:05:10,700 And if you were a success if everything went well then we're gonna show alert that your order is complete. 66 00:05:11,090 --> 00:05:13,300 So let's go show alert. 67 00:05:13,580 --> 00:05:15,670 Then we're passing in the message again. 68 00:05:15,960 --> 00:05:18,750 So we're going to go with the message and your order. 69 00:05:18,770 --> 00:05:26,370 And of course I need to have quotation marks your order is complete and we would want to clear the cart. 70 00:05:26,450 --> 00:05:32,580 That is something that we do structured from our court context so we can just have clear cart. 71 00:05:32,600 --> 00:05:33,740 That is the method. 72 00:05:33,740 --> 00:05:35,810 And then we have history push. 73 00:05:35,810 --> 00:05:41,170 So we have history push and I would want to navigate to let's say home page someone go with history 74 00:05:41,180 --> 00:05:41,930 push. 75 00:05:41,970 --> 00:05:47,990 Navigating to a home page and then of course if already my order is successful I can just return from 76 00:05:47,990 --> 00:05:51,140 the function and just say that's it I'm done. 77 00:05:51,140 --> 00:05:52,400 I would want to return. 78 00:05:52,400 --> 00:05:53,980 So we have two cases again. 79 00:05:54,140 --> 00:05:59,540 Either the order is gonna be successful or there's going to be some kind of error if there is error. 80 00:05:59,570 --> 00:06:01,790 We're just shown the alert in this case. 81 00:06:01,790 --> 00:06:06,350 It doesn't make sense to shoulder because it's not like we're showing it within the paragraph. 82 00:06:06,350 --> 00:06:10,830 And then if everything went well then we're going to have show alert with message. 83 00:06:10,910 --> 00:06:12,480 Your order is complete. 84 00:06:12,560 --> 00:06:15,820 Then we clear the card as well as navigate to a homepage. 85 00:06:15,830 --> 00:06:18,370 Of course we haven't set up our function yet.