1 00:00:00,880 --> 00:00:05,830 Well believe it or not we are on to just about the last step in our App Store our payment service is 2 00:00:05,830 --> 00:00:10,690 emitting not a charge created event but a payment created event. 3 00:00:10,720 --> 00:00:13,690 As we discussed we renamed that kind of on the fly. 4 00:00:13,720 --> 00:00:16,960 We're now going to receive that instead of our order service inside the order service. 5 00:00:16,960 --> 00:00:22,420 We're going to update the order status over to complete or paid for or whatever it was we call that 6 00:00:22,420 --> 00:00:23,580 final status. 7 00:00:23,710 --> 00:00:26,780 So let's get to it back inside of my orders. 8 00:00:26,800 --> 00:00:36,060 Service I'll find my listeners directory then inside there I'll make a new file of payment created listener 9 00:00:36,230 --> 00:00:42,820 got to yes as usual at the very top allowed in a couple of imports from our common module so we're going 10 00:00:42,820 --> 00:00:53,140 to get subjects listener and our payment created events and we'll get all that from our common module 11 00:00:55,290 --> 00:01:02,950 will then go ahead and export a new class of payment read listener that will extend listener base class 12 00:01:02,980 --> 00:01:13,140 throw in payment created event well defined the subject as subjects dot payment created and the value 13 00:01:13,140 --> 00:01:22,600 as payment created at the top I will also add in an import for our Q Group name from the Q Group Name 14 00:01:22,600 --> 00:01:35,450 file and do our assignment so Q Group Name is Q Group Name then finally our on sync async on message 15 00:01:35,510 --> 00:01:43,820 function this will have a type or an argument of data which is of type payment created event at data 16 00:01:46,610 --> 00:01:51,960 and then the message object which is a type message and naturally let's add an import for message at 17 00:01:51,960 --> 00:01:52,840 the top as well. 18 00:01:56,320 --> 00:01:59,200 Okay now the on message function. 19 00:01:59,230 --> 00:02:03,910 So what we really need to do inside of here well pretty much all we need to do is take a look at the 20 00:02:03,970 --> 00:02:05,920 order instead of our order service. 21 00:02:06,130 --> 00:02:11,020 We're going to make sure that we update the order status to paid or complete or again whatever that 22 00:02:11,020 --> 00:02:15,080 status was at the top of the file. 23 00:02:15,080 --> 00:02:17,060 I am going to import our order model 24 00:02:20,220 --> 00:02:27,130 from up on directory up another directory models order and I'll also get our order status number from 25 00:02:27,160 --> 00:02:28,750 our common module. 26 00:02:28,750 --> 00:02:35,930 So order status like so then inside of on message we're gonna first take a look at all of our different 27 00:02:35,930 --> 00:02:38,150 orders and we're going to try to find the appropriate order. 28 00:02:38,150 --> 00:02:45,280 The one that we just paid for as reminder for this step we have an order I.D. property inside of this 29 00:02:45,280 --> 00:02:46,110 data object. 30 00:02:46,120 --> 00:02:50,220 We just put that data object together or the interface together. 31 00:02:50,250 --> 00:03:01,590 So we've got order idea inside their tools they order is a wait order dots find by IP and path in data 32 00:03:02,040 --> 00:03:07,190 order I.T. well then of course do a quick check just to make sure that we actually found the correct 33 00:03:07,190 --> 00:03:07,740 order. 34 00:03:07,760 --> 00:03:10,100 So if there is not in order. 35 00:03:10,200 --> 00:03:19,470 Now let's just throw a new ear and say order not found otherwise we'll update the size of the order 36 00:03:19,470 --> 00:03:20,860 and then save it. 37 00:03:20,960 --> 00:03:27,580 We'll do an order set. 38 00:03:27,640 --> 00:03:29,870 We want to set it status property. 39 00:03:30,130 --> 00:03:33,160 And again we want to take a look at that order status in them. 40 00:03:33,220 --> 00:03:37,120 Inside there I believe the order status was something like paid so we can set it to order status. 41 00:03:37,150 --> 00:03:39,540 Dot complete. 42 00:03:39,560 --> 00:03:40,310 That's what we called it. 43 00:03:40,370 --> 00:03:42,120 Complete. 44 00:03:42,360 --> 00:03:48,390 I mean after setting that property we will say the order and then naturally the last step we're gonna 45 00:03:48,390 --> 00:03:49,780 make sure we act the message. 46 00:03:49,800 --> 00:03:51,170 So message dot ach. 47 00:03:51,270 --> 00:03:55,000 Like so so I going to say this. 48 00:03:55,260 --> 00:03:59,710 And then the last very quick thing we're going to do is go back to our index dot t s file at the root 49 00:04:00,040 --> 00:04:05,560 of our s our city directory inside the order service we will import this payment create a listener and 50 00:04:05,560 --> 00:04:12,860 make sure that we tell it to start listening on our apps startup inside the indexed s file I'm going 51 00:04:12,860 --> 00:04:20,800 to go back up to the top and along with all of our other listeners inside of here I will get the immense 52 00:04:21,790 --> 00:04:23,500 created listener 53 00:04:26,570 --> 00:04:29,750 from events listeners payment created 54 00:04:33,670 --> 00:04:37,690 and then with all the other listeners will create the instance down here and tell it to start listening 55 00:04:37,750 --> 00:04:46,760 for you that's the new payment created listener base in the Nats rapper client and start listening. 56 00:04:46,760 --> 00:04:49,510 Like so and that's pretty much it. 57 00:04:52,220 --> 00:04:54,200 Okay so we got that last listener put together. 58 00:04:54,210 --> 00:04:59,190 Now one thing on to mentioned here is that we are making a change to our order and we are saving it. 59 00:04:59,190 --> 00:05:03,420 And remember every single time we make a save or make a change that's going to increment the version 60 00:05:03,420 --> 00:05:04,140 number. 61 00:05:04,140 --> 00:05:08,880 And as we discussed previously if we ever make a change in income at that version number without emitting 62 00:05:08,880 --> 00:05:14,490 an event that means that any time we met a further event around this order we might have some missing 63 00:05:14,490 --> 00:05:21,460 versions for all of our other dependent services so ideally in this scenario we would have an additional 64 00:05:21,460 --> 00:05:25,570 event type inside of our app something to just do something like I don't know. 65 00:05:25,580 --> 00:05:28,460 Order updated or something very similar to that. 66 00:05:28,630 --> 00:05:33,760 That would definitely be ideal but in the context of our application once an order goes into the complete 67 00:05:33,760 --> 00:05:35,340 status that's pretty much it. 68 00:05:35,350 --> 00:05:36,550 Order is complete. 69 00:05:36,580 --> 00:05:37,840 It's never going to be updated. 70 00:05:37,870 --> 00:05:43,190 Again so although we really technically should emit or publish even here just saying that this thing 71 00:05:43,190 --> 00:05:48,110 has been updated just because I don't expect any other service to ever tried to update in order after 72 00:05:48,110 --> 00:05:49,970 this or to make any further changes. 73 00:05:49,970 --> 00:05:52,220 I'm pretty much just going to leave it as it is. 74 00:05:52,310 --> 00:05:55,410 This is really just in the context of this course to save a little bit of time. 75 00:05:55,460 --> 00:06:00,470 So if you want to create a new event type of order updated and tell everyone else in the world or all 76 00:06:00,580 --> 00:06:04,520 of our other services that the order has been updated absolutely feel free to do so. 77 00:06:04,550 --> 00:06:08,690 But again we're not going to take the time because we've spent quite a bit of time already in this course 78 00:06:08,720 --> 00:06:11,230 on this entire application okay. 79 00:06:11,260 --> 00:06:12,280 So that's pretty much it. 80 00:06:12,280 --> 00:06:16,570 Let's take a pause right here and as your guests we're gonna start to move back onto our ReACT application 81 00:06:16,630 --> 00:06:17,410 in the next section.