﻿1
00:00:01,060 --> 00:00:03,650
‫So in this video let's integrate Stripe

2
00:00:03,650 --> 00:00:07,240
‫into our backend by creating that API endpoint

3
00:00:07,240 --> 00:00:10,983
‫which will create and send back a Stripe checkout session.

4
00:00:12,870 --> 00:00:15,717
‫And so at this point, we're actually gonna start creating

5
00:00:15,717 --> 00:00:17,110
‫our next resource.

6
00:00:17,110 --> 00:00:18,860
‫And so that's the bookings.

7
00:00:18,860 --> 00:00:21,413
‫And I will start here with the booking routes.

8
00:00:24,995 --> 00:00:25,828
‫So booking

9
00:00:27,200 --> 00:00:29,100
‫routes.js.

10
00:00:29,100 --> 00:00:31,660
‫And we've done that so many times now.

11
00:00:31,660 --> 00:00:33,150
‫So then I'm just gonna go ahead

12
00:00:33,150 --> 00:00:34,480
‫copy all of this code

13
00:00:35,890 --> 00:00:37,843
‫and put it here in the booking routes.

14
00:00:39,410 --> 00:00:42,073
‫And then simply remove all of this.

15
00:00:44,230 --> 00:00:45,923
‫And also this one.

16
00:00:47,310 --> 00:00:50,060
‫We also don't need merge params

17
00:00:51,000 --> 00:00:54,530
‫and we will have a booking controller instead of

18
00:00:54,530 --> 00:00:55,593
‫a review controller.

19
00:00:57,850 --> 00:01:02,203
‫So booking controller, let's actually create that.

20
00:01:03,844 --> 00:01:04,677
‫So

21
00:01:09,317 --> 00:01:10,170
‫.js

22
00:01:11,520 --> 00:01:12,570
‫that looks correct

23
00:01:13,460 --> 00:01:17,503
‫and let's also integrate this right into app.js.

24
00:01:18,970 --> 00:01:20,970
‫And so let's put that right here

25
00:01:20,970 --> 00:01:22,423
‫after the review router.

26
00:01:25,430 --> 00:01:29,940
‫So here that's just again bookings

27
00:01:32,100 --> 00:01:34,370
‫and then of course down here integrate that

28
00:01:34,370 --> 00:01:35,513
‫into our API.

29
00:01:40,190 --> 00:01:42,220
‫So bookings and here

30
00:01:43,360 --> 00:01:44,913
‫bookings router.

31
00:01:46,970 --> 00:01:49,223
‫And I think that should only be booking.

32
00:01:50,170 --> 00:01:52,703
‫So let's fix that up here as well.

33
00:01:54,180 --> 00:01:57,010
‫And indeed we call it booking router.

34
00:01:57,010 --> 00:01:58,880
‫And the same here, it's not bookings

35
00:01:58,880 --> 00:02:00,700
‫but booking routes.

36
00:02:00,700 --> 00:02:01,863
‫So give it a save.

37
00:02:04,100 --> 00:02:05,990
‫Close this one and this one

38
00:02:05,990 --> 00:02:09,090
‫and this one here as well.

39
00:02:09,090 --> 00:02:11,670
‫And so now let's actually go ahead and create

40
00:02:11,670 --> 00:02:13,083
‫our first route here.

41
00:02:14,980 --> 00:02:19,980
‫So let's router.get and the route that it will create here

42
00:02:20,930 --> 00:02:24,160
‫will once again not follow the rest principle

43
00:02:24,160 --> 00:02:26,630
‫because this one is not really gonna be about

44
00:02:26,630 --> 00:02:30,080
‫creating or getting or updating any booking.

45
00:02:30,080 --> 00:02:33,060
‫Instead this route will only be for the client

46
00:02:33,060 --> 00:02:35,390
‫to get a checkout session.

47
00:02:35,390 --> 00:02:37,140
‫And so let's actually call this one

48
00:02:38,810 --> 00:02:41,733
‫checkout session.

49
00:02:43,060 --> 00:02:45,600
‫Then we need to protect this route

50
00:02:45,600 --> 00:02:48,820
‫so that only authenticated users can actually get

51
00:02:48,820 --> 00:02:50,380
‫a checkout session.

52
00:02:50,380 --> 00:02:51,863
‫So that makes sense, right?

53
00:02:52,840 --> 00:02:55,603
‫And then add booking controller.

54
00:02:56,460 --> 00:02:59,253
‫We're gonna create a route handler called get

55
00:03:02,477 --> 00:03:06,558
‫checkout session.

56
00:03:06,558 --> 00:03:07,391
‫All right.

57
00:03:08,512 --> 00:03:12,422
‫So let's copy this one and create it here

58
00:03:12,422 --> 00:03:14,839
‫at exports.getCheckoutSession

59
00:03:16,600 --> 00:03:19,513
‫then request responds next.

60
00:03:21,910 --> 00:03:24,740
‫And now let's start working.

61
00:03:24,740 --> 00:03:27,230
‫Now actually there's one more thing we need to do here

62
00:03:27,230 --> 00:03:31,550
‫in the routes which is to specify a URL parameter.

63
00:03:31,550 --> 00:03:34,083
‫And so that's going to be the tour ID.

64
00:03:35,970 --> 00:03:39,350
‫Okay, so basically we want the client to send along

65
00:03:39,350 --> 00:03:42,920
‫the ID of the tour that is currently begin booked.

66
00:03:42,920 --> 00:03:46,010
‫And that is so that we can fill up the checkout session

67
00:03:46,010 --> 00:03:48,230
‫with all the data that is necessary,

68
00:03:48,230 --> 00:03:52,220
‫such as the tour name and the tour price and all that stuff.

69
00:03:52,220 --> 00:03:55,780
‫All right, so we now have access to the tour ID

70
00:03:55,780 --> 00:03:57,470
‫in this handler function

71
00:03:57,470 --> 00:04:00,030
‫and so the first thing that we're actually gonna do

72
00:04:00,030 --> 00:04:02,610
‫is to find that tour in our database.

73
00:04:02,610 --> 00:04:06,260
‫All right, so for that we need of course the tour model.

74
00:04:06,260 --> 00:04:09,210
‫So let's come here to the tour controller

75
00:04:09,210 --> 00:04:11,190
‫and get that from there.

76
00:04:11,190 --> 00:04:14,120
‫Also we're gonna need this catchAsync

77
00:04:14,120 --> 00:04:15,793
‫and so really all of this.

78
00:04:16,870 --> 00:04:18,510
‫So I'm copying all of it

79
00:04:18,510 --> 00:04:20,730
‫and even if I don't need it right away

80
00:04:20,730 --> 00:04:23,363
‫I will probably need it a bit later anyway.

81
00:04:24,629 --> 00:04:25,462
‫All right.

82
00:04:27,840 --> 00:04:30,600
‫So let's layout our steps here again.

83
00:04:30,600 --> 00:04:35,600
‫So get the currently booked tour.

84
00:04:38,250 --> 00:04:43,250
‫Then as a second step, we create the checkout session

85
00:04:45,550 --> 00:04:47,633
‫and then finally send it to the client.

86
00:04:53,376 --> 00:04:57,043
‫All right, so the first step is really easy.

87
00:04:59,930 --> 00:05:01,053
‫So we're gonna wait.

88
00:05:02,140 --> 00:05:06,120
‫So tour.findbyId

89
00:05:07,210 --> 00:05:10,173
‫which is req.params.tourId.

90
00:05:14,790 --> 00:05:18,112
‫Right, so that was the name we gave it

91
00:05:18,112 --> 00:05:19,810
‫in the URL parameter.

92
00:05:19,810 --> 00:05:24,250
‫And of course, this is now an async function

93
00:05:25,120 --> 00:05:29,623
‫with a catchAsync besides that or around that, actually.

94
00:05:33,170 --> 00:05:36,360
‫Great, next up, let's create that session here.

95
00:05:36,360 --> 00:05:38,410
‫And for that we actually need to install

96
00:05:38,410 --> 00:05:40,323
‫this drive NPM package.

97
00:05:41,920 --> 00:05:45,650
‫So let's do that here.

98
00:05:45,650 --> 00:05:50,290
‫NPM install Stripe.

99
00:05:50,290 --> 00:05:54,000
‫And in the meantime we're gonna go to our Stripe dashboard

100
00:05:54,000 --> 00:05:56,003
‫and get our secret key from here.

101
00:05:57,030 --> 00:05:59,280
‫So just hit this button here

102
00:05:59,280 --> 00:06:03,040
‫and then go ahead and copy it.

103
00:06:03,040 --> 00:06:04,630
‫And you see that here in the keys

104
00:06:04,630 --> 00:06:06,380
‫it actually says test.

105
00:06:06,380 --> 00:06:09,920
‫And so again, these ones here are just for testing

106
00:06:09,920 --> 00:06:12,530
‫and then once you have your Stripe account active,

107
00:06:12,530 --> 00:06:14,993
‫you can then get your live API keys.

108
00:06:16,390 --> 00:06:19,230
‫Okay, now as with any other keys

109
00:06:19,230 --> 00:06:22,743
‫we will put them here in our config file.

110
00:06:25,490 --> 00:06:26,370
‫So Stripe

111
00:06:29,490 --> 00:06:32,670
‫secret key equal to this.

112
00:06:32,670 --> 00:06:34,120
‫And this is not correct here.

113
00:06:40,700 --> 00:06:43,163
‫All right, so copy this one.

114
00:06:44,730 --> 00:06:46,610
‫Back to our booking controller.

115
00:06:46,610 --> 00:06:49,400
‫Let's now actually require this drive package

116
00:06:49,400 --> 00:06:52,620
‫with has successfully installed here.

117
00:06:52,620 --> 00:06:54,810
‫And just with all the other packages before

118
00:06:54,810 --> 00:06:56,780
‫please make sure that you're actually on

119
00:06:56,780 --> 00:06:58,030
‫the same version as I am.

120
00:06:59,050 --> 00:07:02,137
‫And you see that I'm here at the brand new 7.0.0.

121
00:07:03,120 --> 00:07:04,730
‫So this is really brand new.

122
00:07:04,730 --> 00:07:07,650
‫And actually that's because a lot of stuff just changed

123
00:07:07,650 --> 00:07:10,370
‫with Stripe a couple of days ago.

124
00:07:10,370 --> 00:07:13,113
‫So I had to change a couple of these implementation.

125
00:07:15,190 --> 00:07:20,190
‫Anyway, const stripe equal require

126
00:07:24,440 --> 00:07:26,000
‫and then stripe.

127
00:07:26,000 --> 00:07:28,890
‫Now this here will then expose a function basically.

128
00:07:28,890 --> 00:07:30,940
‫And usually what we do then right away

129
00:07:30,940 --> 00:07:34,670
‫is to pass our secret key right into that.

130
00:07:34,670 --> 00:07:37,020
‫And so that will then give us a Stripe object

131
00:07:37,020 --> 00:07:38,123
‫that we can work with.

132
00:07:39,410 --> 00:07:43,057
‫So that now at process.env.STRIPE_SECRET_KEY.

133
00:07:46,930 --> 00:07:51,093
‫Okay, and so now let's use that.

134
00:07:52,700 --> 00:07:57,700
‫So we say Stripe.checkout.session.create.

135
00:08:02,450 --> 00:08:06,040
‫And then the usual object of options.

136
00:08:06,040 --> 00:08:08,680
‫All right, now there are a ton of options

137
00:08:08,680 --> 00:08:10,060
‫that we can set here.

138
00:08:10,060 --> 00:08:12,290
‫But only three of them are required.

139
00:08:12,290 --> 00:08:15,083
‫So the first one is the payment method types.

140
00:08:16,010 --> 00:08:20,213
‫So payment method types.

141
00:08:22,950 --> 00:08:26,740
‫So that is an array where we can specify multiple types

142
00:08:26,740 --> 00:08:28,920
‫and card is for credit card.

143
00:08:28,920 --> 00:08:31,780
‫And right now that's actually all the payment options

144
00:08:31,780 --> 00:08:34,330
‫that we can use for Stripe checkout.

145
00:08:34,330 --> 00:08:38,130
‫But I read that in the future they will add a lot more.

146
00:08:38,130 --> 00:08:41,550
‫So you can get informed by that.

147
00:08:41,550 --> 00:08:44,023
‫Then we need to specify the success URL.

148
00:08:46,240 --> 00:08:49,350
‫And so that is basically the URL that will get called

149
00:08:49,350 --> 00:08:52,690
‫as soon as a credit card has been successfully charged.

150
00:08:52,690 --> 00:08:55,780
‫So as soon as the purchase was successful

151
00:08:55,780 --> 00:08:58,860
‫the user will be redirected to this URL.

152
00:08:58,860 --> 00:09:02,123
‫And for now, let's simply specify that as our homepage.

153
00:09:03,060 --> 00:09:06,290
‫All right and we're gonna do that just as before

154
00:09:06,290 --> 00:09:10,963
‫with req.protocol://

155
00:09:14,270 --> 00:09:18,663
‫and then request.get the host.

156
00:09:20,670 --> 00:09:23,403
‫So basically just our home URL.

157
00:09:24,330 --> 00:09:27,707
‫Then we also need to specify the cancel URL.

158
00:09:30,530 --> 00:09:31,773
‫So just like this.

159
00:09:33,010 --> 00:09:34,763
‫And this one is gonna be similar.

160
00:09:36,260 --> 00:09:38,800
‫And so basically it's the page where the user goes

161
00:09:38,800 --> 00:09:41,980
‫if they choose to cancel the current payment.

162
00:09:41,980 --> 00:09:44,610
‫And actually let's make them go to the tour page

163
00:09:44,610 --> 00:09:46,360
‫where they were previously.

164
00:09:46,360 --> 00:09:50,493
‫And so that is basically tour/tour.slug.

165
00:09:56,040 --> 00:09:59,870
‫Next up, we can also specify the customer email.

166
00:09:59,870 --> 00:10:02,410
‫And so that is very handy because of course

167
00:10:02,410 --> 00:10:05,380
‫we already have access to the customer's email.

168
00:10:05,380 --> 00:10:08,090
‫And so with this we can save the user one step

169
00:10:08,090 --> 00:10:11,080
‫and make the checkout experience a lot smoother.

170
00:10:11,080 --> 00:10:15,230
‫All right so remember that this is a protected route.

171
00:10:15,230 --> 00:10:19,320
‫And so as always the user is already at the request.

172
00:10:19,320 --> 00:10:23,763
‫And so we can say request.user.email.

173
00:10:25,030 --> 00:10:28,860
‫Next up, we can then also specify a custom field

174
00:10:28,860 --> 00:10:31,560
‫which is called client reference ID.

175
00:10:31,560 --> 00:10:34,610
‫And that sounds a bit weird but actually it's going to be

176
00:10:34,610 --> 00:10:36,340
‫really important for us.

177
00:10:36,340 --> 00:10:39,900
‫So this field is gonna allow us to pass in some data

178
00:10:39,900 --> 00:10:42,430
‫about the session that we are currently creating.

179
00:10:42,430 --> 00:10:44,400
‫And that's important because later

180
00:10:44,400 --> 00:10:46,530
‫once the purchase was successful,

181
00:10:46,530 --> 00:10:50,250
‫we will then get access to the session object again.

182
00:10:50,250 --> 00:10:52,830
‫And by then, we want to create a new booking

183
00:10:52,830 --> 00:10:54,400
‫in our database.

184
00:10:54,400 --> 00:10:56,380
‫So remember the diagram that I showed you

185
00:10:56,380 --> 00:10:57,610
‫in the last lecture.

186
00:10:57,610 --> 00:10:59,240
‫Basically what I'm talking about here

187
00:10:59,240 --> 00:11:01,890
‫is the last step in that diagram.

188
00:11:01,890 --> 00:11:04,670
‫And also remember how that is only going to work

189
00:11:04,670 --> 00:11:06,130
‫with deployed websites.

190
00:11:06,130 --> 00:11:08,900
‫But still, let's already prepare for that here.

191
00:11:08,900 --> 00:11:12,860
‫Okay, so to create a new booking in our database

192
00:11:12,860 --> 00:11:16,890
‫we will need the user's ID, the tour ID, and the price.

193
00:11:16,890 --> 00:11:18,260
‫Remember that?

194
00:11:18,260 --> 00:11:20,460
‫And in this session we already have access

195
00:11:20,460 --> 00:11:22,315
‫to the user's email

196
00:11:22,315 --> 00:11:26,290
‫and from that we can then recreate the user's ID

197
00:11:26,290 --> 00:11:28,520
‫because email here is unique.

198
00:11:28,520 --> 00:11:31,900
‫We will also specify the tour's price here in a second

199
00:11:31,900 --> 00:11:35,100
‫and so all that's missing is then the tour ID.

200
00:11:35,100 --> 00:11:37,130
‫And so that's what we're gonna specify here

201
00:11:37,130 --> 00:11:39,263
‫on this custom field basically.

202
00:11:41,320 --> 00:11:45,763
‫So that's called client reference ID.

203
00:11:47,500 --> 00:11:49,750
‫And all of what I just explained before

204
00:11:49,750 --> 00:11:52,210
‫actually is gonna make a lot more sense

205
00:11:52,210 --> 00:11:54,630
‫once we actually implement that last step

206
00:11:54,630 --> 00:11:58,240
‫of creating a booking in the database, right?

207
00:11:58,240 --> 00:12:02,667
‫Anyway, that tour ID is at request.params.tourId.

208
00:12:05,371 --> 00:12:08,080
‫All right, and now finally, we're gonna specify

209
00:12:08,080 --> 00:12:11,010
‫some details about the product itself.

210
00:12:11,010 --> 00:12:13,093
‫So our tour in this case.

211
00:12:14,100 --> 00:12:17,720
‫And so that's called line items which accepts

212
00:12:17,720 --> 00:12:19,700
‫an array of objects.

213
00:12:19,700 --> 00:12:22,330
‫So basically one per item

214
00:12:22,330 --> 00:12:24,733
‫and so in our case that's only gonna be one.

215
00:12:25,940 --> 00:12:28,640
‫So we're to specify the name of the product

216
00:12:30,160 --> 00:12:34,810
‫and so that's at tour.name

217
00:12:34,810 --> 00:12:39,423
‫and as always we also add the tour to that name.

218
00:12:41,720 --> 00:12:43,933
‫Then we can also specify a description.

219
00:12:45,840 --> 00:12:48,950
‫And all these field names here they really come from Stripe.

220
00:12:48,950 --> 00:12:51,200
‫So we cannot make up our own fields.

221
00:12:51,200 --> 00:12:54,683
‫So if you try to do that, you will really get some error.

222
00:12:55,530 --> 00:12:57,510
‫All right, so in the description

223
00:12:57,510 --> 00:12:59,373
‫I will put the tour summary,

224
00:13:00,540 --> 00:13:05,540
‫so that nice short phrase that will describe each tour.

225
00:13:06,400 --> 00:13:10,750
‫Then we can also specify an array of images.

226
00:13:10,750 --> 00:13:14,120
‫Now these images here they need to be live images.

227
00:13:14,120 --> 00:13:17,260
‫So basically images that are hosted on the internet

228
00:13:17,260 --> 00:13:20,090
‫because Stripe will actually upload this image

229
00:13:20,090 --> 00:13:21,680
‫to their own server.

230
00:13:21,680 --> 00:13:23,740
‫And so this is another of the things

231
00:13:23,740 --> 00:13:27,470
‫that we can only really do once the website is deployed.

232
00:13:27,470 --> 00:13:30,680
‫But for now, as a placeholder, I will basically use the ones

233
00:13:30,680 --> 00:13:34,760
‫from our hosted example website on natours.dev.

234
00:13:34,760 --> 00:13:36,623
‫So let's go to that website.

235
00:13:38,100 --> 00:13:41,050
‫So that's this one at natours.dev.

236
00:13:41,050 --> 00:13:44,500
‫And the image that I'm gonna choose is the cover image.

237
00:13:44,500 --> 00:13:46,283
‫So let's inspect that image.

238
00:13:47,130 --> 00:13:51,103
‫So this one here and copy link address here.

239
00:13:52,396 --> 00:13:53,710
‫All right.

240
00:13:53,710 --> 00:13:58,140
‫So this is an array because we can specify multiple images

241
00:13:58,140 --> 00:14:00,673
‫but we really only want one of them.

242
00:14:01,790 --> 00:14:05,950
‫And indeed we have natours.dev/images/tours

243
00:14:05,950 --> 00:14:07,940
‫and then the name of the image.

244
00:14:07,940 --> 00:14:11,810
‫And this one I will simply replace with tour.image cover.

245
00:14:11,810 --> 00:14:14,950
‫And that's gonna work because the names of the images

246
00:14:14,950 --> 00:14:18,920
‫on natours.dev are exactly the same as we have here

247
00:14:18,920 --> 00:14:20,053
‫in our project.

248
00:14:21,560 --> 00:14:23,500
‫So tour.imageCover.

249
00:14:26,580 --> 00:14:29,980
‫So this is one more thing that we actually need to change

250
00:14:29,980 --> 00:14:32,520
‫once we put our website into production.

251
00:14:32,520 --> 00:14:35,630
‫And I'm keeping actually a list of that stuff

252
00:14:35,630 --> 00:14:37,280
‫so that we don't forget anything.

253
00:14:38,450 --> 00:14:40,760
‫Anyway, next up is the amount.

254
00:14:40,760 --> 00:14:42,940
‫So basically the price of the product

255
00:14:42,940 --> 00:14:44,163
‫that is being purchased.

256
00:14:45,010 --> 00:14:47,990
‫So that is tour.price

257
00:14:47,990 --> 00:14:50,660
‫and now we need to multiply that by 100.

258
00:14:50,660 --> 00:14:53,673
‫Because this amount is expected to be in cents.

259
00:14:54,870 --> 00:14:57,270
‫And so one dollar or one Euro

260
00:14:57,270 --> 00:15:00,640
‫or really most of the currencies have 100 cents.

261
00:15:00,640 --> 00:15:02,920
‫So one dollar equals 100 cents.

262
00:15:02,920 --> 00:15:06,663
‫And so to convert it to cents, just multiply it by 100.

263
00:15:08,040 --> 00:15:11,790
‫Then we also need to specify the currency.

264
00:15:11,790 --> 00:15:14,110
‫And so that's in this case USD.

265
00:15:14,110 --> 00:15:18,850
‫But it could also be like, for Euro it's EUR

266
00:15:20,439 --> 00:15:23,560
‫and for other currencies, you should probably take a look

267
00:15:23,560 --> 00:15:25,090
‫at the documentation.

268
00:15:25,090 --> 00:15:27,670
‫So of course I cannot cover all the currencies

269
00:15:27,670 --> 00:15:31,000
‫that there are, right?

270
00:15:31,000 --> 00:15:35,760
‫Anyway, finally we also specify the quantity.

271
00:15:35,760 --> 00:15:38,263
‫And so that's just one tour in this case.

272
00:15:41,110 --> 00:15:43,370
‫So that's actually it.

273
00:15:43,370 --> 00:15:47,230
‫And so basically this part here is the information

274
00:15:47,230 --> 00:15:48,800
‫about the session itself.

275
00:15:48,800 --> 00:15:51,630
‫And then here is the information about the product

276
00:15:51,630 --> 00:15:54,060
‫that the user is about to purchase.

277
00:15:54,060 --> 00:15:56,883
‫All right, now let's actually store the session.

278
00:15:57,810 --> 00:15:59,090
‫So const session

279
00:16:00,270 --> 00:16:03,000
‫and now we to await this.

280
00:16:03,000 --> 00:16:05,850
‫So this create here basically returns a premise

281
00:16:05,850 --> 00:16:08,110
‫because setting all these options here

282
00:16:08,110 --> 00:16:11,060
‫will basically do an API call to Stripe

283
00:16:11,060 --> 00:16:14,341
‫and so then of course that's an asynchronous function

284
00:16:14,341 --> 00:16:16,470
‫that we should await here.

285
00:16:16,470 --> 00:16:19,790
‫Okay, but anyway this is now our session

286
00:16:19,790 --> 00:16:22,740
‫and so the last step is of course to send it

287
00:16:22,740 --> 00:16:24,020
‫back to the client.

288
00:16:24,020 --> 00:16:25,493
‫So as always,

289
00:16:29,480 --> 00:16:31,743
‫the status is success.

290
00:16:33,460 --> 00:16:36,463
‫And then let's simply send the session like this.

291
00:16:38,896 --> 00:16:42,510
‫All right, so that should actually be it.

292
00:16:42,510 --> 00:16:44,980
‫Our router is already configured

293
00:16:44,980 --> 00:16:48,260
‫and so I think we could actually now try this out

294
00:16:48,260 --> 00:16:49,950
‫in postman.

295
00:16:49,950 --> 00:16:53,470
‫All right, now later of course we will not allow anyone

296
00:16:53,470 --> 00:16:55,370
‫to do this using postman

297
00:16:55,370 --> 00:16:57,650
‫because that doesn't make much sense.

298
00:16:57,650 --> 00:16:59,990
‫But now since we're only testing this

299
00:16:59,990 --> 00:17:02,060
‫it actually makes a lot of sense.

300
00:17:02,060 --> 00:17:05,660
‫All right so let's head over to postman

301
00:17:05,660 --> 00:17:08,483
‫and create a brand new request.

302
00:17:11,150 --> 00:17:15,770
‫So that's gonna be at bookings/

303
00:17:17,768 --> 00:17:19,313
‫uh, I'm not really sure.

304
00:17:20,261 --> 00:17:24,473
‫Yeah, so checkout session and then /tourId.

305
00:17:26,330 --> 00:17:28,823
‫All right, so let's get our tours here.

306
00:17:31,030 --> 00:17:33,323
‫To get the ID from there basically.

307
00:17:34,560 --> 00:17:36,263
‫So let's do the Sea Explorer.

308
00:17:41,700 --> 00:17:45,950
‫Okay, and that should actually be enough.

309
00:17:45,950 --> 00:17:47,963
‫Oh wait, we are of course not logged in.

310
00:17:50,022 --> 00:17:51,363
‫So log in here.

311
00:17:54,010 --> 00:17:55,460
‫Now we are in admin,

312
00:17:55,460 --> 00:17:57,370
‫but let's use someone else here.

313
00:17:57,370 --> 00:17:59,860
‫And I think we used Leo before

314
00:17:59,860 --> 00:18:01,813
‫so let's now use that user.

315
00:18:04,250 --> 00:18:07,053
‫Now we have an incorrect password.

316
00:18:08,761 --> 00:18:11,320
‫All right so let's see what else we have.

317
00:18:11,320 --> 00:18:14,470
‫So what other users we could use.

318
00:18:14,470 --> 00:18:16,683
‫And actually let's use Monica here.

319
00:18:19,990 --> 00:18:21,530
‫Why not?

320
00:18:21,530 --> 00:18:25,753
‫So hopefully her password is correct.

321
00:18:27,500 --> 00:18:30,410
‫Well, let's actually try to replace this here

322
00:18:32,170 --> 00:18:33,883
‫with test1234.

323
00:18:35,290 --> 00:18:38,040
‫Well, maybe we did change the passwords

324
00:18:38,040 --> 00:18:41,493
‫of all of these users in some other lectures before.

325
00:18:43,740 --> 00:18:46,320
‫So let's use John here.

326
00:18:46,320 --> 00:18:48,740
‫So I know that we never used John

327
00:18:48,740 --> 00:18:51,523
‫so now it has to work.

328
00:18:55,250 --> 00:18:59,000
‫Oh, I actually see the error that I just did before.

329
00:18:59,000 --> 00:19:02,583
‫So here it's not natours, it must be example.com.

330
00:19:06,410 --> 00:19:08,460
‫So let's try that again with Monica here.

331
00:19:11,990 --> 00:19:13,813
‫Or really just with John.

332
00:19:14,850 --> 00:19:18,000
‫This is more difficult than I expected it to be.

333
00:19:18,000 --> 00:19:19,963
‫But now finally we are logged in.

334
00:19:21,130 --> 00:19:24,500
‫All right, and so with that,

335
00:19:24,500 --> 00:19:26,743
‫let's try to get our checkout session.

336
00:19:29,180 --> 00:19:31,463
‫We are missing the authorization from here.

337
00:19:33,180 --> 00:19:37,270
‫One more time, and now we get some real error here.

338
00:19:37,270 --> 00:19:40,370
‫So something that is actually really coming from the code

339
00:19:40,370 --> 00:19:41,713
‫that we just wrote.

340
00:19:43,220 --> 00:19:44,550
‫All right.

341
00:19:44,550 --> 00:19:46,223
‫So let's check that out.

342
00:19:47,740 --> 00:19:51,200
‫And the problem is that here it's actually sessions.

343
00:19:51,200 --> 00:19:54,963
‫So stripe.checkout.sessions.

344
00:19:57,400 --> 00:19:58,383
‫One more time.

345
00:19:59,680 --> 00:20:03,850
‫This time it's taking a lot longer which is a good sign.

346
00:20:03,850 --> 00:20:05,740
‫And we have another error.

347
00:20:05,740 --> 00:20:09,573
‫So line 15 cannot read slug of node.

348
00:20:12,200 --> 00:20:15,510
‫All right, well that sure is weird

349
00:20:15,510 --> 00:20:18,463
‫because there should be a slug on this tour.

350
00:20:19,980 --> 00:20:21,290
‫So uh

351
00:20:22,930 --> 00:20:25,660
‫yeah you see that here it actually is.

352
00:20:25,660 --> 00:20:29,660
‫So maybe something went wrong with actually reading

353
00:20:29,660 --> 00:20:30,623
‫this tour.

354
00:20:31,580 --> 00:20:35,083
‫Which I cannot really understand why that would be.

355
00:20:35,970 --> 00:20:39,273
‫But let's just try to log the tour to the console.

356
00:20:46,970 --> 00:20:50,000
‫All right, and actually we get null.

357
00:20:50,000 --> 00:20:54,480
‫Which probably means that there's a tour ID

358
00:20:54,480 --> 00:20:55,763
‫not correctly defined.

359
00:20:56,750 --> 00:20:58,790
‫Oh, here is the problem.

360
00:20:58,790 --> 00:21:02,330
‫So I have it, ID all uppercase,

361
00:21:02,330 --> 00:21:06,450
‫but then here in the controller I have the D in lowercase.

362
00:21:06,450 --> 00:21:07,840
‫So like this.

363
00:21:07,840 --> 00:21:10,790
‫And so that's the small type of bugs that happen

364
00:21:10,790 --> 00:21:12,183
‫all the time obviously.

365
00:21:13,210 --> 00:21:15,040
‫So let's see what's the next one.

366
00:21:15,040 --> 00:21:18,280
‫Oh and actually this time we got it right.

367
00:21:18,280 --> 00:21:22,050
‫So you see that is the session that we just created.

368
00:21:22,050 --> 00:21:24,290
‫And it edits some more other stuff here

369
00:21:24,290 --> 00:21:27,430
‫but that doesn't really matter for us right now.

370
00:21:27,430 --> 00:21:29,340
‫What's really interesting to see though

371
00:21:29,340 --> 00:21:32,330
‫is that we now can actually already kind of see

372
00:21:32,330 --> 00:21:35,330
‫this payment, or at least this payment request,

373
00:21:35,330 --> 00:21:37,843
‫let's say in our drive dashboards.

374
00:21:39,490 --> 00:21:44,490
‫So if we go there and go to payments

375
00:21:44,540 --> 00:21:49,010
‫and then to all, you will see that this last one here

376
00:21:49,010 --> 00:21:51,320
‫actually just happened right now.

377
00:21:51,320 --> 00:21:56,320
‫So if we click that, then you will see some data about it.

378
00:21:56,630 --> 00:21:59,130
‫So you see for example that it is actually about

379
00:21:59,130 --> 00:22:00,960
‫the Sea Explorer Tour.

380
00:22:00,960 --> 00:22:03,983
‫You also have the price, you also have the image.

381
00:22:04,920 --> 00:22:07,800
‫Probably also some data about the user.

382
00:22:07,800 --> 00:22:10,530
‫And actually no, not really.

383
00:22:10,530 --> 00:22:14,400
‫But what matters here is that it says incomplete.

384
00:22:14,400 --> 00:22:17,160
‫And that's because we only created the checkout session

385
00:22:17,160 --> 00:22:18,310
‫on the server.

386
00:22:18,310 --> 00:22:20,440
‫And so we're missing the second step

387
00:22:20,440 --> 00:22:22,750
‫where we then actually charge the credit card

388
00:22:22,750 --> 00:22:24,450
‫on the client side.

389
00:22:24,450 --> 00:22:26,210
‫So since we're missing that,

390
00:22:26,210 --> 00:22:28,843
‫let's actually do it right in the next video.

