Full Project: How Banks Detect Fraud | Digital Banking System | Spring Boot + kafka + Redis + SAGA — Transcript
Full transcript
- 0:00You tap pay on your phone and in less
- 0:03than two seconds money is transferred.
- 0:06Okay, receipt received and balance
- 0:10updated.
- 0:11But think about this at that exact
- 0:14moment. Okay, at that exact moment
- 0:17millions of transactions are happening
- 0:19across the country across the globe.
- 0:23Yeah, true. So every bank transfer,
- 0:26every digital payment, every ATM
- 0:29withdrawal and now comes the scary part
- 0:33that is fraud. See we are talking about
- 0:36the banks.
- 0:38Okay, banks process millions of
- 0:41transactions on daily basis.
- 0:44Okay, so fraudsters are also running
- 0:46thousands of transactions simultaneously
- 0:49trying to drain accounts before anyone
- 0:51notices.
- 0:54And here is even a scarier question.
- 0:57Okay, listen to me carefully. Important
- 0:59one.
- 1:00Suppose
- 1:02your bank detects the fraud
- 1:06midway through a transaction. Midway
- 1:09through a transfer.
- 1:12Then what? What it means? Let me explain
- 1:14you. Kindly pay attention here. Okay.
- 1:16Important one. Anyway, we're going to
- 1:17build it in coming few minutes. Yeah. So
- 1:21let's say let's say this is you okay
- 1:24this is my user and this is your bank
- 1:27account okay so currently you have how
- 1:30much balance in your bank account $4,250
- 1:34okay now you have initiated a
- 1:39transaction okay transferring amount how
- 1:42much $2500
- 1:45to this receiving account
- 1:48okay this is the receiver
- 1:51Now
- 1:52I said that suppose your bank detects
- 1:58the fraud midway
- 2:01through a transfer.
- 2:04Midway through a transaction.
- 2:06Okay. So let's say your bank has
- 2:09installed some channel. Okay. Or some
- 2:12service fraud detection service. Okay.
- 2:16or uh suspicious activity detection
- 2:19service or some channel. Okay. So what
- 2:23your bank detects that the transaction
- 2:26this transaction has not been initiated
- 2:29by you
- 2:32instead it is initiated by some fraud.
- 2:37You know something suspicious activity
- 2:38found by a bank. So immediately transfer
- 2:43is stopped.
- 2:46Okay. And uh definitely you'll receive a
- 2:50you know bank alerts immediately. Okay.
- 2:52Suspicious activity detected. Transfer
- 2:55has been blocked. Now the real question
- 2:58is I'm going to ask you. Money has
- 3:01already left your account.
- 3:05Where does it go?
- 3:07Does it disappear?
- 3:10Okay. And you'll definitely ask to the
- 3:12bank like where did my money go?
- 3:16Yes or no? So before we building our own
- 3:19digital banking system, we need to make
- 3:21sure that all the functionality should
- 3:24be implemented properly.
- 3:26Okay. And the most important thing is
- 3:30fraud detection service. See there is no
- 3:34banking system without fraud detection.
- 3:36Yeah. Not possible.
- 3:38Okay. We need to secure our users
- 3:42balance money.
- 3:45Okay. So today we are building complete
- 3:48digital
- 3:50banking
- 3:53system from
- 3:55scratch.
- 3:57Account management realtime money
- 4:00transfer. Okay. Fraud detection in real
- 4:03time will implement. Okay. Saga will
- 4:06implement. ensures that your money is
- 4:08never lost. Okay. And with all other
- 4:12modern technologies,
- 4:14yeah, you know, most interesting and
- 4:16exciting project after Uber and Netflix
- 4:19that is already uploaded on my channel.
- 4:21Okay. Yeah. So, without wasting much
- 4:24time, let's proceed forward, okay, with
- 4:26our next section that is understanding
- 4:29the problem. Okay. Then HLD
- 4:32architecture. Please do not miss it
- 4:33because I'm going to sync the real money
- 4:37flow with the HLD architecture. Okay.
- 4:40And then how do we detect the fraud in
- 4:43real time? Okay. And then our project
- 4:45structure. Okay. And finally we'll move
- 4:49to our coding part. Okay. Yeah. So let's
- 4:53start. Let's go. Okay. So before we
- 4:55start building our bank application,
- 4:58first let's understand the actual
- 5:00problem. Okay. Because if you don't
- 5:02understand the problem, the solution
- 5:03won't make sense. Fine. Okay. Let's go.
- 5:07And yeah, important one, important
- 5:08section. Kindly do not miss and pay
- 5:10attention. Okay. So, I guess you all
- 5:14have heard about three terms in the
- 5:17database. What are they? So
- 5:22begin
- 5:26commit and
- 5:30roll back. Yeah, all of you. Yeah, heard
- 5:33about this three terms beginning,
- 5:35commit, roll back in the database
- 5:37system.
- 5:38Okay, now next thing is look at here. So
- 5:43let's say this is my user and this is my
- 5:47user's friend.
- 5:49Okay, I'll refer it as a sender and this
- 5:53is my
- 5:54receiver. Okay, so my user transferring
- 5:58payment to his friend.
- 6:01Okay,
- 6:03so this transfer includes
- 6:07multiple steps to complete.
- 6:11Okay, as we have seen you know uh a few
- 6:15minutes before that what happens once
- 6:19user clicked on the send money button.
- 6:23Okay. So you know the request goes to
- 6:27some uh let's say account service. Okay.
- 6:31Account service job is to validate the
- 6:33balance. Okay. and deduct.
- 6:37Yeah. Then uh request goes to my
- 6:39transaction service to proceed forward.
- 6:43Okay. Then fraud detection service.
- 6:46Okay. And then uh payment service,
- 6:48notification service, whatever all the
- 6:51services.
- 6:53Yes. Okay.
- 6:55Now you all might be thinking okay fine
- 6:58this is okay good. What is the problem
- 7:00in that? Each service has their own
- 7:05database.
- 7:06Account service
- 7:08account DB. Transaction service
- 7:13transaction
- 7:15DB.
- 7:18Yeah. Okay. Now few minutes before we
- 7:22have discussed that if suppose something
- 7:24got failed in midway
- 7:28then who going to inform other service
- 7:31to undo that step
- 7:34I mean to say that let's say in case of
- 7:37traditional single database system
- 7:42okay so what happens is this is what my
- 7:46request comes okay this is my server
- 7:50to my database single database system.
- 7:54Okay. So begin.
- 7:58Okay. Then uh validates deducts credits
- 8:04commit.
- 8:06Okay. And if something fails
- 8:10then roll back entire process.
- 8:16Roll back entire process.
- 8:19Okay. Nothing code required, nothing.
- 8:21Automatically our database has this
- 8:24property begin commit roll back only in
- 8:27case of traditional single database
- 8:31system.
- 8:33Yeah. Because see our database knows. So
- 8:37uh what he'll do is he roll back undo.
- 8:41Okay. But in case of separate separate
- 8:44database in case of microservices
- 8:47architecture
- 8:48the transfer includes multiple steps to
- 8:52complete we'll see once we'll code okay
- 8:55and we'll go with the flow that first we
- 8:57coded our account service okay here then
- 9:00the control goes to the transaction
- 9:01service we'll code this it consumes that
- 9:04it consumes that publish okay around
- 9:08four to five service for one transaction
- 9:12and all have separate databases. So
- 9:15suppose um you know my user initiated a
- 9:20transaction okay done then everything is
- 9:22done on the account service DB side and
- 9:25something got failed uh in our
- 9:27transaction DB
- 9:30then who going to inform my account DB
- 9:33to undo this
- 9:35because
- 9:37here from here account um you know from
- 9:41uh our account service the balance got
- 9:44deducted. Ed the money got deducted from
- 9:46my sender account. Yes or no? But
- 9:49something got failed in the step number
- 9:52two. Step number two. Okay. This is step
- 9:55number one. Step number two.
- 9:59Yes or no. So who will going to inform
- 10:02my account service that you need to undo
- 10:05the process?
- 10:07Because account service is completed
- 10:10successfully. committed
- 10:13whatever fails in another service
- 10:16potentially another server. Okay. Uh
- 10:20other database something got failed.
- 10:24Okay. Then who going to inform my you
- 10:27know that service number one in which
- 10:30already everything got completed
- 10:32committed?
- 10:35Yes. money is in the middle or I can say
- 10:40the money just disappeared.
- 10:43So we need a system.
- 10:47Okay. Or I can say we need to build
- 10:51a system which has undo step in each and
- 10:55every process
- 10:57and that is what done using our saga.
- 11:01Okay, I'll explain it. Okay, I have kept
- 11:03a separate section on this. Okay, and
- 11:07using a great real world example with
- 11:10the cash on delivery. I'll explain it to
- 11:12you. Fine. Okay. So, this is what our
- 11:15first problem. Fine. Okay. Yeah. It's
- 11:18not the case just like our uh this
- 11:21traditional single database system, you
- 11:24know, we have such consistency problem
- 11:27in the distributed system.
- 11:30Okay. Yeah. Fine. Let's move to our next
- 11:34problem. Problem number two. Problem
- 11:37number two is you know fraud.
- 11:43Okay. So imagine imagine a fraudster
- 11:50get access to
- 11:54someone's account.
- 11:58What happened? Okay. So generally
- 12:01fraudsters don't
- 12:05withdraw manually.
- 12:08What they do is they runs uh a script
- 12:14which
- 12:16fires you know 5 10 15 or maybe 100 plus
- 12:22transaction in
- 12:24few minutes or seconds.
- 12:28Okay. So money just disappear before
- 12:30anyone notices. Gone.
- 12:33So we need to build some system. Okay.
- 12:38We'll build it. Okay. There is a
- 12:40separate service fraud detection
- 12:42service. We'll code it.
- 12:45Okay. And that too
- 12:48in milliseconds
- 12:50before money credit to my receiver
- 12:53account.
- 12:56Okay. Now second case maybe uh it is not
- 13:01a fraud it is not a fraudster maybe a
- 13:03genuine user okay so we also need to add
- 13:08the functionality to verify the user I
- 13:13guess we all have experienced that okay
- 13:15so suppose one day we have purchased you
- 13:18know iPhone or Mac and uh suppose we
- 13:22have initiated a transaction of you know
- 13:2450,000
- 13:26Okay. 80,000.
- 13:29So that transaction that money is not
- 13:33credited immediately to the merchant
- 13:36account. No, first we'll get the call
- 13:40from the bank
- 13:43that this is you know uh unusual higher
- 13:46amount you have initiated. So is it you
- 13:49only or some someone other you don't
- 13:51know about it. If you confirm that yeah
- 13:54it is me then the money got credited
- 13:58else refund back.
- 14:01So this scenario also we need to build
- 14:05and and we going to build it.
- 14:08Okay. Verify transaction then uh also
- 14:12generate OTP. Okay. Verify OTP. What
- 14:15happens if not if expired? everything we
- 14:19are going to build in this uh our
- 14:22digital banking system application.
- 14:26Okay fine. So yeah this is you know kind
- 14:28of you know most serious problem
- 14:30definitely fraud always on the upper
- 14:33hand. We need to make sure that our
- 14:35users balance should be secure. Okay.
- 14:39Locker fine. Okay. So these are our
- 14:42problems. Okay. And definitely we'll
- 14:45code it in coming few minutes. And yeah,
- 14:48uh it takes a huge coding effort. Okay.
- 14:50So we need to code each and every
- 14:52services
- 14:54and wrap everything perfectly. Also we
- 14:58need to test the entire project
- 15:00thoroughly. Okay. Yeah. So I told you
- 15:04most exciting and important project.
- 15:06Okay. After Uber and Netflix uh we have
- 15:10uploaded on our channel. Okay. So now
- 15:12let's move to our next section that is
- 15:15HLD architecture. Okay. Highle design
- 15:17architecture important one. So let's uh
- 15:21start that. Okay. Let's go. Okay. So now
- 15:24let's see our highle design
- 15:26architecture. Okay. Yeah. Kindly all pay
- 15:30attention on my screen. Important one.
- 15:33Okay. So at first let me you know draw
- 15:38the entire architecture.
- 15:40Okay. Here comes my decider service.
- 15:44Okay. Then next one. Connecting
- 15:48everything.
- 15:51Okay. And then next.
- 15:55Okay. Fine.
- 15:59And finally.
- 16:03Yeah. Okay. So at first my
- 16:09API gateway. Okay. Then here comes my
- 16:13account service or I'll refer it as a
- 16:16bank. Okay. Then comes my transaction
- 16:20service. Our most important service.
- 16:23Okay. Saga orchestrator.
- 16:26Okay. And then comes my payment
- 16:31service. Okay. Connecting everything. My
- 16:36Apache
- 16:38Kafka. Okay. Then comes my fraud
- 16:42detection
- 16:44service. Okay. And then
- 16:48notification
- 16:51service. And again my account service.
- 16:55Why? Credit receiver.
- 17:00Okay. Credit receiver. Fine. Now let me
- 17:04just, you know.
- 17:08Okay. Okay,
- 17:11fine.
- 17:13And connecting everything.
- 17:19Okay.
- 17:27Fine.
- 17:28Yeah. So now let me explain you each and
- 17:32every component one by one. Okay. So at
- 17:34first comes our API gateway. We all know
- 17:37that it is our single point entry. Okay,
- 17:41all request comes through here. Also,
- 17:43we'll add the configuration for rate
- 17:47limiter. Okay, we'll set it up. Why? See
- 17:51we are building bank application and we
- 17:54need to protect our user from attackers
- 17:59to request you know 5,000
- 18:046,000 7,000 or you know some thousands
- 18:06of request. Okay. So what we'll do is
- 18:10you know we'll uh add the configuration
- 18:14replenish rate as 10 and burst capacity
- 18:1920. Okay. And we'll change it
- 18:21accordingly the values just like uh
- 18:24we'll reduce the values for our payment
- 18:26service. Okay. Fine. So this is what our
- 18:29API gateway. See don't worry if you'll
- 18:31not get anything what I have just
- 18:32explained it to you. Okay. Replenish
- 18:34rate burst capacity rate limiter. No
- 18:37worries. At the time of coding our API
- 18:40gateway I'm going to explain you each
- 18:42and every terminologies.
- 18:45Why that? Why not that? Okay. So don't
- 18:48worry about that.
- 18:50Fine. Now let's come to our next
- 18:52component that is our account service.
- 18:55Okay. So treat it as a bank. You know it
- 19:01holds user bank data and responsible
- 19:06for all the money movements.
- 19:09Okay. So the first thing is you know
- 19:11account creation. Okay. Get balance.
- 19:14Okay. Get account and money movement.
- 19:17Okay. So deduct
- 19:20deduct money okay method and then credit
- 19:24to the receiver okay or refund refund
- 19:29step number three okay refund back to my
- 19:32sender so all type of money moments okay
- 19:36fine now let's come to our next service
- 19:41that is heart of any banking system
- 19:46backbone of any banking system okay or
- 19:49I'll call it as a decider why because uh
- 19:53this is our saga orchestrator and it
- 19:57plays a deciding role what to do first
- 20:01request comes to my transaction service
- 20:03and then need to validate okay uh
- 20:07proceed with the fraud check to verify
- 20:09to generate
- 20:11so everything is done by our transaction
- 20:15service okay the backbone, the heart.
- 20:19Fine. Yeah. Next comes our payment
- 20:22service. So, payment service is
- 20:25responsible to integrate with payment
- 20:29gateways. Okay. So, two most popular
- 20:33payment gateways. The first one is
- 20:34Stripe. Okay. Accepted uh over 100 plus
- 20:38countries. Okay. And second is Razer
- 20:41Pay. Yeah. You know, two most popular
- 20:44payment gateways. So we'll use one of
- 20:46them. Okay. Fine. And for the external
- 20:50payments. Yeah, definitely. So that is
- 20:53also a job a part of a bank. Okay. We're
- 20:55building a bank system. So yeah,
- 20:57definitely we need to you know uh build
- 20:59that too. Okay. Now connecting
- 21:02everything our Apache Kafka.
- 21:06Okay. So you might be thinking that
- 21:10why you kept
- 21:12Apache Kafka in the middle. Why? So here
- 21:17we have okay we can see account service,
- 21:19transaction service, payment service.
- 21:21Here is our fraud detection service as
- 21:23the name indicating that you know it is
- 21:25responsible to detect the fraud. Yeah.
- 21:27Okay. Notification service and again
- 21:30account service.
- 21:33But why uh this Apache Kafka in the
- 21:35middle? Why? Because
- 21:39what we want is
- 21:41we want my fraud detection service will
- 21:47consume each and every initiated
- 21:51transaction.
- 21:53Okay. So here is my user. User click on
- 21:57the send money transaction initiated.
- 22:00Stop. Stop. uh at that point
- 22:05first let my fraud detection service
- 22:07consume that event via Kafka.
- 22:12Okay.
- 22:15And start checking the transaction.
- 22:20Okay. Try to detect whether there is
- 22:23some suspicious or not. This transaction
- 22:26is initiated by some genuine user or
- 22:29some fraudster.
- 22:32Yes or no? And then then okay just look
- 22:35at here um my fraud detection service
- 22:39again revert it back. So transaction
- 22:42service again need to decide
- 22:46if detected not detected.
- 22:50Yes. So my transaction service again
- 22:53consume the event and decide what to do
- 22:56next.
- 22:59Fine. Also uh next comes our
- 23:02notification service. Yeah, as the name
- 23:04indicating that it is responsible to
- 23:06send the alerts all type of alerts.
- 23:08Debit alert, credit alert, suspicious
- 23:11activity directed. We have seen uh you
- 23:13know a few minutes before alert you know
- 23:16on email phone. Okay. Uh verify OTP.
- 23:20Okay. Generated and everything all type
- 23:23of alerts refund alert. Okay. Yeah. So
- 23:27this is what on our email and uh phone
- 23:30SMS okay or on WhatsApp. Okay. Next
- 23:33comes our account service same. Okay. So
- 23:38finally to complete the transaction.
- 23:40Okay. Credit receiver.
- 23:43Okay. So this is our entire highle
- 23:47design architecture and this is why we
- 23:50have kept Apache Kafka in the middle.
- 23:53Fine. consume
- 23:57uh revert it back. Okay. Yeah. And uh
- 24:02so after this section I'm going to show
- 24:05you the real money flow. If you
- 24:07understand that and if you understood
- 24:08this HLD architecture you can code the
- 24:11entire banking system at your own
- 24:14because see what you need the flow and
- 24:18the architecture. Yeah. So without
- 24:21wasting much time, let's proceed with
- 24:23our next section that is our real money
- 24:26flow. Okay. We're going to do a real
- 24:28payment transfer. Okay. Fine. Let's
- 24:31let's go. Okay. So now let's see
- 24:33complete money flow. Okay. Yeah. Pay
- 24:36attention here. Important one. So here
- 24:39is my user.
- 24:41Okay. Here is my user. And once user hit
- 24:45the button
- 24:48send money. Okay. Or transfer or
- 24:52whatever. The first request goes to my
- 24:56you know API gateway and then it starts
- 25:01from here. My API gateway
- 25:05calls transaction service. Transaction
- 25:10service the decider. Okay. Fine. Then it
- 25:14executes saga. Okay. Uh step by step. So
- 25:18my transaction service calls my account
- 25:24service. Okay. And then my account
- 25:28service will what?
- 25:32Validates
- 25:34the
- 25:35balance. Okay. And deduct
- 25:40the amount from the balance. Fine.
- 25:44Done. Then
- 25:47uh again my account service you know
- 25:52calls transaction service back to the
- 25:55transaction
- 25:57service.
- 25:59Okay transaction service
- 26:02what I'll do is my transaction service
- 26:05saves this transaction this ongoing
- 26:08transactions. Okay save the transaction.
- 26:13Okay, we discussed you different
- 26:14different separate databases. Okay, and
- 26:18uh as status
- 26:22processing
- 26:24processing okay not yet completed, not
- 26:28failed, not flagged. Okay, nothing
- 26:32processing.
- 26:33Fine. Okay, stop there. Then my
- 26:36transaction service
- 26:39you know
- 26:41uh once we saved you know the
- 26:44transaction as processing then my Kafka
- 26:48comes into the picture okay and we'll
- 26:50publish the event as transaction
- 26:53initiated event we'll monitor each and
- 26:57every transaction
- 27:00okay so this event is going to consumed
- 27:04by our fraud fraud detection service.
- 27:09Okay, like fraud detection service
- 27:10consumes. Okay, and starts checking that
- 27:14you know some transaction has been
- 27:16initiated. Let's get uh get back to
- 27:19work. Okay, fine. So, fraud detection
- 27:24service tries hard to detect
- 27:29the you know any suspicious activity.
- 27:32Okay, we'll code it. Okay, we'll code
- 27:34the entire our fraud detection service.
- 27:36Okay, so
- 27:39if nothing is detected, if okay, if uh
- 27:43you know no fraud detected, everything
- 27:48is clean. Yeah. So again back to my
- 27:51transaction service,
- 27:54you know, need to report.
- 27:57Okay. And transaction service will
- 27:59initiate the process of completion.
- 28:02Okay, that means the process of you know
- 28:05money should be credit to the receiver.
- 28:10Okay. And then comes my notification
- 28:14service to send the alert to both my
- 28:17user. Debited from your account credited
- 28:22to your account.
- 28:25Okay. Clean clean process. But if
- 28:28something's suspicious detected then
- 28:31what? Let's see. So if any suspicious
- 28:34activity detected then first we need to
- 28:39verify
- 28:42you know uh
- 28:45about that
- 28:47transaction about this transaction with
- 28:51my user sender.
- 28:58Is it is it you or not?
- 29:01Okay. There are multiple steps for
- 29:03verification.
- 29:05Okay. Yeah. And if verified then we'll
- 29:08proceed.
- 29:10Okay. Another thing you know there's
- 29:12another thing fine. So we have uh we'll
- 29:15create another method for the blocking
- 29:17of account. In that case, you know,
- 29:19we'll uh check verify and once failed,
- 29:23then we'll proceed forward with
- 29:26temporarily block the account sender
- 29:31account. Okay. And we'll uh send the
- 29:33alert like uh account has been blocked.
- 29:36Okay. Uh been continuously seen
- 29:39suspicious activity in your account and
- 29:42uh please contact your bank as soon as
- 29:45possible. So there too we have
- 29:47possibilities.
- 29:50At the worst case we will proceed uh
- 29:53with blocking user account, blocking
- 29:56sender account.
- 29:58Okay. And finally again we'll call my
- 30:01notification service to notify. Okay.
- 30:05And then proceed forward.
- 30:08Yeah. Yes or no? Okay. Now
- 30:13any questions? Okay. Yeah. If you have
- 30:15then you can just ask me in your comment
- 30:17section. Okay fine. So with this our
- 30:20first part
- 30:22of money
- 30:25flow
- 30:27is completed. Now you all might be
- 30:29thinking that is there is some second
- 30:31part also. Yes there is second part.
- 30:34Okay. Honestly speaking the second part
- 30:37is the code itself. Okay. So I'll
- 30:40explain it to you once we'll start
- 30:42coding. Okay. Yeah. So here it completes
- 30:46the entire you know money flow first
- 30:48part. Okay. Second part we'll uh you
- 30:51know see at the time of coding. Okay.
- 30:54Fine. So now let's move to our next
- 30:57section that is saga pattern. Okay.
- 31:00Fine. And uh then fraud detection
- 31:03service. Okay. How do we detect? Okay.
- 31:05And uh then we'll set up our project.
- 31:08And final thing is we'll start coding
- 31:11our banking system. Okay. Yeah. So let's
- 31:14proceed. Let's go. Okay. So now let me
- 31:18explain you the saga with something we
- 31:20have already experienced that. Okay. And
- 31:24that is cash on
- 31:27delivery.
- 31:29Cash on delivery. Okay. Fine. So all
- 31:33kindly pay attention on my screen. Okay.
- 31:36So look at here. This is my user. Okay.
- 31:39and my user ordered something
- 31:42uh from Amazon. Okay. Let's say my user
- 31:46order phone
- 31:48from Amazon. Okay. Yeah. And put the
- 31:54payment
- 31:56method
- 31:59as
- 32:00cash on delivery.
- 32:05Okay. Done. Yeah. Now one day delivery
- 32:11person
- 32:12arrives
- 32:15on the door and hand it to my user. What
- 32:21the box? Okay. In exchange user pay the
- 32:26amount. Okay. Let's say $1,000.
- 32:31Okay. Fine.
- 32:33Okay. Okay. Fine. So this is our step
- 32:38number one. H step number one.
- 32:44Now
- 32:46my user is step number two. Okay. Pay
- 32:49attention. My user just uh open that
- 32:52box.
- 32:54Okay. And uh
- 32:58and found something wrong product. Okay.
- 33:01Or some damaged product.
- 33:04Okay. Damaged
- 33:08product. Okay. This is my step number
- 33:11two. Agreed? Okay. Understood? Yeah. Now
- 33:17I'll ask you you know uh question to you
- 33:21all of you guys that uh what he'll do
- 33:25next? What my user will do next?
- 33:30Definitely call to return it. put return
- 33:34request.
- 33:36Yeah. So my user
- 33:41call to
- 33:44return it.
- 33:46Will it step number three
- 33:51or will this uh return request undo
- 33:57these two step? Tell me.
- 34:03user call to return the product. So will
- 34:06it a explicit another step or once a
- 34:11user put the uh return request okay so
- 34:15that request will undo everything like
- 34:18you know um whatever user paid 15,000
- 34:22okay revert it back to the user and undo
- 34:26step number two is step number one
- 34:29is it no right no call to return it is
- 34:34another explicit step. Once we receive
- 34:38damage product, we'll call to return it.
- 34:42That means now we need to move to the
- 34:46next step. Step number three to initiate
- 34:49our refund.
- 34:52Not like you know to undo step number
- 34:55one and step number two. It's not like
- 34:58that.
- 34:59Next step another separate step and that
- 35:03is what saga
- 35:05okay differs with traditional single
- 35:08database okay we have discussed at the
- 35:10time we are you know seeing our uh
- 35:13problem okay so
- 35:17yeah traditional single database system
- 35:21that begin commit roll back so what's
- 35:26the roll back roll back is automatic,
- 35:30invisible.
- 35:32Okay, you don't need to, you know, uh
- 35:35just do much effort. No extra code.
- 35:39What? What is that? Just undo
- 35:42everything.
- 35:44Yes or no? Yeah, that is not an extra
- 35:48step. Saga is what? Uh we need to call
- 35:53to return it. That means another step
- 35:55for refund.
- 35:57We discussed you know that uh there are
- 36:00separate separate services.
- 36:03Okay. And with all have their own
- 36:07databases.
- 36:10Fine. So we need someone to inform
- 36:14you know and uh to process the next step
- 36:18and inform all the services to undo the
- 36:22operation.
- 36:24Okay, that is what
- 36:27uh actually our refund process
- 36:31that uh you know next is okay the
- 36:34request goes to whatever company okay
- 36:37and then initiate the refund okay that
- 36:39means we need to undo a step number one
- 36:43step number one means user paid to the
- 36:47company now undo step number one that
- 36:50means company again pay back to my user
- 36:58understood
- 37:00saga.
- 37:03Okay. Yeah. And uh anyway we are going
- 37:06to implement each and everything one by
- 37:09one. Okay. Also I'm going to explain it
- 37:12to you from a scratch once we'll start
- 37:15coding. Yeah. Okay. So this is what our
- 37:18saga. Now next. Okay. How do we detect
- 37:20the fraud? Okay. So what I'm thinking is
- 37:23let's proceed forward okay let's uh you
- 37:26know set up our project fine and start
- 37:29the coding part okay once we'll reach
- 37:31the fraud detection at that time I'll
- 37:33explain to you everything okay like this
- 37:36is what the techniques and this and that
- 37:39okay everything how do we detect the
- 37:41fraud okay yeah so that will be good now
- 37:44the next step is let's move to our you
- 37:47know yeah first we need to set up our
- 37:49data flow infrastructure Okay, all the
- 37:51services data services should be up and
- 37:53running and then project uh structure
- 37:57setup and then coding part. Okay, fine.
- 38:01So yeah, let's move to our uh you know
- 38:05what next thing let's go. So here's my
- 38:08docker desktop. Okay, I hope you already
- 38:11installed and kept it open in your
- 38:13machine. Fine. If not, then uh the link
- 38:16is given in the description. Just go to
- 38:18that link download and installed Docker
- 38:21desktop in your machine. Fine. Okay. So
- 38:24now let me just go to my file explorer.
- 38:27Okay. So I created a folder that is
- 38:30banking system. In that I have one file.
- 38:32Okay. That is my docker compost. Let me
- 38:36open that. Okay. So yeah. So here you
- 38:41know we have four services.
- 38:44So the first one is radius. Okay. And
- 38:47then MySQL, Zookeeper and Kafka. Okay.
- 38:51So, first we need to, you know, set up
- 38:53our data flow. That means we need to
- 38:57keep all these services up and running.
- 39:00Fine. So, for that, let me minimize it.
- 39:03Now, let me open bash here. Okay. Open g
- 39:06bash here. Fine. Yeah. So, you can also
- 39:10do the same using uh command prompt.
- 39:12Okay. Let me just go with the bash.
- 39:16Okay. And here just run this command
- 39:19docker compose up - d and
- 39:25uh you know here you'll write the
- 39:29service name okay if if you don't want
- 39:33to you know uh fetch all the service
- 39:37images okay so here you know what I need
- 39:41is I need my radius and zookeeper and
- 39:46Kafka. Okay, not MySQL. Why? Because I
- 39:49already installed MySQL on my local.
- 39:51Okay, so just need to give the name of
- 39:54these services. Radius, Zookeeper and
- 39:57Kafka. Okay, let me give that
- 40:00radius.
- 40:02Okay. And Zookeeper
- 40:05and Kafka. Okay. Fine. So my docker
- 40:11compose will start pulling the images.
- 40:15Okay. And you can see pulling zookeeper
- 40:19kafka radius. Okay. So it takes you know
- 40:22a few minutes. Fine. Let's wait for it
- 40:25and then after it creates the container
- 40:28in our docker desktop.
- 40:32Okay. Fine. And then finally we'll uh
- 40:36proceed forward. Okay. So fine. Let's
- 40:38wait for a few, you know, minutes till
- 40:41it completes.
- 40:42Okay. So,
- 40:45uh container created and started. Let me
- 40:48just open my docker and yeah, can you
- 40:50see banking system? Okay. Let me just
- 40:54click on it and and you can see uh my
- 40:58radius, zookeeper, kafka all are up and
- 41:00running. Okay. And the fourth one is my
- 41:03MySQL. So that two up and running
- 41:05because I installed that in uh my local.
- 41:08Okay. Yeah. Obvious fine. So now let's
- 41:11move to my browser and let's set up our
- 41:14banking system. Okay. All the
- 41:16microservices. Fine. Okay. So here's my
- 41:20browser. Fine. And let me type spring
- 41:23initializer. Okay. Click on the very
- 41:26first link. Start.io. Okay. We'll land
- 41:30here. Okay. Yeah. Project Maven language
- 41:34Java Springwood version automatically
- 41:36selected and now project metadata. Okay
- 41:40fine. So the first service com dot
- 41:43banking and
- 41:45account
- 41:47service.
- 41:49Okay fine. Let me remove hyphen from my
- 41:52package name. Yeah. Next dependencies.
- 41:56So spring web then uh Apache Kafka.
- 42:00Okay. a spring for Apache Kafka then u
- 42:04what JPA and MySQL driver validation
- 42:11okay Lombok
- 42:14fine and actuator okay spring boot
- 42:18actuator okay fine so yeah spring for
- 42:22apache kafka data JPA MySQL driver okay
- 42:27yeah so in future if we required any
- 42:30more depend dependency then we'll add
- 42:32using external resources. Okay. Yeah.
- 42:34For now let's proceed. So packaging jar
- 42:36configuration YAML and let me select
- 42:39Java version as 17. Okay. And now let me
- 42:42generate my account service. Yeah. Save
- 42:46it. Similarly my next is transaction
- 42:52transaction service. Okay. Let me remove
- 42:54hyphen from my transaction service.
- 42:56Okay. Now in the transaction service we
- 42:58need to add one more dependency. Okay.
- 43:00Belongs to the cloud. Okay. That is open
- 43:03fain. Yeah. Okay.
- 43:06Open fain and uh rest all remain same.
- 43:11Okay. That's it. Generate it. Fine. Save
- 43:15it. Then next comes my fraud detection.
- 43:19Fraud
- 43:21detection. Okay. Service.
- 43:24Fine.
- 43:26H okay yeah so in this service I don't
- 43:31need my myql driver and jpa
- 43:35okay also you know validation
- 43:39f open f what I need is I need radius
- 43:44okay radius okay spring data radius so
- 43:49explore and yeah spring boot starter
- 43:52data radius okay fine let me generated.
- 43:57Okay. Save. Next is my
- 44:01what? Notification service.
- 44:04Notification service. Okay. So, as the
- 44:10name indicates notification, I need
- 44:13Java. Okay. Java mail. Fine. And uh for
- 44:19our SMS, we'll add using external
- 44:22resources. Okay. Fine. Let me remove
- 44:25data radius and uh okay.
- 44:30Yeah, that's it. Fine. Let me generate
- 44:34it.
- 44:35Save. Okay. And then our payment
- 44:39service. Yeah. Payment service. Okay.
- 44:43Let me remove this.
- 44:46Fine. So in the payment service, I need
- 44:52JPA. Okay. And MySQL fine. Okay. And
- 45:00validation
- 45:02Lombok
- 45:04spring for Apache Kafka. And one more
- 45:07dependency we need that is our payment
- 45:10gateway. Okay. So let's proceed with the
- 45:13Razer Pay. Okay. Widely used. So for
- 45:16that just you know in a new tab type MVN
- 45:22repository okay MVN repository just
- 45:25click on the very first link mvvin
- 45:27repository.com
- 45:29okay and yeah few verification security
- 45:34verification and we'll land here
- 45:38fine in the search just type razer pay
- 45:43java
- 45:45Okay. Scroll down. Scroll down. Yeah.
- 45:48Can you see this? Razer Pay Java. Click
- 45:51on this. Okay. And here current version
- 45:55is 1.4.9.
- 45:57Okay.
- 45:58And yeah, here
- 46:01this is what the dependency. Okay. So
- 46:05once we'll uh open our microser you know
- 46:08this microser in our uh editor intellig
- 46:11editor. At that time we'll copy this and
- 46:14paste it in your pom.xml. Okay. Fine.
- 46:20So for now that's it for my payment
- 46:23service and generate it. Okay. Save. And
- 46:27at last our API gateway. API
- 46:31gateway. Okay.
- 46:34Fine.
- 46:37API gateway.
- 46:39Okay. And in this
- 46:42let me remove spring web. Okay. Kafka
- 46:47actuator Lombok.
- 46:50Okay. And let me remove mail sender data
- 46:54JPA MySQL validation. Okay. Here let me
- 46:58add gateway.
- 47:01Okay. Fine. And uh for rate limiting
- 47:06radius data radius reactive. Okay. So,
- 47:11radius, where is that? A spring data
- 47:14reactive. Reds. Yeah, this one. Okay,
- 47:19fine. A spring boot starter data radius
- 47:23reactive. Okay, that's it. Let me now
- 47:27generate it to and saved. Okay, so all
- 47:31our six microservices is you know
- 47:34downloaded. Now let me quickly
- 47:38uh extract them and import them in our
- 47:43IntelligJ code editor. Okay fine. Okay.
- 47:46So I imported all our microservices in
- 47:48our banking system. Yeah. So at first we
- 47:52need to start with our account service.
- 47:55Okay. First you know user need to create
- 47:58account. Create bank account. Yeah.
- 48:00Receiver sender. Okay. And then proceed
- 48:02forward. Okay. Yeah. So without wasting
- 48:05much time, let's start and let's
- 48:07proceed. And also also you know uh if
- 48:10you like the video then you can
- 48:12subscribe my channel. Okay. Hit the like
- 48:14button, subscribe my channel. Okay.
- 48:16Yeah. Also you can thank me. Fine. Okay.
- 48:20So yeah let's start. Let's go. Fine. So
- 48:23let's start with our account entity.
- 48:26Okay. So
- 48:28entity dot
- 48:31account. Yeah. Okay. So now entity and
- 48:39table.
- 48:40So
- 48:42name is accounts. Okay. And then Lombok
- 48:47annotations add data at all arcs and add
- 48:50no arcs constructor. Fine. Now what are
- 48:54my fields? Okay. So at first private
- 49:00string id. Okay. And the ID is
- 49:05not identity but
- 49:08it should be UYU ID. Okay. Yeah. Next is
- 49:13my account number. Okay. So a string
- 49:16account number. Okay. Then private
- 49:21string account holder name.
- 49:25Okay. Then what?
- 49:29Email. Okay. And then uh yeah so private
- 49:36a string phone. Okay. And then account
- 49:40type. Okay. So account type. Okay. And
- 49:46account type. So we have you know few
- 49:49string values like uh you know savings
- 49:52account, current account, fixed deposit.
- 49:54Okay. So let's declare it as enum. Okay.
- 49:59So enum and we have few string values
- 50:02fine later on we'll create okay or let's
- 50:05create it right now. So in the entity
- 50:09java and enum
- 50:12account type okay yeah next field is
- 50:17another enum we need to create for
- 50:21status
- 50:22account
- 50:24status. Okay and status. So account
- 50:28status means you know active. Okay.
- 50:31Blogged or flagged. Okay. So for that
- 50:35too let me create enum.
- 50:37Okay. Yeah. Now the next field we need
- 50:42to add is
- 50:45private and uh balance. Okay. So it
- 50:48should be big decimal and balance. And
- 50:51then also you know uh account should
- 50:56have
- 50:57big decimal and
- 51:00it should have daily
- 51:02what transaction limit.
- 51:06Yes or no? Yes.
- 51:08So daily transaction limit. Okay. And
- 51:12then we have you know our local date
- 51:16time.
- 51:18local
- 51:20date time. Okay. Created at
- 51:24similarly private local date time and
- 51:27updated at. Okay. Now let's add few
- 51:31annotations.
- 51:33So for account number it should be uh
- 51:37nullable false and
- 51:40should be unique. Okay. So unique true.
- 51:43Fine. Okay. Now for the account holder
- 51:46name column nullable false. Okay that's
- 51:49it. And uh for the email same thing let
- 51:54me just copy and paste column nullable
- 51:55false for the phone number same thing.
- 51:58Okay enum and nullable false. Okay same
- 52:02thing for our second enum that is at
- 52:06enumerated and type a string column
- 52:09nullable false. Okay. And yeah here in
- 52:13the balance we need to add you know
- 52:16precision and scale. Okay. So first
- 52:18property is nable false and then
- 52:21precision uh 12. Okay. Let me just
- 52:26modify to 15. Okay. Same thing same
- 52:30thing for the daily transition limit.
- 52:32Okay. So yeah and created at so at
- 52:36creation time stamp. Add creation time
- 52:39stamp. And for this add update time
- 52:42stamp. Okay. Yeah. Fine. So our account
- 52:47entity is done. Now let's complete our
- 52:51enum part. Okay. So account status and
- 52:54account type. Okay. So what are the
- 52:57account status values? Okay. So it is
- 53:01active. Okay. Account status active or
- 53:04uh account blocked.
- 53:07Yes. or account closed. Yeah. Okay. And
- 53:12also let me write the comments. You know
- 53:14account
- 53:16life cycle is status. See comments are
- 53:20really important in my project videos.
- 53:22Okay. In future uh in coming few minutes
- 53:25I'm going to show you the entire code
- 53:28flow. Okay. In the comments so that you
- 53:32can implement at your own first. Okay.
- 53:34Fine. So now the next is what account
- 53:39type. Okay. So what are the account
- 53:42types? The first is savings.
- 53:46Okay. Then uh savings account and then
- 53:51current account. Okay. And also let's
- 53:55add fixed deposit.
- 53:59Yes. Got it. Yeah. Now, now watch next
- 54:04is our
- 54:06DTO. Okay, so we have you know create
- 54:11account request
- 54:13and in response what we'll get. So
- 54:18account
- 54:20response. Okay. So let's add the fields
- 54:24in these two details. Okay. First let me
- 54:26add add data. then add
- 54:30no arcs and add all arcs.
- 54:34Okay, now let me just put them side by
- 54:38side. Okay, account here and my create
- 54:41account request. Okay, so what are the
- 54:44fields I need to create an account?
- 54:46Okay, so first I need this account
- 54:49holder name. Okay.
- 54:53And then
- 54:54next is I need email and phone. Okay.
- 54:58Email, phone.
- 55:01Fine. And then what? Then uh account
- 55:06type.
- 55:08Okay.
- 55:10And one more field. What? Private
- 55:14big decimal. No, not balance.
- 55:17But uh let me rename it as initial
- 55:22uh better initial deposit.
- 55:25Yeah, because once you go to the bank
- 55:28and once you create a new account. Okay.
- 55:30So the bank executive will ask you for
- 55:33initial deposit.
- 55:35Yes. Okay. So now let me add you know
- 55:39the validations first at not blank.
- 55:42Okay. And if it is blank then we'll
- 55:45display a message like account
- 55:49holder name is required. Okay. And
- 55:54similarly for the email at not blank
- 55:59else email is required also also let's
- 56:03check the email format. Okay. So
- 56:07you know
- 56:09invalid email format.
- 56:13Okay. And phone number. Okay. So, same
- 56:16thing not blank.
- 56:19And message that phone is required.
- 56:26Okay. Then next is account type. Okay.
- 56:30So, not null.
- 56:32Not null. And
- 56:35message will display that account type
- 56:39is required. And finally finally we need
- 56:43to add two more annotations here. So
- 56:46first is at not null. Okay we'll display
- 56:50a message
- 56:52that uh initial deposit
- 56:56is
- 56:59is required.
- 57:02Okay. And also what we want we want our
- 57:07deposit in positive. Okay. Should not be
- 57:11in negative. Yeah, definitely balance
- 57:13should be in positive not the negative.
- 57:15Okay. So at positive. Okay. And if
- 57:20suppose you try to hit you try to send
- 57:24the request with negative balance or
- 57:26negative initial deposit then it should
- 57:29show the error like initial deposit
- 57:34must be
- 57:37positive.
- 57:39Yes.
- 57:42create a point. Okay. Yeah. So this is
- 57:45what my uh first create account request
- 57:48DTO. Next in response what all fields
- 57:51we'll get. So I guess we need all the
- 57:55fields. Okay. Let me just directly copy
- 57:57and paste here.
- 58:00Fine. And uh let me just you know
- 58:06remove all these
- 58:09annotations and validations.
- 58:13Okay.
- 58:16Yeah.
- 58:18So
- 58:25fine. So I need ID, account number,
- 58:28account holder name, email, phone and
- 58:31account type, status, balance, daily
- 58:34transaction limit, created at and okay,
- 58:36let me remove updated at. I don't need
- 58:39this.
- 58:41Okay, also these imports statements.
- 58:46Yeah, so our you know uh DTO part is
- 58:49done. Okay, now let me create the full
- 58:51skeleton. Okay. So, first controller dot
- 58:55account controller. Okay. And then
- 59:01next is our service dot
- 59:05account service. Okay. And and what our
- 59:13you know repository dot
- 59:17account repository
- 59:20and it should be interface. Okay.
- 59:24Extends jpa repo.
- 59:27Okay. Account and string. Yeah.
- 59:30Definitely of type is string because our
- 59:33id of type is string. Okay. Yeah. The
- 59:36next is
- 59:39um also also let me you know
- 59:44consumer class. Okay. So account event
- 59:47consumer
- 59:49yes consume the events
- 59:52um the events like we have discussed in
- 59:54the HLD architecture that transaction
- 59:57service. Okay. So our transaction
- 1:00:00service publish the event what
- 1:00:03transaction dot initiated.
- 1:00:07Okay. And that event consumed by our
- 1:00:11account event consumer.
- 1:00:15Okay. So that it hits a method which
- 1:00:20method
- 1:00:22deduct
- 1:00:24balance.
- 1:00:26Okay. which we are going to implement in
- 1:00:28our
- 1:00:30account service. Okay. All the you know
- 1:00:34money movement method is going to
- 1:00:36implement in this deduct balance credit
- 1:00:41you know and uh uh receiver refund
- 1:00:45everything else. Okay. Yeah. So that's
- 1:00:49it. Okay. Fine. Next is uh account
- 1:00:54controller. Okay. and
- 1:00:58got it.
- 1:01:00Okay. So at first rest controller and
- 1:01:05request mapping. Okay. API
- 1:01:09and V1
- 1:01:12and
- 1:01:13accounts
- 1:01:16then SLF 4J. Okay. And now let me
- 1:01:22private final account
- 1:01:26service. Okay. For that let me also add
- 1:01:29one more annotation that is required
- 1:01:32asks constructor.
- 1:01:35Okay. Yeah.
- 1:01:37Now let's start adding the endpoints.
- 1:01:41Okay. So what are the endpoints we need
- 1:01:42to add here? First is create account.
- 1:01:46Okay. Then get account. Okay. Get
- 1:01:50balance.
- 1:01:52Fine. Next is our block account. Yes,
- 1:01:56block account. And then our saga is step
- 1:02:01number one.
- 1:02:04Okay. That is our um deduct balance.
- 1:02:12Okay. And then and then what?
- 1:02:16Um,
- 1:02:18credit
- 1:02:19credit balance. Okay, that means uh
- 1:02:24what? Receiver. Okay, so credit
- 1:02:28receiver,
- 1:02:30credit sender. Okay, that means refund.
- 1:02:36So this is I guess uh you know saga step
- 1:02:40number I guess uh four. Yeah. So these
- 1:02:46all endpoints we need to add and
- 1:02:50implement it in the our account service.
- 1:02:54Okay.
- 1:02:56Yeah. So also need to consume two events
- 1:03:00from fraud detection
- 1:03:02and uh from
- 1:03:04transaction service. Okay. So let's do
- 1:03:08it. Let's implement it and then let's
- 1:03:10quickly finish it. Okay. Fine. So public
- 1:03:15response entity. Okay. And uh I'm
- 1:03:20returning the what account response
- 1:03:22account
- 1:03:25response. And first is my create
- 1:03:29account.
- 1:03:31Okay. And at valid.
- 1:03:35Okay. At valid. Okay. And at request
- 1:03:40body. Let me pass the create account
- 1:03:43request and let's keep it short request.
- 1:03:48Okay.
- 1:03:51Yeah. So
- 1:03:54fine.
- 1:03:56Return
- 1:03:57response entity. Okay. And dot status
- 1:04:02http. Okay. Status dot created
- 1:04:08dot body. And let me call the method
- 1:04:13account service dot create account.
- 1:04:16Okay, which we are going to implement in
- 1:04:19the account service class. Okay. And let
- 1:04:23me pass this request here.
- 1:04:27Okay. Yeah, it is what? Post mapping.
- 1:04:31Post mapping. Okay. Next method is what?
- 1:04:35public
- 1:04:38and response entity account response.
- 1:04:43Okay. And what? Get account.
- 1:04:48Okay. Get account.
- 1:04:51And get account at path variable. Okay.
- 1:04:56By
- 1:04:58account number.
- 1:05:02Okay.
- 1:05:04So
- 1:05:06return
- 1:05:07response
- 1:05:09entity dot okay and account service dot
- 1:05:15get account oops get account
- 1:05:19and let me pass the account number okay
- 1:05:23and it is my get mapping okay
- 1:05:29and
- 1:05:32this is what my account
- 1:05:36number. Yeah. Okay. Fine.
- 1:05:40So the next method is our
- 1:05:45public also. Just let me you know copy
- 1:05:49paste this one.
- 1:05:51So
- 1:05:53it should be get balance.
- 1:05:57Okay. And get balance by account number.
- 1:06:00Okay. It is fine. Get balance.
- 1:06:04Okay. And here in the mapping balance.
- 1:06:10Yeah. Fine. Also also here I'm getting
- 1:06:14the balance. Okay. So big decimal.
- 1:06:18Okay. Fine. Now comes our block account.
- 1:06:23Okay. So public
- 1:06:26response entity.
- 1:06:29Okay. and a string. Yeah. And block
- 1:06:35account.
- 1:06:37Okay. So by same thing add path variable
- 1:06:42string account number. Yes.
- 1:06:45And then then what? Account service dot
- 1:06:51block
- 1:06:54account. Okay. Let me pass the account
- 1:06:57number and we'll return
- 1:07:00response entity dot okay
- 1:07:05and account blocked
- 1:07:09successfully. Yeah, here the mapping.
- 1:07:13Okay, tell me uh which mapping I need to
- 1:07:17put here.
- 1:07:19Yes, get. No, not get. It should be put
- 1:07:24mapping. Okay.
- 1:07:26And
- 1:07:30uh it is let me pass the account number.
- 1:07:35Okay. And block.
- 1:07:39Yeah. Next is next. What? Next is our
- 1:07:44saga step number one. Okay. Saga step
- 1:07:48one. Fine.
- 1:07:51Deduct balance. Okay. also called by
- 1:07:57transaction
- 1:08:00service when
- 1:08:03transaction service when
- 1:08:06yes tell me when transfer is initiated
- 1:08:13okay yeah got it that's why I told you
- 1:08:18the comments are really important in my
- 1:08:20videos so public and
- 1:08:25response entity.
- 1:08:28Okay,
- 1:08:30type a string and deduct balance. Okay,
- 1:08:36and need to pass two things obviously.
- 1:08:39So, first I need to pass the account
- 1:08:41number and definitely the balance. Okay,
- 1:08:44the amount. So, add request param
- 1:08:47request param. Okay, big decimal amount.
- 1:08:50Fine.
- 1:08:53and account service dot deduct balance.
- 1:09:01Okay. Uh let me pass the account number
- 1:09:03and
- 1:09:04amount here. And then return
- 1:09:10response entity dot okay amount. Okay.
- 1:09:14Amount. Okay.
- 1:09:17Or I can say balance deducted
- 1:09:21successfully.
- 1:09:23Okay.
- 1:09:25Put mapping and
- 1:09:29here account number
- 1:09:32to pass. Okay.
- 1:09:36And deduct.
- 1:09:38Fine. Okay. Okay. Okay. Now the
- 1:09:41important one that is our
- 1:09:45saga step
- 1:09:49uh four h that is compensating. Okay. So
- 1:09:55compensating
- 1:09:57and
- 1:09:59transaction
- 1:10:02endpoint fine and it is called
- 1:10:07by
- 1:10:09transaction service.
- 1:10:13Okay. So um listen to me here
- 1:10:17compensating transaction endpoint. Okay.
- 1:10:20So either we'll create two separate
- 1:10:23methods. Okay. So credit receiver
- 1:10:29and you know refund.
- 1:10:32Okay. So definitely it is you know uh we
- 1:10:35are crediting sender or we'll handle
- 1:10:41both in one that is credit balance.
- 1:10:47Okay. and we'll handle it in our
- 1:10:49transaction
- 1:10:50uh service.
- 1:10:52Yes. Okay. So, called by transaction
- 1:10:57service in two scenarios. Okay.
- 1:11:05What are they? The first one is my
- 1:11:09fraud.
- 1:11:11Fraud detected.
- 1:11:14Okay. So I need to refund sender.
- 1:11:20Okay, that means I'll undo
- 1:11:24a step one. Okay, second thing
- 1:11:29transaction
- 1:11:31completed.
- 1:11:33Okay, so
- 1:11:35I'll credit
- 1:11:38receiver. Okay, fraud that means refund.
- 1:11:41Transaction completed that means credit
- 1:11:43receiver. Okay. Fine.
- 1:11:46So now
- 1:11:49public
- 1:11:50response entity. Okay. And a string
- 1:11:57credit balance. Okay.
- 1:12:02Now add path variable account number and
- 1:12:07big decimal amount. Fine. So account
- 1:12:12service dot
- 1:12:14credit balance. Okay. And account number
- 1:12:20and amount.
- 1:12:22Okay. And then return
- 1:12:26response entity
- 1:12:29dot. Okay.
- 1:12:32And what
- 1:12:35balance
- 1:12:37credited
- 1:12:39successfully.
- 1:12:41Okay. The endpoint is again put mapping.
- 1:12:49Okay. Account
- 1:12:54number
- 1:12:56and credit. Okay. So these are our
- 1:13:00endpoints.
- 1:13:02We need to implement it. Okay. So kindly
- 1:13:06pay attention here on my account
- 1:13:10service. Okay, let's go for it. So
- 1:13:17service and then SLF 4J. Okay, then
- 1:13:24private
- 1:13:25final account repository. Okay, so for
- 1:13:30that let me also add required arcs
- 1:13:35constructor. Okay,
- 1:13:38fine. So our first endpoint is public
- 1:13:42and I'm returning account response and
- 1:13:46create account. Okay, what I'm getting
- 1:13:50I'm getting the request create account
- 1:13:52request and uh let's keep it short
- 1:13:56request. Okay, first let me add the
- 1:13:59login. So info log.info info and
- 1:14:04I am creating account
- 1:14:08for
- 1:14:11okay and let me pass the request dot get
- 1:14:16email okay now first let me check
- 1:14:21whether account is already exist or not
- 1:14:24in my account repository okay so account
- 1:14:27dot
- 1:14:29exist by email. Okay. So, I need to
- 1:14:35create this method in my account
- 1:14:36repository. Okay.
- 1:14:40Account repository. Account repository.
- 1:14:43Fine. And boolean
- 1:14:47exist by email. And I'm passing the
- 1:14:50string email. Okay. Back to our account
- 1:14:54service.
- 1:14:56Fine. And
- 1:14:59um let me pass the get email. Okay. So
- 1:15:04if it is true then let's throw new
- 1:15:08runtime exception and account already
- 1:15:13exist
- 1:15:15for email. Okay. And our request dot get
- 1:15:21email.
- 1:15:22If not then uh then then what?
- 1:15:27So if not then first let me create
- 1:15:31account object.
- 1:15:33Okay. So you can create in two ways
- 1:15:36either by new operator account account
- 1:15:39uh equals new account or else using the
- 1:15:43builder. Okay. So just you need to add
- 1:15:46here add builder annotation.
- 1:15:50Okay. and then account account equals
- 1:15:54account dot
- 1:15:57builder. Okay. And then all the fields
- 1:15:59will populate here. So you need to just
- 1:16:01set the values like account holder name.
- 1:16:04Okay. So what you are getting from here
- 1:16:07request dot get account holder name.
- 1:16:09Okay. Like this in all the fields. Okay.
- 1:16:12But for now let me just keep the simple
- 1:16:14one. Okay. So account new account and
- 1:16:18then set the values also let me remove
- 1:16:22this. Okay no use fine and yeah
- 1:16:29so let me just set the values account
- 1:16:33dot set holder name and request dot get
- 1:16:38holder name. Next is account dot
- 1:16:42set email. Okay. Get email. Fine.
- 1:16:48And uh you know what else?
- 1:16:52Email, phone, account type and initial
- 1:16:55deposit.
- 1:16:56Then account dot set phone.
- 1:17:01Okay. So yeah, get phone and then
- 1:17:06account dot set account type. Okay.
- 1:17:11Account type. So I'm getting the account
- 1:17:14type. Okay. Also status. So account dot
- 1:17:19set you know uh set status. So status
- 1:17:25should be active. Okay. So account
- 1:17:27status dotactive. Fine. And then finally
- 1:17:31uh account dot we need to set the
- 1:17:34balance. Okay. So the balance set
- 1:17:38balance should be the initial deposit.
- 1:17:42Yeah, definitely the initial deposit is
- 1:17:44only our balance. So request dot
- 1:17:48get initial deposit. Okay. And now now
- 1:17:53our important logic account dot set
- 1:17:57account number. Okay. Now I cannot do
- 1:18:01like this account dot get account
- 1:18:03number. No, we need to generate the
- 1:18:07account number.
- 1:18:09Yes or no? So just look here. We need to
- 1:18:14generate
- 1:18:16uh account number because we have the
- 1:18:19specifications.
- 1:18:20Okay. Like account number should be
- 1:18:23first unique.
- 1:18:25Second thing is must be
- 1:18:29uh of 12 digits.
- 1:18:32Yeah. So for that we need to write a
- 1:18:36separate logic. Okay.
- 1:18:39Fine. Let me just you know add here
- 1:18:44generate
- 1:18:46account number. Okay. And we'll
- 1:18:49implement this method. Fine. Okay. So
- 1:18:52now I want you to answer me for our next
- 1:18:55field that is account dot set daily
- 1:18:59transition limit. Yeah. So now tell me
- 1:19:03uh what will be my user who is creating
- 1:19:07a new account
- 1:19:09transaction limit. What should I write
- 1:19:11here? Okay. So now pay attention here.
- 1:19:15Well, it depends on account type. We
- 1:19:19have three types of account. Savings,
- 1:19:21current and fixed deposit. And it
- 1:19:23differs just like if a person is
- 1:19:26creating an account and uh it's saving
- 1:19:30account. Okay. Savings account. Then his
- 1:19:34transition limit may be 100,000.
- 1:19:37Yeah. And rest for uh current account or
- 1:19:41uh you know let's say fixed deposit.
- 1:19:44We'll set our daily transaction limit as
- 1:19:47let's say 500,000.
- 1:19:50Yes or no? So request dot you know first
- 1:19:54let me get the account type okay and if
- 1:19:58it is equals savings
- 1:20:02okay then new big decimal and uh yeah
- 1:20:09uh the daily transaction limit is
- 1:20:10100,000
- 1:20:13okay
- 1:20:14else
- 1:20:17okay
- 1:20:19else what new big decimal for our uh you
- 1:20:23know fixed deposit and current account
- 1:20:26the daily transaction limit is 500,000.
- 1:20:30Yes. Okay. Fine. Now let me account and
- 1:20:35saved account equals account repository.
- 1:20:39Okay. Saved. And also let me just add
- 1:20:42the login that is account created.
- 1:20:48Okay. and
- 1:20:50saved account dot get account
- 1:20:55number. Okay. And let me return the you
- 1:20:59know now I need to return account
- 1:21:02response. Okay. But I'm getting here
- 1:21:05account. Okay. So I need to convert it.
- 1:21:08So for that let me create a method map
- 1:21:11to
- 1:21:13response.
- 1:21:14Okay. And let me pass the saved account.
- 1:21:19Okay.
- 1:21:21Yeah.
- 1:21:23Now quickly let me just
- 1:21:27private and need to return the account
- 1:21:31response and map to response. Okay fine.
- 1:21:35So account
- 1:21:37response response
- 1:21:42equals new account response. Okay. and
- 1:21:44then just set the values.
- 1:21:47Okay. in the response object.
- 1:21:51Fine. Okay. So, just like response dot
- 1:21:56set.
- 1:21:57Okay. I guess let me Yeah. So, I haven't
- 1:22:01mentioned the Lombok
- 1:22:03at data at all arcs at no args. Okay.
- 1:22:08Fine. Now, set ID. Okay. So, what I'm
- 1:22:15getting account ID. Similarly for all
- 1:22:17the fields. Okay. So let me just do fast
- 1:22:20forward. Okay. And then return response.
- 1:22:27Yeah. Fine. Okay. Now we are going to
- 1:22:30implement one of the most important
- 1:22:32method that is generate account number.
- 1:22:37Okay. So private string and we going to
- 1:22:41generate unique 12digit account number.
- 1:22:45But how? Can you tell me any guesses? So
- 1:22:49first let me take secure random. Okay.
- 1:22:53Private
- 1:22:55static
- 1:22:57secure random. Okay.
- 1:23:01Equals secure random. Fine. And now let
- 1:23:06me open the dowhile loop. Okay. So first
- 1:23:09let me also take you know my variable in
- 1:23:12which I'm going to store my account
- 1:23:14number. Okay. And then do while loop.
- 1:23:18Yes.
- 1:23:23Okay. So now uh let me first generate a
- 1:23:28unit uh random number. Okay. Here is a
- 1:23:32you know tricky part. So secure random
- 1:23:35my variable and dot next long and let me
- 1:23:39just set the upper limit. Okay. So my
- 1:23:43upper limit is 1. Okay. And 2 3 4 5 6 7
- 1:23:508 9 10 11 12 13.
- 1:23:55Okay. Yeah. Now look at here. So you
- 1:23:57might be thinking that I have set my
- 1:24:01upper limit, set my bound
- 1:24:04as this number that is 1 2 3
- 1:24:094 5 6 7 8 9 10 11 12 13. Okay, that is
- 1:24:14correct because this line, you know,
- 1:24:17this line generates
- 1:24:20a random numbers from 0 to uh this
- 1:24:26number minus one that is 999 until 12
- 1:24:29digits. Okay. Yeah, definitely inclusive
- 1:24:33and this is exclusive. Okay. Now there
- 1:24:37is one issue you might be thinking that
- 1:24:39why from zero to uh you know this uh
- 1:24:43last 12-digit number as you mentioned
- 1:24:46that we need a count number is specific
- 1:24:5112digit number and unique.
- 1:24:55So you should have to set the range from
- 1:25:00you know 1 2 3 4 5 6 7 8 9 10 11 12 to
- 1:25:06this last 12-digit number.
- 1:25:10Okay, then only we'll get only 12digit
- 1:25:14number.
- 1:25:16Okay. And for the unique we'll uh check
- 1:25:19in the database.
- 1:25:21Yeah, you're correct. But what I'm
- 1:25:24thinking is so let's say this line
- 1:25:27generates the number as 1 2 3 4 5. Yeah,
- 1:25:33possible. So it can generate any number
- 1:25:36from zero to last 12-digit number. Let's
- 1:25:40say this number.
- 1:25:42So this is not a 12digit number. But it
- 1:25:46is specific that we only need
- 1:25:5112 dual digit number and should be
- 1:25:52unique. So how about let's convert it.
- 1:25:57Yes. So
- 1:26:001 2 3 4 5 and put the zeros. Okay.
- 1:26:06Remaining seven zeros. So 1 2 3 4 5 6 7.
- 1:26:12it becomes my 12digit
- 1:26:15number.
- 1:26:17Yes or no? So 1 2 3 4 5 6 7 8 9 10 11
- 1:26:2212. Similarly, if suppose it generates
- 1:26:25uh you know 1 2 so 1 2 3 4 5 6 7 8 9 10.
- 1:26:36Okay. And for the uniqueness we are
- 1:26:39going to check in the our repo rep
- 1:26:41repository database.
- 1:26:44Yeah. So that's why this is what our
- 1:26:47logic. Okay. Let's write it. Let's uh
- 1:26:49you know code the complete logic. Okay.
- 1:26:54Fine. So now my account number equals
- 1:26:58Okay. Uh let me format it. String dot
- 1:27:02format. Now let me explain to you. So
- 1:27:06format starts. So this is a percentage
- 1:27:09that means format start. Now I need to
- 1:27:12replace with the zeros zero. Now I need
- 1:27:1612digit number 12. Okay. And d for the
- 1:27:19decimal integer.
- 1:27:22Yes or no?
- 1:27:24See how I'm explaining line by line,
- 1:27:26word by word. Okay. So percent means
- 1:27:29format starts. Zero means replacing with
- 1:27:32zeros. 12. Okay, need 12-digit you know
- 1:27:37uh account number 12digit number and D
- 1:27:41means decimal integer. Okay, fine. Now
- 1:27:44here while so account repository dot
- 1:27:50exist by account
- 1:27:53number. Okay. And we'll pass the account
- 1:27:56number. Okay. So yeah this account
- 1:28:01number.
- 1:28:03Okay. what it means? Let me explain you.
- 1:28:06First, let me create this method in our
- 1:28:08repository. Account repository. Okay.
- 1:28:12And boolean.
- 1:28:16Fine. And I'm getting the account
- 1:28:18number.
- 1:28:20Okay. Yeah. So now just
- 1:28:24Okay. So look at here. What we are
- 1:28:26checking in this condition that
- 1:28:30is there any user available with the
- 1:28:34same account number which generated
- 1:28:37here. Okay. So let's say this is my you
- 1:28:40know user uh database and there are few
- 1:28:44users already registered. Okay. So fine
- 1:28:49and this is what account number and few
- 1:28:52us are already registered. Okay. with
- 1:28:54the account number let's say 0 0 0 till
- 1:28:571 2 3 4 5 and uh 0 0 4 5 6 whatever till
- 1:29:0312 digit and you know just like that.
- 1:29:06Now suppose a new user came create
- 1:29:09account. Okay, create account and then
- 1:29:12finally generate account. So this method
- 1:29:14called control come here comes here
- 1:29:16comes here and it generates
- 1:29:19a random account number. Let's say 1 2 3
- 1:29:234 5 a random number. Okay. So now it
- 1:29:27converted to
- 1:29:303 4 5 6 7 and 1 2 3 4 5. Now with this
- 1:29:35account number there is already a record
- 1:29:39exist in our database.
- 1:29:43That is what we are checking here. If it
- 1:29:46is exist then continue the loop.
- 1:29:50Generate another number. Generate
- 1:29:52another number.
- 1:29:54Once this condition failed there is no
- 1:29:56any entry in our database. That means
- 1:29:59that account number is unique one. So
- 1:30:01that is assigned to that particular
- 1:30:04user.
- 1:30:06Getting my point? Yes or no? Okay. Fine.
- 1:30:10So here and then
- 1:30:13we are returning the account number.
- 1:30:18Yes, understood the concept how we have
- 1:30:21implemented and how we have generated.
- 1:30:24Okay. So also let me write the comment
- 1:30:26generate unique 12
- 1:30:31digit account number.
- 1:30:36Yeah. Okay.
- 1:30:38Fine. Now let's implement our next
- 1:30:41methods. Okay. So get account get
- 1:30:44balance. Okay. Let me just implement it
- 1:30:46quickly and then we'll move to our uh
- 1:30:49saga methods. Okay.
- 1:30:52So
- 1:30:54public
- 1:30:56account response and get account. Okay,
- 1:31:03the string account number.
- 1:31:06Okay, now first let me get the account.
- 1:31:09So account
- 1:31:14account equals
- 1:31:18um account repository dot find by
- 1:31:23account number. Okay. So we need to
- 1:31:26create this method to account repository
- 1:31:30and yeah
- 1:31:33so optional.
- 1:31:36Okay.
- 1:31:38and account find by account number
- 1:31:43and I'm getting the
- 1:31:46account number.
- 1:31:49Okay.
- 1:31:51Yeah. Now comes here. Let me pass the
- 1:31:56account number or else throw
- 1:32:02new runtime exception
- 1:32:07account not found.
- 1:32:11Yes. Yeah. Now so that's it and we'll
- 1:32:15return map to response account. Okay.
- 1:32:18Yeah.
- 1:32:20Now similarly um let me just copy and
- 1:32:24paste for our get balance. Okay. So get
- 1:32:28balance
- 1:32:31and this is my
- 1:32:34well I'm returning the big decimal.
- 1:32:37Okay.
- 1:32:38Okay. First I got my account and then
- 1:32:42return
- 1:32:44account dot get balance.
- 1:32:48Okay.
- 1:32:49Mhm. Yeah. Now let's implement our next
- 1:32:54that is block account which is uh called
- 1:32:58by fraud detection. Okay. So public void
- 1:33:04block account.
- 1:33:07Okay. And
- 1:33:09a string account number.
- 1:33:14Fine.
- 1:33:16Okay. and called
- 1:33:21uh what?
- 1:33:24Okay. So, block account
- 1:33:29and
- 1:33:31called by
- 1:33:34prod detection
- 1:33:37service via
- 1:33:40Kafka. H okay.
- 1:33:44Okay.
- 1:33:47So yeah also let me just quickly you
- 1:33:51know get account by account number.
- 1:33:57Okay
- 1:33:59comments are must yes and get
- 1:34:04account
- 1:34:05balance.
- 1:34:07Fine called by fraud detection service.
- 1:34:10Okay, definitely because once fraud
- 1:34:14detected
- 1:34:15then
- 1:34:17this service gets called. Okay, so first
- 1:34:21let me add the login. Okay, and it's
- 1:34:24like I'm blocking account.
- 1:34:29Okay,
- 1:34:32I'm blocking the account. Okay, and
- 1:34:35account number. Fine. Then first let me
- 1:34:38get the account. Okay, let me just copy
- 1:34:42that you know the complete thing.
- 1:34:47I'm getting the account using account
- 1:34:49number. Okay, got the account and let me
- 1:34:52just set the status account dot you know
- 1:34:56set status as account dot you know
- 1:34:59status do.blogged. Okay. And at the time
- 1:35:02of transfer we'll check that account
- 1:35:05must be in active state. Okay. Yeah. So
- 1:35:10let me just save it. Account repository
- 1:35:13save and log dot info account blocked
- 1:35:18account number. Yes. Okay. Yeah. Now now
- 1:35:23what? So now next is
- 1:35:28uh
- 1:35:29h
- 1:35:32deduct balance.
- 1:35:35Okay, deduct
- 1:35:38balance and
- 1:35:41I'm getting account number and big
- 1:35:46decimal
- 1:35:48amount.
- 1:35:51Okay. Mhm.
- 1:35:54So now
- 1:35:57deduct balance from
- 1:36:01sender
- 1:36:03account
- 1:36:04and it is called by
- 1:36:08transaction service.
- 1:36:12Yes or no? Yes.
- 1:36:15Fine. So log dot info and I am deducting
- 1:36:20balance. Okay. So deducting balance
- 1:36:25and from account.
- 1:36:28Okay. So deducting balance that is
- 1:36:31amount
- 1:36:33H. Okay.
- 1:36:36Now let me get that account first.
- 1:36:39Yeah. So
- 1:36:42let me get the account. Okay. Got it.
- 1:36:45And now let's check if if what if
- 1:36:50account
- 1:36:51dot get status
- 1:36:56is
- 1:36:58not active.
- 1:37:00If the status is not active then
- 1:37:06throw runtime exception that account is
- 1:37:09not active. Okay. And account number.
- 1:37:14Yes. Then let's check the balance. Okay.
- 1:37:18Because we need to add both. Fine. Some
- 1:37:22of you might forget to check the status.
- 1:37:25Yeah. That's why status is the most
- 1:37:27important field. Okay. Yes. So now once
- 1:37:31active then we'll check the balance. Uh
- 1:37:34account dot
- 1:37:36get balance dot compare to compare to.
- 1:37:43Okay. amount
- 1:37:45and less than zero.
- 1:37:48Less than zero. Then here
- 1:37:54row new
- 1:37:56runtime exception that insufficient
- 1:37:59funds for account. Yeah. Okay. And then
- 1:38:04account dot set balance. Okay. We need
- 1:38:08to set the balance. What? account dot
- 1:38:11get balance dots subtract.
- 1:38:15Okay.
- 1:38:19Subtract amount.
- 1:38:22Fine. And then let me save it.
- 1:38:25Repository and then log dot info. So
- 1:38:29balance balance updated
- 1:38:34and new
- 1:38:36balance
- 1:38:38is
- 1:38:40account dot get balance.
- 1:38:45Yes. Okay. Okay. Okay. Now let's
- 1:38:48implement our last method that is
- 1:38:52uh yeah credit balance. Okay.
- 1:38:57So public void and credit balance
- 1:39:04a string account
- 1:39:07number and big decimal
- 1:39:13amount.
- 1:39:17Okay.
- 1:39:19Yeah. So now comments are most
- 1:39:23important. So credit balance and called
- 1:39:28by
- 1:39:30transaction
- 1:39:32service via Kafka. Okay, we need to also
- 1:39:36you know handle it in uh our transaction
- 1:39:39service. This is you know the heart of
- 1:39:43our banking system. Please do not miss
- 1:39:45the service method implementation.
- 1:39:48Everything goes here. Okay. And our
- 1:39:50fraud detection. Okay. Yeah. So let me
- 1:39:55just add some loggings log.info and
- 1:39:59I am crediting
- 1:40:02what
- 1:40:04uh two
- 1:40:07account
- 1:40:11fine and crediting this amount to this
- 1:40:15account.
- 1:40:17Okay. This can be anyone. Fine. Yeah. So
- 1:40:20first let me let me get that.
- 1:40:27Okay.
- 1:40:29Yeah. And then I need to add. Okay. So
- 1:40:32account dot set balance. Okay. Then
- 1:40:39account dot get balance. And we need to
- 1:40:42dot add amount.
- 1:40:45Yes. And then account repository dot
- 1:40:48save and log dot info. So balance
- 1:40:54credited.
- 1:40:56Okay. And new balance
- 1:41:00account dot get balance. Yeah. So this
- 1:41:04is what our uh you know completed
- 1:41:08everything all the method implementation
- 1:41:12done. Yeah. account controller.
- 1:41:15Yes. And now now let's move to our
- 1:41:20account event consumer
- 1:41:22where we are going to consume
- 1:41:25transaction completed event and fraud
- 1:41:29detection event.
- 1:41:32Okay. Yeah. To block the account or to
- 1:41:35credit the balance. Yeah. Okay.
- 1:41:38Important one. So let's start add
- 1:41:41service and at SLF 4J. Fine. Now here we
- 1:41:47are consuming two events. The first one
- 1:41:50is public void and consume
- 1:41:55transaction completed.
- 1:41:58Okay. and add payload and map
- 1:42:05a string object.
- 1:42:09Okay. And payload.
- 1:42:13Yes. Now
- 1:42:16comments are consume what? Transaction
- 1:42:20dot completed. Okay. Yeah.
- 1:42:23Completed event from Kafka. And also I
- 1:42:28want you to tell me that what it means
- 1:42:31like what we are doing here
- 1:42:34transaction completed means what? Okay.
- 1:42:38So here look at here transaction
- 1:42:40completed means
- 1:42:42everything is done and no fraud detected
- 1:42:46and now finally we are
- 1:42:49crediting to receiver. Yes or no? Yeah.
- 1:42:54Okay.
- 1:42:55So here
- 1:42:58credits
- 1:43:00receiver account H. Now let me open my
- 1:43:05try catch. And
- 1:43:09here
- 1:43:11let me first get the
- 1:43:15receiver account equals
- 1:43:19payload dot get
- 1:43:24receiver account
- 1:43:27number.
- 1:43:29Okay.
- 1:43:31Yeah. Let me type cast it the string
- 1:43:36and and what big decimal.
- 1:43:41Okay. And amount.
- 1:43:43So
- 1:43:45new big decimal. Okay. And then payload
- 1:43:50dot get amount dot to string. Yeah.
- 1:43:55And then let me first add the login that
- 1:43:58we are crediting
- 1:44:01account.
- 1:44:03Okay.
- 1:44:05And amount.
- 1:44:09Fine.
- 1:44:11So receiver account. And this is amount.
- 1:44:15Got it? Okay. Now what we need? We need
- 1:44:19to call that method. Okay. So account
- 1:44:22service first. Let me get that private
- 1:44:26final account service and account
- 1:44:29service. Okay, for that let me add
- 1:44:33required asks constructor. Okay, now
- 1:44:37I need to credit. Okay, so account
- 1:44:40service dot we already created a method
- 1:44:43in the account service.
- 1:44:45Okay, if you remember just now few
- 1:44:47minutes before credit balance. Okay,
- 1:44:51same thing. And let me pass the account
- 1:44:54and amount. Okay,
- 1:44:58that's it. And in our exception, let me
- 1:45:01just add log error.
- 1:45:05Okay, and error
- 1:45:08crediting account.
- 1:45:12Okay. E dot get message. H. Yeah. Now
- 1:45:18add Kafka listener and topics. So
- 1:45:24transaction dot completed.
- 1:45:27Yeah, that's what we mentioned here in
- 1:45:30the comments. Yeah, and the group we are
- 1:45:35going to handle
- 1:45:38uh in our where uh in our uh application
- 1:45:43dot yiml file. Okay, properties file
- 1:45:46because we are going to consume two
- 1:45:51events from two different services.
- 1:45:55Okay, so let's keep a single group for
- 1:45:58both of them. Yeah, fine. Now the next
- 1:46:00is next event we are consuming that is
- 1:46:04public void consume
- 1:46:07prod.
- 1:46:10Okay, because we have one more method in
- 1:46:12our account service that is
- 1:46:15uh block account. Okay, so once fraud is
- 1:46:18detected, we need to consume that and we
- 1:46:21need to block account. Okay, payload
- 1:46:25and and what h
- 1:46:29uh let me open my try catch. Okay,
- 1:46:35fine also.
- 1:46:38Yeah. So at first uh
- 1:46:43comments yeah
- 1:46:46comments are most important. So consume
- 1:46:50fraud dot detected
- 1:46:52event
- 1:46:54from Kafka and it blocks
- 1:47:00h blocks the
- 1:47:03flagged account. H okay. So first let me
- 1:47:08get that. So a string account
- 1:47:11number equals
- 1:47:14payload dot get
- 1:47:18account number. Okay. So
- 1:47:22let me type casted a string
- 1:47:26and and what let me add the login
- 1:47:29log.info info that prod detected and uh
- 1:47:35I'm blocking the account.
- 1:47:38Okay.
- 1:47:43Account number. Fine. Okay. And then let
- 1:47:47me call account service dot blog
- 1:47:50account. Pass the account number. Yeah.
- 1:47:54In the catch block log dot error.
- 1:47:58Okay. and error blocking account E.get
- 1:48:02message.
- 1:48:04Yeah. At Kafka listener and topics
- 1:48:10what
- 1:48:11fraud dot detected.
- 1:48:15Yeah. So I guess my account service is
- 1:48:19about to finish. Okay. Just one thing
- 1:48:22remaining that is application dot you
- 1:48:24know properties file. So controller
- 1:48:27DTO's and all the entities enum
- 1:48:30repository
- 1:48:32and service event consumer and service.
- 1:48:34Fine. Now let's configure our
- 1:48:36properties.
- 1:48:38So spring dot
- 1:48:41application dot name. Okay. So account
- 1:48:46service and then data source.
- 1:48:51Okay.
- 1:48:53So URL JDBC
- 1:48:56MySQL.
- 1:48:58Okay. And localhost 3306.
- 1:49:02Fine. And let's create our first
- 1:49:06database for our account service. Okay.
- 1:49:10So let's say account DB. Okay. Also
- 1:49:13let's uh add a property create database
- 1:49:18if not
- 1:49:20not exist
- 1:49:23equals true.
- 1:49:26Okay.
- 1:49:28Yeah. Then username. So my username is
- 1:49:33root
- 1:49:35password. My password is you know root.
- 1:49:38You can just enter your own uh MySQL
- 1:49:41password. Okay. and driver
- 1:49:44class name that is com dot MySQL dot CJ
- 1:49:50dot
- 1:49:52uh JDBC dot driver.
- 1:49:58Okay fine. Now next is JPA
- 1:50:02hibernate and DDL auto. So update. Okay.
- 1:50:09and then show SQL
- 1:50:13true fine then dialect. Okay. So
- 1:50:18properties dot hibernate
- 1:50:22dot dialect. Okay. So
- 1:50:26just go to this uh you know search and
- 1:50:31classes type my SQL
- 1:50:35dialect. Click here and this is the you
- 1:50:39know MySQL dialect class file. Okay. So
- 1:50:44copy full path or dot hibernate dialect
- 1:50:47dot MySQL dialect. Okay. Close this.
- 1:50:53Paste it here. Dot MySQL
- 1:50:57dialect. H. Okay. Fine. Now our Kafka
- 1:51:01properties. So Kafka dot
- 1:51:05bootstrap
- 1:51:07servers
- 1:51:09localhost
- 1:51:119092.
- 1:51:12Okay. Then consumer.
- 1:51:16Okay. So group ID. Yes. So let's say
- 1:51:21group ID. Let's keep it as account
- 1:51:24service group. Okay. A single group. We
- 1:51:28are consuming two events.
- 1:51:31Fine. Then auto
- 1:51:35offset reset.
- 1:51:39So earliest
- 1:51:42H. Okay. And then key value D
- 1:51:45serializer. Okay. So
- 1:51:51key D serializer. Okay. It is
- 1:51:54org.apache.
- 1:51:57Kafka common. Okay. Then serialization
- 1:52:03dot string
- 1:52:06d serializer.
- 1:52:10Fine. Similarly, value d serializer.
- 1:52:12Okay. Key d serializer and value
- 1:52:16d serializer.
- 1:52:19Fine. So it is spring framework or dot
- 1:52:23spring
- 1:52:24framework.
- 1:52:27Okay. dot kafka
- 1:52:30dots support
- 1:52:32dot serializer dot json d serializer.
- 1:52:39Yes. Okay. Then properties
- 1:52:43then spring
- 1:52:46json.
- 1:52:49Okay. Then
- 1:52:51trusted then packages.
- 1:52:55Okay. So yeah and
- 1:53:00use
- 1:53:02type
- 1:53:04headers
- 1:53:06let me set it as false
- 1:53:09and payload package value
- 1:53:15default.
- 1:53:17Okay type. Okay. So our payload
- 1:53:23you know of type map.
- 1:53:26Okay. So packages java dot util dot
- 1:53:32hashmap.
- 1:53:34Fine. Okay. Now producer.
- 1:53:39Yes. Producer.
- 1:53:43Okay. Let me just copy paste these two.
- 1:53:46Okay. So producer
- 1:53:50now here it should be key serializer
- 1:53:53instead of d serializer. Okay.
- 1:53:57And here to a string serializer.
- 1:54:01Oh JSON
- 1:54:04d serializer. Uh sorry serializer.
- 1:54:08Okay fine. Now port.
- 1:54:11So
- 1:54:16here server dot port it is running on
- 1:54:218081
- 1:54:22and
- 1:54:24management then endpoints then
- 1:54:29web.
- 1:54:31Okay then exposure
- 1:54:35and include what?
- 1:54:39Health info.
- 1:54:42Okay. Fine. So this is what our account
- 1:54:45service is completed. Okay. Account
- 1:54:48service is completed. Everything is
- 1:54:50done. Yeah. And all our methods. Now
- 1:54:56comes our next
- 1:54:59crucial service that is transaction
- 1:55:03service. The heart of our banking
- 1:55:05system. Okay. Yeah. So without wasting
- 1:55:09much time, let's start. Let's go. Okay.
- 1:55:13So let's start with our transaction
- 1:55:16entity.
- 1:55:17Okay.
- 1:55:19Transaction
- 1:55:21entity. Fine. And
- 1:55:25entity then table
- 1:55:29name
- 1:55:31transactions.
- 1:55:33Fine. Then my Lombok annotations at all
- 1:55:38arcs at no arcs. Fine. Now what all
- 1:55:42fields we should add in our transaction
- 1:55:45entity. So the first is private string
- 1:55:49ID.
- 1:55:51Okay. ID and should be UU ID. UU ID.
- 1:55:57Okay. Fine. Now next we need to add uh
- 1:56:02both user account number. Okay. So
- 1:56:05private string first my sender account
- 1:56:10number. Okay. Then private string and
- 1:56:15receiver
- 1:56:17account number.
- 1:56:20Okay fine. Then comes my uh obviously
- 1:56:26amount. So big decimal amount. Then we
- 1:56:30have
- 1:56:31uh
- 1:56:33you know what type. Okay. So transaction
- 1:56:39type
- 1:56:40and we are going to create a enum for
- 1:56:44that because we have a bunch of values.
- 1:56:47Let me just create it. Okay. So Java
- 1:56:53enum. Okay. transaction type.
- 1:56:57Fine. And and what one more enum will
- 1:57:02create that is transaction status.
- 1:57:08Okay. Status.
- 1:57:10Fine. So let me also create that.
- 1:57:16Okay.
- 1:57:18Fine. Now next let me add uh
- 1:57:22description.
- 1:57:25Okay then uh yeah so a string and if
- 1:57:30transition got failed then failure
- 1:57:35reason
- 1:57:36obviously then private string reference
- 1:57:41number. Okay.
- 1:57:44Reference number fine. And finally our
- 1:57:49two fields that is local date time
- 1:57:53created at
- 1:57:55and private local date time updated at.
- 1:58:01No not updated at instead we'll write it
- 1:58:05here as completed at.
- 1:58:11Yeah. Transaction completed should not
- 1:58:14be updated. Yes or no. Now let's add you
- 1:58:18know few validations. So
- 1:58:22column nullable
- 1:58:24false. Okay
- 1:58:27fine. And same thing nullable false. For
- 1:58:30amount I need to add two more properties
- 1:58:33that is precision.
- 1:58:35So let's keep it as 15 and scale two.
- 1:58:38Okay. Now transaction type. Okay. So it
- 1:58:41is enumerated string and column nullable
- 1:58:46false. Same thing goes with my another
- 1:58:48enum. Okay. And description. Okay.
- 1:58:54Yeah. Created at at creation timestamp.
- 1:58:58Fine. Okay. Now let's you know add the
- 1:59:03fields in our
- 1:59:05enums. Okay. So our transaction entity
- 1:59:08is completed. Fine. transaction status.
- 1:59:11Yeah, this one is important. So, first
- 1:59:14let me add the comments and also show
- 1:59:19you the life cycle flow. Okay, so
- 1:59:23transaction life cycle flow that is just
- 1:59:28just pay attention here. First is
- 1:59:30pending. Okay, from pending to
- 1:59:34processing, okay, and at last completed.
- 1:59:39Okay. So this case happens in case of
- 1:59:46clean
- 1:59:47transaction. Yes or no? So once the
- 1:59:50transaction is clean, nothing fraud,
- 1:59:53nothing suspicious activity detected. So
- 1:59:56directly from uh pending processing and
- 2:00:00then completed
- 2:00:03you know money
- 2:00:05credit
- 2:00:06to
- 2:00:08receiver. Yeah. Okay. Fine. The next is
- 2:00:13our
- 2:00:15pending processing and if something
- 2:00:20suspicious found. Okay. So our next
- 2:00:23status is pending verification.
- 2:00:28Okay. And suspicious
- 2:00:33detected. Yes or no? Yeah. And if
- 2:00:36suspicious detected then bank needs to
- 2:00:40verify with the user. Yes or no? So if
- 2:00:44user verified then we'll complete the
- 2:00:48transaction. Completed.
- 2:00:50Okay. verified.
- 2:00:53Yeah. OTP. Okay. Phone call and other
- 2:00:57medium. And if not verified.
- 2:01:01Okay. So if verified and if not
- 2:01:04verified, okay, then we will flag the
- 2:01:09transaction and we will block the
- 2:01:12account. Okay. Saga. Saga
- 2:01:16refund.
- 2:01:18Yes or no? Definitely we need to refund
- 2:01:21to the sender back now if the
- 2:01:24transaction is failed you know
- 2:01:26processing failed. Okay. So yeah it
- 2:01:30comes here these two inside our
- 2:01:33verification
- 2:01:35and yeah flagged.
- 2:01:39Okay already mentioned. So these are our
- 2:01:42status and flow. Fine. So pending then
- 2:01:47processing then pending
- 2:01:51verification.
- 2:01:54Okay. Then
- 2:01:56completed. Okay. Then failed. Then
- 2:02:02flagged. Yes or no. Okay. Fine. Now next
- 2:02:07comes our transaction type. So you'll
- 2:02:10know that transaction type deposit you
- 2:02:14know withdrawal
- 2:02:17fine
- 2:02:19and
- 2:02:22uh you know payment
- 2:02:24okay and transfer
- 2:02:27yeah for transaction type okay so here
- 2:02:31is our entity part is completed now
- 2:02:34let's
- 2:02:36implement our DTO so DTO dot But now I
- 2:02:39need to uh put the transfer request.
- 2:02:44Okay. So transfer
- 2:02:47request. Okay. And in response
- 2:02:52what transaction response.
- 2:02:56Yeah.
- 2:02:58Fine. Okay. So now where is my
- 2:03:01transaction entity? Let me put them side
- 2:03:03by side as I need to add the fields from
- 2:03:06that two. Yeah, transfer request first.
- 2:03:10Let me add Lombog data. All arcs, no
- 2:03:14arcs.
- 2:03:16Okay,
- 2:03:17so first I need what to initiate the
- 2:03:21transfer. I need my sender account
- 2:03:24number.
- 2:03:26Okay, I need my receiver account number
- 2:03:32and amount.
- 2:03:34Definitely I need amount
- 2:03:37and let's add description.
- 2:03:42Okay, fine. Yeah. So at not blank. Okay.
- 2:03:50And uh if it is blank then we'll display
- 2:03:53a message that is sender
- 2:03:57account number is required.
- 2:04:02Yes. Okay.
- 2:04:04Similarly, let me just
- 2:04:07copy this
- 2:04:10and here
- 2:04:13receiver account number is required in
- 2:04:15case of amount not null. Okay. Message
- 2:04:22uh amount is required. Okay. And also
- 2:04:28amount should be in positive. Okay. So
- 2:04:32message
- 2:04:34and amount
- 2:04:37must be positive.
- 2:04:41Yes. Fine. Okay.
- 2:04:45Next is our transaction response.
- 2:04:51Okay. So first add data. Okay. Then add
- 2:04:59all arcs. at no hearts.
- 2:05:02Okay. Now in response, let me just take
- 2:05:06all of them.
- 2:05:09Okay. Yeah. So let me remove
- 2:05:15all these annotations.
- 2:05:19Okay. I don't need them.
- 2:05:26Okay. Fine. ID. Sender. Account number.
- 2:05:29receiver amount type status description
- 2:05:31failure reference number created at and
- 2:05:36what
- 2:05:37completed at. Okay, now let me build the
- 2:05:42skeleton. Okay, so quickly first
- 2:05:47controller and transaction
- 2:05:51controller.
- 2:05:52Yeah.
- 2:05:54Then service
- 2:05:57transaction
- 2:05:59service. Okay. Then repository
- 2:06:04dot
- 2:06:06transaction
- 2:06:08repository.
- 2:06:10Okay. Extends JPA
- 2:06:15repo. Okay.
- 2:06:17And what? Oh, one second. One second. It
- 2:06:21should be
- 2:06:23interface.
- 2:06:25Okay. Yeah. So, transaction.
- 2:06:31Okay. And
- 2:06:34here a string. Yeah.
- 2:06:38Next is our client.
- 2:06:41Okay. Client dot account service client.
- 2:06:47Fine. Uh also I need the radius here too
- 2:06:52because I need my OTP to be stored in
- 2:06:58the radius.
- 2:07:00Okay. And uh I guess we have not added
- 2:07:04the radius dependency here.
- 2:07:08Yeah, let me check open F. No, fine.
- 2:07:12We'll add it uh once we'll start coding
- 2:07:15our you know uh that verify OTP and uh
- 2:07:19fraud detection part. Okay. But for now
- 2:07:22let's keep as it is. Okay. And what else
- 2:07:27remaining? Repository service entity
- 2:07:29DTO.
- 2:07:33Okay. So config dot radius
- 2:07:38config H. Yeah.
- 2:07:41Fine. So now let's start adding our
- 2:07:45endpoints. Okay. So rest controller and
- 2:07:50request
- 2:07:51mapping. Okay.
- 2:07:54API
- 2:07:56v1 then
- 2:07:59oops where I'm writing transactions.
- 2:08:04Okay. Then add slf 4j. Okay. Also, let
- 2:08:10me just take account service.
- 2:08:14Yeah,
- 2:08:16account service. Account service.
- 2:08:19Oh, sorry. Transaction service. I
- 2:08:22forgot. Transaction
- 2:08:24service.
- 2:08:26Okay, transaction service. Okay, for
- 2:08:28that I need to add required arcs
- 2:08:31constructor. Fine. Now, let's add here
- 2:08:34endpoints. forget one thing to create
- 2:08:38one class. Okay, you know in the service
- 2:08:42the actual decider the actual decider
- 2:08:45class. Okay, that is my transaction
- 2:08:50uh event consumer
- 2:08:54H here only I'm going to consume the
- 2:08:58event
- 2:09:00okay and then proceed according to that.
- 2:09:03Yeah. So now again let's continue with
- 2:09:07our transaction controller. Okay. Fine.
- 2:09:10Okay. So public and then uh response
- 2:09:17response entity. Okay. I am returning
- 2:09:21what transaction response.
- 2:09:24Okay. And our first endpoint is transfer
- 2:09:30at valid. Fine. and add request body.
- 2:09:37Okay. And transfer request
- 2:09:41request.
- 2:09:45Fine. Yeah.
- 2:09:47And
- 2:09:49here I am returning what? Response
- 2:09:54entity dot
- 2:09:57status. HTTP
- 2:10:00status dot
- 2:10:03you know created okay dot body and let
- 2:10:09me call our transaction
- 2:10:12service dot
- 2:10:15transfer and I'll pass the request okay
- 2:10:22it is my post mapping okay oops post
- 2:10:27mapping mapping
- 2:10:29and
- 2:10:32transfer.
- 2:10:34Okay, the next is our public and
- 2:10:38response entity returning the
- 2:10:41transaction response and get
- 2:10:44transaction.
- 2:10:46Okay, I'm getting the transaction
- 2:10:50using my transaction ID. Transaction ID.
- 2:10:55Okay, fine. So return response entity
- 2:11:02okay dot okay and my transaction service
- 2:11:08dot get transaction let me pass the
- 2:11:13transaction
- 2:11:14ID okay
- 2:11:18and this is get mapping okay transaction
- 2:11:23ID fine now let me just copy copy and
- 2:11:29paste it here. So the next is get
- 2:11:33transaction
- 2:11:35history. Okay. And
- 2:11:38I'll get the transaction history
- 2:11:40definitely using user account number.
- 2:11:45Okay. So user account number and here to
- 2:11:51transaction service get transaction
- 2:11:54history.
- 2:11:56Let me pass account number
- 2:12:01here too. Account number and
- 2:12:06account.
- 2:12:08Yeah. Okay. The next comes our OTP
- 2:12:11verification endpoint.
- 2:12:14Okay. Important one. So this is what I'm
- 2:12:17talking about. Public and response
- 2:12:21entity. Okay.
- 2:12:24in return 1 second 1 second so here it
- 2:12:29should be list
- 2:12:32okay because I'm getting
- 2:12:36uh history transaction history based on
- 2:12:38account number so I'll get the list of
- 2:12:43transaction for this account number def
- 2:12:46so definitely uh it is the list of
- 2:12:49transaction response
- 2:12:52okay Yeah, fine. Now let's come to here
- 2:12:56response entity and transaction response
- 2:13:00and verify
- 2:13:02OTP.
- 2:13:03Okay. Or uh yeah verify OTP and add path
- 2:13:09variable.
- 2:13:11So the first is no not a string account
- 2:13:16number transaction ID. Okay. and second
- 2:13:22is request param.
- 2:13:25Okay. And a string OTP.
- 2:13:31Fine. So
- 2:13:33also let me just add the loggings log
- 2:13:36dot info that OTP
- 2:13:41and verification
- 2:13:44request
- 2:13:47transaction.
- 2:13:49Okay. and
- 2:13:52transaction ID. Yeah. And return
- 2:13:57response entity.
- 2:13:59Okay. Dot. Okay.
- 2:14:03Transaction service dot verify
- 2:14:09OTP.
- 2:14:10Okay. And let me pass
- 2:14:14transaction ID and OTP.
- 2:14:20Fine.
- 2:14:23Post mapping
- 2:14:26H. Okay. And here
- 2:14:30it is transaction
- 2:14:34ID. Okay. And verify. Okay. So these are
- 2:14:40all our endpoints. Fine. Now let's
- 2:14:44implement these all one by one. Okay.
- 2:14:46And uh I want you to keep an eye on
- 2:14:52verify OTP and my transfer.
- 2:14:56Okay. Endpoints. Fine. So my transaction
- 2:15:00service
- 2:15:02and add service at SLF 4J. Okay. And now
- 2:15:09let me take private final and
- 2:15:13transaction repository. Okay,
- 2:15:16transaction repository. So for that let
- 2:15:20me add one more annotation that is
- 2:15:23required ask arxs constructor. Now let's
- 2:15:26create our Kafka topic variables. Okay
- 2:15:31like transaction initiated, transaction
- 2:15:33completed, transaction refunded. Okay.
- 2:15:37So private static final a string and
- 2:15:45transaction
- 2:15:47initiated
- 2:15:49topic definitely we need
- 2:15:54transaction
- 2:15:55dot initiated.
- 2:15:58Okay. And now let me just
- 2:16:04copy and paste.
- 2:16:06Okay.
- 2:16:08Fine.
- 2:16:10Yeah. So the second one is transaction
- 2:16:14dot
- 2:16:16completed and transaction dot refunded
- 2:16:23here too. Transaction dot completed
- 2:16:28and transaction dot refunded.
- 2:16:32Okay. Fine. Yeah. So now let's implement
- 2:16:37our first method that is transaction.
- 2:16:42Okay. And response and
- 2:16:46method name is transfer. Yeah, I'm
- 2:16:49getting transfer request.
- 2:16:53Transfer request and request. Okay, the
- 2:16:57comments are most important.
- 2:17:00So it is our saga step number one.
- 2:17:04Okay. Initiate
- 2:17:08transfer. Fine. And deducts from sender
- 2:17:15via fain client. Okay. Then saves
- 2:17:22transaction
- 2:17:24as processing.
- 2:17:27Fine.
- 2:17:28and then publish
- 2:17:32event to Kafka for fraud check.
- 2:17:38Okay,
- 2:17:40fine. And then returns.
- 2:17:43See why I'm writing these comments?
- 2:17:46Because I want you to implement first at
- 2:17:49your own by just reading these comments.
- 2:17:53Pause the video, okay? and try to
- 2:17:56implement at your own first. Step number
- 2:17:58one, initiate transfer. Then deduct
- 2:18:01balance via FIN. Okay. Account service
- 2:18:03client. F client. Then uh
- 2:18:07what? Save transition as processing.
- 2:18:10Okay. Repository we have. Fine.
- 2:18:13Okay. And then publish event to Kafka.
- 2:18:17Okay. So Kafka template and then return.
- 2:18:20Okay. Let's implement it one by one all
- 2:18:24the steps. So
- 2:18:26first let me add some bloggings that
- 2:18:31saga start. Okay. And transfer from this
- 2:18:37account to this account and this much is
- 2:18:42the amount. So from request dot sender
- 2:18:47to uh receiver. So get receiver and
- 2:18:51amount.
- 2:18:53Okay. Now
- 2:18:56um deduct from sender. Okay. So via f
- 2:19:00client account service client. Okay. And
- 2:19:04uh you all know that we have deduct
- 2:19:08method in our account service main java
- 2:19:12service and account service account
- 2:19:15controller. Actually I need direct
- 2:19:18balance. Yeah. So you just come here and
- 2:19:22my transaction service account service
- 2:19:24client. Yeah.
- 2:19:27In this client, let me just
- 2:19:31you know returning the string. Okay.
- 2:19:35A string and entire method
- 2:19:39deduct balance.
- 2:19:42Fine. And full path put mapping.
- 2:19:46Oh 1 second. So it should be interface.
- 2:19:50Yeah.
- 2:19:52So put mapping
- 2:19:54fine and the entire path.
- 2:19:59Okay.
- 2:20:00Fine.
- 2:20:02Oops.
- 2:20:06And
- 2:20:08here
- 2:20:10our account number and deduct.
- 2:20:16Okay. Yeah. Done. And here
- 2:20:22faint client
- 2:20:24then
- 2:20:25name. So from account service and URL.
- 2:20:32Okay. So what
- 2:20:37account dot service dot URL?
- 2:20:42Okay. That's it. Yes or no? and
- 2:20:46semicolon I'm missing. Okay, back to our
- 2:20:50account service transaction service.
- 2:20:53Okay, and here
- 2:20:56let me what
- 2:20:59saga is step number one deduct
- 2:21:06from
- 2:21:08sender. Yes. So also let me just get the
- 2:21:13object private final account service
- 2:21:18client and account service client
- 2:21:23in the account service client we have
- 2:21:24just now created
- 2:21:28okay dot deduct balance okay and let me
- 2:21:32pass so we need to deduct from sender
- 2:21:34okay so request dot get sender account
- 2:21:38number and amount So request dot get
- 2:21:42amount.
- 2:21:45Yes, that's it. Okay.
- 2:21:49Yeah. Fine. Now next step is save
- 2:21:52transaction as processing. Okay. So
- 2:21:56transaction.
- 2:21:59Okay.
- 2:22:02Transaction.
- 2:22:05Fine.
- 2:22:06And transaction equals new transaction.
- 2:22:12And now what?
- 2:22:15Let's set the properties set the you
- 2:22:17know fields
- 2:22:19values. So transaction dot set and
- 2:22:24sender account number. Okay. So request
- 2:22:27dot get sender account number. Similarly
- 2:22:30transaction dot receiver get receiver
- 2:22:33and then uh amount. Okay. Then type.
- 2:22:38Okay. So, transaction dot set type.
- 2:22:42Okay. So,
- 2:22:45let it be transfer. Okay. And status.
- 2:22:50Okay. So, transition dot set status. I
- 2:22:55have mentioned here processing. Okay.
- 2:22:57So, because currently it is uh you know
- 2:23:00in the processing state.
- 2:23:02Okay. Fine.
- 2:23:05And then also transaction dot
- 2:23:10set description get description.
- 2:23:14Yes. And reference number also. So set
- 2:23:19reference number. So let me just
- 2:23:22generate it. UID dot random do.2.
- 2:23:27Okay. Now let's save. So transaction and
- 2:23:33saved transaction equals
- 2:23:36transaction repository dot save and
- 2:23:41transaction.
- 2:23:43Yes, also blog dot info
- 2:23:48and transaction saved as processing.
- 2:23:55Fine. and saved
- 2:23:59transaction dot get ID H. Now our next
- 2:24:05step that is publish okay publish event
- 2:24:09to Kafka.
- 2:24:11So we need to publish initiated event.
- 2:24:14Here
- 2:24:16what you know uh we are doing the transa
- 2:24:19transaction has been initiated.
- 2:24:22Okay. Deduct balance just initiated.
- 2:24:25Okay. processing. So we need to you know
- 2:24:29publish the initiated event. For that I
- 2:24:32have already created oh not created fine
- 2:24:35let me create that too. So event dot
- 2:24:40transaction
- 2:24:42initiated event.
- 2:24:45Okay. Add data
- 2:24:49at all arcs. No arcs.
- 2:24:53Fine. So let me just add the values
- 2:24:59uh sorry fields that is private string
- 2:25:02first transaction ID okay second is uh a
- 2:25:08string
- 2:25:09sender
- 2:25:11account number.
- 2:25:15Okay,
- 2:25:17next is private string
- 2:25:21uh receiver account number then okay big
- 2:25:25decimal amount and finally let me add
- 2:25:29description also
- 2:25:33okay yeah back to our service and here
- 2:25:37let me just you know get that
- 2:25:40transaction initiated event okay event
- 2:25:45equals
- 2:25:47new transaction initiated event and let
- 2:25:50me set the values.
- 2:25:52Okay, so my save transaction let me get
- 2:25:55that and set here.
- 2:25:58Okay.
- 2:26:00Dot get id first is ID only. Right.
- 2:26:05ID account amount and the description.
- 2:26:07Okay.
- 2:26:10So save transaction dot sender account.
- 2:26:14Save transaction dot receiver.
- 2:26:18Okay. Then uh amount. Okay. And then
- 2:26:22description. Okay. Fine. Then now let me
- 2:26:27you know send. So I need to get the
- 2:26:31Kafka template
- 2:26:34private final
- 2:26:37Kafka template. Okay. Here
- 2:26:42object H Kafka template
- 2:26:46dot send dot send. Okay. and the event
- 2:26:51topic is transaction initiated event.
- 2:26:56Okay, fine.
- 2:26:58Then saved transaction.get ID and event.
- 2:27:03Then let me just add log.info
- 2:27:07and uh our
- 2:27:10saga is step number two. Okay. So fine
- 2:27:16this is what our
- 2:27:19saga is step number two. Okay publish
- 2:27:24for fraud
- 2:27:27check.
- 2:27:29So saga is step number two that is
- 2:27:33transaction
- 2:27:35initiated
- 2:27:37event
- 2:27:39published.
- 2:27:42Yeah.
- 2:27:46Saved transaction dot get ID and I need
- 2:27:51to return what I'm returning. I'm
- 2:27:53returning the transaction response.
- 2:27:56Okay. But I have transaction. Okay. So I
- 2:28:00need to convert it map
- 2:28:03to
- 2:28:05uh response. Let me pass saved
- 2:28:08transaction. Okay. Quickly let me create
- 2:28:12this method returning the transaction
- 2:28:15response map to response. Okay. Also let
- 2:28:18me rename it as transaction. Fine. Now
- 2:28:23uh let me just take transition response
- 2:28:28response new transition response and
- 2:28:31then set the values. So response
- 2:28:36dot set id transaction dot get ID. Okay.
- 2:28:40Similarly with all the fields. So let me
- 2:28:42just do fast forward. Okay. Fine. And
- 2:28:45then return response. Okay. So our
- 2:28:49transfer method is implemented. Okay.
- 2:28:53Returning the transaction response. Now
- 2:28:55let's implement other endpoints. Get
- 2:28:59transaction. Get transaction history.
- 2:29:01Okay. Don't think about verify OTP.
- 2:29:04Okay. Why? Because we are going to
- 2:29:07implement this endpoint at last.
- 2:29:12Why? See here the name indicating that
- 2:29:15verify OTP
- 2:29:18that means at last once uh my
- 2:29:22transaction initiated. Okay. Then fraud
- 2:29:24detection service does his check. Okay.
- 2:29:28Detected some suspicious activity. then
- 2:29:30my notification service. Okay. Then um
- 2:29:35sends the OTP notification and finally
- 2:29:39we will verify the OTP by entering the
- 2:29:43OTP. If it is verified then okay. If not
- 2:29:46verified then proceed forward. Yes or
- 2:29:50no? That's why I'm telling you this is
- 2:29:53the most complex. Okay. And uh the most
- 2:29:59crucial part heart of banking system
- 2:30:03center point of banking system. So
- 2:30:05please do not miss a single part of our
- 2:30:09transaction service till we completes.
- 2:30:13Okay. So let's implement our next
- 2:30:15endpoint that is get transaction. Fine.
- 2:30:18And then get transaction history. Okay.
- 2:30:21So
- 2:30:23yeah here public
- 2:30:28okay and I'm returning transaction
- 2:30:31response get transaction
- 2:30:35okay and what I'm getting I'm getting
- 2:30:39the transaction ID
- 2:30:43fine okay okay so first let me get the
- 2:30:47transaction
- 2:30:49okay
- 2:30:50Um
- 2:30:52yeah. So transaction also also directly
- 2:30:57let me pass return
- 2:31:00map to response. Okay. And transaction
- 2:31:04repository dot find by ID. Okay.
- 2:31:10Find by ID. Okay. and
- 2:31:17dot
- 2:31:19or else throw.
- 2:31:22And new
- 2:31:24runtime exception
- 2:31:28that is
- 2:31:33transaction
- 2:31:35not found.
- 2:31:38Okay.
- 2:31:40transaction ID. That's it. Done. Okay.
- 2:31:45Next is our get transaction history
- 2:31:51public. And I'm returning the list of
- 2:31:56transaction response
- 2:31:59transaction.
- 2:32:01One second. Yeah. Response and get
- 2:32:07transaction
- 2:32:09history.
- 2:32:11Okay. And I'm getting the account
- 2:32:14number. Yeah. So
- 2:32:18in this method we need to create a query
- 2:32:22method. We need to query my database my
- 2:32:25repository. Okay. So what return and
- 2:32:29transaction repository
- 2:32:32then I need history the complete
- 2:32:36transaction history for a particular
- 2:32:39user okay whose account number is this
- 2:32:43okay so
- 2:32:46it's like
- 2:32:48find by find by
- 2:32:53transaction history
- 2:32:55okay so Yeah. Find by sender account
- 2:33:01number.
- 2:33:02Okay. And uh then order by order by
- 2:33:10created at
- 2:33:12descending. Yes. Comes on the top. Okay.
- 2:33:16Recent one. And we'll pass the account
- 2:33:19number here. Okay. Fine. Let's do it.
- 2:33:23So my transaction repository transaction
- 2:33:28repository
- 2:33:30and here
- 2:33:32list.
- 2:33:34Okay. Of
- 2:33:37transaction.
- 2:33:39One second. Let me import it. Okay. And
- 2:33:44find by
- 2:33:47sender account number. Okay. and order
- 2:33:54order by created at
- 2:33:58dc
- 2:34:00a string and account number.
- 2:34:06Yes. Okay.
- 2:34:09Fine. Let me just copy that.
- 2:34:13And here
- 2:34:16dot find by sender account number order
- 2:34:20by created at dsc
- 2:34:23and I'm passing account number dot
- 2:34:27stream dot map okay this
- 2:34:32map to response okay dot collect and to
- 2:34:37list
- 2:34:41okay fine
- 2:34:42Done. Yeah. Now everything is done.
- 2:34:46Okay. Uh regarding our endpoints.
- 2:34:51Fine. So
- 2:34:53transfer get transaction get transaction
- 2:34:56history. Okay. Don't think about verify
- 2:34:59OTP for now. We'll implement but at last
- 2:35:02I already told you. Yeah. After
- 2:35:05notification service. So I am taking you
- 2:35:08with the flow.
- 2:35:10Okay. The flow is The flow is uh
- 2:35:13currently
- 2:35:15currently
- 2:35:17my user. Okay. My user initiated
- 2:35:22a transaction
- 2:35:24and we have published a event. That's
- 2:35:27it. That is my current flow.
- 2:35:30Okay. Like this.
- 2:35:33My user initiated a transaction. That's
- 2:35:36it.
- 2:35:38Okay. Next is transaction service
- 2:35:42published. So my fraud detection service
- 2:35:45consume this event and start checking.
- 2:35:49So next we need to jump to our fraud
- 2:35:52detection service.
- 2:35:55So let's do it
- 2:35:58you know so what else remaining which is
- 2:36:00independent.
- 2:36:02Okay. So my account service client
- 2:36:07radius config at uh later we'll just see
- 2:36:10controller okay response request is done
- 2:36:15everything is done initiated
- 2:36:17repository
- 2:36:19okay the one thing remaining that is my
- 2:36:22application yml so let's do it you know
- 2:36:25uh quickly and then we'll jump directly
- 2:36:27into our next fraud detection service
- 2:36:30okay fine so Spring
- 2:36:34application
- 2:36:36name
- 2:36:38transaction
- 2:36:40service.
- 2:36:41Okay. Then data source
- 2:36:45URL. So URL is JDBC
- 2:36:50MySQL
- 2:36:52and
- 2:36:53localhost 3306
- 2:36:56and
- 2:36:58transaction DB. Okay. Another database.
- 2:37:02Let me add a property create
- 2:37:06database if not exist equals true. Okay.
- 2:37:12Then my username root my password root.
- 2:37:18You can enter your own username password
- 2:37:22driver class name that is com dot mysql
- 2:37:27dot cj dot
- 2:37:30jdbc dot driver. Okay. Then jpa
- 2:37:37then hibernate
- 2:37:39ddl auto
- 2:37:42update.
- 2:37:44Then what? Show SQL. So true. Then
- 2:37:51properties.
- 2:37:53Okay. Then uh what? Hibernate.
- 2:37:58Okay. Dot dialect.
- 2:38:02Fine. So we have already added dialect
- 2:38:06here in our application
- 2:38:10yml of account service. Okay. Let me
- 2:38:13directly copy and paste.
- 2:38:16Okay. Or else just go to this search and
- 2:38:20classes. Type MySQL
- 2:38:24dialect. Click on this class and copy
- 2:38:28the entire path. Org.hibernate
- 2:38:31dot dialect dot MySQL dialect. Okay. And
- 2:38:36paste it here. Fine. Next is my Kafka
- 2:38:40properties. Kafka dot bootstrap
- 2:38:45servers. Okay. So localhost
- 2:38:509092.
- 2:38:52Fine. Then consumer. So I've already
- 2:38:55added in my account service. Let me
- 2:38:57directly copy and paste consumer and
- 2:39:01producer
- 2:39:03you know till producer.
- 2:39:06Okay.
- 2:39:07Fine. Yeah. Okay. Next, next comes our
- 2:39:14server port. Okay. 8082.
- 2:39:18Fine. And then our uh faint client
- 2:39:24properties. So account service URL.
- 2:39:29Okay. On which URL? My account service
- 2:39:31is running. So account service URL and
- 2:39:35HTTP
- 2:39:37localhost
- 2:39:3980
- 2:39:4281. Okay. And finally my actuator
- 2:39:47property
- 2:39:49management
- 2:39:51then endpoints
- 2:39:54web
- 2:39:56exposure
- 2:39:59include
- 2:40:02health and info done. So now in this
- 2:40:06what else is remaining only one thing
- 2:40:08remaining that is our verify OTP. Okay.
- 2:40:12So I want you to visualize the flow.
- 2:40:16Okay. The flow is transaction service.
- 2:40:20Fine. So just just visualize that uh
- 2:40:24there is some user sitting and uh just
- 2:40:27click on the send money transaction
- 2:40:29initiated according to our code
- 2:40:31initiated initiated status is uh
- 2:40:34processing and we have published that
- 2:40:37event to Kafka.
- 2:40:40Now the flow will go to my fraud
- 2:40:43detection service because fraud
- 2:40:46detection service going to consume this
- 2:40:49event and start checking the transaction
- 2:40:53for any suspicious activity. Okay. So
- 2:40:56let's code our fraud detection service
- 2:41:00first. Let me
- 2:41:03uh you know service and
- 2:41:07fraud
- 2:41:09detection event consumer
- 2:41:13h consumer event consumer okay let's
- 2:41:17consume that yeah
- 2:41:20you know see this is luxury what I'm
- 2:41:23teaching you this is luxury
- 2:41:26I'm teaching you in a flow I can also do
- 2:41:29like you know uh this is my transaction
- 2:41:31service here is my controller let's
- 2:41:33implement that
- 2:41:36but if I'll follow that process then
- 2:41:39nothing will gets into your head nothing
- 2:41:42you'll ask me like why we are uh you
- 2:41:45know verifying the OTP first where from
- 2:41:47where my OTP is coming okay then uh you
- 2:41:52know uh why we are doing this fraud
- 2:41:54detection service consuming event at
- 2:41:56last it should be at the first that is
- 2:41:59why I'm going with the flow my user
- 2:42:03initiated. Next is transaction service
- 2:42:06consuming. Okay. Yeah. So it is public
- 2:42:11void and consume
- 2:42:15transaction
- 2:42:17initiated.
- 2:42:19Yeah. And payload.
- 2:42:22Okay. Payload map.
- 2:42:27Fine. a string
- 2:42:31object and payload.
- 2:42:36Okay,
- 2:42:38fine. So now first let me add some
- 2:42:42loggings. Okay. Log dot info and
- 2:42:49what received
- 2:42:52transaction
- 2:42:54for fraud check.
- 2:42:58Okay.
- 2:43:00Yeah. And payload dot get transaction
- 2:43:04ID. Okay. Now let me open my try catch.
- 2:43:10Okay. Here. And uh
- 2:43:15okay let me so also let me create fraud
- 2:43:18detection service.
- 2:43:22Fraud detection service. Okay fine.
- 2:43:29And
- 2:43:30here
- 2:43:33private final
- 2:43:36fraud detection service. Fraud detection
- 2:43:38service.
- 2:43:40Add required asks in that we are going
- 2:43:44to create one method that is check
- 2:43:48transaction.
- 2:43:51Okay. We'll pass the payload.
- 2:43:54Okay. And this check transaction is
- 2:43:57responsible to do the checks for this
- 2:44:00transaction. I'm getting the payload for
- 2:44:03okay from my transaction.initiated
- 2:44:06Initiated event at Kafka listener
- 2:44:11topic is what? H transaction dot
- 2:44:17initiated.
- 2:44:19Okay. And group ID
- 2:44:23fraud
- 2:44:25detection
- 2:44:28group.
- 2:44:30Yes or no? Yes. Also let me add the
- 2:44:34comments that is
- 2:44:39oops one second.
- 2:44:43Yeah. So
- 2:44:46listens to
- 2:44:49transaction dot initiated
- 2:44:53topic.
- 2:44:56Okay. And every transaction
- 2:45:00goes
- 2:45:02through
- 2:45:05fraud
- 2:45:07check
- 2:45:09before
- 2:45:11completing
- 2:45:13yes or no. Okay. Yeah. Now let me create
- 2:45:17this uh method check transaction in our
- 2:45:20fraud detection service. So
- 2:45:24service then
- 2:45:27sl 4j
- 2:45:30h and public void check transaction I'm
- 2:45:35getting the payload right
- 2:45:38so
- 2:45:40map string payload okay so at first one
- 2:45:47second okay
- 2:45:51fine So at first let me get my
- 2:45:54transaction ID. Okay, transaction ID
- 2:45:58payload dot get transaction ID and then
- 2:46:02let me get account number.
- 2:46:07Okay, so
- 2:46:10let me just copy and paste and here
- 2:46:14my sender account number.
- 2:46:19Yes. Okay. And I need amount. So big
- 2:46:23decimal and amount equals new big
- 2:46:28decimal. Fine. And payload dot get
- 2:46:34amount dot to a string. Okay. Now also I
- 2:46:39need to fetch the real balance.
- 2:46:45Okay. balance
- 2:46:47from account service.
- 2:46:51Okay. So if you remember in the account
- 2:46:54service we have one more method that is
- 2:46:59get balance. Okay. So that's why in the
- 2:47:02fraud detection service I need to fetch
- 2:47:04the balance. Okay. Now why I need it?
- 2:47:08Because for the fraud check. Okay.
- 2:47:11Suppose if uh any suspicious or uh any
- 2:47:14three times five times you know uh the
- 2:47:18amount initiated from the sender's
- 2:47:21account so I need to check okay this is
- 2:47:24what the balance and uh 90% or five
- 2:47:26times of the balance is being initiated
- 2:47:29so there is something suspicious so I
- 2:47:32need to check with the user yes or no
- 2:47:35yeah so so let's fetch it and uh how to
- 2:47:38fetch it via faint client
- 2:47:41So
- 2:47:43here client dot account
- 2:47:48service client. Okay. And interface.
- 2:47:52Fine. So my account service controller.
- 2:47:57Okay. You just come here and here.
- 2:48:02Now
- 2:48:05get balance. Yeah. So big decimal. Okay.
- 2:48:09Big decimal. And here get balance.
- 2:48:14Fine. Now
- 2:48:19get mapping. Okay. And my full path API
- 2:48:26v1 accounts.
- 2:48:30And
- 2:48:34what account number and balance?
- 2:48:40Okay. Done. Also fe client
- 2:48:45name is from account service.
- 2:48:49Okay. And
- 2:48:52URL
- 2:48:54is
- 2:48:56what? account dot service dot URL.
- 2:49:02Yeah,
- 2:49:04let's get back to our uh notification uh
- 2:49:07sorry fraud detection service.
- 2:49:10So my yeah fraud detection service and
- 2:49:14let me also
- 2:49:17first take the object of that. So
- 2:49:19private final account
- 2:49:22service client.
- 2:49:24Okay, also for that I need to add
- 2:49:28required arcs constructor.
- 2:49:31Now let me get the balance.
- 2:49:34Okay, so big decimal and sender balance
- 2:49:40equal
- 2:49:41account serviceclient dot get balance
- 2:49:43and
- 2:49:45I'm passing the account number. Okay,
- 2:49:49fine. Now next log dot info and checking
- 2:49:57transaction.
- 2:50:00Okay. Account.
- 2:50:04Okay.
- 2:50:06Amount
- 2:50:08and balance.
- 2:50:11H fine. So transaction transaction ID
- 2:50:15account number amount amount and balance
- 2:50:19sender balance. Fine. Now I need to
- 2:50:24perform
- 2:50:26fraud checks or perform suspicious
- 2:50:29activity whatever.
- 2:50:32Okay. And let me pass account number
- 2:50:36amount and sender balance.
- 2:50:40Okay. And let me return.
- 2:50:45Okay. So let me return you know if fraud
- 2:50:51detected. So I'll return true or false
- 2:50:54that means boolean. Oh let me do one
- 2:50:57thing. Let me create a model. Okay. Here
- 2:51:00in uh itself
- 2:51:02model
- 2:51:04dot
- 2:51:06fraud check result. Yes.
- 2:51:11at data at all arcs no arcs in that let
- 2:51:18me add private boolean
- 2:51:22fraud and private string reason H this
- 2:51:28is good this is the best one okay
- 2:51:33and here I'm returning the fraud
- 2:51:37check result
- 2:51:40and result.
- 2:51:42Okay,
- 2:51:44fine. So, fraud check result contains is
- 2:51:48fraud in boolean. If it is fraud, yes or
- 2:51:51no. And if it is fraud, then reason of
- 2:51:54that. Yeah. So, I'm returning the entire
- 2:51:57object. Fine. It contains everything.
- 2:52:01H this is good. Fine. And then we'll
- 2:52:04check if result
- 2:52:08okay dot is fraud
- 2:52:12then then what any suspicious activity
- 2:52:17detected.
- 2:52:19Okay then what? So log dot info and
- 2:52:24first suspicious
- 2:52:28activity detected.
- 2:52:31Okay. And where in account?
- 2:52:37Okay.
- 2:52:41And reason.
- 2:52:44Okay. What is the reason? Yes.
- 2:52:47Now requesting OTP verification.
- 2:52:52Fine. we need uh to request an OTP
- 2:52:57and ask user to enter is this is you
- 2:53:01only or some other fraudster is doing
- 2:53:04something else. Okay. So account account
- 2:53:08number and reason is result dot get
- 2:53:13reason. Fine. Now we are going to
- 2:53:17publish an event. Which event? Tell me
- 2:53:21which event. So we are inside result dot
- 2:53:25is fraud condition that means we have
- 2:53:29detected something suspicious.
- 2:53:32So which event we are going to publish
- 2:53:35that is verification
- 2:53:39required.
- 2:53:41Yes or no? So we need to verify with the
- 2:53:44user that is it you who initiated this
- 2:53:48transaction? Yes or no? Yeah, in case if
- 2:53:53our fraud detection service detected
- 2:53:57something suspicious,
- 2:53:59in that case we need to
- 2:54:01uh publish this event verification dot
- 2:54:06required.
- 2:54:08Yeah. Now my transaction service consume
- 2:54:12this event. My transaction service gets
- 2:54:14to know that okay fraud detection
- 2:54:17service detected something suspicious.
- 2:54:20So now let's consume that.
- 2:54:24Okay fine. Now uh we have discussed that
- 2:54:28we need to verify the user how via OTP.
- 2:54:35Yes. So my uh transaction service
- 2:54:37consume this event and
- 2:54:41generate OTP.
- 2:54:44Yes. Generate OTP. Fine. And then again
- 2:54:49publish
- 2:54:52event. Which event? OTP dot generated.
- 2:54:58Okay. Yeah. So this is what our event.
- 2:55:03Now
- 2:55:04this event is going to consume by my
- 2:55:09notification service.
- 2:55:12Why? Because see anyhow
- 2:55:17we need to notify to the user then only
- 2:55:20user can add the OTP. Yes or no? If
- 2:55:24verification is required if bank needs
- 2:55:27to verify the user then bank will send
- 2:55:30the OTP. How? Via SMS via email. Okay.
- 2:55:37So once OTP generated now my
- 2:55:40notification service consume
- 2:55:43this event.
- 2:55:45Okay and call API which API verify OTP.
- 2:55:53If you remember you know we have
- 2:55:57discussed that in our transaction
- 2:56:01controller
- 2:56:02uh this verify OTP. I told you that we
- 2:56:07are going to code this uh endpoint at
- 2:56:10the end. So here we are going to verify
- 2:56:13the OTP whatever OTP our system
- 2:56:16generated and whatever OTP my user
- 2:56:19entered. If yes then proceed with the
- 2:56:22transaction. Okay. And if no then then
- 2:56:26what? Then block the account flag the
- 2:56:31transaction.
- 2:56:33Understood? So this is our entire flow
- 2:56:36and we are going to code it step by step
- 2:56:40and that is why I haven't coded this
- 2:56:46verify OTP yes or no okay yeah let's
- 2:56:50start coding the remaining part so now
- 2:56:56is fraud detected okay suspicious
- 2:56:58activity detected okay so let me
- 2:57:02uh string
- 2:57:04object and
- 2:57:07verification verification event. We are
- 2:57:10going to publish new hashmap.
- 2:57:14Okay. Then verification event. First let
- 2:57:17me put the transaction ID. Okay. Then
- 2:57:20verification event. Let me put the
- 2:57:22account number. Okay. And then amount.
- 2:57:25Okay. That's good. And verification
- 2:57:28event dot let me put the reason. Okay. I
- 2:57:32need the reason. Fine. Reason and result
- 2:57:38dot get reason. Fine. So,
- 2:57:44okay. Okay. Okay. So I need to create my
- 2:57:47topic variable private static final
- 2:57:53a string and
- 2:57:56verification
- 2:58:00you know required
- 2:58:04topic.
- 2:58:07So verification.
- 2:58:10Okay. Verification dot required.
- 2:58:16Yes. Okay. Yeah. Let me just copy this.
- 2:58:20And now I'm going to send. Okay. I need
- 2:58:24that too. Private
- 2:58:27final Kafka
- 2:58:29template.
- 2:58:31Okay. a string object and
- 2:58:36Kafka template.
- 2:58:39Okay,
- 2:58:41so Kafka template dot send and
- 2:58:44verification required topic and also
- 2:58:50transaction ID. Yeah,
- 2:58:54good good. Okay, so this is our first
- 2:58:57case. If result dot is fraud. Okay. If
- 2:59:01anything detected else if nothing
- 2:59:04detected then what? Then clean proceed
- 2:59:07with the transaction. Okay. So that
- 2:59:10means transaction is clean. Fine. So log
- 2:59:15dot info and my transaction clean. Okay.
- 2:59:22So here map. Okay. and uh transaction
- 2:59:30clean event.
- 2:59:33Okay,
- 2:59:37fine. So clean event let me put the
- 2:59:41transaction ID. Okay. And uh transaction
- 2:59:45clean event dot let me put is fraud uh
- 2:59:49you know value. So is fraud
- 2:59:55that is false.
- 2:59:57Okay. And transaction
- 3:00:01dotput and reason as null. Yeah. If
- 3:00:06everything is clean then no reason.
- 3:00:10Now let me just Kafka template dot send.
- 3:00:13So also let me you know create the
- 3:00:15variable for that.
- 3:00:18Okay. So
- 3:00:23h
- 3:00:26fraud check
- 3:00:30clean result
- 3:00:35topic. Okay.
- 3:00:38So
- 3:00:42uh fraud dot check. Clean.
- 3:00:48Yes.
- 3:00:51Let me just
- 3:00:54uh you know
- 3:00:58send.
- 3:01:00Okay. And transaction ID and transaction
- 3:01:05clean event. Yeah. So this is done.
- 3:01:12Okay.
- 3:01:13Uh and now we need to implement this
- 3:01:17method perform fraud checks. Okay. So we
- 3:01:20are going to perform generally three uh
- 3:01:24fraud checks three patterns. Okay. And
- 3:01:28uh yeah so that's it. Proceed according
- 3:01:31to that. So let's implement one by one.
- 3:01:34So private okay and I'm returning fraud
- 3:01:39check result. Okay. perform fraud check
- 3:01:43and account number, amount and sender
- 3:01:45balance.
- 3:01:46So, private fraud check result perform
- 3:01:50fraud check. Okay. And a string account
- 3:01:55number then big decimal amount and then
- 3:02:01big decimal
- 3:02:03sender balance.
- 3:02:06Okay. Fine. Now I want you all to focus
- 3:02:11on my screen.
- 3:02:13Okay.
- 3:02:15Yeah. Just look at here. So in this
- 3:02:19fraud check we are going to generally
- 3:02:22perform uh three checks or I can say
- 3:02:26three patterns.
- 3:02:29Yes. The first pattern is velocity
- 3:02:33check.
- 3:02:34Velocity check. Okay. Because as we
- 3:02:38discussed that you know fraudster
- 3:02:41fraudster don't withdraw manually.
- 3:02:45Yeah. Instead what they'll do is they
- 3:02:48run a script and which fires multiple
- 3:02:53transaction in seconds.
- 3:02:56Yes or no? Yeah. So what we're going to
- 3:02:59check is
- 3:03:01um if suppose we detected let's say five
- 3:03:05transaction or 10 transaction maybe 20
- 3:03:08transaction in 1 minute
- 3:03:11okay 60 seconds. So let's take the least
- 3:03:15one five transaction if it detected
- 3:03:18then we'll detect
- 3:03:22that as suspicious and that two in the
- 3:03:2660 seconds because generally normal user
- 3:03:30won't do it. Okay. Now the fact is see
- 3:03:34we are not blocking the account.
- 3:03:37It is just a suspicious activity
- 3:03:40detected. Yeah. So what we need to do is
- 3:03:43we need to get back to the user. Yes.
- 3:03:47And uh ask user for the verification via
- 3:03:51OTP. Is this you? If it is then let's
- 3:03:54proceed. No worries.
- 3:03:57Yes or no? But there is another case.
- 3:04:00Okay. And that comes our you know uh
- 3:04:03second and third pattern. Fine. So yeah
- 3:04:07the second pattern is let's say a user
- 3:04:11has initiated a transaction okay and
- 3:04:15that transaction is three times or five
- 3:04:20times
- 3:04:22of his average transaction he usually
- 3:04:27make.
- 3:04:29So what my second pattern will do is
- 3:04:32first we'll get the average transactions
- 3:04:37of that particular user.
- 3:04:39Okay, let's say 50
- 3:04:43$45. Okay, or in any currency. Fine. And
- 3:04:48uh let's say $100 65 35 10 120 56 and so
- 3:04:56on. Okay. So we'll calculate the average
- 3:05:00and then
- 3:05:02uh on any day suppose my user initiated
- 3:05:06a transaction of 10,000
- 3:05:1012,000
- 3:05:12okay 5,000
- 3:05:1515,000 so that is quite you know
- 3:05:20suspicious
- 3:05:21marked
- 3:05:24okay and we'll transfer
- 3:05:26that uh you know request to our
- 3:05:29verification window. Please verify the
- 3:05:32user that the uh you know transaction
- 3:05:36initiated by our genuine user or some
- 3:05:40fraud. Okay. Because we have detected
- 3:05:42you know unusual
- 3:05:44uh bigger amount transactions.
- 3:05:48Yes or no? And our pattern number three
- 3:05:52is uh you know similar to the second
- 3:05:54pattern that is uh balance uh 90% or
- 3:05:5850%. Okay. So balance check that means
- 3:06:02if suppose a user initiated a transfer
- 3:06:04okay and uh that transaction is 90%
- 3:06:10okay of
- 3:06:12user's balance. Okay. So that is you
- 3:06:16know suspicious.
- 3:06:18Okay. Yeah. So let's implement it and uh
- 3:06:24our
- 3:06:26pattern number one that is
- 3:06:29velocity check.
- 3:06:32Okay. Also we need three variables you
- 3:06:35know because uh we need to what uh we
- 3:06:39need to just tell our methods that
- 3:06:45uh these are the fixed values. If
- 3:06:48exceeded then make it suspicious. Okay,
- 3:06:51I mean to say let's say in case of
- 3:06:53velocity check if suppose user
- 3:06:58initiated five transaction. Okay, five
- 3:07:01transaction in 60 seconds. So this five
- 3:07:04we need to give it explicitly.
- 3:07:07Okay, we can give any number five 6 7.
- 3:07:10So we'll handle it from our resources
- 3:07:14application yml. Okay. Similarly, if
- 3:07:17suppose uh transition is three times or
- 3:07:20five times greater, okay, then mark it
- 3:07:23as a suspicious. So three or five we
- 3:07:26need to give via variable. Okay.
- 3:07:30And similarly 90% or 95%. Okay. Yeah. So
- 3:07:38let's do it. The first is our uh you
- 3:07:42know velocity check. If also let me
- 3:07:46create a method velocity
- 3:07:49or
- 3:07:51is
- 3:07:53velocity
- 3:07:56exceeded.
- 3:07:58Okay. And let me pass the account
- 3:08:01number.
- 3:08:02Fine. Then I'll return new fraud check
- 3:08:07result. Okay. And fraud check result
- 3:08:09contains two field that is fraud. Yes,
- 3:08:12it is fraud. Okay. Or maybe suspicious.
- 3:08:16Fine. So, we have already named it as a
- 3:08:18fraud. Okay. Let's keep it. It might be.
- 3:08:22Okay. Yeah. And the reason is too many
- 3:08:28transactions
- 3:08:30in
- 3:08:3260 seconds.
- 3:08:35Yes. Okay.
- 3:08:39and
- 3:08:41velocity
- 3:08:44limit
- 3:08:46exceeded.
- 3:08:49Okay.
- 3:08:52H yes. Similarly the next pattern is our
- 3:08:57uh
- 3:09:00pattern number two that is amount check.
- 3:09:06F
- 3:09:09is amount
- 3:09:13suspicious. Okay.
- 3:09:16And let me pass account number and
- 3:09:19amount.
- 3:09:21Okay. So this two method will implement
- 3:09:24in that we are going to check. Okay.
- 3:09:28Like uh we'll find out the average.
- 3:09:31Okay. And everything else. So we'll
- 3:09:34return new. Let me just copy and
- 3:09:39paste it here.
- 3:09:41Okay. And uh the fraud is true. The
- 3:09:44reason is what
- 3:09:47unusual
- 3:09:50transaction amount.
- 3:09:53Okay.
- 3:09:55And
- 3:09:57exceeds
- 3:09:59let's say three times 3 X.
- 3:10:04Okay. your
- 3:10:06average.
- 3:10:08Okay. Fine. And our pattern number three
- 3:10:15that is
- 3:10:18balance check. Okay.
- 3:10:22Fine. So if transaction transaction
- 3:10:26amount is 90%. Okay. So let's say sender
- 3:10:30balance dot compare to. Okay. And big
- 3:10:36decimal big decimal
- 3:10:39dot zero H. Yeah. Okay. Greater than
- 3:10:45zero
- 3:10:47and
- 3:10:50and is balance
- 3:10:54check failed. Okay. So this is two a
- 3:10:58method will create. Let me pass sender
- 3:11:01balance and amount.
- 3:11:04Okay. So if it is then we'll return new
- 3:11:09and same thing
- 3:11:12h just
- 3:11:15the reason is
- 3:11:17what the reason transaction
- 3:11:20exceeds
- 3:11:2290%
- 3:11:25of account balance.
- 3:11:29Yeah. Okay. Now let's implement one by
- 3:11:32one. Okay. And also also if uh nothing
- 3:11:37gets satisfied. Okay. All get failed
- 3:11:40that means transition is clean. Okay. So
- 3:11:43return new
- 3:11:46fraud check result false and null.
- 3:11:51Yes. Okay. So fraud is uh you know false
- 3:11:56no fraud and there is no reason okay
- 3:12:00okay fine let's implement one by one so
- 3:12:03is velocity exceeded
- 3:12:06okay
- 3:12:07private boolean is velocity exceeded and
- 3:12:12uh I'm getting a string account
- 3:12:17number
- 3:12:19okay so we going to use the radius Yes.
- 3:12:23Yes or no? Yeah. So that is the best way
- 3:12:26to keep the count a string key. Okay.
- 3:12:32So first let's create our key as fraud
- 3:12:36and velocity. Okay. And account number
- 3:12:41fine. And then count. So we'll pass the
- 3:12:46key. Okay. First let me get the radius
- 3:12:48template.
- 3:12:50private final radius template.
- 3:12:55Okay. And a string string radius
- 3:13:00template.
- 3:13:02Okay. And
- 3:13:05so here radius template dot ops for
- 3:13:08value. Okay. And dot increment increment
- 3:13:12key. Okay. So if user initiated one
- 3:13:16transaction increment one then two then
- 3:13:19three then four then five and from sixth
- 3:13:21flagged need to check the user but in 60
- 3:13:25seconds. Okay. So how to check
- 3:13:30uh we are going to set the expiry time
- 3:13:33as 60cond. Okay. Because see user can
- 3:13:36make multiple transaction in uh you know
- 3:13:39first transaction in first minute and
- 3:13:42then second minute and then uh after 2
- 3:13:44hours that is okay but in 60 seconds
- 3:13:47continuously that is suspicious. Okay.
- 3:13:50So if we'll check if count not equals
- 3:13:55not equals null. Okay. And and
- 3:14:00count
- 3:14:02equals 1.
- 3:14:05Okay, that means radius template dot
- 3:14:08expire. Fine. Let's expire. Okay. And uh
- 3:14:13this is key 60 and in seconds. Okay.
- 3:14:20Fine.
- 3:14:22Yes. Yeah.
- 3:14:24Also some loggings log.info
- 3:14:28and velocity
- 3:14:31velocity check
- 3:14:34amount.
- 3:14:36Okay. Count
- 3:14:40fine. Okay. Amount. No. Here account.
- 3:14:46Yeah. Account number. Okay. Then count.
- 3:14:50Okay. Count. And yeah, the next is count
- 3:14:56this by this. Okay, so we need to
- 3:15:00provide what we need to provide, we need
- 3:15:02to provide uh on which count we need to
- 3:15:06flag. Okay, for that let's create the
- 3:15:09variable and handle it via application
- 3:15:12yiml. Uh yeah, yl int max
- 3:15:17transactions
- 3:15:18per minute.
- 3:15:21Okay. And add value.
- 3:15:26Okay.
- 3:15:29Yeah.
- 3:15:31So fraud dot max transactions
- 3:15:38per minute.
- 3:15:42Okay. And also let me handle it
- 3:15:48resources. And here
- 3:15:51fraud
- 3:15:53dot max transaction per minute. Okay. So
- 3:15:57we are allowing five. Yeah. Five
- 3:16:00transaction my user can do per minute.
- 3:16:03Okay. And from the very sixth
- 3:16:05transaction immediately you will get uh
- 3:16:09you know OTP. And if it is uh genuine
- 3:16:13then you can just verify and proceed
- 3:16:14with the transaction else
- 3:16:17get the refund back fraud detection
- 3:16:19service and here we'll provide that
- 3:16:22variable max transaction per minute.
- 3:16:24Okay. And then we are returning count
- 3:16:28first count not equal
- 3:16:31null. Okay. And and
- 3:16:36what
- 3:16:37count greater than if count greater than
- 3:16:41max transaction per minute 6 7 8 9 10
- 3:16:44whatever then yeah it uh it hits true
- 3:16:47and uh fine too many transactions okay
- 3:16:52next is is amount suspicious account
- 3:16:54number and amount I'm getting let's
- 3:16:57implement this too private
- 3:16:59boolean
- 3:17:01is amount suspicious string string
- 3:17:04account number and big decimal
- 3:17:10amount.
- 3:17:11So first let me you know
- 3:17:15just set the key. So average key okay
- 3:17:19because see here
- 3:17:22this is uh is amount suspicious. So what
- 3:17:26we're doing we are first checking the
- 3:17:31amount the initiated transaction is
- 3:17:35uh three times of average. So first we
- 3:17:39need to get the average average key
- 3:17:42first let me you know just set it. So
- 3:17:44let's say fraud and
- 3:17:48average
- 3:17:50amount. Okay. and account number. And
- 3:17:53also let me pass a string
- 3:17:58average. Okay. Radius template dot ops
- 3:18:02for value. Okay. And dot get what key
- 3:18:08average key H. Got it. Fine. Now, now
- 3:18:13first let me pre-check that if coming as
- 3:18:17null then uh it is safe. radius template
- 3:18:21dot ops for value dot will set our key
- 3:18:26and amount dot to string. Okay. And
- 3:18:30we'll return it as false.
- 3:18:33Yeah. Okay. All good.
- 3:18:38Fine. And then uh we need to get the
- 3:18:42average. Okay. So big decimal and
- 3:18:47average amount equals new big decimal.
- 3:18:52Okay.
- 3:18:53Average str.
- 3:18:56Fine. And then also let me get the
- 3:19:00threshold
- 3:19:02big decimal. And this is what our
- 3:19:05threshold. Okay. Threshold means average
- 3:19:09amount dot multiply. Okay. and multiply
- 3:19:14with what? So multiply with what? Uh
- 3:19:17again private
- 3:19:20double and
- 3:19:22suspicious
- 3:19:25amount
- 3:19:27multiplier.
- 3:19:30Okay. And here add value
- 3:19:36find
- 3:19:39dot
- 3:19:41suspicious
- 3:19:45amount
- 3:19:47multiplier.
- 3:19:50Okay, let me just handle it right away
- 3:19:56here.
- 3:19:57suspicious amount multiplier which is uh
- 3:20:01h if the amount is let's say five times
- 3:20:05okay five times if the initiated amount
- 3:20:07is five times of average then we will
- 3:20:11you know
- 3:20:13uh mark it as suspicious. So average
- 3:20:15amount
- 3:20:18okay multiply big decimal dot value of
- 3:20:23and suspicious amount multiplier
- 3:20:27okay
- 3:20:30correct correct
- 3:20:32and then we will update
- 3:20:36running average. So how to update big
- 3:20:41decimal
- 3:20:43new average
- 3:20:46equals average amount dot add amount.
- 3:20:52Okay. Dot divide divide what? Big
- 3:20:56decimal.
- 3:20:58Okay. Big decimal dot value of two H.
- 3:21:04And the scale is two. and rounding mode
- 3:21:09half up. Half up. Okay, fine. And then
- 3:21:14radius radius template dot ops for
- 3:21:18value. So we need to set it set. Okay.
- 3:21:22And
- 3:21:24is new average dot to a string. Yes.
- 3:21:29Some loggings log.info and so amount
- 3:21:32check. Okay. amount.
- 3:21:37Fine. And then threshold.
- 3:21:44Uh
- 3:21:46threshold. Okay.
- 3:21:49And what? Suspicious.
- 3:21:54Fine. So amount is amount. Threshold.
- 3:21:59Threshold. And suspicious is we need to
- 3:22:02compare. Okay. So amount
- 3:22:05amount dot compare to with threshold
- 3:22:09okay greater than zero.
- 3:22:12Okay whatever comes and finally we will
- 3:22:16return amount dot compare to threshold
- 3:22:21greater than zero.
- 3:22:24Yes fine. This is what our is amount
- 3:22:28suspicious pattern. Okay. Next one. So
- 3:22:32the last one is is balance check field.
- 3:22:36Okay. And I'm getting sender balance and
- 3:22:38amount. Okay. So private
- 3:22:44private and
- 3:22:47boolean
- 3:22:48is balance check field
- 3:22:51big decimal
- 3:22:53center balance and amount. Here what we
- 3:22:56are checking that if transaction amount
- 3:23:00you know is uh 90% of balance.
- 3:23:05Okay. So 90% of balance we need to
- 3:23:08multiply balance dot multiply
- 3:23:13and uh 90%. Okay. So this is what in a
- 3:23:16variable we'll get just like uh
- 3:23:18suspicious amount multiplier and
- 3:23:20whatever. Okay. and then uh yeah we'll
- 3:23:24uh compare it.
- 3:23:26Okay. So,
- 3:23:29big decimal. Okay. And maximum allowed.
- 3:23:33Maximum allowed equals
- 3:23:37the balance I'm getting.
- 3:23:40Okay. Center balance
- 3:23:44dot multiply H. And
- 3:23:49our third variable
- 3:23:531 second. multiplier.
- 3:23:56Okay. Private double. And this is max
- 3:24:02balance
- 3:24:04percentage.
- 3:24:07Okay.
- 3:24:09Double max balance percentage. Okay. And
- 3:24:12here add
- 3:24:14value.
- 3:24:18Fine. fraud dot max
- 3:24:22balance
- 3:24:24percentage.
- 3:24:26Fine. Let me handle it.
- 3:24:32Okay. And 90%. Okay. So 0.90.
- 3:24:37Okay. We'll multiply it by this number.
- 3:24:42Yes. So,
- 3:24:46oh, once what?
- 3:24:50Yeah.
- 3:24:52Okay. So, sender balance dot multiply
- 3:24:57and big decimal dot value of and
- 3:25:02whatever just now created max balance
- 3:25:05percentage
- 3:25:07H. So, this is what max allowed.
- 3:25:10Okay. Yeah. Now log dot info and balance
- 3:25:16check
- 3:25:18amount.
- 3:25:22Okay.
- 3:25:24And max allowed.
- 3:25:27Fine. And suspicious.
- 3:25:32Yes or no?
- 3:25:35Okay.
- 3:25:37Fine. So amount is amount max allowed is
- 3:25:42max allowed and suspicious is let's
- 3:25:45compare it. So amount dot compare to max
- 3:25:49allowed greater than zero. Yeah. And
- 3:25:51that two we need to return. So amount
- 3:25:54dot compare to max allowed greater than
- 3:25:59zero.
- 3:26:02Yes. Fine. So this is our pattern number
- 3:26:05three implementation. Okay. So, here is
- 3:26:08our fraud detection service completed.
- 3:26:11Fine. Now, now uh we are on our second
- 3:26:14stage. Okay. The first stage is
- 3:26:18you know transaction service user
- 3:26:20initiated this transaction and publish
- 3:26:23the event transaction initiated topic.
- 3:26:26This is consumed by our fraud detection.
- 3:26:29H fraud detection here.
- 3:26:33Okay. Consumed transaction.initiated
- 3:26:35initiated and checks the transaction.
- 3:26:38Fine. Here in the service checking the
- 3:26:40transaction. Okay. Now if something got
- 3:26:44flagged and result dot is fraud gets
- 3:26:48true. Okay. Among these three patterns
- 3:26:50something got flagged and result. Fraud
- 3:26:53gets true. Then here comes and here my
- 3:26:56fraud detection again publishing an
- 3:26:58event which is verification required.
- 3:27:03Verification required. And that is going
- 3:27:06to consume by our again transaction
- 3:27:09service. So now
- 3:27:12let's come here and let's consume that.
- 3:27:16Yes. Okay. Let's do that. See how you
- 3:27:19know the flow is going. That is the pure
- 3:27:22luxury. Okay. For that uh you can
- 3:27:25subscribe my channel. Yeah. Okay. Let's
- 3:27:28do it. And also if you want to thank me
- 3:27:31then uh there is a button just adjacent
- 3:27:34to like or share button you can just tap
- 3:27:37on that and you can thank me. Okay fine.
- 3:27:41So let's proceed with our event
- 3:27:44consumer. Okay
- 3:27:46public
- 3:27:48void and consume what verification
- 3:27:54required.
- 3:27:56Okay. And add payload
- 3:28:00map.
- 3:28:02Yeah.
- 3:28:04A string object and
- 3:28:08payload.
- 3:28:11Okay. Fine. So now what we are consuming
- 3:28:15fraud detection service. Okay. And
- 3:28:20if fraud is detected then we need to
- 3:28:23verify verify required topic and it is
- 3:28:26verification dot required. Okay we need
- 3:28:30to verify and
- 3:28:32uh via OTP. Yeah. So first we need to
- 3:28:36generate OTP.
- 3:28:39Okay. Yeah.
- 3:28:43Also let me just write the comments as
- 3:28:47consume
- 3:28:49verification dot required. Okay. And uh
- 3:28:55generate OTP
- 3:28:58and
- 3:29:00ask user to
- 3:29:03verify. Okay.
- 3:29:07Fine.
- 3:29:08Now let me open my try catch.
- 3:29:13Okay. And first let me get transaction
- 3:29:18ID. Transaction ID equals
- 3:29:22Okay. Fine. Payload that uh get
- 3:29:24transaction ID. Then uh I need account
- 3:29:28number.
- 3:29:30Account number.
- 3:29:33Okay. Fine. And then I need reason.
- 3:29:39Okay. Yeah.
- 3:29:43So log info. Okay. One second. Let me
- 3:29:47add the annotation
- 3:29:49at service at slf4j.
- 3:29:53Yeah. Okay.
- 3:29:55log dot
- 3:29:58info and
- 3:30:01verification
- 3:30:04required.
- 3:30:06Okay.
- 3:30:07Transaction
- 3:30:10and uh reason.
- 3:30:14So
- 3:30:16what transaction ID and reason. Okay.
- 3:30:21Now first let me get the transaction.
- 3:30:25Okay. So transaction and
- 3:30:31transaction equals transaction
- 3:30:33repository. Okay. So for that private
- 3:30:38final
- 3:30:39and transaction
- 3:30:45transaction repository.
- 3:30:48Okay. Also let me add required asks
- 3:30:52constructor. Fine. So transaction
- 3:30:55repository dot find by ID. We have the
- 3:30:59ID. Okay. Transaction ID. Let me pass
- 3:31:01it.
- 3:31:03Dot or else throw
- 3:31:08new runtime exception.
- 3:31:10Okay. And
- 3:31:13transaction not found.
- 3:31:17Okay. transaction ID.
- 3:31:21Fine.
- 3:31:23Now, now what? Now we need to add an
- 3:31:27item potency guard. Okay. So, what is
- 3:31:31that? uh item potency guard because in
- 3:31:36order to prevent
- 3:31:41two time
- 3:31:43credit
- 3:31:46to my
- 3:31:49receiver or to my sender.
- 3:31:55Yes. So see we are uh you know verifying
- 3:32:02the user
- 3:32:04only if the status is in processing.
- 3:32:11If the transaction status is in
- 3:32:13processing, if suppose my status is not
- 3:32:17processing that means either either uh
- 3:32:23you know transaction has been already
- 3:32:25completed
- 3:32:26or the transaction has been flagged
- 3:32:31that means you know uh blocked out.
- 3:32:34Okay. So the status should be in the
- 3:32:36processing
- 3:32:38otherwise there is chance of twice
- 3:32:41credit to my receiver or sender. Okay
- 3:32:45fine. I hope you got the point. So
- 3:32:49let me just add that check. Okay.
- 3:32:55Yeah. So if
- 3:32:58transaction
- 3:33:01dot get status
- 3:33:05not equals
- 3:33:08not equals processing. Okay. In that
- 3:33:12case we need to send first warning.
- 3:33:16Okay. uh transaction
- 3:33:21not
- 3:33:23processing
- 3:33:26skipping
- 3:33:29okay and transaction ID fine and from
- 3:33:32here we'll return
- 3:33:36okay
- 3:33:38next let's go forward okay so if it is
- 3:33:41processing then uh we need to generate
- 3:33:44generate sixdigit
- 3:33:48OTP. Okay. Yeah. So, a string OTP equals
- 3:33:54a string dot format. Okay. And uh
- 3:34:01formatting starts fine.
- 3:34:04and uh 06 you know length is uh six
- 3:34:07digit and then d that means decimal
- 3:34:11integer and uh what math dot random
- 3:34:18okay and times 900,000
- 3:34:23okay plus
- 3:34:27100,000 okay
- 3:34:31fine okay and uh also
- 3:34:37int.
- 3:34:38Okay,
- 3:34:41fine. So I got my sixdigit OTP. Now I
- 3:34:46need to store OTP in radius.
- 3:34:51Okay. And uh I'll put my OTP expiry
- 3:34:57expires in 5 minutes. Let me first you
- 3:35:02know set up the key OTP key equals and
- 3:35:08verification
- 3:35:11OTP. Okay. Then what? Then transaction
- 3:35:16ID. Okay. And then radius template. So I
- 3:35:22also need here private final radius
- 3:35:27template. One second. We haven't added
- 3:35:32uh radius dependency in our transaction
- 3:35:34service.
- 3:35:36Okay.
- 3:35:41I guess no. Yeah. Not. So first let me
- 3:35:45add
- 3:35:48in the fraud detection. We have yes we
- 3:35:50have spring data radius. Okay. Let me
- 3:35:53just copy
- 3:35:56and
- 3:35:59paste it here.
- 3:36:03Yeah,
- 3:36:04fine.
- 3:36:08Okay,
- 3:36:10let it reload.
- 3:36:13Yeah, done. So now back to our event
- 3:36:16consumer and radius template.
- 3:36:23Okay, radius template. Fine.
- 3:36:28Let me get that radius template.
- 3:36:31Okay. Dot opts for value. Okay. And dot
- 3:36:36set
- 3:36:38what? OTP key. OTP. Okay. And expiry.
- 3:36:44So, let me also set the OTP expiry
- 3:36:48variable. private
- 3:36:51static final long and OTP
- 3:36:57expiry
- 3:37:00minutes.
- 3:37:01Okay. Equals five.
- 3:37:05Fine. So here reduce template set OTP
- 3:37:09key OTP and OTP expiry minutes and in
- 3:37:15minutes. Okay.
- 3:37:18Yeah, fine. And now we need to update it
- 3:37:22status.
- 3:37:24Okay, because we have added transaction
- 3:37:26status processing to pending
- 3:37:29verification.
- 3:37:31Yes, that's uh what we have discussed.
- 3:37:35Yeah, see how the flow is going. Okay,
- 3:37:38so transaction
- 3:37:41dot set status as pending verification.
- 3:37:47Okay. And then we need to save it. So,
- 3:37:49transaction repository save. Okay. And
- 3:37:53then log dot info.
- 3:37:57Okay. And OTP generated
- 3:38:01for
- 3:38:03transaction
- 3:38:06and expires.
- 3:38:09Okay. Expires in this much minute. Okay.
- 3:38:15So transaction ID and OTP expiry
- 3:38:19minutes. Fine. Now I need to what? I
- 3:38:24need to notify
- 3:38:26notify
- 3:38:29user. Okay. Yes or no? So once once my
- 3:38:34bank system
- 3:38:37okay generates
- 3:38:40OTP what will be the next step?
- 3:38:45user
- 3:38:46gets the OTP on his phone
- 3:38:50via SMS or
- 3:38:54email.
- 3:38:56Yes or no? So we need to uh notify to
- 3:39:01the user because OTP generated. How will
- 3:39:04notify? We are going to publish
- 3:39:09an event.
- 3:39:12Okay, event like uh transaction
- 3:39:16OTP generated
- 3:39:19and that event is going to consume
- 3:39:22by our notification service
- 3:39:27and notification service calls verify
- 3:39:29OTP which we have created
- 3:39:34uh in our transaction controller. This
- 3:39:36one
- 3:39:37verify OTP
- 3:39:40getting a point. Yes or no? Okay. Yes.
- 3:39:44Fine. So let's do it. Uh okay.
- 3:39:50Transaction event consumer notify user.
- 3:39:55So let me just put the values map and
- 3:40:01okay
- 3:40:03let me rename my variable name OTP
- 3:40:06event.
- 3:40:08Now the first thing let me put as OTP
- 3:40:11event dot put
- 3:40:16and transaction ID. Okay, transaction ID
- 3:40:20then uh account number. Okay, fine. Then
- 3:40:24reason. Okay. Fine. And then I need to
- 3:40:27put OTP also. Okay. Yeah. OTP. Okay. And
- 3:40:32also amount. Okay. OTP event dot
- 3:40:38put. Okay. And amount.
- 3:40:44Fine.
- 3:40:47payload dot
- 3:40:50get
- 3:40:52amount.
- 3:40:55Okay. Yes. So then next Kafka. Okay. Let
- 3:41:01me also get that
- 3:41:03private final Kafka
- 3:41:07template
- 3:41:09string object.
- 3:41:13Kafka template. Let me just
- 3:41:17you know
- 3:41:19Kafka template dot send.
- 3:41:22Okay. And uh
- 3:41:26Okay. So
- 3:41:30h
- 3:41:32private
- 3:41:35static final a string and
- 3:41:41transaction
- 3:41:44OTP
- 3:41:47generated
- 3:41:50topic. Okay. So transaction
- 3:41:54OTP dot
- 3:41:56generated
- 3:41:59let me copy it.
- 3:42:03Fine. And then transaction ID and
- 3:42:08OTP event
- 3:42:11H. Yeah.
- 3:42:13In the catch block, let me just add log
- 3:42:17dot error.
- 3:42:19Okay. And here
- 3:42:24error handling
- 3:42:27verification
- 3:42:30required.
- 3:42:32Okay.
- 3:42:35And e dot get message.
- 3:42:38Yeah. So this is what yes or no. Yeah.
- 3:42:42Understood. Uh OTP generated and event
- 3:42:46published. Now this this OTP generated
- 3:42:49event is going to consume by our
- 3:42:53notification. Okay. And then calls this
- 3:42:56method.
- 3:43:00This method
- 3:43:02okay fine let's do it.
- 3:43:06So my notification service yeah src main
- 3:43:12java. Okay. Let me quickly create
- 3:43:17service dot
- 3:43:19notification
- 3:43:21service
- 3:43:23and add slj
- 3:43:27at
- 3:43:29service. Okay. Yeah. Now what public
- 3:43:34void and consume
- 3:43:37OTP
- 3:43:39generated.
- 3:43:41Okay. add payload.
- 3:43:45Okay. And map
- 3:43:49a string object and payload.
- 3:43:55Yeah.
- 3:43:58Fine. Yeah. Now let me open my try
- 3:44:01catch. Okay. And here a string first.
- 3:44:06Let me get account number. Okay. string
- 3:44:10account
- 3:44:12number. Okay, account number. Then let
- 3:44:15me get the OTP. Okay, OTP equals
- 3:44:20payload dot get
- 3:44:25and OTP
- 3:44:28fine. And let me type cast it.
- 3:44:32Okay. And then let me get the
- 3:44:36transaction ID. Okay, transaction ID and
- 3:44:41then let me get the amount.
- 3:44:46Okay, so payload dot get amount dot to a
- 3:44:53string. Okay, and then reason.
- 3:45:00Okay, so reason H. Yeah, now uh send
- 3:45:07alert. Okay. So we'll implement this
- 3:45:10method. Okay. And the job of this method
- 3:45:14is to send the alert to my user. Okay.
- 3:45:19And in this method we have you know few
- 3:45:22parameters. First is subject. Okay. So
- 3:45:26subject should be transaction
- 3:45:31verification
- 3:45:33required.
- 3:45:35Okay. Verification required.
- 3:45:38Yeah. And message. So message string
- 3:45:44format. Okay. And suspicious.
- 3:45:48Okay. Suspicious
- 3:45:52activity
- 3:45:54detected.
- 3:45:56Yes. On your account.
- 3:46:00H.
- 3:46:01Okay.
- 3:46:03and
- 3:46:07reason.
- 3:46:09So reason is what percent s h okay and
- 3:46:16then then what
- 3:46:19then
- 3:46:22a transaction
- 3:46:24of percent s is pending
- 3:46:30verification.
- 3:46:32Okay. Yes or no?
- 3:46:35And and also about expiry. So
- 3:46:42your OTP is
- 3:46:48percent
- 3:46:49s and valid for 5 minutes.
- 3:46:57Yes.
- 3:46:58And
- 3:47:00uh what? Yeah. So also if this wasn't
- 3:47:07you.
- 3:47:09Okay. Then
- 3:47:12ignore
- 3:47:13this message.
- 3:47:16H. This is good. Yeah.
- 3:47:20Okay. And in the catch block log dot
- 3:47:25error
- 3:47:27and
- 3:47:30error sending OTP
- 3:47:34notification.
- 3:47:37Okay.
- 3:47:39Fine. Uh notification.
- 3:47:45Yeah. Okay. Now uh we need to you know
- 3:47:50create this method send alert. Okay. So
- 3:47:55private
- 3:47:58private void send alert. Okay. And I'm
- 3:48:03taking subject
- 3:48:06and a string message.
- 3:48:08Okay. Uh also also let me add one more
- 3:48:12thing that is account number.
- 3:48:16Yeah. Okay. So here
- 3:48:20a string account
- 3:48:24number H. Now it is good. Yeah. Okay. So
- 3:48:29we'll implement this method. Okay. Later
- 3:48:31on. First let's complete the other
- 3:48:33parts. Okay. So in this method we are
- 3:48:37going to add you know the code to send
- 3:48:42the alerts to the user. Okay. Maybe it
- 3:48:46is uh credit alert, debit alert, fraud
- 3:48:50alert, suspicious activity detector
- 3:48:53alert, OTP alert. Okay. So alerts fine.
- 3:48:56So just one method for all. Yeah. Okay.
- 3:49:01Also let me add at Kafka listener
- 3:49:05annotation. Okay. And uh the topic is
- 3:49:10yeah transaction.
- 3:49:13Ootp.enerated.
- 3:49:14generated.
- 3:49:16Okay. Yeah. Now tell me where are we in
- 3:49:19our flow? So I guess we are in our last
- 3:49:22step. Okay. So I want you all to focus
- 3:49:26here that is
- 3:49:29our notification service is consuming
- 3:49:33what this uh transaction OTP generated.
- 3:49:38That means what that means is user
- 3:49:40notified.
- 3:49:42Our user
- 3:49:44notified
- 3:49:46with
- 3:49:48OTP.
- 3:49:49The next thing is user needs to verify
- 3:49:54the transaction.
- 3:49:58Okay. And uh to do that he needs to
- 3:50:03enter the OTP
- 3:50:06and we'll match it with our stored OTP.
- 3:50:12Okay. So first thing is verify. How to
- 3:50:15verify? Simple. We have already created
- 3:50:18a method here uh you know transaction
- 3:50:22controller and our endpoint that is
- 3:50:25verify OTP. Now
- 3:50:28at this stage we need to implement this
- 3:50:33method yes or no. So this is why you
- 3:50:37know I told you the flow is really
- 3:50:39important in this project and that's
- 3:50:42what I want to make you feel how to
- 3:50:45start coding and go with the flow
- 3:50:49otherwise you know it will really become
- 3:50:51a mess. Okay. So yeah also here in the
- 3:50:57transaction event consumer we have
- 3:51:00consumed
- 3:51:02verification required. Okay. So, Kafka
- 3:51:05listener and topic
- 3:51:10verification dot required. Fine. Okay.
- 3:51:14So, now let's do our uh let's implement
- 3:51:17this verify OTP and transaction ID and
- 3:51:20OTP. Okay.
- 3:51:24Public transaction. Okay. Response and
- 3:51:29verify OTP. Fine. a string and
- 3:51:33transaction ID and a string OTP. Okay.
- 3:51:39Now, first let me add some loggings that
- 3:51:42uh OTP
- 3:51:43verification for the transaction.
- 3:51:49Okay. And transaction ID. Okay. Now
- 3:51:52first uh let me get the transaction
- 3:51:55transaction. Okay. Using ID. So
- 3:51:57transaction repository dotfind by ID.
- 3:51:59Let me pass the transaction ID and or
- 3:52:01else through. Okay. New runtime
- 3:52:04exception. New runtime exception. Okay.
- 3:52:08And transaction not found. Okay. Yes.
- 3:52:14And transaction ID. Yeah. Now the next
- 3:52:17thing is we need to get the OTP stored
- 3:52:22OTP. Then only we can you know compare
- 3:52:24it with our uh user entered OTP. So
- 3:52:27first let me you know set up the key. So
- 3:52:30OTP key equals okay what was the key?
- 3:52:33Yeah this is the key at the time we have
- 3:52:35generated our OTP and stored the OTP in
- 3:52:37our radius. You can see set okay so this
- 3:52:42is my key and uh
- 3:52:45fine and now let me get the stored OTP
- 3:52:50which is radius template. So I guess we
- 3:52:52haven't you know imported that.
- 3:52:56So private final and uh radius template.
- 3:53:02Okay. A string a string and radius
- 3:53:05template.
- 3:53:07Okay fine. The next thing is radius
- 3:53:10template dot ops forvalue dot get. Okay.
- 3:53:12Because we need to get and we'll pass
- 3:53:14the key. So here I'm getting the stored
- 3:53:16OTP.
- 3:53:18Okay. And expiry time is 5 minutes. Now
- 3:53:21we need to check if stored OTP is null
- 3:53:24coming as null that means that means OTP
- 3:53:27already expired. Okay. So in that case
- 3:53:30what we need to do is we need to
- 3:53:31compensate. Okay. And uh okay first let
- 3:53:35me you know log dot warning. Okay. And
- 3:53:38OTP expired for transaction
- 3:53:43and transaction ID.
- 3:53:46Fine. And then we will compensate
- 3:53:50transaction.
- 3:53:51Okay. Let me pass the transaction. Okay.
- 3:53:55And uh then what? Return map to response
- 3:53:59and transaction.
- 3:54:02Yes or no. Yeah. Also let me just pass
- 3:54:06some message that OTP expired. OTP
- 3:54:10expired. Okay. And transaction
- 3:54:14cancelled.
- 3:54:16Fine and amount refunded. Okay. Because
- 3:54:20see we are you know verifying the
- 3:54:23transaction because we have detected
- 3:54:25something suspicious that is why cancel
- 3:54:28and amount refunded. Okay. Second case
- 3:54:31if uh stored OTP not equals to the enter
- 3:54:35OTP. Okay. That means user entered wrong
- 3:54:38OTP. Okay. Suspicious. Fine. So stored
- 3:54:41OTP and not fine. So what we'll do is we
- 3:54:47will you know block account and refund
- 3:54:51and log dot warning. So wrong wrong OTP.
- 3:54:57Okay. And blocking account and
- 3:55:01refunding. Yeah. Transaction ID. Okay.
- 3:55:05So first radius template dotdelete.
- 3:55:07Okay. In this case if OTP entered wrong
- 3:55:09then first we'll delete. Okay. And let
- 3:55:11me pass the OTP key and then block
- 3:55:14account. Okay. And compensate.
- 3:55:19Okay. Let me pass the transaction and uh
- 3:55:23wrong OTP received. Okay. Or let's say
- 3:55:27wrong OTP entered. Yeah. So transaction
- 3:55:32cancelled.
- 3:55:34Okay.
- 3:55:36And uh
- 3:55:39account
- 3:55:41blocked for security.
- 3:55:44Yes. Fine. And then we'll return map to
- 3:55:47response and uh yeah transaction. Fine.
- 3:55:51Else else what? Else OTP. Correct. Okay.
- 3:55:55Then we need to complete the
- 3:55:58transaction. So log dot info and uh you
- 3:56:03know OTP verified. Yes. Completing
- 3:56:08transaction.
- 3:56:10Okay. And uh transaction ID. Fine. So we
- 3:56:15need to first radius template dotdelete
- 3:56:17OTP key and then complete
- 3:56:20transaction that means we need to credit
- 3:56:22to our receiver okay let me pass the
- 3:56:25transaction okay that's it and return
- 3:56:28map to response transaction so we need
- 3:56:30to implement these three methods okay I
- 3:56:33told you uh once we'll uh verify the OTP
- 3:56:35then u further we'll have three cases
- 3:56:38okay so these are our three cases in
- 3:56:40case OTP expired in case wrong OTP in
- 3:56:42case correct OTP fine so quickly you
- 3:56:45know let's implement one by one first
- 3:56:47compensate transaction okay so private
- 3:56:50void and compensate transaction I'm
- 3:56:53getting transaction transaction and a
- 3:56:55string message or maybe reason yeah okay
- 3:57:00now log dot warning okay and saga
- 3:57:04compensation
- 3:57:06yes refunding okay refunding
- 3:57:12okay and amount
- 3:57:14Yeah.
- 3:57:17Transaction dot get sender account
- 3:57:20number H. And amount is what?
- 3:57:22Transaction dot get amount. Okay. Next
- 3:57:25is uh we need to credit we need to
- 3:57:27credit money back to sender. Okay. And
- 3:57:32synchronously. Okay. So
- 3:57:36fine synchronously. So how to do it? Uh
- 3:57:40we will not do it. Actually our faint
- 3:57:42client will do it. Okay. Because you
- 3:57:45know credit balance. Okay. Our account
- 3:57:48service has one method we have created
- 3:57:50that is our yeah this one credit
- 3:57:53balance. Okay. So first where is our f
- 3:57:55client? My account controller comes here
- 3:57:57and transaction service. Yeah
- 3:58:01I'm just returning the string. Okay. And
- 3:58:05credit balance. Yes. Copy and paste it
- 3:58:08here. Okay. put mapping the entire path
- 3:58:11that means API v1 accounts.
- 3:58:16Okay. And account number credit.
- 3:58:20Okay, that's it. Now back to our uh
- 3:58:24transaction service.
- 3:58:26Okay. And uh yeah, here. So also let me
- 3:58:30just get it. Okay, already there. Fine.
- 3:58:33No worries. So credit money back to our
- 3:58:36sender. H account service client dot
- 3:58:39credit balance. Okay. And credit balance
- 3:58:41to you know back to sender. So
- 3:58:43transaction dot get sender account
- 3:58:44number and how much amount? Yeah this
- 3:58:46much. Okay that's it. Now I need to
- 3:58:49change first the status. So transaction
- 3:58:51status dot set uh dot set status as
- 3:58:55flagged. Yes or no? Okay. Flagged. Fine.
- 3:59:00And also let me you know transition dot
- 3:59:03set failure reason. you know we have one
- 3:59:05field in the transition entity as
- 3:59:06failure reason so you know what is the
- 3:59:09reason uh I'm getting the reason okay
- 3:59:12and
- 3:59:15so saga
- 3:59:17okay compensation
- 3:59:20executed
- 3:59:22and amount
- 3:59:25refunded at
- 3:59:28what
- 3:59:30local date time dot now okay and now Let
- 3:59:34me save the transaction once saved and
- 3:59:39publish
- 3:59:40refund
- 3:59:42event. Okay. Why? Because notification
- 3:59:46service will alert user that uh uh you
- 3:59:50know that uh the refund has been
- 3:59:54received just know because we need to
- 3:59:56notify user for every money movement.
- 3:59:59Okay. So you know money credited back to
- 4:00:03the sender. So definitely we need to
- 4:00:05notify. Okay. Now let me take map and
- 4:00:08what we need to put object refund event
- 4:00:13equals new hashmap. Okay. And then
- 4:00:16refund event dotput.
- 4:00:19Okay. First transaction id. Okay.
- 4:00:24Fine. And uh then what? So refund event
- 4:00:27dotput
- 4:00:29sender account number. Okay. So yeah.
- 4:00:33Then what? Refund dot put and uh amount.
- 4:00:38Okay. So transaction dot get amount.
- 4:00:41Okay. And refund event dotput
- 4:00:44reason. Okay. Fine. Then Kafka template
- 4:00:49dot send. And uh we have one topic.
- 4:00:54Yeah. Yeah. this one refunded topic
- 4:00:56transaction. Refunded. Okay.
- 4:01:00Fine. And then transaction dot get ID
- 4:01:04and refund event also log dot info and
- 4:01:09saga compensation
- 4:01:12complete. Okay. And refunded to what
- 4:01:19transaction dot get amount. Okay.
- 4:01:24and transaction
- 4:01:26dot get
- 4:01:29sender account number.
- 4:01:32Yes. So this is our uh you know
- 4:01:35compensate transaction method is
- 4:01:36implemented successfully. Next method
- 4:01:38that is block account and compensate.
- 4:01:41Okay. Compensate. Fine. Let's implement
- 4:01:44it. I'm getting the okay transaction
- 4:01:46fine. So private and void
- 4:01:51transaction. Okay. transaction and a
- 4:01:54string reason. So here in this we need
- 4:01:58not to do okay much just we need to
- 4:02:00publish fraud.detected detected event.
- 4:02:03Okay. So, publish fraud dot detected.
- 4:02:08Okay. And account
- 4:02:12account
- 4:02:15service will block account. Okay. So,
- 4:02:20map. Okay. And here let me rename my
- 4:02:23event variable that is fraud event.
- 4:02:26Okay. First let me just you know fraud
- 4:02:30event dot put transaction id. Okay let
- 4:02:33me directly copy paste. Fine. And then
- 4:02:36uh account number. Okay. So fraud event
- 4:02:39dot put account number. Okay. So
- 4:02:44transaction dot get sender account
- 4:02:46number. Fine. And then reason. So
- 4:02:50reason. And here fraud event. Okay. And
- 4:02:54uh uh yeah that's it. Now Kafka template
- 4:02:58dot send. Okay. And uh so I guess we
- 4:03:02haven't created fraud detected. Okay.
- 4:03:04Let me create that too. Private static
- 4:03:07final string fraud detected topic.
- 4:03:13Okay. So fraud
- 4:03:15dot detected.
- 4:03:18Yes.
- 4:03:20Let me just copy it. Okay. and uh paste
- 4:03:23it here.
- 4:03:25And then what? H so transaction dot get
- 4:03:31uh sender account number and fraud
- 4:03:34event.
- 4:03:36Yeah. Log dot warning. Okay. And uh
- 4:03:42fraud dot detected published.
- 4:03:47Fine. and
- 4:03:50account
- 4:03:53will be blocked.
- 4:03:57Kindly
- 4:03:59contact to your bank.
- 4:04:03Fine. So transaction dot get sender
- 4:04:05account number. Okay. And then what we
- 4:04:09need to do? Yeah. So we need to now saga
- 4:04:16compensation. H. Okay. And refund
- 4:04:20sender. Okay. And then we'll call
- 4:04:22compensate transaction transaction and
- 4:04:24reason. Yeah. So this is good. Yes. So
- 4:04:27if if you know uh something suspicious
- 4:04:30activity detected and wrong OTP. So in
- 4:04:33that case we are blocking the account.
- 4:04:35Okay. And uh going forward in the
- 4:04:37blocking account and compensate first we
- 4:04:39have published this event. Okay. And if
- 4:04:42you remember that our account service
- 4:04:44has already a method. The method which
- 4:04:46method my account service already
- 4:04:48consuming fraud dot detected?
- 4:04:52Yes or no? Consume fraud detected
- 4:04:53method. Okay. It is blocking the
- 4:04:55account. Block account here and here we
- 4:04:56are blocking the account. After that
- 4:04:58user will not able to uh initiate any
- 4:05:02transaction. Okay. And then finally
- 4:05:04finally after that we are compensating.
- 4:05:07Okay. So once blocked and then finally
- 4:05:09referred to the sender. So this is our
- 4:05:11block account and uh compensate
- 4:05:13implementation. Okay. Now the next and
- 4:05:15last one is we need to complete the
- 4:05:17transaction. That means we need to
- 4:05:18credit to our receiver. Okay. So private
- 4:05:22void and complete transaction and I'm
- 4:05:25getting just transaction transaction.
- 4:05:27Okay. So first let me set the status as
- 4:05:31set uh status as completed. Okay. And
- 4:05:35then I also need to set the completed at
- 4:05:40local date time. Okay. dot set completed
- 4:05:42at if you remember we have added one
- 4:05:44field in the transaction that is
- 4:05:46completed at. Okay. So you know
- 4:05:50completed at local time dot now and then
- 4:05:53we are you know saving in our repo
- 4:05:56transaction. Okay. And then finally
- 4:06:01uh we'll publish the event which event
- 4:06:04transaction completed event. So look at
- 4:06:07here in the event package we have
- 4:06:10already created one event transaction
- 4:06:11initiated one more event let me create
- 4:06:14okay that is transaction completed event
- 4:06:19okay and at data at all arcs at no arcs
- 4:06:24fine so the fields I'm going to add in
- 4:06:27this is a string okay private a string
- 4:06:32and transaction ID okay then private a
- 4:06:36string string sender account number
- 4:06:40then private a string and uh receiver
- 4:06:45account number.
- 4:06:48Okay, account number.
- 4:06:52Fine. And next is uh obviously private
- 4:06:55big decimal and amount and then private
- 4:07:00string description.
- 4:07:03Okay, this is it. Let me just get the
- 4:07:07transaction completed event object.
- 4:07:08Okay. So, transaction completed event.
- 4:07:13Okay. And completed event equals
- 4:07:15transaction new transaction completed
- 4:07:18event. In this let me set the values.
- 4:07:20So, transaction dot uh get id. Okay.
- 4:07:24Then transaction dot get sender account
- 4:07:27number. Then uh transaction dot
- 4:07:30receiver. Then transaction dot amount.
- 4:07:33then transaction dot get description.
- 4:07:37Okay. And Kafka template dot send. Okay.
- 4:07:41We have already added this uh topic
- 4:07:43variable that is transaction completed
- 4:07:45event. Only thing remaining. Okay. Yeah.
- 4:07:48So now transaction completed event and
- 4:07:52uh transaction.get ID and completed
- 4:07:54event. Now saga completed. So log.info
- 4:07:58saga complete. Okay. and transaction
- 4:08:05completed. Yes, transaction dot get ID.
- 4:08:09Okay, our first part is completed and uh
- 4:08:12now let's start the second part. Okay,
- 4:08:14so I guess you all might be thinking
- 4:08:16that uh we have implemented a lot
- 4:08:17methods. Okay, consumed a lot uh events
- 4:08:20and still you are seeing the second part
- 4:08:22is remaining. Okay, so what's that?
- 4:08:24Yeah. So I want you all to remind uh one
- 4:08:27thing that uh yeah so user initiated the
- 4:08:30transfer okay transaction and uh we have
- 4:08:32published transaction initiated topic
- 4:08:34and uh our fraud detection service
- 4:08:37consume this event and starts checking
- 4:08:38the transaction. Okay now I just want
- 4:08:41you all to focus on my screen and line
- 4:08:43number 55 or 53. Okay. If result dot is
- 4:08:46fraud if fraud detected suspicious
- 4:08:48activity detected. Okay then we start
- 4:08:50the verification. So till this point
- 4:08:52what we have done is regarding this
- 4:08:55verification started verification then
- 4:08:58we have uh implemented the method to
- 4:09:00generate OTP then that event is consumed
- 4:09:03by notification okay then verify OTP
- 4:09:05based on verification we have
- 4:09:06implemented uh whether need to
- 4:09:07compensate or complete or block okay but
- 4:09:10if result dot is fraud uh is false
- 4:09:15that means everything is clean there is
- 4:09:17no fraud detected okay so control comes
- 4:09:19here line number 69 transaction clean
- 4:09:22that means uh another event published
- 4:09:25fraud check result clean. Okay. So yeah
- 4:09:29fraud check clean in that case we need
- 4:09:31to directly uh you know credit the money
- 4:09:35to the receiver. Okay. So that too we
- 4:09:37need to consume event in our transaction
- 4:09:39service. This is what our last thing.
- 4:09:41Okay. Transaction event consumer.
- 4:09:44Okay. Yeah. So if fraud detection uh
- 4:09:48fails to detect any fraud any suspicious
- 4:09:51then we have published clean event. So
- 4:09:53we need to consume this. Okay. What's
- 4:09:56that? Fraud.check. Okay. Fine. And
- 4:09:59transaction event consumer. Fine. And
- 4:10:01public void. Okay. Consume fraud check
- 4:10:06clean. Okay. Result
- 4:10:11and add payload.
- 4:10:14Fine. map
- 4:10:17a string object payload.
- 4:10:20Okay. Also at Kafka listener and
- 4:10:26topic fraud dot check dot clean. Yeah.
- 4:10:31Let's finish it quickly and wrap our
- 4:10:33transaction
- 4:10:35uh what transaction service. So first
- 4:10:37let me open my try catch. Okay.
- 4:10:42And uh then first let me get my
- 4:10:44transaction ID. Transaction ID equals
- 4:10:49payload dot 1 second. So yeah, let me
- 4:10:53directly copy paste. Okay. Transaction
- 4:10:57ID H. Okay.
- 4:11:02Okay. Fine. And now next just we need to
- 4:11:06call uh a method. We need to create one
- 4:11:08method in our transaction service. Why?
- 4:11:10Because see here uh we are consuming
- 4:11:13fraud check result clean. Okay,
- 4:11:15fraud.clean that means everything is
- 4:11:17clean. We need to credit to the
- 4:11:18receiver. Okay, that means we need to
- 4:11:21call this method complete transaction.
- 4:11:24Yeah, because this is only crediting uh
- 4:11:26to the receiver. Okay, transaction
- 4:11:28status completed but it is private how
- 4:11:30to call it. So for that you know let me
- 4:11:34just
- 4:11:35first uh get private final transaction
- 4:11:40service transaction service. Okay. And
- 4:11:43here let me call transaction service dot
- 4:11:46process
- 4:11:48fraud check
- 4:11:51or process clean result.
- 4:11:54Okay. And I'm passing the transaction
- 4:11:56ID. Okay. in log dot error and error
- 4:12:03processing fraud check result
- 4:12:08E dot get message. Okay. Now let me
- 4:12:12quickly create this method to here.
- 4:12:15Okay. Public void. Okay. And getting the
- 4:12:20transaction
- 4:12:22ID. Okay. Now first let me get the
- 4:12:25transaction. Okay. Using the ID. So
- 4:12:28better to directly Yeah. Copy. Okay.
- 4:12:34Fine. Then we need to add uh item
- 4:12:36potency guard. Okay. In order to prevent
- 4:12:39the duplicate events. Okay. Just like we
- 4:12:41have added in our this uh verification
- 4:12:44required event. Yeah. This one. Okay. So
- 4:12:49yes, paste it here. Fine. And then
- 4:12:50directly call complete transaction and
- 4:12:53pass the transaction. Yes. Yeah.
- 4:12:57um transaction id okay
- 4:13:01fine so whenever the request comes that
- 4:13:04uh whenever the fraud detected service
- 4:13:06gives the green signal to our
- 4:13:08transaction okay here I'm consuming
- 4:13:10fraud check clean and from here I'm
- 4:13:12calling this method and this method is
- 4:13:15finally completing our transaction
- 4:13:17crediting money to our receiver fully
- 4:13:19completed our transaction service is
- 4:13:21fully completed okay and uh our fraud
- 4:13:25detection service. Okay. Account service
- 4:13:28uh client. Okay. Fraud check and event
- 4:13:31consumer and fraud detection. Fine. So
- 4:13:33here too everything is done. Only one
- 4:13:35thing remaining that is our application.
- 4:13:36YML. Let me quickly uh complete that.
- 4:13:40Yeah. We have added you know few
- 4:13:42properties for our fraud max transaction
- 4:13:44suspicious amount multiplier and max
- 4:13:46balance percentage. Okay. Fine. And
- 4:13:50here. So let me start
- 4:13:53application name. So it is fraud
- 4:13:56detection service. Okay. And then data
- 4:14:01radius. Okay. Host port. One second.
- 4:14:07Radius host and port. Okay. So host is
- 4:14:09our local host and port is 6379 6379.
- 4:14:14Also also in our transaction service
- 4:14:18uh application YAML properties file.
- 4:14:22I guess we haven't added the radius
- 4:14:24properties. No, we need to add it. Why?
- 4:14:27Because we have used the radius,
- 4:14:30you know, created uh the OTP stored OTP.
- 4:14:33Okay. Yeah. So, let's add here too.
- 4:14:36Okay. And
- 4:14:39data radius
- 4:14:42host local host. Oops. And port 6379.
- 4:14:49H. Now, it is good. Okay. Back to our
- 4:14:52fraud detection property file. Yeah. And
- 4:14:55uh then our Kafka properties. Okay. So,
- 4:14:57let me directly copy and paste from my
- 4:15:01Kafka and till producer.
- 4:15:05Okay. Back to our flaw detection and
- 4:15:08yes, done fine. Then watch server
- 4:15:12dot port 8084.
- 4:15:15Okay. We do have this account service
- 4:15:18client. So, we need to add the
- 4:15:20properties.
- 4:15:21Okay. account
- 4:15:24you know service URL for
- 4:15:28fain client
- 4:15:32okay and what's that account dos service
- 4:15:36URL
- 4:15:38yes http
- 4:15:40and localhost
- 4:15:438081 okay on this uh address my account
- 4:15:46service is running fine and fraud
- 4:15:49detection is already there we have added
- 4:15:52while coding and then management. Okay.
- 4:15:56Endpoints then web exposure.
- 4:16:01Okay.
- 4:16:03Then include health and info. So
- 4:16:07everything is done in our fraud
- 4:16:08detection. Now only thing remaining that
- 4:16:10is our notification service and we need
- 4:16:12to consume few more events also. We need
- 4:16:15to implement this send alert method.
- 4:16:17Okay. So first event we have implemented
- 4:16:19uh sorry consumed that OTP generated.
- 4:16:22Next we need to consume our you know
- 4:16:24debit alert credit alert yes or no. So
- 4:16:27once money debited so debit alert
- 4:16:30credited credit alert okay and uh for
- 4:16:34the Razer pay side yeah Razer payment
- 4:16:36gateway external payments yes or no once
- 4:16:39you know uh using our bank application
- 4:16:42you are paying to some external
- 4:16:44merchants just like Amazon. Okay. So at
- 4:16:47that point our payment gateway comes
- 4:16:48into the picture. Okay. And for that two
- 4:16:51we need to uh set up and we have already
- 4:16:53one service that is you know our payment
- 4:16:55service. Where is that? Where is that?
- 4:16:58Uh yeah this one. Okay. So payment
- 4:17:02success alert payment failure alert.
- 4:17:05Okay. So for all these alert we need to
- 4:17:07consume the events here and notify user.
- 4:17:10Okay. Yeah. So quickly first let's
- 4:17:13complete our payment service and then
- 4:17:14finally we'll come up here and consume
- 4:17:17all the uh alert events and implement
- 4:17:20this method. Which one? Our send alert.
- 4:17:23Okay. Yeah. So now now next thing is
- 4:17:27let's start our final thing. Not final
- 4:17:31second last. Okay. Payment service.
- 4:17:33Okay. Okay. So let's start with our
- 4:17:36payment entity.
- 4:17:39Okay. payment and now entity.
- 4:17:46Okay,
- 4:17:48then
- 4:17:50table
- 4:17:52name. So, payments
- 4:17:56and add data add no args and all args.
- 4:18:01Fine. Now, let's add the fields. So
- 4:18:04first is private string id and my id
- 4:18:09should be what at generated
- 4:18:14value
- 4:18:16strategy and uyu ID. Okay. Yeah. Next.
- 4:18:21So we going to use the razer pay. Okay.
- 4:18:24So for that let me create a variables
- 4:18:28for order ID and payment ID. So, Razer
- 4:18:32Pay order ID and private
- 4:18:37string Razer Pay payment ID.
- 4:18:42Yeah, fine. Now, uh I need a account
- 4:18:47number. So, private
- 4:18:50account number as we already fetching
- 4:18:53you know using the payload. Okay. Column
- 4:18:57and null label false. The next is I need
- 4:19:02big decimal
- 4:19:05and amount.
- 4:19:09Next, let me add uh what? Currency.
- 4:19:13So, currency.
- 4:19:15Okay. Yeah. And now private
- 4:19:20payment status.
- 4:19:23Okay. Yeah. So we'll create a enum for
- 4:19:26that you know because we have bunch of
- 4:19:28string values.
- 4:19:30So
- 4:19:32entity and
- 4:19:34you know enum
- 4:19:37payment status. Yeah fine. Later on
- 4:19:41we'll add the fields. Okay. Then private
- 4:19:46string
- 4:19:47description. Okay. Then private string
- 4:19:53failure reason. Okay. Payment failure
- 4:19:55reason. And then private
- 4:19:59local date time. Okay. Uh created at
- 4:20:07and our last field that is local date
- 4:20:10time updated at.
- 4:20:14Okay. So add update timestamp
- 4:20:19and add creation timestamp.
- 4:20:23Okay. Yeah. Then uh payment status.
- 4:20:26Okay. So this is my enum enumerated of
- 4:20:30type string. Fine. And then uh for this
- 4:20:35column nullable false. Yeah. Okay. For
- 4:20:40this two nullable false. And let me add
- 4:20:42precision that is uh 15 and scale two.
- 4:20:47Okay. Yeah. So it is done.
- 4:20:51Now let me add the fields for our enum
- 4:20:54that is payment status.
- 4:20:56So status can be you know created. Okay.
- 4:21:01And then pending okay or completed or
- 4:21:07failed. and
- 4:21:10uh refunded. Yes, definitely. Yeah.
- 4:21:15Okay. Now, uh let me just add the DTO
- 4:21:22dot
- 4:21:24create
- 4:21:27you know payment
- 4:21:29request.
- 4:21:31Okay.
- 4:21:32And uh in response what we'll get. So,
- 4:21:38payment response
- 4:21:41or I can just add order payment order
- 4:21:46response. Yeah. Now, let's add the
- 4:21:50fields here. Okay.
- 4:21:53So, payment and
- 4:21:57fine. So, at first add
- 4:22:01data and add no arcs and all arcs. Okay.
- 4:22:07So now what I need what all fields I
- 4:22:10need. So I need first account number.
- 4:22:15Okay. And then I need amount.
- 4:22:20Okay. And finally let me add the
- 4:22:23description.
- 4:22:27Okay. Yeah. So add not blank
- 4:22:33and Okay.
- 4:22:35And if it is blank then we'll display a
- 4:22:38message that account number is required.
- 4:22:44Okay. Then at not null. Okay.
- 4:22:51Else will display a message amount is
- 4:22:54required also amount must be in
- 4:22:57positive.
- 4:22:59So positive message is amount
- 4:23:05must be positive. Okay. Yeah, that's it.
- 4:23:10Now, now let's add the fields here in
- 4:23:14the response. First, let me take the
- 4:23:20payment ID. Okay. Then uh yeah, Razer
- 4:23:24Pay order ID. Okay. in response. Fine.
- 4:23:30And then amount. Okay.
- 4:23:34Yeah. And uh Yeah. Then
- 4:23:39currency.
- 4:23:41Okay. Currency status. Okay. So
- 4:23:48instead of enum here, let's you know uh
- 4:23:53set the variable as a string. Okay.
- 4:23:55because we can set it as a string value.
- 4:23:59Yeah. Fine. Also one more thing uh we
- 4:24:04need that is
- 4:24:07private a string and
- 4:24:11razor pay
- 4:24:13razer pay key ID. Okay.
- 4:24:18Fine.
- 4:24:20Add data and add all arcs. Add no arcs.
- 4:24:25Okay. So this is what our DTO has done.
- 4:24:28Now let me just build the entire
- 4:24:30skeleton. So first configuration we can
- 4:24:34just add. Okay. Configuration dot
- 4:24:39cross origin config
- 4:24:42because we need to run our you know
- 4:24:44front end files and need the permission.
- 4:24:48Okay. Then only we can uh make the real
- 4:24:51payment in our own banking page. Okay.
- 4:24:55Then uh what our controller dot payment
- 4:25:01controller. Okay. And then our
- 4:25:06service dot
- 4:25:08payment service. Okay. And then our
- 4:25:15repository dot
- 4:25:17payment
- 4:25:20repository.
- 4:25:22Okay. interface extends
- 4:25:26JPA repo.
- 4:25:30Okay. And
- 4:25:35payment.
- 4:25:38Okay. A string.
- 4:25:42Fine. And uh uh what else? Yeah, that's
- 4:25:47it. Okay. So add rest controller
- 4:25:54at request mapping. Okay. API v1.
- 4:26:02Fine. API1 and
- 4:26:05payments.
- 4:26:07Yeah. Okay. at SLF4J
- 4:26:12H and then uh private final
- 4:26:18payment service payment service. So for
- 4:26:21that I need to add required arcs
- 4:26:24constructor.
- 4:26:26Okay. Now you know there are two
- 4:26:30important endpoints. First is create
- 4:26:33order. Okay. So once a user click on the
- 4:26:36send money at the bank page create order
- 4:26:40fine and the next thing is web hook.
- 4:26:46Okay if you heard about once the status
- 4:26:48changes so web hook is inbuilt with the
- 4:26:51events if the status you know if the
- 4:26:53payment successful web hook captured
- 4:26:56that success event and then update the
- 4:27:00back end. Okay so I'll show you. Okay,
- 4:27:04in the web hook fine once we'll set up
- 4:27:06our Razer Pay account. So our first
- 4:27:09endpoint is public. Okay, and response
- 4:27:13entity I'm returning the payment order
- 4:27:17response. Okay, our DTO and create
- 4:27:23payment order.
- 4:27:27Okay, fine.
- 4:27:30And add valid. Okay. Add request body
- 4:27:37and create.
- 4:27:40Okay. Payment request request.
- 4:27:45Okay.
- 4:27:48So,
- 4:27:51return
- 4:27:53response entity dot status. HTTP status.
- 4:28:00Okay. dot created
- 4:28:04dot body. Okay. And payment service dot
- 4:28:10create
- 4:28:13payment order. Let me pass the request.
- 4:28:18Okay.
- 4:28:20It is my post mapping
- 4:28:24and
- 4:28:25create
- 4:28:27order.
- 4:28:29Okay. Yeah. The next is our public and
- 4:28:35response entity.
- 4:28:38Okay. Of type a string and handle
- 4:28:43web hook.
- 4:28:44Okay. So add request body
- 4:28:49and uh let me take a map a string object
- 4:28:54and payload. Okay. Fine. Okay, we'll
- 4:28:58fetch it. So here payment service dot
- 4:29:05handle web hook. Okay, we'll pass the
- 4:29:09payload and
- 4:29:12return
- 4:29:14response entity dot okay and web hook
- 4:29:23processed
- 4:29:26H. Yeah. So here it is to post mapping
- 4:29:33and
- 4:29:35web hook. Okay. Fine. Also let me just
- 4:29:40write Razer Pay
- 4:29:43web hook endpoint. Fine. Now let's
- 4:29:47implement. So all of your focus should
- 4:29:50be on my payment service. Okay. Yeah.
- 4:29:53important one
- 4:29:55service at SLF 4J. Okay.
- 4:30:01And
- 4:30:03private final.
- 4:30:06So payment repository. Okay. For that
- 4:30:10let me add required arcs constructor.
- 4:30:13Now let me also create our you know
- 4:30:17Kafka
- 4:30:18topic variable. Okay. a static final a
- 4:30:23string and payment
- 4:30:28completed
- 4:30:31topic. Okay.
- 4:30:33So payment dot completed
- 4:30:37and similarly
- 4:30:41similarly our failed.
- 4:30:43So payment
- 4:30:46failed topic payment dot
- 4:30:50failed. Okay fine.
- 4:30:54Now yeah important one payment.
- 4:30:59Okay order response
- 4:31:03and create payment order. This is what
- 4:31:06our first method we need to implement.
- 4:31:08And I'm getting the create payment
- 4:31:10request.
- 4:31:11Okay. create payment request and
- 4:31:14request.
- 4:31:17Okay,
- 4:31:19one second. Yeah,
- 4:31:23fine. So now let me add here comments
- 4:31:31that uh you know create
- 4:31:34razor payment
- 4:31:37order and the flow flow is like first
- 4:31:44need to create order in Razer Pay okay
- 4:31:48or whatever our uh you know payment
- 4:31:51gateway then we need to save the payment
- 4:31:55that's why
- 4:31:57we have added our MySQL dependency in
- 4:32:00this. So payment record in DB okay then
- 4:32:04third is we need to return order details
- 4:32:09to front end
- 4:32:12okay and then
- 4:32:15fourth is front end shows
- 4:32:19Razer Pay checkout page. Yeah, on the
- 4:32:24check out page only we'll uh make the
- 4:32:26payment. And then fifth is user pays.
- 4:32:31Okay. And sixth is then razor pay calls
- 4:32:37what? We hook. I told you web hook is
- 4:32:39what status. Okay. It has the events
- 4:32:43after user pays whether it is success or
- 4:32:45failed. We hbook captured that. Okay.
- 4:32:48Fine. So this is one you know uh
- 4:32:50complete flow. I told you my comments
- 4:32:53are really important. I'm going to show
- 4:32:54you the entire flow so that you can if
- 4:32:58you can then you can code at your own at
- 4:33:00first otherwise video is there I'm
- 4:33:02coding. Yeah. Okay. So let's start with
- 4:33:05our uh some login. Okay. At first what
- 4:33:08we need to do is first in our flow it is
- 4:33:11create order in Razer Pay. Yeah. So
- 4:33:15creating payment order for account.
- 4:33:21Okay.
- 4:33:23And
- 4:33:25amount.
- 4:33:26Yeah. So I'm getting request dot get
- 4:33:30account number. Okay. And similarly
- 4:33:33request
- 4:33:35request dot get amount. Okay. Fine. The
- 4:33:38next thing is let me get my Razer Pay
- 4:33:41client. Okay. So, Razer Pay client.
- 4:33:46Okay. Razer pay client equals new Razer
- 4:33:50Pay client. Fine. So, now we need to
- 4:33:52pass few things here. Okay. Look at
- 4:33:55here.
- 4:33:57So, at first we need to pass here my
- 4:33:59Razer Pay key ID. Okay. And second thing
- 4:34:02is I need to pass Razer Pay key secret.
- 4:34:07Yeah. So from where we'll get it these
- 4:34:10two things
- 4:34:12once we'll set up our Razer Pay payment
- 4:34:15gateway. Okay, I'll show you. Okay, at
- 4:34:18that time and we'll generate our unique
- 4:34:21key ID and key secret. Okay. Yeah. So
- 4:34:26you know with these uh two fields we'll
- 4:34:30able to make our real you know transfer
- 4:34:33real payments. Okay. And then we'll uh
- 4:34:36directly copy and paste it into our uh
- 4:34:38you know properties file and we'll
- 4:34:40handle it here using our variables.
- 4:34:43Yeah. So let's do that. Okay. Let me
- 4:34:48create two variables for that. Private
- 4:34:51string and key id. Okay. And private
- 4:34:55string key secret. Okay. So add value H.
- 4:35:02Okay.
- 4:35:04and
- 4:35:06Razer pay dot key id h and similarly
- 4:35:15what razor pay dot key secret h okay
- 4:35:19fine let me pass both of them here so
- 4:35:24key id and
- 4:35:26key secret okay fine now the next thing
- 4:35:30is also
- 4:35:32uh why I'm getting here some uh you know
- 4:35:36error. Uh okay fine. So I need to you
- 4:35:40know throws razor pay
- 4:35:43exception. Okay. Also in the controller
- 4:35:48method throws razor pay exception. Okay
- 4:35:54fine. H yeah. Now the next thing is I
- 4:35:58need to convert my you know amount into
- 4:36:00the smaller one. Okay. convert my
- 4:36:03currency into the smaller one. Let's say
- 4:36:05just look at here. So suppose if I'm
- 4:36:08using USD okay so I need to convert it
- 4:36:11into cents. Okay. So one USD
- 4:36:15is how much cents? 100
- 4:36:18cents. Okay. So I need to multiply
- 4:36:22you know uh by 100.
- 4:36:28Yes or no? Yeah. And uh let's say I'm
- 4:36:32using INR
- 4:36:34okay Indian rupees okay so I need to
- 4:36:36convert it into what the smaller one is
- 4:36:39pes yeah so yeah same thing 1 INR equals
- 4:36:44100 fine similarly whatever currency you
- 4:36:48have you can just proceed with that okay
- 4:36:51so let me now
- 4:36:55you know just
- 4:36:58code that So converted amount okay and
- 4:37:04uh int converted amount
- 4:37:09okay equals what first let me get the
- 4:37:12amount request dot get
- 4:37:16uh amount okay and then dot multiply
- 4:37:19what big decimal dot value of and
- 4:37:24multiply with 100 dot int value okay
- 4:37:29Yeah. So this is now my final converted
- 4:37:31amount. Okay. I need to put it uh in uh
- 4:37:34into my order request. Yeah. Fine. So my
- 4:37:39JSON object. Let's create our order
- 4:37:41request. Order request
- 4:37:45equals new JSON object. Okay. And let's
- 4:37:48put few things in our this request.
- 4:37:51Okay. Order request. Okay. As the name
- 4:37:53indicating order request. So first let
- 4:37:56me put my amount obviously. Okay. And uh
- 4:38:00then okay currency. Okay. USD or INR.
- 4:38:03Okay. Fine. Okay. Let me put the USD.
- 4:38:07Fine. And uh then finally our receipt. H
- 4:38:12order
- 4:38:14request dot put H. And our receipt ID.
- 4:38:20Okay. Receipt. So
- 4:38:25let's say receipt ID. Okay. So we need
- 4:38:28to generate a unique and random id.
- 4:38:32Okay, for that yeah so one question for
- 4:38:35you. Okay, let me generate using uu ID
- 4:38:38dot random UU ID dot2 string. Okay, but
- 4:38:41there might be possible not practically.
- 4:38:43Okay, it's a lot of combinations but
- 4:38:45theoretically you know it can generate
- 4:38:49um same UU ID.
- 4:38:53I know it's not practically possible lot
- 4:38:55of combinations. Okay. But theoretically
- 4:38:57it is possible. Okay. So for that you
- 4:39:00know one solution. Let's you know uh add
- 4:39:06what's that? So we can also concatenate
- 4:39:09our
- 4:39:11uh
- 4:39:12system dot current times. Okay.
- 4:39:18Then UID. Okay. And then dot will
- 4:39:22replace. Okay. So
- 4:39:26replace hyphen.
- 4:39:29Yeah. Okay. And dot substring 0 comma
- 4:39:3510.
- 4:39:37Okay. Yeah. Why I'm doing this? Why I'm
- 4:39:41doing this? Because just look at here.
- 4:39:44So
- 4:39:46you know our receipt ID should not
- 4:39:49exceed 30 characters.
- 4:39:52Okay. And here I'll get something like
- 4:39:55uh you know sum 8 9 e b okay for hyphen
- 4:40:02uh a 29 b something like that okay our
- 4:40:06uh random ID so I'm replacing hyphen
- 4:40:10okay and then restricting it to 10 okay
- 4:40:14yeah so that will be you know kind of
- 4:40:17our unique receipt ID okay fine let's
- 4:40:20proceed with that Okay, next thing is
- 4:40:24what?
- 4:40:26Uh, I need to just, you know, get the
- 4:40:28order. So, or I can just write Razer Pay
- 4:40:33Razer Pay order. Okay. Equals I have,
- 4:40:37you know, Razer Pay client
- 4:40:39from the Razer Pay client dot orders
- 4:40:43dot, you know, create.
- 4:40:46Okay. And let me pass this order
- 4:40:49request.
- 4:40:50H. Okay. Fine. And also now let me just
- 4:40:54add some login that our you know Razer
- 4:40:57Pay order created. Razer Pay order
- 4:41:01created. Okay. And also let me just you
- 4:41:06know send the ID Razer Pay order dot get
- 4:41:11ID dot to a string.
- 4:41:15Okay fine. So our first thing is done.
- 4:41:18First job is done. Okay. create order in
- 4:41:20Razer Pay. That is done. Now the next
- 4:41:23thing is save payment
- 4:41:26uh record in database. Okay fine. So
- 4:41:29let's do that.
- 4:41:31Save payment record H. Okay. So let me
- 4:41:36get that payment. Okay. Our entity
- 4:41:40payment
- 4:41:42equals new and payment. Fine. Okay. And
- 4:41:47then let's uh set the values. So at very
- 4:41:50first thing let me set my Razer Pay
- 4:41:52order ID. Okay, Razer Pay order ID.
- 4:41:56Okay, same thing.
- 4:42:00Fine. Get ID dot to string. Okay, and
- 4:42:03then let me just set the account number.
- 4:42:06Set account number. Okay, I'm getting in
- 4:42:09our request dot get account number.
- 4:42:12Okay, then uh what amount? Okay,
- 4:42:16obviously. And then uh currency. So
- 4:42:19payment dot set currency USD okay or INR
- 4:42:23okay fine and uh then payment dot yeah
- 4:42:28also status so it is created okay and
- 4:42:33then finally let me also set my
- 4:42:35description okay so description okay
- 4:42:38payment uh sorry request dot get
- 4:42:41description yeah now let me save it
- 4:42:45payment uh you know repository dots save
- 4:42:48payment payment and
- 4:42:51I'm getting payment saved payment. Okay,
- 4:42:57fine. Now I'm returning payment order
- 4:43:01response. Okay, let me just put it here.
- 4:43:05Okay, and
- 4:43:07need to return payment order response.
- 4:43:09So
- 4:43:10return new payment order response. The
- 4:43:14first field is payment ID. Okay. So from
- 4:43:18the save payment, let me set it. So get
- 4:43:22ID. Okay. Next is our Razer Pay order
- 4:43:25ID. So yeah, this is
- 4:43:30Razer Pay order ID. Okay. Next is our
- 4:43:34amount. So from the request, let me set
- 4:43:36it amount. Okay. And then next is our
- 4:43:40currency. Okay. So USD INR. Okay. And
- 4:43:46yeah uh one more thing you have to write
- 4:43:48it one one currency either USD okay or
- 4:43:52INR I'm just writing for both okay or
- 4:43:55for any of the user USD INR euros
- 4:43:59whatever pounds whatever okay you just
- 4:44:01have to write it uh one currency not you
- 4:44:05know multiple like this USD INR okay or
- 4:44:08uh separated by you know slash no USD
- 4:44:12okay USD INR okay INR
- 4:44:15Okay. Fine. GBP and whatever
- 4:44:19fine. Okay. Yeah. And the next thing is
- 4:44:23status. So my status is created. And the
- 4:44:26last thing is Razer Pay key ID. Okay. So
- 4:44:29ID which I'm getting from the Razer Pay.
- 4:44:32Let me set it. Okay. Razer Pay key ID.
- 4:44:35And that is done. Okay. Done. Okay. Let
- 4:44:38me just close this. And uh with this we
- 4:44:43have completed our first method that is
- 4:44:46our create payment order. Fine. Next
- 4:44:49method come ups that is our web hook. Hm
- 4:44:52handle web hook. Yeah. So remember one
- 4:44:55thing. Okay. One note point
- 4:44:58H. So for the real payments you know
- 4:45:02payments okay web hook is not mandatory
- 4:45:06but it is recommended. Okay. and most
- 4:45:09important functionality because you know
- 4:45:12payment gateways like uh stripe okay or
- 4:45:16razor pay we are using so you know they
- 4:45:19have web hook and what web hook does is
- 4:45:23it capture events
- 4:45:26you know so web hook contains you know
- 4:45:28around 100 plus events okay for all the
- 4:45:31payment related events like if payment
- 4:45:34is failed so web hook has the event
- 4:45:37payment failed Okay, payment success,
- 4:45:39order created, order you know cancelled,
- 4:45:42payment pending, whatever 100 plus
- 4:45:45events.
- 4:45:47Okay, so whatever happens in the you
- 4:45:49know at the time of checkout let's say
- 4:45:52you have purchased something uh from
- 4:45:53Amazon and uh here is my checkout page
- 4:45:56and let's say payment failed.
- 4:46:00So our web hook captured that event and
- 4:46:03notify to our back end.
- 4:46:07Why? Because in the back end we have
- 4:46:09returned a method to handle uh you know
- 4:46:13failure events like you know in coming
- 4:46:16few minutes we'll uh write we'll
- 4:46:18implement the method handle payment
- 4:46:20failure.
- 4:46:22Okay. And let's say if suppose payment
- 4:46:25got successful. So first web hook
- 4:46:28capture that event. Yeah we see we need
- 4:46:31something from the payment gateway side.
- 4:46:34This is another resource. This is not a
- 4:46:36part of our uh code, not a part of our
- 4:46:39digital banking system. Payment gateway
- 4:46:41is another you know resource, another
- 4:46:43company.
- 4:46:45So payment gateway provides a web hook
- 4:46:48which capture the events okay on the
- 4:46:51front end side and notify to our back
- 4:46:54end so that we can you know uh take
- 4:46:58action after that. If failed then what?
- 4:47:03If success then what we just need our
- 4:47:06back end just need our banking system
- 4:47:08just need uh that web hook notify us
- 4:47:12okay and then finally we'll uh proceed
- 4:47:15forward according to that okay as per
- 4:47:17our code yeah so that is what and yeah
- 4:47:21definitely I'll show you we'll set up
- 4:47:23our web hook okay I'll show you the all
- 4:47:25the events okay while setting up uh in
- 4:47:28our testing part okay yeah so fine
- 4:47:33Let's first code our you know web hook
- 4:47:36handle webbook method and then we'll uh
- 4:47:39also implement the payment success and
- 4:47:42payment failure events. Okay. Yeah.
- 4:47:45Let's proceed. So public and what it is
- 4:47:51handle web hook. Okay.
- 4:47:54void and handle web hook map
- 4:48:01a string object
- 4:48:06payload. Yeah.
- 4:48:08Now log dot info. Okay. So here first
- 4:48:14whatever payment status okay that failed
- 4:48:18dot success. So here received
- 4:48:21Razer Pay
- 4:48:23web hook. Okay. And payload dot get
- 4:48:30event.
- 4:48:32Yes. Okay. Now a string event equals
- 4:48:39let me just
- 4:48:41copy this payload dot
- 4:48:45get event and type casted. Fine. And now
- 4:48:51if if just listen to me, okay, pay
- 4:48:54attention here. Payment dot there is one
- 4:48:58event captured. Okay. So, payment dot
- 4:49:01captured
- 4:49:03dot equals
- 4:49:06this event.
- 4:49:08If it is then our we need to handle
- 4:49:12payment payment
- 4:49:16success. Okay, that is what you know uh
- 4:49:18payment successful.
- 4:49:20Yeah. So, let me create another method
- 4:49:22for that and we'll handle the payment
- 4:49:25success.
- 4:49:27else if
- 4:49:31our payment dot failed.
- 4:49:35Okay, there is one more event. I'll show
- 4:49:37you the list of events. Okay, equals
- 4:49:41event.
- 4:49:43Okay, then uh we'll handle our payment
- 4:49:49failure.
- 4:49:50Okay, and we'll pass the payload. Yeah.
- 4:49:54Okay, fine. So now let's implement these
- 4:49:58two method. Handle payment success.
- 4:50:01Okay. Private void handle payment
- 4:50:05success. Okay. And let me open my try
- 4:50:08catch.
- 4:50:11So first I need to extract the data from
- 4:50:14the payload. Okay. So how to do it? Map
- 4:50:19and a string object. Okay. and payment
- 4:50:27data equals let me create one more
- 4:50:30method
- 4:50:32extract
- 4:50:34payment data okay and I'll pass the
- 4:50:38payload okay we'll implement this method
- 4:50:40and we'll extract the data fine then
- 4:50:44from that data I need few things just
- 4:50:46like order ID so payment
- 4:50:51you
- 4:50:53payment data. There's payment data.
- 4:50:56Okay. Extracted one. And dot get
- 4:51:01what?
- 4:51:02Order ID. Yeah. Fine. Okay. And the same
- 4:51:07way how I'm writing.
- 4:51:09Okay. A string. Fine. One second.
- 4:51:14Payment. Okay. Here to payment.
- 4:51:18Fine. And also I need a payment id.
- 4:51:24Okay. So from the payment data okay dot
- 4:51:28get
- 4:51:29fine and id also let me type cast
- 4:51:36a string. Yes. Okay. Fine. So now let me
- 4:51:40get the payment and using order ID.
- 4:51:44Okay. So, payment and payment equals
- 4:51:50payment repository dot
- 4:51:54find by Razer Pay. Razer
- 4:52:00uh yeah, Razer Pay order ID. Okay. And
- 4:52:05let me pass the order ID. Okay. Find by
- 4:52:08Razer Pay order ID. So, let's create
- 4:52:10this method in our payment repository.
- 4:52:14So optional
- 4:52:17and
- 4:52:18payment
- 4:52:20and I'm passing the order id. Okay. So
- 4:52:26dot or else throw and new runtime
- 4:52:33exception what payment not
- 4:52:40found for order. Okay. See because
- 4:52:45uh as we have already written in the
- 4:52:47flow create order in Razer Pay and then
- 4:52:50save payment record return order. Okay.
- 4:52:54So at the time of uh you know handling
- 4:52:56the success payment we need to get by
- 4:53:02order ID. Okay. Payment not found for
- 4:53:05order.
- 4:53:07Okay. and
- 4:53:10order ID.
- 4:53:12Okay, if yes, then first we'll set the
- 4:53:16payment ID. Okay, so set Razer Pay
- 4:53:19payment ID which is payment ID. Okay,
- 4:53:22and then we need to set the status
- 4:53:25payment dot set status as completed.
- 4:53:30H because you know we are handling the
- 4:53:32payment success. So it only triggers
- 4:53:36when our web hook which is a integrated
- 4:53:40you know uh functionality of razer pay.
- 4:53:43So it captured success payment okay its
- 4:53:45own headache and then we are just
- 4:53:47handling the payment success okay to
- 4:53:51proceed forward
- 4:53:53and then we'll save that saved fine then
- 4:53:57now publish payment
- 4:54:01completed event to Kafka
- 4:54:06okay
- 4:54:08yeah so map
- 4:54:11and a string
- 4:54:14object event equals new hashmap.
- 4:54:20Okay. And then what we need to put so
- 4:54:24first let's put the payment ID. Okay. So
- 4:54:31payment dot get ID. Yeah. And then let's
- 4:54:36put our
- 4:54:38account number. So yeah from the same
- 4:54:43thing payment dot get account number
- 4:54:47and then let's put
- 4:54:51uh what
- 4:54:53event doput
- 4:54:56um okay
- 4:55:00payment payment
- 4:55:02where is that yeah
- 4:55:06amount yeah okay
- 4:55:10So
- 4:55:12amount and
- 4:55:14yes get amount and one more thing. Okay.
- 4:55:18So one more thing
- 4:55:24Razer Pay payment ID. Okay. This one.
- 4:55:29So event dot put
- 4:55:34and Razer Pay payment ID.
- 4:55:38This is our payment ID. Okay. And then
- 4:55:42Kafka dot
- 4:55:46Okay. I guess uh yeah,
- 4:55:50private final Kafka
- 4:55:54and template string
- 4:55:57object
- 4:55:59Kafka template. Okay.
- 4:56:03Then yeah, Kafka
- 4:56:07template dot send. Okay. So, payment
- 4:56:13completed topic.
- 4:56:16Okay. Then payment dot get id
- 4:56:21get ID and what event.
- 4:56:27Okay. and log.info
- 4:56:30our payment
- 4:56:33completed
- 4:56:36and payment dot get
- 4:56:40ID.
- 4:56:42Okay. Yeah. And log dot error. So error
- 4:56:50handling
- 4:56:52payment success
- 4:56:55e dot get message.
- 4:56:59Fine. Done. Now let's handle our payment
- 4:57:03failure. Okay. So private void handle
- 4:57:09payment failure.
- 4:57:11Okay. And
- 4:57:13fine. So same thing. Let me first open
- 4:57:17try and catch. Now let me copy few
- 4:57:22things. First let me same thing extract
- 4:57:25the payment data. Okay. And then uh yeah
- 4:57:30also I need order ID. Okay. Failure or
- 4:57:34success I need order ID. Okay. First
- 4:57:37order created. Okay. Then uh yeah also I
- 4:57:41need my payment by order ID. Okay. Then
- 4:57:48I need to set the status.
- 4:57:52Okay. So
- 4:57:55no I don't need this payment ID. Okay.
- 4:57:58Because payment failed. So just this
- 4:58:03two.
- 4:58:04Okay. And also I have one more field.
- 4:58:08Okay. H failure reason. Okay. So,
- 4:58:12payment status as failed
- 4:58:16and payment dot set failure reason.
- 4:58:22Okay. Payment failed via
- 4:58:27Razer Pay. Okay. And we'll save it and
- 4:58:32then we'll publish. Okay. So let me just
- 4:58:35copy this and
- 4:58:38let me just check. So event payment ID,
- 4:58:42account number, amount. Okay. And here
- 4:58:47reason. Okay. So reason is uh same thing
- 4:58:52we can uh
- 4:58:55add payment field via Razer Pay. Yeah.
- 4:58:59Okay. And then then what? Kafka template
- 4:59:06dot send
- 4:59:09here it should be failed. Okay.
- 4:59:13Yeah. Failed topic.
- 4:59:18Okay. And get ID event.
- 4:59:23Yeah. Log dot warning and payment
- 4:59:29failed.
- 4:59:31Okay. Payment dot get ID.
- 4:59:36Got it.
- 4:59:38Log dot error. Okay. So, error handling
- 4:59:45payment
- 4:59:47failure.
- 4:59:50Yes. E dot get message. Fine. Now only
- 4:59:54one thing remaining that is extract
- 4:59:56payment data. Okay. Okay. Fine. So
- 5:00:00nothing big deal. Let me just implement
- 5:00:03it. Private and returning the map string
- 5:00:08object. Okay.
- 5:00:10Extract payment data H. So map and a
- 5:00:16string
- 5:00:19a string
- 5:00:21object. Okay. And let it be entity.
- 5:00:26Okay. Fine. uh equals
- 5:00:31payload dot get okay the entire payload
- 5:00:36and I'll type cast it as
- 5:00:40map
- 5:00:42and yeah a string object
- 5:00:46okay then what then map a string object
- 5:00:51and I need the wrapper
- 5:00:54okay so
- 5:00:56wrapper Or I can just write payment
- 5:01:01wrapper equals
- 5:01:03okay entity from the entity let me get
- 5:01:07the payment
- 5:01:11okay and I'll type cast it as map okay
- 5:01:18okay and then finally let me return
- 5:01:22what payment wrapper dot get
- 5:01:27entity entity. Okay. Yeah. Entity
- 5:01:31and uh then type cast it as Okay. Fine.
- 5:01:36So
- 5:01:38I got my you know extracted data done.
- 5:01:42So this is done. We have implemented the
- 5:01:46entire order. Okay. Order done. saved
- 5:01:49and then handle status, payment success,
- 5:01:52payment failure, handle web hook is all
- 5:01:56done. Yeah. Okay. Now, now what? Now,
- 5:02:01let me just add the configurations. So,
- 5:02:04add configuration.
- 5:02:07Okay.
- 5:02:09Public web MVC configure. Okay. So now
- 5:02:15return new web MVC configur inside
- 5:02:21uh you know we'll override that method.
- 5:02:24So public okay and yeah definitely
- 5:02:29add cross origin mappings. Okay. Add
- 5:02:33override.
- 5:02:35Okay. And then registry dot add
- 5:02:39mappings. Here we have added what? API.
- 5:02:43Yeah. Dot allowed origins.
- 5:02:47So yeah. And then dot allowed methods.
- 5:02:52Get
- 5:02:54and post put delete. Okay. Allowed
- 5:02:58headers. Okay.
- 5:03:02And
- 5:03:04uh yeah, that's it. Fine.
- 5:03:09Okay. Done.
- 5:03:12Also
- 5:03:14at bin H.
- 5:03:19Yeah.
- 5:03:20Done. Now only one thing remaining that
- 5:03:23is our properties file. Let's do it.
- 5:03:27Okay. Fine. So spring application
- 5:03:32name
- 5:03:34payment service. Okay. Then data source.
- 5:03:39Okay. So just let me copy paste from my
- 5:03:44account service. Okay. I have yeah this
- 5:03:47one. Okay. Till dialect.
- 5:03:52Okay.
- 5:03:54So
- 5:03:56and here I need another database. Okay.
- 5:04:01See how many database we are using.
- 5:04:04Okay. And everything
- 5:04:07fine. JPA hibernate dialect. Okay. Now
- 5:04:10my Kafka properties. So that too. Let me
- 5:04:16just
- 5:04:18get it. One second. So we have
- 5:04:24uh published. Yes, just published. Just
- 5:04:27published. Okay. If just published then
- 5:04:30we don't need consumer.
- 5:04:33So we just need this producer.
- 5:04:36Okay. And where is my payment?
- 5:04:42So first I need my bootstrap
- 5:04:47servers localhost
- 5:04:499092
- 5:04:52and then just producer
- 5:04:55fine
- 5:04:57server
- 5:04:58dot port 8083.
- 5:05:03Okay. Yeah. Three is missing. Okay.
- 5:05:06Fine. Now our Razer Pay configuration.
- 5:05:11So razor pay
- 5:05:15config
- 5:05:17duration.
- 5:05:19Okay. So what we have you know just
- 5:05:24added the variables razer pay dot key ID
- 5:05:28and key secret.
- 5:05:31Okay. Razer pay.
- 5:05:35So Razer Pay dot key ID. Okay. So you
- 5:05:40know it's like some uh R Z P and
- 5:05:45something like fine and then uh key
- 5:05:50secret. Okay. And uh then our you know
- 5:05:55what
- 5:05:57web hook
- 5:05:58and
- 5:06:00secret. Okay. Yeah. Next is yeah simple
- 5:06:05management.
- 5:06:06Okay. Then endpoints
- 5:06:09web
- 5:06:11exposure
- 5:06:14include
- 5:06:15health
- 5:06:17and info. Okay. Fine. So this is what
- 5:06:22completed each and everything. Okay. Now
- 5:06:26only our last thing remaining that is
- 5:06:30what our API gateway need to set the
- 5:06:35routing and
- 5:06:37uh configuration for rate limiting.
- 5:06:41Okay. Yeah. So without wasting much time
- 5:06:44let's start and let's go. Okay. So let's
- 5:06:47start with our API gateway all the
- 5:06:49routings and uh configurations. Okay. So
- 5:06:53at first let me code my rate limiter
- 5:06:55config.
- 5:06:59Rate limiter config. Okay.
- 5:07:05Configuration.
- 5:07:08Fine. Public and key resolver. Key
- 5:07:13resolver.
- 5:07:14Okay. Key resolver.
- 5:07:17Then return exchange.
- 5:07:21Okay.
- 5:07:22Then mono dot just
- 5:07:27exchange dot get request dot get remote
- 5:07:33address. Okay. Then dot get address and
- 5:07:36dot host host address.
- 5:07:40Yeah.
- 5:07:41Okay.
- 5:07:43At bin. That's it. And now let's add the
- 5:07:48routings in our application dotl.
- 5:07:52So spring application
- 5:07:56name api
- 5:07:59gateway. Okay. And then data
- 5:08:04radius host. So local host and
- 5:08:12local host and port 6379.
- 5:08:17Yeah. And then what? Cloud
- 5:08:22gateway
- 5:08:24and routes.
- 5:08:27Okay. Yeah. Now let's start. So account
- 5:08:33service
- 5:08:35routes. Okay.
- 5:08:39One second.
- 5:08:42Okay. Fine.
- 5:08:45Yeah.
- 5:08:47So now
- 5:08:50ID
- 5:08:52account
- 5:08:54service. Okay. Then URI. So HTTP
- 5:09:00localhost
- 5:09:02and 80 81. and then predicates.
- 5:09:09So
- 5:09:11path. Okay. So path is what? API v1 and
- 5:09:18accounts. Yeah. Okay. Fine. Then
- 5:09:21filters.
- 5:09:23Okay. So yeah, filters.
- 5:09:27Okay.
- 5:09:29name is
- 5:09:31request
- 5:09:33rate
- 5:09:34limiter.
- 5:09:36Okay. And
- 5:09:39arcs radius
- 5:09:42rate
- 5:09:44limiter and replenish rate. Okay.
- 5:09:52Rate. Okay. Let me keep it as 10.
- 5:09:56Okay. also the burst capacity.
- 5:09:59So rate limiter
- 5:10:03and
- 5:10:04burst capacity
- 5:10:1020. Fine. Okay. Now the same thing goes
- 5:10:18with our transaction service. Okay.
- 5:10:23Uh yeah
- 5:10:26fine. So here
- 5:10:29transaction service routes.
- 5:10:33Okay. And
- 5:10:36transaction service localhost 8082
- 5:10:42API v1
- 5:10:46transactions.
- 5:10:47Fine. And yeah, next is our payment
- 5:10:52service. Okay.
- 5:10:55So,
- 5:10:57okay.
- 5:10:59Here payment service routes
- 5:11:03and payment service
- 5:11:078083
- 5:11:08API v1 payments.
- 5:11:13Okay. One second.
- 5:11:17uh in our Java.
- 5:11:22Okay, fine. API v1 payments.
- 5:11:26Yeah. Okay, that's it.
- 5:11:30Uh also
- 5:11:32payment service. Fine. So let me just
- 5:11:35modify this as five and 10 H. Now it is
- 5:11:41good. Okay. So now this will be our
- 5:11:45entry point. So server.port 8080. Okay.
- 5:11:498080
- 5:11:51and then
- 5:11:53management then endpoints
- 5:11:57web
- 5:12:00exposure.
- 5:12:02Okay. Include here health info and
- 5:12:08gateway.
- 5:12:12Okay. Yeah. Health info and gateway.
- 5:12:17Okay. This is done. Now what else
- 5:12:19remaining is uh I guess in our
- 5:12:22notification service
- 5:12:25uh yeah notification service. Okay. So I
- 5:12:28told you that uh you know we have
- 5:12:31consumed we have already consumed our
- 5:12:33OTP generated event. Okay. And uh also
- 5:12:38we have created send alert method. Okay,
- 5:12:41you can see this.
- 5:12:43Yeah, this one. Now, uh we need to also
- 5:12:47consume few more methods. What methods?
- 5:12:49So, you know, uh if suppose transaction
- 5:12:53transaction is completed.
- 5:12:56Okay. So, in that case we need to
- 5:12:59consume that uh you know the completed
- 5:13:02event and need to update or notify to
- 5:13:05the user. Yeah. So in that case we need
- 5:13:10to notify both the user sender and
- 5:13:13receiver that uh you know some x amount
- 5:13:17debited. Okay. And some x amount
- 5:13:21credited.
- 5:13:22Yes or no? Yeah. So we need to you know
- 5:13:25just notify the debit alert credit
- 5:13:27alert. Okay. Second thing is if suppose
- 5:13:30fraud is detected, if suppose any
- 5:13:32suspicious activity detected then in
- 5:13:35that case too we need to notify to the
- 5:13:37user.
- 5:13:38Okay fine. Uh third case is um you know
- 5:13:43in case of Razer Pay Razer Pay or I'm
- 5:13:46talking about external payments. Okay.
- 5:13:49Suppose you have purchased something
- 5:13:50from the Amazon.
- 5:13:52Okay. Or you know whatever website.
- 5:13:54Okay. And uh once you click on the check
- 5:13:57out button okay so it will take you on
- 5:14:00some check out page banking page okay
- 5:14:02and something got failed there something
- 5:14:04got failed or the bank you know uh the
- 5:14:07payment got success okay so we also need
- 5:14:11to handle that case
- 5:14:14you know that is what the external
- 5:14:15payment suppose you are paying to some
- 5:14:17external merchants okay so we also need
- 5:14:21to handle payment success and handle
- 5:14:24payment failure. Okay. Yeah. So I
- 5:14:27already told you that we need to inform
- 5:14:29user each and every money moment where
- 5:14:32his money is going and that is what the
- 5:14:34real banking application do. Okay. Yeah.
- 5:14:37So you know that is quite most important
- 5:14:40and uh yeah we can't left it. So let's
- 5:14:43implement that too. Okay.
- 5:14:46Yeah.
- 5:14:49So at first we have consumed OTP
- 5:14:52generated. Okay. The next is public
- 5:14:54void. Yeah. Any guesses? Okay. Consume
- 5:14:58transaction
- 5:15:00completed.
- 5:15:02Fine. Add payload.
- 5:15:05Okay. And map. Okay. Let me just copy
- 5:15:09and paste. Okay.
- 5:15:12Fine.
- 5:15:15Yeah. Okay. And uh
- 5:15:20here this is at Kafka listener. Okay.
- 5:15:24Topic is what h in our transaction
- 5:15:28service. Okay. Transaction service
- 5:15:31and src main service. Transaction
- 5:15:36service. Okay. Um yeah. Can you see this
- 5:15:39transaction initiated topic transaction
- 5:15:42completed topic? Okay. If transaction is
- 5:15:45completed then we need to you know
- 5:15:47consume this event and notify both the
- 5:15:50users. Okay. So back to our notification
- 5:15:54service and topic is our transaction dot
- 5:15:57completed. Okay. Now let me open my try
- 5:16:01catch.
- 5:16:02Okay
- 5:16:04fine. And first let me you know get my
- 5:16:10sender account. Okay. sender account
- 5:16:14equals
- 5:16:17payload dot get
- 5:16:20sender
- 5:16:22account number.
- 5:16:24Oh yeah. Okay. And also let me type cast
- 5:16:28it a string. Fine. Okay. Next is
- 5:16:34what? Receiver. Same thing with a
- 5:16:37receiver. receiver account equals
- 5:16:40payload dot get and receiver account
- 5:16:46number. Okay,
- 5:16:50fine.
- 5:16:52H yeah. So let me do the same thing. Let
- 5:16:55me type cast it. Okay. And third thing I
- 5:16:59need what? I need the amount. Okay. So a
- 5:17:03string amount equals
- 5:17:06payload dot get okay and amount dot to a
- 5:17:13string.
- 5:17:14Yeah. Okay. Fine. Now let me call this
- 5:17:18method. Okay. Send alert. So send alert.
- 5:17:24Okay. And what I'm passing first first
- 5:17:28let me also write comments debit alert.
- 5:17:33Okay. So in the debit alert first let me
- 5:17:35pass the sender account. Okay. Then I'm
- 5:17:38accepting subject. Okay. So subject is
- 5:17:41let's say debit alert. Okay. And finally
- 5:17:45message. Okay. So first let me format a
- 5:17:49string dot format. Okay. And then then
- 5:17:54what? So percent s percent s
- 5:17:58debited
- 5:17:59h from account which account
- 5:18:05okay account and percent s okay so uh
- 5:18:12percent s debited okay that means amount
- 5:18:15debited from account sender account okay
- 5:18:19h yeah yeah
- 5:18:21fine sounds good and Now credit alert.
- 5:18:27So similarly, okay, let me just copy
- 5:18:30this and paste it here. Instead of
- 5:18:33sender, it is now receiver and
- 5:18:38it is credit alert. Okay. And percent is
- 5:18:43now it is credited from account and it
- 5:18:47is
- 5:18:49receiver H. Okay. Yeah. Done. And in the
- 5:18:55catch block log dot
- 5:18:58error and error sending transaction
- 5:19:03notification. Okay. Notification. Fine.
- 5:19:08Yeah. And e dot
- 5:19:11uh get message. Okay. Done. Yeah. Done.
- 5:19:15Next thing let's consume our fraud
- 5:19:18detected. Okay. So public void and
- 5:19:21consume fraud detected.
- 5:19:25Yeah. Add payload and again let me just
- 5:19:31directly copy this from here and paste
- 5:19:35it here. Okay. Now add Kafka listener
- 5:19:40and what's the topic? So the topic is
- 5:19:44fraud.detected. Okay. Yeah. Fraud dot
- 5:19:48detected. Where am I? Notification
- 5:19:51service. And here
- 5:19:54topics fraud dot detected. Okay.
- 5:19:58Fine. Now here to let me open first my
- 5:20:02try catch and Okay. So first let me get
- 5:20:08the account number. Okay. Payload dot
- 5:20:13get
- 5:20:15account number. Okay. Let me type cast
- 5:20:18it
- 5:20:20fine.
- 5:20:22Okay. Then also I want reason. Okay.
- 5:20:28Because see if fraud detected then uh
- 5:20:32where is my fraud detection? Yeah it is
- 5:20:34main Java and model. In the model we
- 5:20:38have two fields that is fraud and
- 5:20:39reason. Okay. So I need that too.
- 5:20:43notification service and uh payload dot
- 5:20:47get
- 5:20:49reason. Okay. And this is what my string
- 5:20:55h okay fine now again let me just call
- 5:20:59send alert. Okay. And here let me pass
- 5:21:01the account number. My subject is let's
- 5:21:05say account. Okay. or uh suspicious
- 5:21:11activity
- 5:21:13you know
- 5:21:15detected.
- 5:21:17Okay. And then a string dot format
- 5:21:22H one second. Yeah. So the message will
- 5:21:27write as your account you know percent s
- 5:21:33has been blocked.
- 5:21:36Okay. And
- 5:21:42next is this is what reason. Okay. And
- 5:21:47percent s
- 5:21:49percent s m. Okay. and
- 5:21:56and what please
- 5:22:00contact
- 5:22:02your bank immediately. Okay. So
- 5:22:10yeah fine. Okay. So
- 5:22:17it is your account. Okay. Account number
- 5:22:20and reason. Re reason. Yes.
- 5:22:25Okay, that's it. And in our catch block
- 5:22:29log dot error and error sending fraud
- 5:22:35alert
- 5:22:37e dot get message.
- 5:22:41Okay, it's done. Fine. Next is we are
- 5:22:44consuming our refunded event. Okay, if
- 5:22:47you know uh something got failed and our
- 5:22:50bank process the refund you know refund
- 5:22:54process let me you know consume that
- 5:22:58okay public void consume
- 5:23:03and transaction
- 5:23:05refunded
- 5:23:07okay
- 5:23:09then I'm getting the payload
- 5:23:14yeah Okay,
- 5:23:17here at Kafka listener. Okay, what's the
- 5:23:21topic? Transaction service and yeah,
- 5:23:25transaction dot refunded. H okay.
- 5:23:30Notification service and
- 5:23:33topic
- 5:23:35transaction dotreunded. Okay, fine. Let
- 5:23:37me open my try catch. Okay. And here. So
- 5:23:45let me get my first sender account.
- 5:23:47Okay. Already the code is there. Just
- 5:23:49need to copy
- 5:23:51get sender account. Okay. H then uh I
- 5:23:56need amount. Okay. Refund. So you know I
- 5:24:01need the amount.
- 5:24:03Okay. I'm getting it. And then
- 5:24:07uh refund. Okay. So also I need reason.
- 5:24:11Okay. reason I'm getting okay I got it
- 5:24:15fine now let me call send alert again
- 5:24:18and first my sender account okay the
- 5:24:22subject I put as refund and processed
- 5:24:28okay and message string dot format
- 5:24:33okay so your transaction of percent s
- 5:24:40was cancelled
- 5:24:42Okay.
- 5:24:45And
- 5:24:46transaction cancelled. Okay. And percent
- 5:24:49s has been
- 5:24:52refunded
- 5:24:54to account percent s. Okay. And what? So
- 5:25:00your transaction of
- 5:25:03uh one second. What is that?
- 5:25:07Transaction of percentile was canceled.
- 5:25:09And okay percent s
- 5:25:13has been refunded to percent s
- 5:25:16h
- 5:25:18also also let me just you know
- 5:25:22uh yeah let me give the reason two so
- 5:25:28percent s
- 5:25:30okay yeah now it is fine
- 5:25:35so there are total four fields we need
- 5:25:38to fill Okay. So your transaction of
- 5:25:42amount. Okay. And reason is reason.
- 5:25:46Okay. Then percent as has been refunded.
- 5:25:48Okay. So that to amount. Okay. And
- 5:25:52refunded to account sender account.
- 5:25:55Okay. Done. Yeah. Now in our catch block
- 5:25:59log dot error and error sending
- 5:26:06refund notification.
- 5:26:10Okay. E dot get message.
- 5:26:16Yes. Done. Next is next two more uh you
- 5:26:21know we need to consume two more events.
- 5:26:23Okay. So that two of our payment service
- 5:26:28first is public void and consume payment
- 5:26:33completed.
- 5:26:35Okay. So yeah same thing at payload
- 5:26:40payload
- 5:26:42H. Yeah.
- 5:26:45Okay. And at Kafka listener. So we
- 5:26:51already seen we coded our payment
- 5:26:54service just few minutes before. Okay.
- 5:26:58And our payment service payment service.
- 5:27:01Yeah. Payment completed and payment
- 5:27:04failed. So payment dot completed. Okay.
- 5:27:08Fine. And in coming few minutes we are
- 5:27:10going to test it. Okay. Real money uh
- 5:27:14testing. Okay. So topic and payment dot
- 5:27:18completed. now.
- 5:27:21Okay. And what I need? So, first I need
- 5:27:26account number. Okay. I already have
- 5:27:28already coded here. Uh, not here. Not
- 5:27:31here. Yeah, here.
- 5:27:33Account number. Okay. And then I need
- 5:27:38amount. Okay. From here. I get it.
- 5:27:43I got it. Okay. Fine. Now, let me call
- 5:27:46the send alert method. Okay. And let me
- 5:27:49pass account number. Okay. And then the
- 5:27:52subject, let me keep it as payment
- 5:27:58successful. Okay. And then string dot
- 5:28:03format. Okay. The message is payment of
- 5:28:09percent is completed. Okay.
- 5:28:13And
- 5:28:15then then what? So I also need to you
- 5:28:19know just display razor pay id okay and
- 5:28:25that to percent s okay fine
- 5:28:29yeah so
- 5:28:32um payment of percent s okay so payment
- 5:28:35of amount and razer pay id okay so that
- 5:28:40to let me get it from payload okay so
- 5:28:43payload dot get and razer pay. Okay.
- 5:28:47What's that?
- 5:28:49Payment. Payment service
- 5:28:53entity. Okay.
- 5:28:56Razer Pay payment ID. Okay. Fine. Back
- 5:29:00to our notification service and Razer
- 5:29:04Pay payment ID.
- 5:29:06Yeah,
- 5:29:09looks good. Now log dot error in the
- 5:29:13exception. Okay. Error sending
- 5:29:19error sending payment notification.
- 5:29:24Okay. And e do.get message. Fine.
- 5:29:28Similarly, let me also consume you know
- 5:29:30payment failed. Okay. In uh payment
- 5:29:34gateway side if something got failed.
- 5:29:35Okay. So that two we are handling. Okay.
- 5:29:38So public void consume
- 5:29:42payment
- 5:29:44failed.
- 5:29:46Okay. And payload.
- 5:29:49So
- 5:29:51okay fine. Thank you for autopop
- 5:29:55populating. Okay. Add kafka listener.
- 5:29:59What's the you know
- 5:30:02topic name? Payment service. And here we
- 5:30:05are payment dot failed.
- 5:30:09Okay.
- 5:30:11Notification service and
- 5:30:14topics
- 5:30:16payment dot failed. Yeah. Try catch.
- 5:30:21Okay. Exception
- 5:30:24and
- 5:30:27yeah. So now in this two let me directly
- 5:30:31copy and paste both of these fields
- 5:30:33account number and amount. Okay. done.
- 5:30:38And then uh send alert. Okay, I'm
- 5:30:42passing account number. Okay, in this
- 5:30:44case, subject is my payment and failed.
- 5:30:49Okay, and uh also one more thing. Yeah.
- 5:30:54So, a string dot format. Yeah. And uh
- 5:31:01your payment of percent s
- 5:31:06could could not be
- 5:31:09could not be processed. Okay.
- 5:31:17And
- 5:31:19then what? Please try again our
- 5:31:24contact support.
- 5:31:29Fine. Yeah, that will be good. And we
- 5:31:32have you know your payment of okay
- 5:31:35amount. That's it. Could not be
- 5:31:37processed. Please try again or contact
- 5:31:39support. Okay. in the catch block log
- 5:31:42dot
- 5:31:44error and
- 5:31:47error
- 5:31:50sending.
- 5:31:53Okay, payment failure.
- 5:31:59Yeah, we need to specify
- 5:32:01and notification
- 5:32:04e dot get message. Okay, so it is done.
- 5:32:07We have consumed all our you know uh
- 5:32:11events.
- 5:32:12Yeah. The first thing is OTP generated.
- 5:32:15Okay. Find and then uh what
- 5:32:20transaction completed debit alert credit
- 5:32:22alert and then if fraud detected that
- 5:32:24two we have consumed and then refunded
- 5:32:27also we have consumed payment completed
- 5:32:30and payment failed. Fine. So in each
- 5:32:33method we are you know calling one
- 5:32:35method that is send alert. Okay, because
- 5:32:37this method is only responsible to send
- 5:32:39alert and notify my user. Okay, so for
- 5:32:42now let me take all the alerts and
- 5:32:44notification in my logs my log terminal.
- 5:32:47Okay, because uh as our current focus
- 5:32:50should be on end to end testing of our
- 5:32:53digital banking system application.
- 5:32:55Okay, we need to test the important
- 5:32:57functionality. Okay, most importantly
- 5:33:00you know transfer method. Okay. And then
- 5:33:02what uh in the transaction service we
- 5:33:05have written you know verify OTP method.
- 5:33:08Okay. Before that fraud detection in
- 5:33:10real time. Okay. And uh you know OTP
- 5:33:14generated. Okay. Fine. And uh our
- 5:33:17notification service consume that and it
- 5:33:20will call verify OTP. Fine. And then you
- 5:33:23know refund process and uh properly
- 5:33:26implemented saga implementation. Okay.
- 5:33:29saga pattern and uh compensating. Okay,
- 5:33:32block and compensating and you know
- 5:33:35completing the transaction. Okay, so
- 5:33:38these are what our important
- 5:33:40functionality we need to test it out
- 5:33:42first. Okay, and we need to make sure
- 5:33:43that none of these broke. Okay, if any
- 5:33:46one of these will broke then we need to
- 5:33:48rectify there itself. Okay, once it is
- 5:33:51confirmed that our digital banking
- 5:33:54system ready to move to the production.
- 5:33:56Okay, then we'll implement this
- 5:33:58functionality. Okay, send alert. See,
- 5:34:00this is not important one. Anyway, we
- 5:34:02can take alerts in our logs. Okay, later
- 5:34:05on we can just implement you know SMS
- 5:34:09via Twilio API. Okay, which enables to
- 5:34:13you know uh send the SMS on our WhatsApp
- 5:34:16and uh you know SMS on phone and uh then
- 5:34:19we'll implement you know Java mail.
- 5:34:21Okay. To receive the, you know,
- 5:34:23notification on our mail. Fine. So,
- 5:34:26yeah, our current focus should be on end
- 5:34:28to end testing. Okay. And I recommend
- 5:34:30you not to miss a single second uh of
- 5:34:33our testing part. Yeah, that's it. So,
- 5:34:36let's you know take the alerts in our
- 5:34:39logs and then finally move to our most
- 5:34:41crucial part that is testing. Okay.
- 5:34:44Yeah, let's go. Okay. So log dot info
- 5:34:48and
- 5:34:51okay fine then log dot info. Okay. So
- 5:34:57account
- 5:34:59account number H. Then log dot info.
- 5:35:04Okay. So subject.
- 5:35:07Yeah.
- 5:35:09Uh subject. Okay. Fine. And then log dot
- 5:35:13info message. Okay. And finally
- 5:35:17log.info.
- 5:35:19Let me close it. Okay. Yeah. Okay. Fine.
- 5:35:23So I'm accepting you know all the
- 5:35:26notification alerts in my logs. Okay.
- 5:35:29Okay. Fine. Fine. Fine. For now. This is
- 5:35:31good. Okay. And let's shift all the
- 5:35:34focus should be on our testing part.
- 5:35:37Okay. Yeah. Fine. So before we start
- 5:35:40testing, let me just check all the
- 5:35:43files. Okay. whether uh any of the file
- 5:35:45remain untouched. Okay. So I guess uh
- 5:35:48you know our application Yeah. Okay. So
- 5:35:52application do yiml of our uh
- 5:35:54notification service is incomplete. Let
- 5:35:57us just complete this two. Okay. So
- 5:36:01spring application okay dot name. So it
- 5:36:05is notification
- 5:36:07and service. Fine.
- 5:36:11And then Kafka properties Kafka. Okay.
- 5:36:15Then bootstrap
- 5:36:18servers. Fine. So local host 9092.
- 5:36:24Okay. And then uh let us directly copy
- 5:36:30paste you know the entire consumer and
- 5:36:34producer. Okay. from my transaction
- 5:36:37service or any other service properties
- 5:36:40file you can just copy. Okay. Yeah.
- 5:36:44Done. Okay. The next thing is we just
- 5:36:47need to set the port number. Okay. So my
- 5:36:52applications uh notification service
- 5:36:55should run on the port 8085. Okay. And
- 5:36:58then management dot endpoints dot you
- 5:37:04know web dot exposure and include. So
- 5:37:10health and info.
- 5:37:13Okay fine. Yeah. So now I guess
- 5:37:16everything is done and we are good to go
- 5:37:18for our testing part. So first let me
- 5:37:22close all my services. Okay, let me just
- 5:37:27close all the tabs. Yeah. Okay. So, at
- 5:37:30very first thing what we need to do is
- 5:37:32just pay attention here. What we need to
- 5:37:34do is
- 5:37:36first thing is uh we need to check our
- 5:37:39data flow.
- 5:37:42Okay. Or I can say infrastructure.
- 5:37:45Yeah. That means uh whether our um you
- 5:37:49know services is running or not. Okay.
- 5:37:51Our data services I'm talking about.
- 5:37:53Okay. So you know Radius, Kafka,
- 5:37:58Zookeeper, MySQL.
- 5:38:01Okay. Yeah. Okay. And the second thing
- 5:38:05is um you know we are going to set up
- 5:38:12our Razer Pay
- 5:38:15payment gateway account and we'll get
- 5:38:19key ID and
- 5:38:23key secret.
- 5:38:25Okay. and we'll you know add both of
- 5:38:30these in our payment service
- 5:38:34you know properties file. Okay. Yeah.
- 5:38:37And third thing is
- 5:38:40third thing is what we need to do is we
- 5:38:43need to run the services one by one.
- 5:38:46Okay. Account service you know uh API
- 5:38:49gateway fraud detection notification
- 5:38:51payment service. Okay. Transaction
- 5:38:54service. Fine. And then finally we'll
- 5:38:56open our postman. Okay. And we'll test
- 5:38:59all our you know internal payments and
- 5:39:01uh endpoints one by one. Okay. We'll
- 5:39:03verify and we'll verif uh verify the
- 5:39:06alerts everything else. Okay. And at
- 5:39:09last we'll verify our you know external
- 5:39:11payments that is our Razer Pay site. So
- 5:39:14ready to go. Okay. We are good to go.
- 5:39:17Let me just
- 5:39:20start. Okay. The very first thing is let
- 5:39:22me you know open my Docker. Okay. We
- 5:39:24have already done setting up all the
- 5:39:27environments at the starting of the
- 5:39:28video. Okay, my banking system and
- 5:39:31Kafka, Radius, Zookeeper is up and
- 5:39:34running beautifully. Okay, and the
- 5:39:36fourth service is MySQL. Okay, so MySQL
- 5:39:39I already installed on my local machine.
- 5:39:41So yeah, definitely that to my up and
- 5:39:43running. Next thing is let me go to my
- 5:39:45you know browser and let's set up our
- 5:39:48payment gateway account. Okay. Yeah.
- 5:39:51Okay. So here's my browser and you just
- 5:39:54need to type here Razerpay. Okay, Google
- 5:39:58it and click on the very first link that
- 5:40:00is razor.com. Okay, you can just check
- 5:40:04out the website. Fine. The very first
- 5:40:07thing we need to do is we need to sign
- 5:40:09up. Okay, so just click on the top right
- 5:40:12button, sign up button. Okay, and yeah,
- 5:40:14we'll land here on the sign up page.
- 5:40:16Fine. Now uh
- 5:40:20you know you'll be asked to enter few
- 5:40:24basic details like uh email okay and uh
- 5:40:28phone number you know whatever name and
- 5:40:31everything else okay and at last you
- 5:40:35know the you know payment gateway ask
- 5:40:38you for your bank account details bank
- 5:40:41account details okay in order to collect
- 5:40:44the payments from other users
- 5:40:48Okay. Yeah, definitely. So, bank account
- 5:40:51details and then just click on the next
- 5:40:53next next and you'll land on the you
- 5:40:56know uh dashboard. Okay. Fine. So, I
- 5:41:00already signed up. So, let me just
- 5:41:02directly log into my account. Okay. So
- 5:41:06once you logged into your account and
- 5:41:08you land here okay on the homepage you
- 5:41:11can see there are a lot of options
- 5:41:12payment links payment you know pages
- 5:41:15payment uh razor pay.m me okay link
- 5:41:18invoices payment button and other
- 5:41:20options fine so what you need to do is
- 5:41:24just you know you can see here account
- 5:41:26and settings okay click on this button
- 5:41:29and you land here on the account and uh
- 5:41:32product settings page fine under website
- 5:41:36and app settings. There's a you know
- 5:41:38link API keys. Just click on it. Okay.
- 5:41:41And you land here. Yeah. So you can see
- 5:41:45there are two options website and API
- 5:41:48keys and web hooks. Okay. Yeah. So at
- 5:41:52first here under website and API keys
- 5:41:55you can just first uh if you have then
- 5:41:58you can just add your website or app.
- 5:42:00Okay. And second is API key and
- 5:42:04integration. Okay. So you know you can
- 5:42:07see I already generated one API key.
- 5:42:09Okay. That is key ID and key secret.
- 5:42:12Okay. In case you know you are if you
- 5:42:14are new to the this uh Razer Pay payment
- 5:42:16gateway then you can just click on the
- 5:42:19button. Okay. And generate a new key ID
- 5:42:22and key secret. Okay. API keys
- 5:42:24credentials. Fine. Okay. And uh this is
- 5:42:29what you know we'll get our key ID key
- 5:42:31secret and once yeah once generated just
- 5:42:34save that into your you know secure
- 5:42:36place in your uh you know file system.
- 5:42:39Okay. Because we need them in our
- 5:42:42payment service. Okay. Yeah. So where we
- 5:42:45need payment service src main resources
- 5:42:49application yiml and yeah here can you
- 5:42:52see we have already added the properties
- 5:42:55razer pick key id and key secret
- 5:42:59okay fine yeah okay so this is what our
- 5:43:03uh you know websites and API keys fine
- 5:43:07next is our web hooks okay so can you
- 5:43:11see here is one button add new web hook.
- 5:43:15Okay, just click on that. Okay, and uh
- 5:43:19yeah, I want all of you to focus on this
- 5:43:22thing active events. Okay, I already
- 5:43:25told you that webbook has the you know
- 5:43:28hundreds of events.
- 5:43:30Okay, my web hook capture the event and
- 5:43:34notify to my back end. Okay, so suppose
- 5:43:37you know suppose there is a user. Okay.
- 5:43:41And uh my user let's say this is my
- 5:43:44user. Okay. And user have purchased
- 5:43:46something from Amazon. Okay. Click on
- 5:43:48the checkout page. Once check out page
- 5:43:51you know this is what my checkout page
- 5:43:53and uh you know enter all the bank
- 5:43:56credentials everything else. Fine. And
- 5:43:59something got failed here.
- 5:44:01Okay. Something got failed from my you
- 5:44:04know that Razer Pay payment gateway
- 5:44:06site. Okay. So my web hook. Okay, with
- 5:44:10the help of web hook, you know what
- 5:44:13he'll do is he will capture that failed
- 5:44:16event. Okay, because my web hook has lot
- 5:44:21of events, you know, mentioned here. So,
- 5:44:24let me just zoom it. Yeah, can you see
- 5:44:27payment events? So, under payment
- 5:44:28events, payment unauthorized,
- 5:44:31payment.failed. So, we'll just check it.
- 5:44:34Okay, payment.aptured. Okay, if payment
- 5:44:36is successfully done, then
- 5:44:38payment.captured captured is you know uh
- 5:44:41is captured by my web hook. Okay. And
- 5:44:44notify to my back end. Then back end
- 5:44:48will uh proceed forward as per our code
- 5:44:50what uh what we have you know written.
- 5:44:53Okay. Next is payment dispute created.
- 5:44:57Payment dispute won lost. Okay. And then
- 5:45:00order events. Order paid. order
- 5:45:03notification delivered, failed, invoice,
- 5:45:05subscription events, active, pending,
- 5:45:08halted, charged, okay, settlements, QR
- 5:45:11events, fund accounts, events, refund
- 5:45:13events, transfer accounts. So, lot of
- 5:45:16events, okay? Almost you know 100 plus.
- 5:45:19So, we don't need to take care because
- 5:45:21see Razer Pay is another party. It's not
- 5:45:24a part of our bank. Okay? So if suppose
- 5:45:27my user is paying something you know uh
- 5:45:29someone to the external merchants to
- 5:45:32Amazon okay or uh to some other uh you
- 5:45:35know on Airbnb or whatever to external
- 5:45:38payments okay so there is someone
- 5:45:41payment gateway okay now if something
- 5:45:44got happened captured whatever okay so
- 5:45:47we need someone to capture that and
- 5:45:50notify to our back end whatever happened
- 5:45:53on the you know front side on the
- 5:45:56payment gateway side. So that is what
- 5:45:58our web hook setup will do for us. Web
- 5:46:02hook is not mandatory. Okay. Yeah. But
- 5:46:06it is recommended. Okay. It is not
- 5:46:08mandatory for the real payments. Fine.
- 5:46:11But it is recommended. Okay. because uh
- 5:46:15you know the payment gateway also has
- 5:46:17their internal handling process for the
- 5:46:20failure and uh for the you know success
- 5:46:25okay like uh once payment got successful
- 5:46:28so they'll redirect on some other
- 5:46:29website okay or on other page or if
- 5:46:32something got failed then they'll ask
- 5:46:35user to retry okay and the third part is
- 5:46:38currently we can't set up our web hook
- 5:46:42okay because you can See here it is
- 5:46:44asking us webbook URL and HTTPS URL is
- 5:46:48recommended. Okay. So the very first
- 5:46:51thing okay we need what we need domain
- 5:46:54name. Okay. Domain
- 5:46:57name let's say
- 5:47:00uh our you know digital banking
- 5:47:03system.com.
- 5:47:05Okay. And and in actual this is not
- 5:47:09enough. Okay. what we need to enter
- 5:47:12here. Just listen to me. So, first once
- 5:47:15we'll uh get our domain name dbs.com/
- 5:47:19our payment
- 5:47:22service
- 5:47:24you know base URL pattern.
- 5:47:28Okay. So in our controller you know we
- 5:47:31have just uh added our URL pattern in
- 5:47:33the request mapping. Okay. So let's say
- 5:47:36this is our domain name. So DBS
- 5:47:39okay.com/appi
- 5:47:42you know v1 and
- 5:47:45payments yeah this is only okay let me
- 5:47:49check it so where is our payment okay
- 5:47:53first java controller payment controller
- 5:47:57yeah this one API v1 payments
- 5:48:02this is what we need to enter okay fine
- 5:48:05so this is what We need to enter and our
- 5:48:09entire URL is this dbs.com. Okay,
- 5:48:12whatever domain name /api v1 and
- 5:48:16payments and this is complete thing we
- 5:48:18need to enter here. Okay, but
- 5:48:20unfortunately we don't have our domain
- 5:48:22name. Okay, fine. So one thing for you,
- 5:48:26okay, one homework for you that uh you
- 5:48:28can just you know complete the project
- 5:48:30and host this project. Okay, even on the
- 5:48:33free tier and then try web hook. I want
- 5:48:37you to try. Okay, and next thing is
- 5:48:42Okay, next thing is secret. Okay, so
- 5:48:44just add you know some uh strong secret
- 5:48:47just like uh we used to add in our JWT
- 5:48:51you know token. So also mentioned here
- 5:48:54that we strongly recommend adding
- 5:48:56secrets for security. Okay, then alert
- 5:48:58email. Okay. And next thing is what? So
- 5:49:04whatever events we have handled. Okay.
- 5:49:07So we have handled payment failed and
- 5:49:09payment capture just check it. Okay. Or
- 5:49:12whatever you know you just uh need to
- 5:49:14check. Just you know have the proper
- 5:49:17handling code in the back end. Okay. And
- 5:49:21create web hook.
- 5:49:23So it will you know uh create a web hook
- 5:49:27and whatever secret you have given here
- 5:49:30just copy that secret and paste it into
- 5:49:35your application yml here web hook
- 5:49:38secret.
- 5:49:39Yeah. So this is you know kind of our uh
- 5:49:43razor pay website a uh sorry API keys
- 5:49:47integration and webbook integration is
- 5:49:49done. we are all good to take you know
- 5:49:54uh payments from the user also one last
- 5:49:58thing that is uh you can see our current
- 5:50:00mode is test mode okay can you see this
- 5:50:03test mode okay test mode so yeah no real
- 5:50:08money moves for now okay so why because
- 5:50:12you know currently we are testing our
- 5:50:13application okay once will uh you know
- 5:50:16once our application is tested
- 5:50:18thoroughly it is confirmed that we can
- 5:50:20move our application to the production
- 5:50:22then we'll uh toggle it and change it to
- 5:50:25the production. Okay. Now important
- 5:50:28thing is once you'll change it to the
- 5:50:30production you need to generate a new
- 5:50:33API key and that two for the production.
- 5:50:37Okay. So the current API key uh API keys
- 5:50:41are for the testing test uh test mode.
- 5:50:45Okay. So these API key will not work
- 5:50:47there. Okay. Once you'll generate the
- 5:50:50API key for uh you know production that
- 5:50:55works as your real payment okay that
- 5:50:58takes your real payment. Okay. So for
- 5:50:59that too you know uh they have a few
- 5:51:02requirement. The first requirement is
- 5:51:04your bank details should be verified.
- 5:51:08Okay. Second thing is you should have a
- 5:51:10proper you know website hosted on a you
- 5:51:13know some domain.
- 5:51:16Yeah definitely. Okay. Then only they'll
- 5:51:18allow you to put their uh API key and
- 5:51:21key ID and key secret on you know your
- 5:51:23website. Okay. Fine. Yeah. Same thing
- 5:51:26with the test mode. Okay. Just uh we'll
- 5:51:29do the you know money transfer
- 5:51:31everything will handle success and
- 5:51:32failure. Okay. But there is no real
- 5:51:35money moment happens here. Okay. Yeah.
- 5:51:38And also I just already told you what
- 5:51:40you need to do that. Yeah. Okay. Fine.
- 5:51:42So now our Razer Pay payment setup is uh
- 5:51:47all done. Okay, we are good to go to
- 5:51:50start all our you know microservices. So
- 5:51:53now let's start our you know all the
- 5:51:55microservices one by one. Fine. So let
- 5:51:58me start with API gateway and yeah one
- 5:52:00more thing one more thing. So make sure
- 5:52:02that you have updated all the values you
- 5:52:05know in our uh account service
- 5:52:08application.
- 5:52:10Okay what values? So values
- 5:52:14uh of MySQL
- 5:52:18username and password.
- 5:52:22Okay, because I updated it. Okay, and
- 5:52:24second thing is you know make sure that
- 5:52:27you have you know set the proper key ID
- 5:52:32and key secret what we have just now
- 5:52:35fetched okay from the Razer P. Yeah. Uh
- 5:52:39okay fine. And also third thing is
- 5:52:43uh add enable fain client annotation.
- 5:52:48Okay. Yeah.
- 5:52:50Fine. Now let me start my you know all
- 5:52:54the microservices. So let's start with
- 5:52:57our API gateway. Okay. Uh
- 5:53:04API gateway. Okay. And run. Yeah. So,
- 5:53:11okay, my API gateway service is
- 5:53:16you know started. Okay. And I guess
- 5:53:20running on the port 8080.
- 5:53:23Okay. Fine. Yeah. So,
- 5:53:28all looks good. Okay. In the application
- 5:53:31yml.
- 5:53:34One second. 1 second.
- 5:53:37Oh, okay. Okay. Okay. Okay. Let me
- 5:53:39terminate it. Okay.
- 5:53:41Fine.
- 5:53:43Yeah. So, close all. And here it should
- 5:53:47be rate
- 5:53:50limiter dot replenish rate and dot burst
- 5:53:54capacity. Okay. Instead of hyphen.
- 5:53:58Okay. Dot. Yeah.
- 5:54:02H because see we are allowing you know
- 5:54:06uh at most 10 request and burst capacity
- 5:54:11is 20 request okay in order to prevent
- 5:54:14our application from attackers. Okay. So
- 5:54:16that they you know can't able to make uh
- 5:54:205,000 or 6,000 request in one go. Okay.
- 5:54:24That is what you know why we have just
- 5:54:26put the rate limiter. Okay. Yeah. Now it
- 5:54:28is good. So just you know uh update your
- 5:54:32application yml too. Okay. And now again
- 5:54:35let me restart.
- 5:54:38See uh so you know
- 5:54:41that is what the benefit of uh testing
- 5:54:44part. Okay. Because we'll get to know
- 5:54:47where we can commit you know the
- 5:54:49mistake. Okay. And will rectify that
- 5:54:52itself. Yeah. Okay. It started. And then
- 5:54:57let me now start my account service.
- 5:55:01Okay. So Java and account service. Okay.
- 5:55:04Fine.
- 5:55:06Run. Also let me parallelly check the
- 5:55:11application. YML. Okay. So my account
- 5:55:14service is running on the port 8081. And
- 5:55:18yeah. So I want you know all of you to
- 5:55:21focus on my screen. Okay. And look at
- 5:55:25here
- 5:55:26in the Kafka properties we have group
- 5:55:28ID. Okay. So make sure that whatever
- 5:55:31group ID you have you know uh kept
- 5:55:36in one service. Okay. That should not be
- 5:55:40repeat in another.
- 5:55:43Okay. So for account service our group
- 5:55:45ID is you know account service group.
- 5:55:48Yeah. And it is running. Yeah. It
- 5:55:51started my application. Okay. Fine.
- 5:55:54Okay. Next is let me start my
- 5:55:57transaction service. Okay. Transaction.
- 5:56:00Okay. First thing is make sure that you
- 5:56:04have added this uh enable f client
- 5:56:07annotation.
- 5:56:09Okay. Yeah. Second thing is in the
- 5:56:12resources
- 5:56:14and yeah can you see this in the
- 5:56:18transaction service application yiml.
- 5:56:21Okay. group ID is same as
- 5:56:24of account service. Okay. So here we
- 5:56:29should have to update you know
- 5:56:31transaction service group.
- 5:56:35Yeah fine. Now it is uh fine else you'll
- 5:56:40face the error. Okay. while testing
- 5:56:45run
- 5:56:47and yeah now my you know transaction
- 5:56:51service is running on the port I guess
- 5:56:548082
- 5:56:57okay yeah
- 5:57:00so
- 5:57:01you know let it run and then uh after
- 5:57:05that we'll start our fraud detection
- 5:57:08service okay fraud detection service
- 5:57:11fine
- 5:57:13So okay it started fine great then fraud
- 5:57:17detection service. Okay you should you
- 5:57:19know add this uh enable fe clients and
- 5:57:22in the resources let me first check.
- 5:57:26Yeah can you see this here too here to
- 5:57:29account service group. Okay fraud
- 5:57:33service group.
- 5:57:35Okay now let me just hit the run.
- 5:57:40Okay. Yeah. Next thing is uh let's start
- 5:57:44our notification service.
- 5:57:47So
- 5:57:49you know notification and
- 5:57:52in the resources
- 5:57:54can you see this because you know we
- 5:57:57have just copied this code from consumer
- 5:58:00till producer. Okay but we forget to
- 5:58:03update this uh group.
- 5:58:07Okay so let's modify it. Notification.
- 5:58:12Okay. Notification
- 5:58:14service group. Yeah. Okay. So, my fraud
- 5:58:18detection service is up and running.
- 5:58:20Now, let me just hit run. Okay. And
- 5:58:26notification service started. Okay. And
- 5:58:29next is our payment service. Okay. So,
- 5:58:34payment service. Fine. and resources
- 5:58:38application yml and here yeah fine no
- 5:58:42consumer so let me start my payment
- 5:58:44service okay
- 5:58:47and
- 5:58:50started on the port I guess 8083
- 5:58:56yeah so
- 5:59:11Yeah.
- 5:59:13On port 8083.
- 5:59:15Okay. Fine. Now let's test our you know
- 5:59:19all the endpoints of our digital banking
- 5:59:22system. Yeah. So for that I already
- 5:59:25opened my Postman. Okay. And the very
- 5:59:29first thing is what we need to do. The
- 5:59:32first thing is we need to create sender
- 5:59:34and receiver account. Okay. So let me
- 5:59:39just go to my account service.
- 5:59:42Okay. Controller account controller.
- 5:59:44Okay. And here API v1 accounts. Okay.
- 5:59:51Fine. And create account. Create account
- 5:59:54request. Yeah. So, HTTP
- 6:00:00localhost
- 6:00:028080.
- 6:00:04Okay. Yeah. All request through gateway
- 6:00:08and then API accounts. That's it. Post
- 6:00:11mapping body. Okay. Raw and
- 6:00:17JSON. Fine. The first is my in the
- 6:00:21request account holder name. Okay. So
- 6:00:25let's say John Doe. Okay. Next is email,
- 6:00:30phone, account type, and initial
- 6:00:32deposit.
- 6:00:34Okay. So, email. Okay. So, let's say
- 6:00:40John at
- 6:00:42testmail.com.
- 6:00:44Okay. Next is our phone. Okay. So
- 6:00:509 9999 99999.
- 6:00:55Okay. Yeah.
- 6:00:57And then account type.
- 6:01:02Okay. So let's say savings.
- 6:01:06Okay. And finally initial deposit.
- 6:01:11Okay. So initial deposit uh let's say
- 6:01:1510,000.
- 6:01:17Okay. Fine. Now let me send the request
- 6:01:20and yeah sending request.
- 6:01:24My account is going to create. Yeah
- 6:01:27created. So phone number account type
- 6:01:30savings status and I want you all to
- 6:01:33focus on this field account number.
- 6:01:37Yeah. So if you remember how we have
- 6:01:40implemented our account number you know.
- 6:01:44So it should be 12 digit unique.
- 6:01:48Yes. And then we have formatted like a
- 6:01:51string. Okay. And inside uh percent then
- 6:01:56replace with zero. Okay. Then of 12
- 6:01:59digit. Okay. And then decimal integer.
- 6:02:02And then here is my random number.
- 6:02:05Remember? Yeah. So this is how you know
- 6:02:09it is our code is perfectly generating
- 6:02:12the 12digit number. Similarly let me
- 6:02:17create the receiver. So let's treat it
- 6:02:19as a sender. And now receiver. So same
- 6:02:23thing. Okay. And post mapping. Okay.
- 6:02:27Body raw text JSON. Let me just copy
- 6:02:33and paste it here. Okay. paste. Fine.
- 6:02:37So, let's say Jane. Okay. And
- 6:02:43Jane. Fine. Phone number. Let me replace
- 6:02:46it with, you know, 88 888
- 6:02:5088 88 88 88 888. Okay. And initial
- 6:02:55deposit, let's say, um, what? 6,000. H.
- 6:03:01Okay. Send it. Yeah. So
- 6:03:06okay done. Now also let me you know
- 6:03:10check the balance. Okay we have that you
- 6:03:14know get balance. Okay using account
- 6:03:16number/balance.
- 6:03:19Okay fine. So
- 6:03:23API accounts and using account number.
- 6:03:27So let me just you know
- 6:03:30paste here account number and
- 6:03:34balance. Okay. So I'm expecting 10,000.
- 6:03:38Okay. This is of uh sender balance
- 6:03:41sender account number. So yeah 10,000.
- 6:03:45So now next thing is let's transfer.
- 6:03:48Okay. The first thing is happy path. H.
- 6:03:51So where is my transaction service?
- 6:03:55Transaction
- 6:03:57controller. Transaction controller.
- 6:03:59Okay. And transfer.
- 6:04:03Okay. Transfer request. Sender account
- 6:04:06number. Okay. Receiver account number.
- 6:04:09I'm transferring amount and description.
- 6:04:13Okay. Fine. And here API v1 transaction
- 6:04:17transfer. Okay. So next is
- 6:04:22you know API v1
- 6:04:25transactions.
- 6:04:27Okay. And
- 6:04:30transfer
- 6:04:32it is post mapping body raw
- 6:04:36JSON. Okay. And the first is what?
- 6:04:43Sender account number.
- 6:04:46H which is sender account number which
- 6:04:49is this.
- 6:04:51Okay.
- 6:04:54Second is my
- 6:04:56receiver account number. Okay. So
- 6:05:01receiver is
- 6:05:03yeah this is
- 6:05:07okay and then amount. Okay. So amount
- 6:05:11let's say what 600. Okay. And
- 6:05:18description.
- 6:05:20Okay. So, description. Let's say test
- 6:05:26transfer.
- 6:05:28Uh okay. Fine. So, first let's consider
- 6:05:32our happy path. Okay. Nothing fraud is
- 6:05:34detected. And let's you know sender
- 6:05:38initiate the you know transaction of
- 6:05:41600. Okay. Let me send it. So
- 6:05:45okay sending request and yeah can you
- 6:05:48see status is pending and this is what
- 6:05:51my ID
- 6:05:53okay sender account receiver account
- 6:05:56fine now I want all of you to focus on
- 6:06:00my logs
- 6:06:02okay first transaction logs okay so
- 6:06:05transaction logs started here you know
- 6:06:09saga is step number two okay step number
- 6:06:11one is Yeah. Saga start. Okay. Transfer.
- 6:06:18Fine. And also let's go here. Okay.
- 6:06:22Service. Transaction service.
- 6:06:24Fine.
- 6:06:26And where is our transfer? Yeah. So this
- 6:06:28is what transfer. And first thing is
- 6:06:31deduct from sender. Okay. So let me just
- 6:06:33check my sender balance. Okay. Initially
- 6:06:3610,000 but now it should be 9.4K. Yeah.
- 6:06:40Can you see? 9,400. Okay. Fine. And then
- 6:06:44transaction created, saved and published
- 6:06:48event. Transaction initiated.
- 6:06:51Okay. This event
- 6:06:54consumed by our fraud detection. Fraud
- 6:06:57detection. Fraud detection.
- 6:07:00Okay. Fraud detection service. H. Where
- 6:07:05is my Yeah. Fraud detection service
- 6:07:09consumed. Okay. this event and call this
- 6:07:14check transaction. Check transaction.
- 6:07:17Done. Done. Done. And nothing fraud is
- 6:07:20detected. Okay. And
- 6:07:23comes outside of the if statement. And
- 6:07:25here fraud check clean. That means
- 6:07:29everything is clean. Complete the
- 6:07:31transaction. Okay. So this event is
- 6:07:34going to consumed by again my
- 6:07:36transaction service.
- 6:07:39Okay. So
- 6:07:43hm where is that? Uh yeah fraud check
- 6:07:47clean which is calling process clean
- 6:07:50result and complete transaction.
- 6:07:54Okay transaction dot completed topic
- 6:07:59H. Okay and transaction completed is
- 6:08:03consumed by my next is notification.
- 6:08:07Notification. Notification.
- 6:08:10Okay. So,
- 6:08:13transaction completed and
- 6:08:16debit alert. Credit alert. Okay. So, now
- 6:08:19just focus on notification and yeah, can
- 6:08:22you just look at this
- 6:08:24debit alert? Okay. This is my sender
- 6:08:28account number, credit alert and
- 6:08:31receiver account number. 600 debited
- 6:08:34from 600 credited uh sorry credited
- 6:08:40here it should be two okay yeah mistake
- 6:08:42so no worries created to uh this account
- 6:08:46okay fine done so this is the happy path
- 6:08:50now let's uh you know add a fraud in
- 6:08:54this okay so which fraud let me just add
- 6:08:58uh velocity fraud H that means uh let's
- 6:09:03say I'm the fraudster and uh you know I
- 6:09:07have ran a script
- 6:09:10okay and that script fires fires you
- 6:09:14know six transaction six transaction
- 6:09:17immediately in uh less than 10 seconds.
- 6:09:22Okay, maybe you know uh the fraudster
- 6:09:25you know just run the script and that
- 6:09:28fires 500 transactions. Okay, 50
- 6:09:31transaction in in a few seconds. Okay,
- 6:09:33so let's take six transaction in uh 10
- 6:09:36seconds or maybe in 6 seconds. Fine. So,
- 6:09:40let me just do that. Okay, fine. Let me
- 6:09:44go to my Okay. Uh
- 6:09:53yeah, Postman. And this is what the
- 6:09:56transfer. Okay. So, let me just hit six
- 6:09:59times. Okay. 1 2 3 4 5 6. Okay. Fine.
- 6:10:09Now transaction service. And
- 6:10:14here
- 6:10:16it is, you know. Can you see this?
- 6:10:201 2 3 four times. Okay.
- 6:10:24And
- 6:10:29finally, yeah, that's what I'm looking
- 6:10:31for. OTP generated for transaction.
- 6:10:34Okay, so just look at here. Every time
- 6:10:37you know we initiate a transaction, my
- 6:10:39fraud detection service will check it.
- 6:10:42Okay, we'll check it and
- 6:10:45it will check all three fraud. Okay. But
- 6:10:49we have now you know explicitly that
- 6:10:52added a fraud. Okay. And that two
- 6:10:55velocity exceeded fraud. Yes or no? The
- 6:10:58too many transaction in 60 seconds. So
- 6:11:01we have you know quickly just uh you
- 6:11:05know made six or more than five
- 6:11:07transactions in few seconds. So
- 6:11:11you know it just hit the count which uh
- 6:11:16becomes greater than uh this maximum
- 6:11:19value allowed. Okay, which we have
- 6:11:21already set it as five.
- 6:11:24Okay, that's why we have you know just
- 6:11:27uh make six transaction quickly. Okay.
- 6:11:31So yeah definitely fraud is detected and
- 6:11:35verification required topic is you know
- 6:11:39sent. Now this verification required
- 6:11:42topic that means verification is
- 6:11:44required. So in that case we need to
- 6:11:46generate OTP and uh who's going to
- 6:11:50generate OTP? My transaction service
- 6:11:52event consumer. Okay. So here
- 6:11:58OTP generator. Okay, can you see in the
- 6:12:00transaction service logs OTP generated?
- 6:12:05Okay, and once OTP generated
- 6:12:09you know uh
- 6:12:12OTP generated event okay I publish this
- 6:12:15and this is going to consume by my
- 6:12:18notification service
- 6:12:20OTP generated
- 6:12:22okay here I'm displaying this
- 6:12:26notification
- 6:12:28Error
- 6:12:31sending OTP notification
- 6:12:34format a specifier.
- 6:12:36Okay.
- 6:12:39Oh, one second. One second. Mistake.
- 6:12:41Mistake. H we haven't you know completed
- 6:12:45this. So suspicious activity detected on
- 6:12:47your account. Reason is reason. Then a
- 6:12:52transaction of what amount
- 6:12:56is pending verification. Your OTP is
- 6:13:00OTP. Okay. Wait for 5 minutes. Okay. And
- 6:13:06yeah, that's it. Okay. Fine. So again,
- 6:13:10let me you know restart it.
- 6:13:14Okay.
- 6:13:17Okay. So notification service and
- 6:13:22stop and rerun. Okay, because see we
- 6:13:24haven't completed it. Okay, so
- 6:13:27definitely format a specify error. Okay,
- 6:13:31so first let it you know rerun.
- 6:13:36Okay fine. So now now what? Now let me
- 6:13:42just do again. Okay, let me
- 6:13:46again
- 6:13:47just commit a fraud. Okay, so 1 2 3 4 5
- 6:13:556. Okay, some fraudster is trying to you
- 6:13:59know uh drain the counts running the run
- 6:14:01the script and initiated few transition
- 6:14:04in 60 seconds. Fine. Now same thing
- 6:14:08happened. The fluke goes like uh yeah
- 6:14:11can you see this suspicious activity
- 6:14:14detected on your account. Okay on the
- 6:14:17sixth transaction. Okay reason too many
- 6:14:20transition in 60 seconds velocity
- 6:14:22exceeded.
- 6:14:24Okay transition of 600 is pending
- 6:14:26verification. Okay because see now bank
- 6:14:29detected that uh you know on this
- 6:14:32account continuously transition is
- 6:14:35happening. So they put on this
- 6:14:37verification and your OTP is this valid
- 6:14:41for 5 minute. If this wasn't you, ignore
- 6:14:44this message. Okay, fine. So
- 6:14:49you know
- 6:14:51uh yeah,
- 6:14:53let me just copy this message. Okay, and
- 6:14:57let me hit the API. Which API?
- 6:15:01Our transaction controller. and this
- 6:15:05verify OTP. Okay, this API
- 6:15:09in the request param let me pass this.
- 6:15:13Okay, fine. My postman
- 6:15:16and transaction.
- 6:15:19Fine.
- 6:15:20Transaction ID. Okay, verify
- 6:15:25transaction ID is what? This is my
- 6:15:28transaction ID. Okay, let me just
- 6:15:34put that.
- 6:15:37Okay, and verify.
- 6:15:40Fine. And then request param. Okay. So,
- 6:15:44question mark. Fine. Then OTP equals
- 6:15:49what is the OTP? 242990.
- 6:15:52242990.
- 6:15:53Okay. Fine. And post mapping. Okay. So,
- 6:15:57send it. And can you see this status is
- 6:16:01completed.
- 6:16:03Okay, that means genuine.
- 6:16:06Genuine. Okay. So now your job is to
- 6:16:09test it with you know wrong OTP. Let's
- 6:16:12say 1 2 3 4 5 6. Okay. And expired OTP.
- 6:16:17Fine. So we have provided for all the
- 6:16:20you know things. Right. So in our
- 6:16:24transaction service
- 6:16:26uh
- 6:16:28you know here block account block and
- 6:16:32compensate refund. Okay. Okay. Yeah. So
- 6:16:36in case of OTP expired in case of wrong
- 6:16:40OTP entered in case of you know else
- 6:16:43there's uh correct OTP. Okay. So you can
- 6:16:46just try these two. Okay. In this case,
- 6:16:49you know, uh user will get refund.
- 6:16:54Okay. Fine. Yeah. Simple. You can try.
- 6:16:57Yeah, you can just try. Fine. Okay. Now,
- 6:17:00let's move to our next part. Okay. See,
- 6:17:03this is what our first part is done.
- 6:17:06Okay. So, every bank system has you know
- 6:17:08two parts. Okay. Same as ours. So, first
- 6:17:11is our internal payments. Fine. Internal
- 6:17:14payments just like we did. Okay. Second
- 6:17:16is our external payments. Yeah. So for
- 6:17:21this we have you know set up our Razer
- 6:17:25Pay uh account.
- 6:17:28Okay. I told you suppose if you have
- 6:17:31purchased something from Amazon. Okay.
- 6:17:33External payments. Okay. Or any other
- 6:17:35website. Yeah. So to the checkout page,
- 6:17:38payment gateway and success or failure.
- 6:17:41Yeah. Let's do that. Okay. Fine. So now
- 6:17:46let's do that and okay. Okay. So for uh
- 6:17:51our external payments I have created
- 6:17:53yeah a simple uh page front end page.
- 6:17:56Okay. Let me just uh go to my file
- 6:17:59explorer.
- 6:18:01Okay. And yeah this is payment. Let me
- 6:18:05just copy
- 6:18:07aspath
- 6:18:10and my browser. and then paste it here.
- 6:18:16So
- 6:18:19yeah, banking payment demo. Okay, so you
- 6:18:24know, let me just write the account
- 6:18:26number here. Okay, or account number
- 6:18:30sending to my receiver account. Okay,
- 6:18:34receiver account number. And here, let
- 6:18:37me just take in dollars. Okay, fine. So
- 6:18:41pay now. Can you see? Creating payment
- 6:18:44order. No key passed.
- 6:18:48Okay.
- 6:18:49Let me go to my code.
- 6:18:54Uh length must Oh, one second. One
- 6:18:57second. I remember
- 6:18:59what we have done. Okay. So, in our
- 6:19:02payment service,
- 6:19:04uh yeah, can you see? I told you here in
- 6:19:07the currency, you should have to put
- 6:19:09just one. Okay, let me put the USD.
- 6:19:12Okay, USD. USD.
- 6:19:17Okay. And US dollar. Okay. Fine. So, you
- 6:19:21can just put uh whatever currency INR,
- 6:19:24GBP, whatever. Okay. Let me put the USD.
- 6:19:28Okay. Fine. And uh then again rerun my
- 6:19:35you know
- 6:19:37payment service. Okay.
- 6:19:41Fine.
- 6:19:42Okay. And we are just about to, you
- 6:19:45know, finish.
- 6:19:48And uh Okay. Running on the port 8083.
- 6:19:53Fine.
- 6:19:56Okay.
- 6:20:04Yeah. So, back to our browser and $10
- 6:20:08pay now. Creating payment order and
- 6:20:12yeah, can you see? So,
- 6:20:16$10.
- 6:20:18Okay, I'm paying and yeah, so let me
- 6:20:22just add the, you know, sample card.
- 6:20:26Okay, so let's say 2 1 3 2 Okay. Okay. 1
- 6:20:312 3 4 21 2 1 4 3 you know 3 2 4 1. Okay.
- 6:20:38Whatever. Fine. And uh expired date
- 6:20:41let's say you know 6 27. Okay. And uh
- 6:20:46CVB 1 2 3. Okay. And continue. Fine.
- 6:20:50Maybe later you can just save it. And
- 6:20:53now this is what our you know banking
- 6:20:55system. Okay. Paying $10 now. Yeah. Can
- 6:20:59you see this page? Okay. So now Razer
- 6:21:03Pay is asking us that uh you know you
- 6:21:06want to proceed as success or failure.
- 6:21:10Okay. Because you know we are testing in
- 6:21:12our testing mode and it is better to
- 6:21:14test both cases. Okay. Fine. And
- 6:21:18obviously we are handling both. Okay.
- 6:21:20Yeah. So let's do the success part.
- 6:21:23Okay. Just click on it and uh then okay
- 6:21:27banking system proceed confirming
- 6:21:30payment. Okay. And then
- 6:21:34it generates what you know 3 2 1. Yeah.
- 6:21:38Can you see this payment id pay
- 6:21:41underscore?
- 6:21:43Yeah. And in case of failure it will not
- 6:21:47generate that. Okay. Fine. So this is
- 6:21:50what you know our entire testing we have
- 6:21:53done. Okay. And here is our you know
- 6:21:57entire digital banking system also. Uh
- 6:22:00we need to add few more things. Okay.
- 6:22:02Few more services. Okay. Few more you
- 6:22:04know fraud detection patterns and Kafka
- 6:22:07streams and everything else. Okay. So
- 6:22:09definitely fine. This is what the basic
- 6:22:12architecture how it works. Okay. You
- 6:22:14know and uh how our fraud detection
- 6:22:16works. Okay. Also if you have any more
- 6:22:19request that uh what you want me to
- 6:22:22upload the next project then please
- 6:22:24comment me down. Okay. Also if you
- 6:22:27haven't subscribed then please subscribe
- 6:22:29my channel. Okay. You can thank me.
- 6:22:31Okay. Subscribe like. Okay. Hit the like
- 6:22:34button and thank you.
About this transcript
This page contains the full transcript of Full Project: How Banks Detect Fraud | Digital Banking System | Spring Boot + kafka + Redis + SAGA by Yeshendra Dhaker, generated from the public captions YouTube serves with the video. The transcript has 35,913 words across 6,695 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.