WEBVTT

00:00.110 --> 00:00.710
Hi everyone.

00:00.710 --> 00:01.280
Welcome back.

00:01.280 --> 00:06.530
In this section we will implement a real time use case using all the concepts we have learned so far.

00:06.560 --> 00:10.970
The example application that we are going to build is a online checkout application.

00:10.970 --> 00:15.800
Here the user submits the order details which will be received by the Checkout Service class here.

00:15.800 --> 00:20.030
Because each block that you see here is a representation of a class.

00:20.030 --> 00:24.260
So the checkout service is going to pass the order details to the payment service.

00:24.260 --> 00:29.840
So from the payment service, the payment call will be made to the appropriate bank to acquire the payment.

00:29.840 --> 00:34.940
And then the response will be sent back to the user stating the order is placed successfully.

00:34.970 --> 00:40.790
If there is an available credit or debit or rewards based on what type of payment option is being sent

00:40.790 --> 00:41.780
to the payment service.

00:41.780 --> 00:47.480
So what we are going to implement is a payment service using all the concepts we have learned so far.

00:47.510 --> 00:52.070
Okay, so with this information in place, let's go ahead and look at the project setup for the checkout

00:52.070 --> 00:56.750
service and the different domains that are involved in this online checkout application.

00:56.750 --> 00:57.740
So I'm back in IntelliJ.

00:57.770 --> 01:02.690
Here in the IntelliJ we'll be working on the checkout service for this specific section.

01:02.690 --> 01:08.120
So if you open the project if you expand to the main folder you will notice three different packages.

01:08.120 --> 01:13.440
Number one is a domain which has all the domain classes that are involved in the checkout service application.

01:13.440 --> 01:17.340
And then you'll notice a package named payment, which has a payment service.

01:17.370 --> 01:20.910
If you go ahead and take a look at the implementation, this is very simple and static.

01:20.940 --> 01:26.160
There is no code logic here because as part of this section, we are going to be implementing the payment

01:26.160 --> 01:29.220
service using all the concepts we have learned so far.

01:29.220 --> 01:33.810
So number three is if you go to the service package you have something called a checkout service.

01:33.810 --> 01:39.060
So the checkout service is the one which is going to orchestrate the whole call of receiving the order

01:39.060 --> 01:39.540
details.

01:39.540 --> 01:43.230
So we have this checkout order function which receives the order details.

01:43.230 --> 01:45.300
And then it makes a call to the payment.

01:45.300 --> 01:48.450
Once a payment response is received the payment is success.

01:48.450 --> 01:52.080
Then it is going to return the response as checkout success.

01:52.110 --> 01:55.260
Otherwise the response is going to be checkout failure.

01:55.290 --> 01:57.300
Let's quickly look at the domain over here.

01:57.300 --> 02:00.450
So in this case we receive the order details.

02:00.450 --> 02:04.620
So if you go and take a look at the order details this is of type record okay.

02:04.650 --> 02:06.180
And it holds three properties.

02:06.210 --> 02:07.620
Number one is the order ID.

02:07.650 --> 02:08.910
Number two is a card.

02:08.940 --> 02:11.070
Number three is a final amount.

02:11.070 --> 02:16.230
I kept the order line items out of this particular domain, because I want to keep this example really

02:16.230 --> 02:20.550
simple, because we don't need to worry about what the order line items are.

02:20.580 --> 02:25.300
What we care about is what is the final amount, and give me the card information so that we can actually

02:25.300 --> 02:27.220
go ahead and process the payment.

02:27.220 --> 02:31.360
And if you go ahead and take a look at the card class, this is again another card class.

02:31.360 --> 02:36.040
So we have not coded a record class that is referencing another record class yet.

02:36.040 --> 02:41.800
So this is a good example of how to reference a record class from another record class.

02:41.800 --> 02:44.110
This is actually pretty simple and straightforward.

02:44.110 --> 02:48.520
This is very similar to how you reference another Java class from your Java class.

02:48.520 --> 02:55.150
So in this case the card information has name, card number, verification code, expiry date and card

02:55.180 --> 02:55.570
type.

02:55.570 --> 02:58.570
So card type is interesting because this is going to drive.

02:58.570 --> 03:01.900
What are the different types of payment implementation that we need to write.

03:01.900 --> 03:05.920
So if you go to the card type we have credit debit and rewards.

03:05.920 --> 03:11.200
So our payment service should support all these different types of implementation.

03:11.200 --> 03:15.910
So these are the different domain classes that are going to be involved in our checkout service.

03:15.910 --> 03:20.170
So with this information let's quickly look at the design of how it's going to look like.

03:20.170 --> 03:23.980
Which means how the payment service design is going to be implemented.

03:23.980 --> 03:26.860
If you go to the next slide we have this payment service design.

03:26.860 --> 03:30.130
So the very first thing is we are going to have a payment gateway class.

03:30.160 --> 03:35.310
This is going to be a sealed abstract class, and that sealed abstract class is going to be providing

03:35.310 --> 03:40.080
the support for a debit card payment, rewards card payment and credit card payment.

03:40.080 --> 03:44.100
Because these are the three different card types that our domain supports, right?

03:44.130 --> 03:50.100
So if you go to the order details and if you go to the card and then the card type, we have three different

03:50.100 --> 03:56.010
types of card our checkout service supports in the future, if any other type comes in, we will add

03:56.010 --> 03:57.270
support for that one too.

03:57.300 --> 03:57.660
Okay.

03:57.690 --> 03:59.610
And then we have a payment factory class.

03:59.640 --> 04:03.450
This is going to be acting as a factory which accepts a card type.

04:03.450 --> 04:08.310
And then it's going to return you the appropriate payment instance class so that we can process the

04:08.310 --> 04:08.790
payment.

04:08.790 --> 04:12.540
So the payment service is going to be the entry point for the whole payment.

04:12.540 --> 04:16.200
From there the payment service is going to interact with payment factory.

04:16.200 --> 04:22.080
And then this is going to retrieve one of the instances of this payment implementation based on what

04:22.080 --> 04:23.160
that card type is.

04:23.190 --> 04:26.580
If you have issues trying to visualize this design, don't worry about it.

04:26.580 --> 04:32.490
In the next lecture, we will go step by step in implementing the payment service using all the concepts

04:32.490 --> 04:33.780
we have learned so far.

04:33.780 --> 04:34.800
So please hang on.

04:34.800 --> 04:37.260
We'll go ahead and implement this in the next lecture.

04:37.290 --> 04:38.670
This marks the end of this lecture.

04:38.700 --> 04:40.350
Catch you all in the next lecture.

04:40.350 --> 04:41.430
Thanks for watching.
