Hi everyone.
Welcome back.
In this section we will implement a real time use case using all the concepts we have learned so far.
The example application that we are going to build is a online checkout application.
Here the user submits the order details which will be received by the Checkout Service class here.
Because each block that you see here is a representation of a class.
So the checkout service is going to pass the order details to the payment service.
So from the payment service, the payment call will be made to the appropriate bank to acquire the payment.
And then the response will be sent back to the user stating the order is placed successfully.
If there is an available credit or debit or rewards based on what type of payment option is being sent
to the payment service.
So what we are going to implement is a payment service using all the concepts we have learned so far.
Okay, so with this information in place, let's go ahead and look at the project setup for the checkout
service and the different domains that are involved in this online checkout application.
So I'm back in IntelliJ.
Here in the IntelliJ we'll be working on the checkout service for this specific section.
So if you open the project if you expand to the main folder you will notice three different packages.
Number one is a domain which has all the domain classes that are involved in the checkout service application.
And then you'll notice a package named payment, which has a payment service.
If you go ahead and take a look at the implementation, this is very simple and static.
There is no code logic here because as part of this section, we are going to be implementing the payment
service using all the concepts we have learned so far.
So number three is if you go to the service package you have something called a checkout service.
So the checkout service is the one which is going to orchestrate the whole call of receiving the order
details.
So we have this checkout order function which receives the order details.
And then it makes a call to the payment.
Once a payment response is received the payment is success.
Then it is going to return the response as checkout success.
Otherwise the response is going to be checkout failure.
Let's quickly look at the domain over here.
So in this case we receive the order details.
So if you go and take a look at the order details this is of type record okay.
And it holds three properties.
Number one is the order ID.
Number two is a card.
Number three is a final amount.
I kept the order line items out of this particular domain, because I want to keep this example really
simple, because we don't need to worry about what the order line items are.
What we care about is what is the final amount, and give me the card information so that we can actually
go ahead and process the payment.
And if you go ahead and take a look at the card class, this is again another card class.
So we have not coded a record class that is referencing another record class yet.
So this is a good example of how to reference a record class from another record class.
This is actually pretty simple and straightforward.
This is very similar to how you reference another Java class from your Java class.
So in this case the card information has name, card number, verification code, expiry date and card
type.
So card type is interesting because this is going to drive.
What are the different types of payment implementation that we need to write.
So if you go to the card type we have credit debit and rewards.
So our payment service should support all these different types of implementation.
So these are the different domain classes that are going to be involved in our checkout service.
So with this information let's quickly look at the design of how it's going to look like.
Which means how the payment service design is going to be implemented.
If you go to the next slide we have this payment service design.
So the very first thing is we are going to have a payment gateway class.
This is going to be a sealed abstract class, and that sealed abstract class is going to be providing
the support for a debit card payment, rewards card payment and credit card payment.
Because these are the three different card types that our domain supports, right?
So if you go to the order details and if you go to the card and then the card type, we have three different
types of card our checkout service supports in the future, if any other type comes in, we will add
support for that one too.
Okay.
And then we have a payment factory class.
This is going to be acting as a factory which accepts a card type.
And then it's going to return you the appropriate payment instance class so that we can process the
payment.
So the payment service is going to be the entry point for the whole payment.
From there the payment service is going to interact with payment factory.
And then this is going to retrieve one of the instances of this payment implementation based on what
that card type is.
If you have issues trying to visualize this design, don't worry about it.
In the next lecture, we will go step by step in implementing the payment service using all the concepts
we have learned so far.
So please hang on.
We'll go ahead and implement this in the next lecture.
This marks the end of this lecture.
Catch you all in the next lecture.
Thanks for watching.