Our payment service is just about complete.
Last thing you do is emit an event saying that.
Well we successfully charge in order.
One thing I want to point out is that we looked at this diagram a little bit ago and inside the payment
service this box right here was meant to reflect a collection of charge objects just you know when I
first put this diagram together I was going to call the payments collection charges but then as we started
to go through these videos I realized that calling this collection charges and also having stripe API
meant is something called charges was really confusing and that's why I eventually end up changing the
name of the collection itself over to payments.
That kind of reflected the name of the service itself pretty well as well.
So then mind we should probably change the name of this event down here to something like event created
so we're going to go back over to our common module we're going to define a new interface or a payment
created event or then going to make sure that after we create a new payment we just emit or published
this event that says Hey a payment was just created and then presumably either our order service or
perhaps the ticket service some other service is going to listen for this event and as soon as it sees
it it's going to say OK this order or ticket has been paid for time to release this ticket to whoever
just paid for it.
That's pretty much it.
We'll get started first by going back over to our common module and defining a new event of payment
created to back inside of our common module up on the S RC directory inside the events folder.
I'll make a new file of payment created event that yes
also open up my subjects out to yes file.
They'll make sure that we add in a new subject so that we can use that inside this new event.
It's going to add in a new subject of immigrated payment.
Colon read it then inside of our event file at the top let's import subjects from subjects and then
we will export a interface called Payment redid event.
As usual this thing is going to have a subject property that is subjects dot image created
and then a data property.
So whenever we create a payment and we tell the rest of the world that a payment is just created well
we're just gonna share all the information tied to the payment.
So share the idea that payment itself.
The idea of these stripe charge and the idea the order as well I can say that this thing is gonna have
an idea as a string and order I.D. as a string and a stripe I.D. as a string as well.
At present no other part of our application really needs a stripe I.D. whatsoever because we don't have
any other part of our app that's actually gonna reach out to the stripe API.
But once again kind of thinking towards the future here maybe we eventually will have some additional
service that verifies payments or handles returns or who knows what.
And so there might eventually be another service in the future that needs that stripe I.D. either way.
Doesn't really cost us a lot through that extra property inside of here so we'll just included.
So there is our event definition gonna close that file out.
Don't forget we do have to export that new event from the common modules index to yes file so inside
of index not to us at the board bottom we'll add in another expert from events payment redid event
after saving all through those files.
So index subjects and the new event file.
Let's go ahead and republish the common module and then update the version of it used in all of our
different services released for right now.
How about just payments.
So back at my terminal I'm going to change into my current module name on area and do an NPM run pub
looks like I'm on version 24.
By this point
so I'll just make sure that gets published and I'll very quickly go around to all my different services
and just update their versions really quickly to first start off with the payment service so inside
of payments NPM update.
All right I'm going to copy that update command because I can run it once or twice after this so I'll
then go back out and change into orders and run the same command
and finally I'll do it once again just for our tickets service.
We only need to update expiration right now because the expiration service doesn't have anything to
do with the idea of payments we'll go back out to tickets update and that will be the last one.
So I just updated payments orders and tickets.
All right now back inside of our payment service here's payments I'm going to find my events directory
inside of events.
I'll make a new folder of publishers and then inside of that I'll make a new file of events created
publisher dot T.S.
those videos a little bit long.
But our publishers are really easy and straightforward to put together.
So let's just write out the publisher really quickly.
At the very top I will import by subject's publisher base class and the payment created events for my
common module you'll notice I'm getting an error around payment created events.
As usual what I do is reload this window or restart my editor and typescript should realize that we
have that new type available.
Yep there we go.
All right.
Then export a new class of payments created publisher that's going to extend my publisher base class
that is a generic type so I will stick in the payment related event and then I will list out my subject
as subject Scott payment created and the value as subject start payment created.
And there we go.
There's our publisher.
Let's take a quick pause right here.
We come back next video we'll just make sure that right after we create our charge and our payment and
save the payment we'll then publish a new event to tell the rest of the world that a payment has been
created.