1 00:00:00,880 --> 00:00:02,880 Our payment service is just about complete. 2 00:00:02,890 --> 00:00:04,940 Last thing you do is emit an event saying that. 3 00:00:04,960 --> 00:00:07,370 Well we successfully charge in order. 4 00:00:07,440 --> 00:00:11,050 One thing I want to point out is that we looked at this diagram a little bit ago and inside the payment 5 00:00:11,050 --> 00:00:17,470 service this box right here was meant to reflect a collection of charge objects just you know when I 6 00:00:17,470 --> 00:00:21,970 first put this diagram together I was going to call the payments collection charges but then as we started 7 00:00:21,970 --> 00:00:27,460 to go through these videos I realized that calling this collection charges and also having stripe API 8 00:00:27,500 --> 00:00:32,050 meant is something called charges was really confusing and that's why I eventually end up changing the 9 00:00:32,050 --> 00:00:34,300 name of the collection itself over to payments. 10 00:00:34,380 --> 00:00:37,700 That kind of reflected the name of the service itself pretty well as well. 11 00:00:37,810 --> 00:00:43,290 So then mind we should probably change the name of this event down here to something like event created 12 00:00:47,590 --> 00:00:52,760 so we're going to go back over to our common module we're going to define a new interface or a payment 13 00:00:52,850 --> 00:00:58,430 created event or then going to make sure that after we create a new payment we just emit or published 14 00:00:58,430 --> 00:01:03,710 this event that says Hey a payment was just created and then presumably either our order service or 15 00:01:03,710 --> 00:01:08,300 perhaps the ticket service some other service is going to listen for this event and as soon as it sees 16 00:01:08,300 --> 00:01:14,420 it it's going to say OK this order or ticket has been paid for time to release this ticket to whoever 17 00:01:14,420 --> 00:01:15,020 just paid for it. 18 00:01:16,440 --> 00:01:17,100 That's pretty much it. 19 00:01:18,090 --> 00:01:23,010 We'll get started first by going back over to our common module and defining a new event of payment 20 00:01:23,070 --> 00:01:30,520 created to back inside of our common module up on the S RC directory inside the events folder. 21 00:01:30,530 --> 00:01:35,030 I'll make a new file of payment created event that yes 22 00:01:40,110 --> 00:01:42,820 also open up my subjects out to yes file. 23 00:01:43,120 --> 00:01:47,120 They'll make sure that we add in a new subject so that we can use that inside this new event. 24 00:01:47,250 --> 00:01:52,620 It's going to add in a new subject of immigrated payment. 25 00:01:52,630 --> 00:02:03,010 Colon read it then inside of our event file at the top let's import subjects from subjects and then 26 00:02:03,040 --> 00:02:07,510 we will export a interface called Payment redid event. 27 00:02:08,910 --> 00:02:15,540 As usual this thing is going to have a subject property that is subjects dot image created 28 00:02:19,400 --> 00:02:21,070 and then a data property. 29 00:02:21,230 --> 00:02:25,070 So whenever we create a payment and we tell the rest of the world that a payment is just created well 30 00:02:25,070 --> 00:02:27,730 we're just gonna share all the information tied to the payment. 31 00:02:27,800 --> 00:02:29,800 So share the idea that payment itself. 32 00:02:30,110 --> 00:02:35,930 The idea of these stripe charge and the idea the order as well I can say that this thing is gonna have 33 00:02:35,930 --> 00:02:42,640 an idea as a string and order I.D. as a string and a stripe I.D. as a string as well. 34 00:02:43,600 --> 00:02:48,250 At present no other part of our application really needs a stripe I.D. whatsoever because we don't have 35 00:02:48,280 --> 00:02:51,910 any other part of our app that's actually gonna reach out to the stripe API. 36 00:02:51,910 --> 00:02:56,110 But once again kind of thinking towards the future here maybe we eventually will have some additional 37 00:02:56,110 --> 00:03:00,610 service that verifies payments or handles returns or who knows what. 38 00:03:00,610 --> 00:03:05,290 And so there might eventually be another service in the future that needs that stripe I.D. either way. 39 00:03:05,320 --> 00:03:10,890 Doesn't really cost us a lot through that extra property inside of here so we'll just included. 40 00:03:10,910 --> 00:03:14,750 So there is our event definition gonna close that file out. 41 00:03:14,780 --> 00:03:21,170 Don't forget we do have to export that new event from the common modules index to yes file so inside 42 00:03:21,170 --> 00:03:28,240 of index not to us at the board bottom we'll add in another expert from events payment redid event 43 00:03:31,150 --> 00:03:32,960 after saving all through those files. 44 00:03:33,020 --> 00:03:35,800 So index subjects and the new event file. 45 00:03:35,800 --> 00:03:40,150 Let's go ahead and republish the common module and then update the version of it used in all of our 46 00:03:40,150 --> 00:03:41,830 different services released for right now. 47 00:03:41,830 --> 00:03:45,370 How about just payments. 48 00:03:45,420 --> 00:03:57,130 So back at my terminal I'm going to change into my current module name on area and do an NPM run pub 49 00:04:00,030 --> 00:04:01,410 looks like I'm on version 24. 50 00:04:01,410 --> 00:04:01,950 By this point 51 00:04:05,800 --> 00:04:09,900 so I'll just make sure that gets published and I'll very quickly go around to all my different services 52 00:04:09,920 --> 00:04:16,690 and just update their versions really quickly to first start off with the payment service so inside 53 00:04:16,690 --> 00:04:22,760 of payments NPM update. 54 00:04:23,040 --> 00:04:28,580 All right I'm going to copy that update command because I can run it once or twice after this so I'll 55 00:04:28,590 --> 00:04:32,610 then go back out and change into orders and run the same command 56 00:04:35,400 --> 00:04:38,560 and finally I'll do it once again just for our tickets service. 57 00:04:38,580 --> 00:04:41,880 We only need to update expiration right now because the expiration service doesn't have anything to 58 00:04:41,880 --> 00:04:49,690 do with the idea of payments we'll go back out to tickets update and that will be the last one. 59 00:04:49,720 --> 00:04:54,510 So I just updated payments orders and tickets. 60 00:04:54,560 --> 00:05:05,950 All right now back inside of our payment service here's payments I'm going to find my events directory 61 00:05:06,460 --> 00:05:07,200 inside of events. 62 00:05:07,210 --> 00:05:15,650 I'll make a new folder of publishers and then inside of that I'll make a new file of events created 63 00:05:16,070 --> 00:05:17,390 publisher dot T.S. 64 00:05:20,510 --> 00:05:21,720 those videos a little bit long. 65 00:05:21,750 --> 00:05:24,290 But our publishers are really easy and straightforward to put together. 66 00:05:24,300 --> 00:05:27,420 So let's just write out the publisher really quickly. 67 00:05:27,420 --> 00:05:37,020 At the very top I will import by subject's publisher base class and the payment created events for my 68 00:05:37,020 --> 00:05:41,910 common module you'll notice I'm getting an error around payment created events. 69 00:05:41,920 --> 00:05:48,040 As usual what I do is reload this window or restart my editor and typescript should realize that we 70 00:05:48,040 --> 00:05:49,150 have that new type available. 71 00:05:49,580 --> 00:05:52,140 Yep there we go. 72 00:05:52,170 --> 00:05:52,420 All right. 73 00:05:52,470 --> 00:06:01,170 Then export a new class of payments created publisher that's going to extend my publisher base class 74 00:06:01,260 --> 00:06:08,820 that is a generic type so I will stick in the payment related event and then I will list out my subject 75 00:06:08,910 --> 00:06:15,150 as subject Scott payment created and the value as subject start payment created. 76 00:06:15,150 --> 00:06:15,730 And there we go. 77 00:06:15,750 --> 00:06:18,710 There's our publisher. 78 00:06:18,760 --> 00:06:20,150 Let's take a quick pause right here. 79 00:06:20,160 --> 00:06:26,000 We come back next video we'll just make sure that right after we create our charge and our payment and 80 00:06:26,000 --> 00:06:30,020 save the payment we'll then publish a new event to tell the rest of the world that a payment has been 81 00:06:30,020 --> 00:06:30,440 created.