Well believe it or not we are on to just about the last step in our App Store our payment service is
emitting not a charge created event but a payment created event.
As we discussed we renamed that kind of on the fly.
We're now going to receive that instead of our order service inside the order service.
We're going to update the order status over to complete or paid for or whatever it was we call that
final status.
So let's get to it back inside of my orders.
Service I'll find my listeners directory then inside there I'll make a new file of payment created listener
got to yes as usual at the very top allowed in a couple of imports from our common module so we're going
to get subjects listener and our payment created events and we'll get all that from our common module
will then go ahead and export a new class of payment read listener that will extend listener base class
throw in payment created event well defined the subject as subjects dot payment created and the value
as payment created at the top I will also add in an import for our Q Group name from the Q Group Name
file and do our assignment so Q Group Name is Q Group Name then finally our on sync async on message
function this will have a type or an argument of data which is of type payment created event at data
and then the message object which is a type message and naturally let's add an import for message at
the top as well.
Okay now the on message function.
So what we really need to do inside of here well pretty much all we need to do is take a look at the
order instead of our order service.
We're going to make sure that we update the order status to paid or complete or again whatever that
status was at the top of the file.
I am going to import our order model
from up on directory up another directory models order and I'll also get our order status number from
our common module.
So order status like so then inside of on message we're gonna first take a look at all of our different
orders and we're going to try to find the appropriate order.
The one that we just paid for as reminder for this step we have an order I.D. property inside of this
data object.
We just put that data object together or the interface together.
So we've got order idea inside their tools they order is a wait order dots find by IP and path in data
order I.T. well then of course do a quick check just to make sure that we actually found the correct
order.
So if there is not in order.
Now let's just throw a new ear and say order not found otherwise we'll update the size of the order
and then save it.
We'll do an order set.
We want to set it status property.
And again we want to take a look at that order status in them.
Inside there I believe the order status was something like paid so we can set it to order status.
Dot complete.
That's what we called it.
Complete.
I mean after setting that property we will say the order and then naturally the last step we're gonna
make sure we act the message.
So message dot ach.
Like so so I going to say this.
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
of our s our city directory inside the order service we will import this payment create a listener and
make sure that we tell it to start listening on our apps startup inside the indexed s file I'm going
to go back up to the top and along with all of our other listeners inside of here I will get the immense
created listener
from events listeners payment created
and then with all the other listeners will create the instance down here and tell it to start listening
for you that's the new payment created listener base in the Nats rapper client and start listening.
Like so and that's pretty much it.
Okay so we got that last listener put together.
Now one thing on to mentioned here is that we are making a change to our order and we are saving it.
And remember every single time we make a save or make a change that's going to increment the version
number.
And as we discussed previously if we ever make a change in income at that version number without emitting
an event that means that any time we met a further event around this order we might have some missing
versions for all of our other dependent services so ideally in this scenario we would have an additional
event type inside of our app something to just do something like I don't know.
Order updated or something very similar to that.
That would definitely be ideal but in the context of our application once an order goes into the complete
status that's pretty much it.
Order is complete.
It's never going to be updated.
Again so although we really technically should emit or publish even here just saying that this thing
has been updated just because I don't expect any other service to ever tried to update in order after
this or to make any further changes.
I'm pretty much just going to leave it as it is.
This is really just in the context of this course to save a little bit of time.
So if you want to create a new event type of order updated and tell everyone else in the world or all
of our other services that the order has been updated absolutely feel free to do so.
But again we're not going to take the time because we've spent quite a bit of time already in this course
on this entire application okay.
So that's pretty much it.
Let's take a pause right here and as your guests we're gonna start to move back onto our ReACT application
in the next section.