1
00:00:00,420 --> 00:00:08,630
All right, and once we have successfully set up the logic to create or items as well as subtotal,

2
00:00:09,300 --> 00:00:10,500
now let's do two things.

3
00:00:10,860 --> 00:00:17,400
First, we want to communicate with Stripe, but this is the case where we'll set up a fake communication

4
00:00:17,520 --> 00:00:20,400
because I don't want to involve another librarian in this project.

5
00:00:21,000 --> 00:00:23,490
And second, we want to create an order.

6
00:00:24,120 --> 00:00:30,570
And, you know, in between the videos, I kind of came to conclusion that it's going to make a little

7
00:00:30,570 --> 00:00:34,350
bit more sense if we're going to call this order items.

8
00:00:34,650 --> 00:00:37,020
So order items in the order address.

9
00:00:37,920 --> 00:00:39,420
And then the same thing over here.

10
00:00:39,420 --> 00:00:40,440
So single.

11
00:00:41,700 --> 00:00:43,680
Or item schema?

12
00:00:43,720 --> 00:00:44,460
My apologies.

13
00:00:45,330 --> 00:00:47,970
For some reason, I thought that cart makes sense.

14
00:00:49,060 --> 00:00:52,630
But as I'm looking at the function right now, I'm thinking.

15
00:00:53,690 --> 00:00:59,270
If I finances this order items and sort of equal to order items, it's going to make more sense in the

16
00:00:59,270 --> 00:00:59,810
long run.

17
00:01:00,140 --> 00:01:03,380
So I've got my items I have here.

18
00:01:04,239 --> 00:01:09,410
Alice Fordham Carte items threat over them and I set up the order items.

19
00:01:09,830 --> 00:01:13,910
Now, if you remember the previous project, the Stripe Payment one.

20
00:01:14,720 --> 00:01:17,030
Let me take a look at the final one stripe controller.

21
00:01:17,780 --> 00:01:23,060
I said that this was just to show you how we would do some kind of calculations.

22
00:01:23,600 --> 00:01:24,050
Correct.

23
00:01:24,710 --> 00:01:27,800
The most important part of this project was communicating with Stripe.

24
00:01:28,400 --> 00:01:35,390
And if you take a look at our create order now, you can kind of see what kind of functionality we're

25
00:01:35,390 --> 00:01:36,080
going to have.

26
00:01:36,890 --> 00:01:39,770
So and here we were, just adding some of.

27
00:01:40,280 --> 00:01:41,840
Normally this is what you'll do.

28
00:01:42,290 --> 00:01:49,910
You'll communicate with your database and you'll set up all the values when it comes to the card subtotal

29
00:01:50,180 --> 00:01:50,870
and all of that.

30
00:01:51,290 --> 00:01:53,510
So now let's communicate with Stripe.

31
00:01:54,170 --> 00:01:55,730
Let's get that payment instead.

32
00:01:55,740 --> 00:01:58,520
But like I said, I'm not going to involve in a library.

33
00:01:59,000 --> 00:02:05,870
Instead, I'll set up a fake one, create this simple function that takes an amount and currency.

34
00:02:06,320 --> 00:02:12,530
And as far as the amount, we are looking for that total, which we haven't calculated yet.

35
00:02:13,130 --> 00:02:18,200
And then we want to return against some fake client secret.

36
00:02:18,590 --> 00:02:22,790
And once all of this is there, then we want to create the order.

37
00:02:23,120 --> 00:02:30,740
And also, one more important point that I would like to make is this where the idea of our backend

38
00:02:31,400 --> 00:02:34,500
is to check whether everything is correct.

39
00:02:34,520 --> 00:02:41,630
So once the user clicks on proceed, the checkout, that's when we run those three things.

40
00:02:41,660 --> 00:02:43,580
That's where we check the product.

41
00:02:43,820 --> 00:02:47,330
We communicate with Stripe and we create an order.

42
00:02:47,570 --> 00:02:54,320
And if at any point something fails, then a user won't be able to see this page.

43
00:02:54,380 --> 00:02:55,740
This is very, very important.

44
00:02:55,760 --> 00:03:02,450
That's the goal for our backend is again to check whether everything is correct with cart, whether

45
00:03:02,450 --> 00:03:05,540
products exist and what are their correct prices.

46
00:03:06,020 --> 00:03:08,900
It is to communicate with Stripe to get that client's secret.

47
00:03:09,380 --> 00:03:11,450
And it's also to create an order.

48
00:03:11,780 --> 00:03:18,380
And if one piece is missing or if something is not provided, then the user won't be able to see this

49
00:03:18,380 --> 00:03:18,770
page.

50
00:03:19,280 --> 00:03:23,330
If the user can see this page, that means that everything is correct, and the only thing that user

51
00:03:23,330 --> 00:03:25,670
needs to do is to provide the card value.

52
00:03:25,670 --> 00:03:26,720
And hopefully that's clear.

53
00:03:26,810 --> 00:03:32,120
So now let me navigate back to our project, and here's what we want to do.

54
00:03:33,100 --> 00:03:35,020
First, I want to calculate the total.

55
00:03:35,620 --> 00:03:36,610
So how do we do that?

56
00:03:36,640 --> 00:03:38,830
Well, I already have the subtotal.

57
00:03:39,460 --> 00:03:40,660
I already have the.

58
00:03:41,480 --> 00:03:42,800
Tax and shipping fee.

59
00:03:43,250 --> 00:03:44,990
So I simply need to add them up.

60
00:03:45,320 --> 00:03:45,710
Correct.

61
00:03:46,490 --> 00:03:53,920
So it may remove this say here, Konst, and I'll call this total is equal to.

62
00:03:54,590 --> 00:04:00,380
And then we'll go with tax plus VAT shipping fee plus and subtotal.

63
00:04:00,830 --> 00:04:04,100
So we iterate over our card get subtotal.

64
00:04:04,400 --> 00:04:07,040
Now we're at everything up to eight total.

65
00:04:07,290 --> 00:04:08,920
So that's total part.

66
00:04:08,930 --> 00:04:12,020
So calculate and then total.

67
00:04:12,470 --> 00:04:15,740
Now we want to communicate with Stripe to get the client secret.

68
00:04:15,920 --> 00:04:17,390
So let's say get.

69
00:04:18,430 --> 00:04:19,779
Client secret.

70
00:04:19,810 --> 00:04:23,230
Now again, we're not going to involve the actual strap library.

71
00:04:23,770 --> 00:04:25,960
We will set up a fake function instead.

72
00:04:26,420 --> 00:04:33,130
So first, let me come up with some kind of variable my cash payment payment intent and that is equal

73
00:04:33,130 --> 00:04:34,000
to a weight.

74
00:04:34,000 --> 00:04:36,370
So it's going to be a synchronous chest.

75
00:04:36,370 --> 00:04:42,280
So we have a little bit more elastic setup up fake stripe API.

76
00:04:42,610 --> 00:04:43,720
And here we pass them.

77
00:04:43,720 --> 00:04:50,500
Two things will pass in the amount which is going to be the total and also part in the currency, which

78
00:04:50,500 --> 00:04:52,990
will be equal to a USD.

79
00:04:53,200 --> 00:04:55,990
Let's say it, and now we're just going to create that fake function.

80
00:04:56,410 --> 00:04:59,170
So let's scroll up above decreed order.

81
00:05:00,010 --> 00:05:04,810
We're going to go here with Konst Fake Stripe API.

82
00:05:05,080 --> 00:05:06,550
It's going to be asynchronous.

83
00:05:06,820 --> 00:05:11,920
And as far as the parameters are, we're looking for the object and in there there's going to be the

84
00:05:11,920 --> 00:05:13,960
amount and currency.

85
00:05:14,500 --> 00:05:20,650
And when it comes to functionality, I want to create some fake client.

86
00:05:20,650 --> 00:05:22,930
Secret messages are going to be some random value.

87
00:05:22,960 --> 00:05:26,110
So client secret variable.

88
00:05:26,290 --> 00:05:30,940
And that is equal to some random and value.

89
00:05:30,980 --> 00:05:36,490
And just like with normal stripe, I want to return something.

90
00:05:36,490 --> 00:05:40,720
I'm going to return a object and I'm just going to return a client secret.

91
00:05:41,290 --> 00:05:47,110
And then also the amount this is just a fake function that returns those values.

92
00:05:47,500 --> 00:05:54,520
And again, if there's some kind of issue, there's going to be an error and user won't be able to proceed

93
00:05:54,610 --> 00:05:55,420
to the checkout.

94
00:05:56,020 --> 00:06:01,180
So let's imagine that we successfully got back our client's secret now.

95
00:06:01,750 --> 00:06:04,120
Well, now we want to finally create that order.

96
00:06:04,390 --> 00:06:13,000
So we go here with constant order and that is equal to await or dot create and then let's pass in the

97
00:06:13,000 --> 00:06:13,360
object.

98
00:06:13,780 --> 00:06:19,480
And now we want to add all the properties that are required and those are order items.

99
00:06:19,990 --> 00:06:27,220
You also want to pass it all where you want to pass them subtotal and we want to set up packs a shipping

100
00:06:27,220 --> 00:06:29,260
fee and client secret.

101
00:06:29,380 --> 00:06:30,910
Now what is the client's secret?

102
00:06:31,000 --> 00:06:35,590
Why wait is payment intent and whatever the name here?

103
00:06:35,900 --> 00:06:38,260
And my guess that is client secret.

104
00:06:38,650 --> 00:06:42,340
So let's set it up where we go with client.

105
00:06:43,510 --> 00:06:51,880
Client and secret, and that is equal to my payment intent, Bath and then Client Secret Client underscore

106
00:06:51,890 --> 00:06:52,240
secret.

107
00:06:52,500 --> 00:06:55,990
And lastly, we want to tie this to our user and where the user is located.

108
00:06:56,350 --> 00:06:58,360
Well, in record user.

109
00:06:58,600 --> 00:06:58,970
Correct.

110
00:06:58,990 --> 00:07:00,460
So user property.

111
00:07:01,530 --> 00:07:09,630
Is equal to a rec user and the user I.D. Let's save it.

112
00:07:10,200 --> 00:07:17,970
And now, once we create the order now we want to send back that status and we'll go with status codes

113
00:07:18,390 --> 00:07:21,000
and two a one created man.

114
00:07:21,060 --> 00:07:24,900
When it comes to response, let's send back the object in.

115
00:07:24,900 --> 00:07:33,000
There will have to your friends were and clients secret client secret, which is again equal.

116
00:07:33,450 --> 00:07:38,670
You can either pull it out of the order or you can just go with payment intent in secret.

117
00:07:38,970 --> 00:07:45,270
Some of my guys and I think I'm going to go with order and then client's secret with me, by the way.

118
00:07:45,720 --> 00:07:46,710
Set up your karma.

119
00:07:46,800 --> 00:07:48,000
I have a typo.

120
00:07:48,240 --> 00:07:52,950
So out of comma here and nine, we're looking for client and secret.

121
00:07:53,430 --> 00:07:59,070
So once we save all of this, we can go back to the postman and send it.

122
00:07:59,610 --> 00:08:00,750
So we're centered here.

123
00:08:01,080 --> 00:08:02,400
We create the order.

124
00:08:02,640 --> 00:08:03,480
And now check it out.

125
00:08:04,140 --> 00:08:11,510
That's my tax shipping fee, subtotal total and the order items as far as status is pending.

126
00:08:11,520 --> 00:08:16,920
But if everything is correct, the only thing that user need to do is actually pay.

127
00:08:17,820 --> 00:08:22,440
Now let's start out with few values in the array, whether our functionality works.

128
00:08:22,830 --> 00:08:28,440
So again, I'm going to go back to my mock data where it is located bum bum, bum, bum, bum, bum

129
00:08:28,440 --> 00:08:28,710
bum.

130
00:08:28,920 --> 00:08:30,300
That's the stripe one.

131
00:08:30,780 --> 00:08:31,740
It has orders.

132
00:08:32,010 --> 00:08:33,520
So now let me take a rest.

133
00:08:33,539 --> 00:08:40,620
But again, what you want to do is set up properties, otherwise you'll be getting back the errors.

134
00:08:41,070 --> 00:08:42,210
So let me take this.

135
00:08:43,380 --> 00:08:47,160
Let me removed and replaced with this.

136
00:08:48,120 --> 00:08:52,080
Then get all products banned in my case, I have right away two of them.

137
00:08:53,300 --> 00:08:59,870
So if you don't burn, I suggest adding them now, that's my first order.

138
00:09:00,320 --> 00:09:02,780
I want a second one product idea here.

139
00:09:03,860 --> 00:09:05,420
And let's keep scrolling.

140
00:09:07,090 --> 00:09:08,030
Let's get this very.

141
00:09:09,870 --> 00:09:11,910
And let's also add it here as well.

142
00:09:14,000 --> 00:09:15,230
Once we have both of them.

143
00:09:16,200 --> 00:09:24,120
Once we send while we have the order again, in this case, bags are different, but the idea is exactly

144
00:09:24,120 --> 00:09:24,540
the same.

145
00:09:24,780 --> 00:09:28,170
So now we have a second or as well.

146
00:09:28,610 --> 00:09:34,050
And if you get back, same results now we can start working on the rest of the controllers.

