1 00:00:00,990 --> 00:00:04,780 I'm inside of our root handler so at the very top we're going to import that publisher that we just 2 00:00:04,780 --> 00:00:10,100 created and make sure that we publish the payment Create Event after saving our newly created payment. 3 00:00:10,240 --> 00:00:13,100 So the very top I will import my publisher 4 00:00:17,100 --> 00:00:23,260 and I'll import that from up one directory events publishers name integrated publisher 5 00:00:26,720 --> 00:00:30,040 then back down right after our payment got saved. 6 00:00:30,320 --> 00:00:35,360 I'm gonna create a new instance of the payment created a publisher. 7 00:00:35,360 --> 00:00:39,560 Don't forget we do have to provide a Nats client to this thing and that means we need to also import 8 00:00:39,590 --> 00:00:42,200 our Nats wrapper at the top of the file as well. 9 00:00:42,200 --> 00:00:51,350 So at the very top I will also import my Nats wrapper from up one directory Nats wrapper 10 00:00:54,390 --> 00:01:01,180 then right after we create the new publisher I'll stick in the Nats wrapper client. 11 00:01:01,380 --> 00:01:06,780 We have to call publish on there and to publish we have to provide some data for the event itself. 12 00:01:06,810 --> 00:01:10,450 So again if we forget what we have to provide we can always mouse over the air will be sold. 13 00:01:10,450 --> 00:01:15,030 We have to be get to provide the idea of the payment to what's created the order I.D. and the stripe 14 00:01:15,030 --> 00:01:17,080 idea as well. 15 00:01:17,150 --> 00:01:17,870 No idea. 16 00:01:17,870 --> 00:01:25,390 We will throw in payment that 80 where the order I.D. we could use the order I.D. that was defined backup 17 00:01:25,400 --> 00:01:31,880 here but as best practice we really like to take information directly off the record that we just saved 18 00:01:32,030 --> 00:01:36,830 instead because who knows we might be making some adjustment to the order I.D. we might be changing 19 00:01:36,830 --> 00:01:39,180 in some fashion team with a stripe I.D.. 20 00:01:39,380 --> 00:01:43,670 Obviously we're not doing that in this case but it's usually just best practice to take information 21 00:01:43,730 --> 00:01:48,110 off the record we just saved because we don't know if there's something kind of massaging that information 22 00:01:48,290 --> 00:01:50,230 before it actually gets stored inside the database. 23 00:01:51,760 --> 00:01:57,810 So for the order I.D. or reference payment what order I.D. and then for the stripe by the same thing 24 00:01:57,810 --> 00:01:59,790 here payment dots stripe I.D. 25 00:02:04,840 --> 00:02:11,010 Now again we might choose to await this if we await this then we're going to make sure that we await 26 00:02:11,010 --> 00:02:14,430 to publish the event before we send a response back. 27 00:02:14,430 --> 00:02:18,930 Alternately we could remove the awaits and just say hey let's just send back a response as soon as possible 28 00:02:19,230 --> 00:02:23,120 and we're not going to worry about handling or waiting for the event to be published. 29 00:02:25,350 --> 00:02:30,280 So going to save it like this and now the very last thing that we might want to do is return some more 30 00:02:30,280 --> 00:02:32,140 meaningful data than just a success. 31 00:02:32,140 --> 00:02:33,360 True right here. 32 00:02:33,400 --> 00:02:39,250 So maybe instead we should return let's say maybe the entire payment object or maybe just the payment 33 00:02:39,280 --> 00:02:40,100 objects I.D.. 34 00:02:40,840 --> 00:02:45,400 Really in this case just about any return value is totally fine because we're not really going to make 35 00:02:45,400 --> 00:02:49,220 use of this information at any point in time inside of our ReACT application. 36 00:02:49,240 --> 00:02:53,110 So how about right now we'll just return the idea of the payment that was created 37 00:02:58,420 --> 00:02:59,010 if you want to. 38 00:02:59,010 --> 00:03:03,190 You could definitely write out a test around this and make sure that the idea that is being sent back 39 00:03:03,580 --> 00:03:06,520 is the same as the payment that was actually saved to the database. 40 00:03:06,530 --> 00:03:09,760 Totally up to you but I'm not gonna worry about it too much. 41 00:03:09,840 --> 00:03:11,010 All right well that's pretty much it. 42 00:03:11,010 --> 00:03:17,270 That is our payment service or at least the payment route handler let's take a pause right here as usual. 43 00:03:17,270 --> 00:03:18,290 Continue in just a moment.