YouTube2Text

Full Project: How Banks Detect Fraud | Digital Banking System | Spring Boot + kafka + Redis + SAGA — Transcript

by Yeshendra Dhaker · 35,913 words · 6,695 segments · language en · Watch on YouTube

Full transcript

  1. 0:00You tap pay on your phone and in less
  2. 0:03than two seconds money is transferred.
  3. 0:06Okay, receipt received and balance
  4. 0:10updated.
  5. 0:11But think about this at that exact
  6. 0:14moment. Okay, at that exact moment
  7. 0:17millions of transactions are happening
  8. 0:19across the country across the globe.
  9. 0:23Yeah, true. So every bank transfer,
  10. 0:26every digital payment, every ATM
  11. 0:29withdrawal and now comes the scary part
  12. 0:33that is fraud. See we are talking about
  13. 0:36the banks.
  14. 0:38Okay, banks process millions of
  15. 0:41transactions on daily basis.
  16. 0:44Okay, so fraudsters are also running
  17. 0:46thousands of transactions simultaneously
  18. 0:49trying to drain accounts before anyone
  19. 0:51notices.
  20. 0:54And here is even a scarier question.
  21. 0:57Okay, listen to me carefully. Important
  22. 0:59one.
  23. 1:00Suppose
  24. 1:02your bank detects the fraud
  25. 1:06midway through a transaction. Midway
  26. 1:09through a transfer.
  27. 1:12Then what? What it means? Let me explain
  28. 1:14you. Kindly pay attention here. Okay.
  29. 1:16Important one. Anyway, we're going to
  30. 1:17build it in coming few minutes. Yeah. So
  31. 1:21let's say let's say this is you okay
  32. 1:24this is my user and this is your bank
  33. 1:27account okay so currently you have how
  34. 1:30much balance in your bank account $4,250
  35. 1:34okay now you have initiated a
  36. 1:39transaction okay transferring amount how
  37. 1:42much $2500
  38. 1:45to this receiving account
  39. 1:48okay this is the receiver
  40. 1:51Now
  41. 1:52I said that suppose your bank detects
  42. 1:58the fraud midway
  43. 2:01through a transfer.
  44. 2:04Midway through a transaction.
  45. 2:06Okay. So let's say your bank has
  46. 2:09installed some channel. Okay. Or some
  47. 2:12service fraud detection service. Okay.
  48. 2:16or uh suspicious activity detection
  49. 2:19service or some channel. Okay. So what
  50. 2:23your bank detects that the transaction
  51. 2:26this transaction has not been initiated
  52. 2:29by you
  53. 2:32instead it is initiated by some fraud.
  54. 2:37You know something suspicious activity
  55. 2:38found by a bank. So immediately transfer
  56. 2:43is stopped.
  57. 2:46Okay. And uh definitely you'll receive a
  58. 2:50you know bank alerts immediately. Okay.
  59. 2:52Suspicious activity detected. Transfer
  60. 2:55has been blocked. Now the real question
  61. 2:58is I'm going to ask you. Money has
  62. 3:01already left your account.
  63. 3:05Where does it go?
  64. 3:07Does it disappear?
  65. 3:10Okay. And you'll definitely ask to the
  66. 3:12bank like where did my money go?
  67. 3:16Yes or no? So before we building our own
  68. 3:19digital banking system, we need to make
  69. 3:21sure that all the functionality should
  70. 3:24be implemented properly.
  71. 3:26Okay. And the most important thing is
  72. 3:30fraud detection service. See there is no
  73. 3:34banking system without fraud detection.
  74. 3:36Yeah. Not possible.
  75. 3:38Okay. We need to secure our users
  76. 3:42balance money.
  77. 3:45Okay. So today we are building complete
  78. 3:48digital
  79. 3:50banking
  80. 3:53system from
  81. 3:55scratch.
  82. 3:57Account management realtime money
  83. 4:00transfer. Okay. Fraud detection in real
  84. 4:03time will implement. Okay. Saga will
  85. 4:06implement. ensures that your money is
  86. 4:08never lost. Okay. And with all other
  87. 4:12modern technologies,
  88. 4:14yeah, you know, most interesting and
  89. 4:16exciting project after Uber and Netflix
  90. 4:19that is already uploaded on my channel.
  91. 4:21Okay. Yeah. So, without wasting much
  92. 4:24time, let's proceed forward, okay, with
  93. 4:26our next section that is understanding
  94. 4:29the problem. Okay. Then HLD
  95. 4:32architecture. Please do not miss it
  96. 4:33because I'm going to sync the real money
  97. 4:37flow with the HLD architecture. Okay.
  98. 4:40And then how do we detect the fraud in
  99. 4:43real time? Okay. And then our project
  100. 4:45structure. Okay. And finally we'll move
  101. 4:49to our coding part. Okay. Yeah. So let's
  102. 4:53start. Let's go. Okay. So before we
  103. 4:55start building our bank application,
  104. 4:58first let's understand the actual
  105. 5:00problem. Okay. Because if you don't
  106. 5:02understand the problem, the solution
  107. 5:03won't make sense. Fine. Okay. Let's go.
  108. 5:07And yeah, important one, important
  109. 5:08section. Kindly do not miss and pay
  110. 5:10attention. Okay. So, I guess you all
  111. 5:14have heard about three terms in the
  112. 5:17database. What are they? So
  113. 5:22begin
  114. 5:26commit and
  115. 5:30roll back. Yeah, all of you. Yeah, heard
  116. 5:33about this three terms beginning,
  117. 5:35commit, roll back in the database
  118. 5:37system.
  119. 5:38Okay, now next thing is look at here. So
  120. 5:43let's say this is my user and this is my
  121. 5:47user's friend.
  122. 5:49Okay, I'll refer it as a sender and this
  123. 5:53is my
  124. 5:54receiver. Okay, so my user transferring
  125. 5:58payment to his friend.
  126. 6:01Okay,
  127. 6:03so this transfer includes
  128. 6:07multiple steps to complete.
  129. 6:11Okay, as we have seen you know uh a few
  130. 6:15minutes before that what happens once
  131. 6:19user clicked on the send money button.
  132. 6:23Okay. So you know the request goes to
  133. 6:27some uh let's say account service. Okay.
  134. 6:31Account service job is to validate the
  135. 6:33balance. Okay. and deduct.
  136. 6:37Yeah. Then uh request goes to my
  137. 6:39transaction service to proceed forward.
  138. 6:43Okay. Then fraud detection service.
  139. 6:46Okay. And then uh payment service,
  140. 6:48notification service, whatever all the
  141. 6:51services.
  142. 6:53Yes. Okay.
  143. 6:55Now you all might be thinking okay fine
  144. 6:58this is okay good. What is the problem
  145. 7:00in that? Each service has their own
  146. 7:05database.
  147. 7:06Account service
  148. 7:08account DB. Transaction service
  149. 7:13transaction
  150. 7:15DB.
  151. 7:18Yeah. Okay. Now few minutes before we
  152. 7:22have discussed that if suppose something
  153. 7:24got failed in midway
  154. 7:28then who going to inform other service
  155. 7:31to undo that step
  156. 7:34I mean to say that let's say in case of
  157. 7:37traditional single database system
  158. 7:42okay so what happens is this is what my
  159. 7:46request comes okay this is my server
  160. 7:50to my database single database system.
  161. 7:54Okay. So begin.
  162. 7:58Okay. Then uh validates deducts credits
  163. 8:04commit.
  164. 8:06Okay. And if something fails
  165. 8:10then roll back entire process.
  166. 8:16Roll back entire process.
  167. 8:19Okay. Nothing code required, nothing.
  168. 8:21Automatically our database has this
  169. 8:24property begin commit roll back only in
  170. 8:27case of traditional single database
  171. 8:31system.
  172. 8:33Yeah. Because see our database knows. So
  173. 8:37uh what he'll do is he roll back undo.
  174. 8:41Okay. But in case of separate separate
  175. 8:44database in case of microservices
  176. 8:47architecture
  177. 8:48the transfer includes multiple steps to
  178. 8:52complete we'll see once we'll code okay
  179. 8:55and we'll go with the flow that first we
  180. 8:57coded our account service okay here then
  181. 9:00the control goes to the transaction
  182. 9:01service we'll code this it consumes that
  183. 9:04it consumes that publish okay around
  184. 9:08four to five service for one transaction
  185. 9:12and all have separate databases. So
  186. 9:15suppose um you know my user initiated a
  187. 9:20transaction okay done then everything is
  188. 9:22done on the account service DB side and
  189. 9:25something got failed uh in our
  190. 9:27transaction DB
  191. 9:30then who going to inform my account DB
  192. 9:33to undo this
  193. 9:35because
  194. 9:37here from here account um you know from
  195. 9:41uh our account service the balance got
  196. 9:44deducted. Ed the money got deducted from
  197. 9:46my sender account. Yes or no? But
  198. 9:49something got failed in the step number
  199. 9:52two. Step number two. Okay. This is step
  200. 9:55number one. Step number two.
  201. 9:59Yes or no. So who will going to inform
  202. 10:02my account service that you need to undo
  203. 10:05the process?
  204. 10:07Because account service is completed
  205. 10:10successfully. committed
  206. 10:13whatever fails in another service
  207. 10:16potentially another server. Okay. Uh
  208. 10:20other database something got failed.
  209. 10:24Okay. Then who going to inform my you
  210. 10:27know that service number one in which
  211. 10:30already everything got completed
  212. 10:32committed?
  213. 10:35Yes. money is in the middle or I can say
  214. 10:40the money just disappeared.
  215. 10:43So we need a system.
  216. 10:47Okay. Or I can say we need to build
  217. 10:51a system which has undo step in each and
  218. 10:55every process
  219. 10:57and that is what done using our saga.
  220. 11:01Okay, I'll explain it. Okay, I have kept
  221. 11:03a separate section on this. Okay, and
  222. 11:07using a great real world example with
  223. 11:10the cash on delivery. I'll explain it to
  224. 11:12you. Fine. Okay. So, this is what our
  225. 11:15first problem. Fine. Okay. Yeah. It's
  226. 11:18not the case just like our uh this
  227. 11:21traditional single database system, you
  228. 11:24know, we have such consistency problem
  229. 11:27in the distributed system.
  230. 11:30Okay. Yeah. Fine. Let's move to our next
  231. 11:34problem. Problem number two. Problem
  232. 11:37number two is you know fraud.
  233. 11:43Okay. So imagine imagine a fraudster
  234. 11:50get access to
  235. 11:54someone's account.
  236. 11:58What happened? Okay. So generally
  237. 12:01fraudsters don't
  238. 12:05withdraw manually.
  239. 12:08What they do is they runs uh a script
  240. 12:14which
  241. 12:16fires you know 5 10 15 or maybe 100 plus
  242. 12:22transaction in
  243. 12:24few minutes or seconds.
  244. 12:28Okay. So money just disappear before
  245. 12:30anyone notices. Gone.
  246. 12:33So we need to build some system. Okay.
  247. 12:38We'll build it. Okay. There is a
  248. 12:40separate service fraud detection
  249. 12:42service. We'll code it.
  250. 12:45Okay. And that too
  251. 12:48in milliseconds
  252. 12:50before money credit to my receiver
  253. 12:53account.
  254. 12:56Okay. Now second case maybe uh it is not
  255. 13:01a fraud it is not a fraudster maybe a
  256. 13:03genuine user okay so we also need to add
  257. 13:08the functionality to verify the user I
  258. 13:13guess we all have experienced that okay
  259. 13:15so suppose one day we have purchased you
  260. 13:18know iPhone or Mac and uh suppose we
  261. 13:22have initiated a transaction of you know
  262. 13:2450,000
  263. 13:26Okay. 80,000.
  264. 13:29So that transaction that money is not
  265. 13:33credited immediately to the merchant
  266. 13:36account. No, first we'll get the call
  267. 13:40from the bank
  268. 13:43that this is you know uh unusual higher
  269. 13:46amount you have initiated. So is it you
  270. 13:49only or some someone other you don't
  271. 13:51know about it. If you confirm that yeah
  272. 13:54it is me then the money got credited
  273. 13:58else refund back.
  274. 14:01So this scenario also we need to build
  275. 14:05and and we going to build it.
  276. 14:08Okay. Verify transaction then uh also
  277. 14:12generate OTP. Okay. Verify OTP. What
  278. 14:15happens if not if expired? everything we
  279. 14:19are going to build in this uh our
  280. 14:22digital banking system application.
  281. 14:26Okay fine. So yeah this is you know kind
  282. 14:28of you know most serious problem
  283. 14:30definitely fraud always on the upper
  284. 14:33hand. We need to make sure that our
  285. 14:35users balance should be secure. Okay.
  286. 14:39Locker fine. Okay. So these are our
  287. 14:42problems. Okay. And definitely we'll
  288. 14:45code it in coming few minutes. And yeah,
  289. 14:48uh it takes a huge coding effort. Okay.
  290. 14:50So we need to code each and every
  291. 14:52services
  292. 14:54and wrap everything perfectly. Also we
  293. 14:58need to test the entire project
  294. 15:00thoroughly. Okay. Yeah. So I told you
  295. 15:04most exciting and important project.
  296. 15:06Okay. After Uber and Netflix uh we have
  297. 15:10uploaded on our channel. Okay. So now
  298. 15:12let's move to our next section that is
  299. 15:15HLD architecture. Okay. Highle design
  300. 15:17architecture important one. So let's uh
  301. 15:21start that. Okay. Let's go. Okay. So now
  302. 15:24let's see our highle design
  303. 15:26architecture. Okay. Yeah. Kindly all pay
  304. 15:30attention on my screen. Important one.
  305. 15:33Okay. So at first let me you know draw
  306. 15:38the entire architecture.
  307. 15:40Okay. Here comes my decider service.
  308. 15:44Okay. Then next one. Connecting
  309. 15:48everything.
  310. 15:51Okay. And then next.
  311. 15:55Okay. Fine.
  312. 15:59And finally.
  313. 16:03Yeah. Okay. So at first my
  314. 16:09API gateway. Okay. Then here comes my
  315. 16:13account service or I'll refer it as a
  316. 16:16bank. Okay. Then comes my transaction
  317. 16:20service. Our most important service.
  318. 16:23Okay. Saga orchestrator.
  319. 16:26Okay. And then comes my payment
  320. 16:31service. Okay. Connecting everything. My
  321. 16:36Apache
  322. 16:38Kafka. Okay. Then comes my fraud
  323. 16:42detection
  324. 16:44service. Okay. And then
  325. 16:48notification
  326. 16:51service. And again my account service.
  327. 16:55Why? Credit receiver.
  328. 17:00Okay. Credit receiver. Fine. Now let me
  329. 17:04just, you know.
  330. 17:08Okay. Okay,
  331. 17:11fine.
  332. 17:13And connecting everything.
  333. 17:19Okay.
  334. 17:27Fine.
  335. 17:28Yeah. So now let me explain you each and
  336. 17:32every component one by one. Okay. So at
  337. 17:34first comes our API gateway. We all know
  338. 17:37that it is our single point entry. Okay,
  339. 17:41all request comes through here. Also,
  340. 17:43we'll add the configuration for rate
  341. 17:47limiter. Okay, we'll set it up. Why? See
  342. 17:51we are building bank application and we
  343. 17:54need to protect our user from attackers
  344. 17:59to request you know 5,000
  345. 18:046,000 7,000 or you know some thousands
  346. 18:06of request. Okay. So what we'll do is
  347. 18:10you know we'll uh add the configuration
  348. 18:14replenish rate as 10 and burst capacity
  349. 18:1920. Okay. And we'll change it
  350. 18:21accordingly the values just like uh
  351. 18:24we'll reduce the values for our payment
  352. 18:26service. Okay. Fine. So this is what our
  353. 18:29API gateway. See don't worry if you'll
  354. 18:31not get anything what I have just
  355. 18:32explained it to you. Okay. Replenish
  356. 18:34rate burst capacity rate limiter. No
  357. 18:37worries. At the time of coding our API
  358. 18:40gateway I'm going to explain you each
  359. 18:42and every terminologies.
  360. 18:45Why that? Why not that? Okay. So don't
  361. 18:48worry about that.
  362. 18:50Fine. Now let's come to our next
  363. 18:52component that is our account service.
  364. 18:55Okay. So treat it as a bank. You know it
  365. 19:01holds user bank data and responsible
  366. 19:06for all the money movements.
  367. 19:09Okay. So the first thing is you know
  368. 19:11account creation. Okay. Get balance.
  369. 19:14Okay. Get account and money movement.
  370. 19:17Okay. So deduct
  371. 19:20deduct money okay method and then credit
  372. 19:24to the receiver okay or refund refund
  373. 19:29step number three okay refund back to my
  374. 19:32sender so all type of money moments okay
  375. 19:36fine now let's come to our next service
  376. 19:41that is heart of any banking system
  377. 19:46backbone of any banking system okay or
  378. 19:49I'll call it as a decider why because uh
  379. 19:53this is our saga orchestrator and it
  380. 19:57plays a deciding role what to do first
  381. 20:01request comes to my transaction service
  382. 20:03and then need to validate okay uh
  383. 20:07proceed with the fraud check to verify
  384. 20:09to generate
  385. 20:11so everything is done by our transaction
  386. 20:15service okay the backbone, the heart.
  387. 20:19Fine. Yeah. Next comes our payment
  388. 20:22service. So, payment service is
  389. 20:25responsible to integrate with payment
  390. 20:29gateways. Okay. So, two most popular
  391. 20:33payment gateways. The first one is
  392. 20:34Stripe. Okay. Accepted uh over 100 plus
  393. 20:38countries. Okay. And second is Razer
  394. 20:41Pay. Yeah. You know, two most popular
  395. 20:44payment gateways. So we'll use one of
  396. 20:46them. Okay. Fine. And for the external
  397. 20:50payments. Yeah, definitely. So that is
  398. 20:53also a job a part of a bank. Okay. We're
  399. 20:55building a bank system. So yeah,
  400. 20:57definitely we need to you know uh build
  401. 20:59that too. Okay. Now connecting
  402. 21:02everything our Apache Kafka.
  403. 21:06Okay. So you might be thinking that
  404. 21:10why you kept
  405. 21:12Apache Kafka in the middle. Why? So here
  406. 21:17we have okay we can see account service,
  407. 21:19transaction service, payment service.
  408. 21:21Here is our fraud detection service as
  409. 21:23the name indicating that you know it is
  410. 21:25responsible to detect the fraud. Yeah.
  411. 21:27Okay. Notification service and again
  412. 21:30account service.
  413. 21:33But why uh this Apache Kafka in the
  414. 21:35middle? Why? Because
  415. 21:39what we want is
  416. 21:41we want my fraud detection service will
  417. 21:47consume each and every initiated
  418. 21:51transaction.
  419. 21:53Okay. So here is my user. User click on
  420. 21:57the send money transaction initiated.
  421. 22:00Stop. Stop. uh at that point
  422. 22:05first let my fraud detection service
  423. 22:07consume that event via Kafka.
  424. 22:12Okay.
  425. 22:15And start checking the transaction.
  426. 22:20Okay. Try to detect whether there is
  427. 22:23some suspicious or not. This transaction
  428. 22:26is initiated by some genuine user or
  429. 22:29some fraudster.
  430. 22:32Yes or no? And then then okay just look
  431. 22:35at here um my fraud detection service
  432. 22:39again revert it back. So transaction
  433. 22:42service again need to decide
  434. 22:46if detected not detected.
  435. 22:50Yes. So my transaction service again
  436. 22:53consume the event and decide what to do
  437. 22:56next.
  438. 22:59Fine. Also uh next comes our
  439. 23:02notification service. Yeah, as the name
  440. 23:04indicating that it is responsible to
  441. 23:06send the alerts all type of alerts.
  442. 23:08Debit alert, credit alert, suspicious
  443. 23:11activity directed. We have seen uh you
  444. 23:13know a few minutes before alert you know
  445. 23:16on email phone. Okay. Uh verify OTP.
  446. 23:20Okay. Generated and everything all type
  447. 23:23of alerts refund alert. Okay. Yeah. So
  448. 23:27this is what on our email and uh phone
  449. 23:30SMS okay or on WhatsApp. Okay. Next
  450. 23:33comes our account service same. Okay. So
  451. 23:38finally to complete the transaction.
  452. 23:40Okay. Credit receiver.
  453. 23:43Okay. So this is our entire highle
  454. 23:47design architecture and this is why we
  455. 23:50have kept Apache Kafka in the middle.
  456. 23:53Fine. consume
  457. 23:57uh revert it back. Okay. Yeah. And uh
  458. 24:02so after this section I'm going to show
  459. 24:05you the real money flow. If you
  460. 24:07understand that and if you understood
  461. 24:08this HLD architecture you can code the
  462. 24:11entire banking system at your own
  463. 24:14because see what you need the flow and
  464. 24:18the architecture. Yeah. So without
  465. 24:21wasting much time, let's proceed with
  466. 24:23our next section that is our real money
  467. 24:26flow. Okay. We're going to do a real
  468. 24:28payment transfer. Okay. Fine. Let's
  469. 24:31let's go. Okay. So now let's see
  470. 24:33complete money flow. Okay. Yeah. Pay
  471. 24:36attention here. Important one. So here
  472. 24:39is my user.
  473. 24:41Okay. Here is my user. And once user hit
  474. 24:45the button
  475. 24:48send money. Okay. Or transfer or
  476. 24:52whatever. The first request goes to my
  477. 24:56you know API gateway and then it starts
  478. 25:01from here. My API gateway
  479. 25:05calls transaction service. Transaction
  480. 25:10service the decider. Okay. Fine. Then it
  481. 25:14executes saga. Okay. Uh step by step. So
  482. 25:18my transaction service calls my account
  483. 25:24service. Okay. And then my account
  484. 25:28service will what?
  485. 25:32Validates
  486. 25:34the
  487. 25:35balance. Okay. And deduct
  488. 25:40the amount from the balance. Fine.
  489. 25:44Done. Then
  490. 25:47uh again my account service you know
  491. 25:52calls transaction service back to the
  492. 25:55transaction
  493. 25:57service.
  494. 25:59Okay transaction service
  495. 26:02what I'll do is my transaction service
  496. 26:05saves this transaction this ongoing
  497. 26:08transactions. Okay save the transaction.
  498. 26:13Okay, we discussed you different
  499. 26:14different separate databases. Okay, and
  500. 26:18uh as status
  501. 26:22processing
  502. 26:24processing okay not yet completed, not
  503. 26:28failed, not flagged. Okay, nothing
  504. 26:32processing.
  505. 26:33Fine. Okay, stop there. Then my
  506. 26:36transaction service
  507. 26:39you know
  508. 26:41uh once we saved you know the
  509. 26:44transaction as processing then my Kafka
  510. 26:48comes into the picture okay and we'll
  511. 26:50publish the event as transaction
  512. 26:53initiated event we'll monitor each and
  513. 26:57every transaction
  514. 27:00okay so this event is going to consumed
  515. 27:04by our fraud fraud detection service.
  516. 27:09Okay, like fraud detection service
  517. 27:10consumes. Okay, and starts checking that
  518. 27:14you know some transaction has been
  519. 27:16initiated. Let's get uh get back to
  520. 27:19work. Okay, fine. So, fraud detection
  521. 27:24service tries hard to detect
  522. 27:29the you know any suspicious activity.
  523. 27:32Okay, we'll code it. Okay, we'll code
  524. 27:34the entire our fraud detection service.
  525. 27:36Okay, so
  526. 27:39if nothing is detected, if okay, if uh
  527. 27:43you know no fraud detected, everything
  528. 27:48is clean. Yeah. So again back to my
  529. 27:51transaction service,
  530. 27:54you know, need to report.
  531. 27:57Okay. And transaction service will
  532. 27:59initiate the process of completion.
  533. 28:02Okay, that means the process of you know
  534. 28:05money should be credit to the receiver.
  535. 28:10Okay. And then comes my notification
  536. 28:14service to send the alert to both my
  537. 28:17user. Debited from your account credited
  538. 28:22to your account.
  539. 28:25Okay. Clean clean process. But if
  540. 28:28something's suspicious detected then
  541. 28:31what? Let's see. So if any suspicious
  542. 28:34activity detected then first we need to
  543. 28:39verify
  544. 28:42you know uh
  545. 28:45about that
  546. 28:47transaction about this transaction with
  547. 28:51my user sender.
  548. 28:58Is it is it you or not?
  549. 29:01Okay. There are multiple steps for
  550. 29:03verification.
  551. 29:05Okay. Yeah. And if verified then we'll
  552. 29:08proceed.
  553. 29:10Okay. Another thing you know there's
  554. 29:12another thing fine. So we have uh we'll
  555. 29:15create another method for the blocking
  556. 29:17of account. In that case, you know,
  557. 29:19we'll uh check verify and once failed,
  558. 29:23then we'll proceed forward with
  559. 29:26temporarily block the account sender
  560. 29:31account. Okay. And we'll uh send the
  561. 29:33alert like uh account has been blocked.
  562. 29:36Okay. Uh been continuously seen
  563. 29:39suspicious activity in your account and
  564. 29:42uh please contact your bank as soon as
  565. 29:45possible. So there too we have
  566. 29:47possibilities.
  567. 29:50At the worst case we will proceed uh
  568. 29:53with blocking user account, blocking
  569. 29:56sender account.
  570. 29:58Okay. And finally again we'll call my
  571. 30:01notification service to notify. Okay.
  572. 30:05And then proceed forward.
  573. 30:08Yeah. Yes or no? Okay. Now
  574. 30:13any questions? Okay. Yeah. If you have
  575. 30:15then you can just ask me in your comment
  576. 30:17section. Okay fine. So with this our
  577. 30:20first part
  578. 30:22of money
  579. 30:25flow
  580. 30:27is completed. Now you all might be
  581. 30:29thinking that is there is some second
  582. 30:31part also. Yes there is second part.
  583. 30:34Okay. Honestly speaking the second part
  584. 30:37is the code itself. Okay. So I'll
  585. 30:40explain it to you once we'll start
  586. 30:42coding. Okay. Yeah. So here it completes
  587. 30:46the entire you know money flow first
  588. 30:48part. Okay. Second part we'll uh you
  589. 30:51know see at the time of coding. Okay.
  590. 30:54Fine. So now let's move to our next
  591. 30:57section that is saga pattern. Okay.
  592. 31:00Fine. And uh then fraud detection
  593. 31:03service. Okay. How do we detect? Okay.
  594. 31:05And uh then we'll set up our project.
  595. 31:08And final thing is we'll start coding
  596. 31:11our banking system. Okay. Yeah. So let's
  597. 31:14proceed. Let's go. Okay. So now let me
  598. 31:18explain you the saga with something we
  599. 31:20have already experienced that. Okay. And
  600. 31:24that is cash on
  601. 31:27delivery.
  602. 31:29Cash on delivery. Okay. Fine. So all
  603. 31:33kindly pay attention on my screen. Okay.
  604. 31:36So look at here. This is my user. Okay.
  605. 31:39and my user ordered something
  606. 31:42uh from Amazon. Okay. Let's say my user
  607. 31:46order phone
  608. 31:48from Amazon. Okay. Yeah. And put the
  609. 31:54payment
  610. 31:56method
  611. 31:59as
  612. 32:00cash on delivery.
  613. 32:05Okay. Done. Yeah. Now one day delivery
  614. 32:11person
  615. 32:12arrives
  616. 32:15on the door and hand it to my user. What
  617. 32:21the box? Okay. In exchange user pay the
  618. 32:26amount. Okay. Let's say $1,000.
  619. 32:31Okay. Fine.
  620. 32:33Okay. Okay. Fine. So this is our step
  621. 32:38number one. H step number one.
  622. 32:44Now
  623. 32:46my user is step number two. Okay. Pay
  624. 32:49attention. My user just uh open that
  625. 32:52box.
  626. 32:54Okay. And uh
  627. 32:58and found something wrong product. Okay.
  628. 33:01Or some damaged product.
  629. 33:04Okay. Damaged
  630. 33:08product. Okay. This is my step number
  631. 33:11two. Agreed? Okay. Understood? Yeah. Now
  632. 33:17I'll ask you you know uh question to you
  633. 33:21all of you guys that uh what he'll do
  634. 33:25next? What my user will do next?
  635. 33:30Definitely call to return it. put return
  636. 33:34request.
  637. 33:36Yeah. So my user
  638. 33:41call to
  639. 33:44return it.
  640. 33:46Will it step number three
  641. 33:51or will this uh return request undo
  642. 33:57these two step? Tell me.
  643. 34:03user call to return the product. So will
  644. 34:06it a explicit another step or once a
  645. 34:11user put the uh return request okay so
  646. 34:15that request will undo everything like
  647. 34:18you know um whatever user paid 15,000
  648. 34:22okay revert it back to the user and undo
  649. 34:26step number two is step number one
  650. 34:29is it no right no call to return it is
  651. 34:34another explicit step. Once we receive
  652. 34:38damage product, we'll call to return it.
  653. 34:42That means now we need to move to the
  654. 34:46next step. Step number three to initiate
  655. 34:49our refund.
  656. 34:52Not like you know to undo step number
  657. 34:55one and step number two. It's not like
  658. 34:58that.
  659. 34:59Next step another separate step and that
  660. 35:03is what saga
  661. 35:05okay differs with traditional single
  662. 35:08database okay we have discussed at the
  663. 35:10time we are you know seeing our uh
  664. 35:13problem okay so
  665. 35:17yeah traditional single database system
  666. 35:21that begin commit roll back so what's
  667. 35:26the roll back roll back is automatic,
  668. 35:30invisible.
  669. 35:32Okay, you don't need to, you know, uh
  670. 35:35just do much effort. No extra code.
  671. 35:39What? What is that? Just undo
  672. 35:42everything.
  673. 35:44Yes or no? Yeah, that is not an extra
  674. 35:48step. Saga is what? Uh we need to call
  675. 35:53to return it. That means another step
  676. 35:55for refund.
  677. 35:57We discussed you know that uh there are
  678. 36:00separate separate services.
  679. 36:03Okay. And with all have their own
  680. 36:07databases.
  681. 36:10Fine. So we need someone to inform
  682. 36:14you know and uh to process the next step
  683. 36:18and inform all the services to undo the
  684. 36:22operation.
  685. 36:24Okay, that is what
  686. 36:27uh actually our refund process
  687. 36:31that uh you know next is okay the
  688. 36:34request goes to whatever company okay
  689. 36:37and then initiate the refund okay that
  690. 36:39means we need to undo a step number one
  691. 36:43step number one means user paid to the
  692. 36:47company now undo step number one that
  693. 36:50means company again pay back to my user
  694. 36:58understood
  695. 37:00saga.
  696. 37:03Okay. Yeah. And uh anyway we are going
  697. 37:06to implement each and everything one by
  698. 37:09one. Okay. Also I'm going to explain it
  699. 37:12to you from a scratch once we'll start
  700. 37:15coding. Yeah. Okay. So this is what our
  701. 37:18saga. Now next. Okay. How do we detect
  702. 37:20the fraud? Okay. So what I'm thinking is
  703. 37:23let's proceed forward okay let's uh you
  704. 37:26know set up our project fine and start
  705. 37:29the coding part okay once we'll reach
  706. 37:31the fraud detection at that time I'll
  707. 37:33explain to you everything okay like this
  708. 37:36is what the techniques and this and that
  709. 37:39okay everything how do we detect the
  710. 37:41fraud okay yeah so that will be good now
  711. 37:44the next step is let's move to our you
  712. 37:47know yeah first we need to set up our
  713. 37:49data flow infrastructure Okay, all the
  714. 37:51services data services should be up and
  715. 37:53running and then project uh structure
  716. 37:57setup and then coding part. Okay, fine.
  717. 38:01So yeah, let's move to our uh you know
  718. 38:05what next thing let's go. So here's my
  719. 38:08docker desktop. Okay, I hope you already
  720. 38:11installed and kept it open in your
  721. 38:13machine. Fine. If not, then uh the link
  722. 38:16is given in the description. Just go to
  723. 38:18that link download and installed Docker
  724. 38:21desktop in your machine. Fine. Okay. So
  725. 38:24now let me just go to my file explorer.
  726. 38:27Okay. So I created a folder that is
  727. 38:30banking system. In that I have one file.
  728. 38:32Okay. That is my docker compost. Let me
  729. 38:36open that. Okay. So yeah. So here you
  730. 38:41know we have four services.
  731. 38:44So the first one is radius. Okay. And
  732. 38:47then MySQL, Zookeeper and Kafka. Okay.
  733. 38:51So, first we need to, you know, set up
  734. 38:53our data flow. That means we need to
  735. 38:57keep all these services up and running.
  736. 39:00Fine. So, for that, let me minimize it.
  737. 39:03Now, let me open bash here. Okay. Open g
  738. 39:06bash here. Fine. Yeah. So, you can also
  739. 39:10do the same using uh command prompt.
  740. 39:12Okay. Let me just go with the bash.
  741. 39:16Okay. And here just run this command
  742. 39:19docker compose up - d and
  743. 39:25uh you know here you'll write the
  744. 39:29service name okay if if you don't want
  745. 39:33to you know uh fetch all the service
  746. 39:37images okay so here you know what I need
  747. 39:41is I need my radius and zookeeper and
  748. 39:46Kafka. Okay, not MySQL. Why? Because I
  749. 39:49already installed MySQL on my local.
  750. 39:51Okay, so just need to give the name of
  751. 39:54these services. Radius, Zookeeper and
  752. 39:57Kafka. Okay, let me give that
  753. 40:00radius.
  754. 40:02Okay. And Zookeeper
  755. 40:05and Kafka. Okay. Fine. So my docker
  756. 40:11compose will start pulling the images.
  757. 40:15Okay. And you can see pulling zookeeper
  758. 40:19kafka radius. Okay. So it takes you know
  759. 40:22a few minutes. Fine. Let's wait for it
  760. 40:25and then after it creates the container
  761. 40:28in our docker desktop.
  762. 40:32Okay. Fine. And then finally we'll uh
  763. 40:36proceed forward. Okay. So fine. Let's
  764. 40:38wait for a few, you know, minutes till
  765. 40:41it completes.
  766. 40:42Okay. So,
  767. 40:45uh container created and started. Let me
  768. 40:48just open my docker and yeah, can you
  769. 40:50see banking system? Okay. Let me just
  770. 40:54click on it and and you can see uh my
  771. 40:58radius, zookeeper, kafka all are up and
  772. 41:00running. Okay. And the fourth one is my
  773. 41:03MySQL. So that two up and running
  774. 41:05because I installed that in uh my local.
  775. 41:08Okay. Yeah. Obvious fine. So now let's
  776. 41:11move to my browser and let's set up our
  777. 41:14banking system. Okay. All the
  778. 41:16microservices. Fine. Okay. So here's my
  779. 41:20browser. Fine. And let me type spring
  780. 41:23initializer. Okay. Click on the very
  781. 41:26first link. Start.io. Okay. We'll land
  782. 41:30here. Okay. Yeah. Project Maven language
  783. 41:34Java Springwood version automatically
  784. 41:36selected and now project metadata. Okay
  785. 41:40fine. So the first service com dot
  786. 41:43banking and
  787. 41:45account
  788. 41:47service.
  789. 41:49Okay fine. Let me remove hyphen from my
  790. 41:52package name. Yeah. Next dependencies.
  791. 41:56So spring web then uh Apache Kafka.
  792. 42:00Okay. a spring for Apache Kafka then u
  793. 42:04what JPA and MySQL driver validation
  794. 42:11okay Lombok
  795. 42:14fine and actuator okay spring boot
  796. 42:18actuator okay fine so yeah spring for
  797. 42:22apache kafka data JPA MySQL driver okay
  798. 42:27yeah so in future if we required any
  799. 42:30more depend dependency then we'll add
  800. 42:32using external resources. Okay. Yeah.
  801. 42:34For now let's proceed. So packaging jar
  802. 42:36configuration YAML and let me select
  803. 42:39Java version as 17. Okay. And now let me
  804. 42:42generate my account service. Yeah. Save
  805. 42:46it. Similarly my next is transaction
  806. 42:52transaction service. Okay. Let me remove
  807. 42:54hyphen from my transaction service.
  808. 42:56Okay. Now in the transaction service we
  809. 42:58need to add one more dependency. Okay.
  810. 43:00Belongs to the cloud. Okay. That is open
  811. 43:03fain. Yeah. Okay.
  812. 43:06Open fain and uh rest all remain same.
  813. 43:11Okay. That's it. Generate it. Fine. Save
  814. 43:15it. Then next comes my fraud detection.
  815. 43:19Fraud
  816. 43:21detection. Okay. Service.
  817. 43:24Fine.
  818. 43:26H okay yeah so in this service I don't
  819. 43:31need my myql driver and jpa
  820. 43:35okay also you know validation
  821. 43:39f open f what I need is I need radius
  822. 43:44okay radius okay spring data radius so
  823. 43:49explore and yeah spring boot starter
  824. 43:52data radius okay fine let me generated.
  825. 43:57Okay. Save. Next is my
  826. 44:01what? Notification service.
  827. 44:04Notification service. Okay. So, as the
  828. 44:10name indicates notification, I need
  829. 44:13Java. Okay. Java mail. Fine. And uh for
  830. 44:19our SMS, we'll add using external
  831. 44:22resources. Okay. Fine. Let me remove
  832. 44:25data radius and uh okay.
  833. 44:30Yeah, that's it. Fine. Let me generate
  834. 44:34it.
  835. 44:35Save. Okay. And then our payment
  836. 44:39service. Yeah. Payment service. Okay.
  837. 44:43Let me remove this.
  838. 44:46Fine. So in the payment service, I need
  839. 44:52JPA. Okay. And MySQL fine. Okay. And
  840. 45:00validation
  841. 45:02Lombok
  842. 45:04spring for Apache Kafka. And one more
  843. 45:07dependency we need that is our payment
  844. 45:10gateway. Okay. So let's proceed with the
  845. 45:13Razer Pay. Okay. Widely used. So for
  846. 45:16that just you know in a new tab type MVN
  847. 45:22repository okay MVN repository just
  848. 45:25click on the very first link mvvin
  849. 45:27repository.com
  850. 45:29okay and yeah few verification security
  851. 45:34verification and we'll land here
  852. 45:38fine in the search just type razer pay
  853. 45:43java
  854. 45:45Okay. Scroll down. Scroll down. Yeah.
  855. 45:48Can you see this? Razer Pay Java. Click
  856. 45:51on this. Okay. And here current version
  857. 45:55is 1.4.9.
  858. 45:57Okay.
  859. 45:58And yeah, here
  860. 46:01this is what the dependency. Okay. So
  861. 46:05once we'll uh open our microser you know
  862. 46:08this microser in our uh editor intellig
  863. 46:11editor. At that time we'll copy this and
  864. 46:14paste it in your pom.xml. Okay. Fine.
  865. 46:20So for now that's it for my payment
  866. 46:23service and generate it. Okay. Save. And
  867. 46:27at last our API gateway. API
  868. 46:31gateway. Okay.
  869. 46:34Fine.
  870. 46:37API gateway.
  871. 46:39Okay. And in this
  872. 46:42let me remove spring web. Okay. Kafka
  873. 46:47actuator Lombok.
  874. 46:50Okay. And let me remove mail sender data
  875. 46:54JPA MySQL validation. Okay. Here let me
  876. 46:58add gateway.
  877. 47:01Okay. Fine. And uh for rate limiting
  878. 47:06radius data radius reactive. Okay. So,
  879. 47:11radius, where is that? A spring data
  880. 47:14reactive. Reds. Yeah, this one. Okay,
  881. 47:19fine. A spring boot starter data radius
  882. 47:23reactive. Okay, that's it. Let me now
  883. 47:27generate it to and saved. Okay, so all
  884. 47:31our six microservices is you know
  885. 47:34downloaded. Now let me quickly
  886. 47:38uh extract them and import them in our
  887. 47:43IntelligJ code editor. Okay fine. Okay.
  888. 47:46So I imported all our microservices in
  889. 47:48our banking system. Yeah. So at first we
  890. 47:52need to start with our account service.
  891. 47:55Okay. First you know user need to create
  892. 47:58account. Create bank account. Yeah.
  893. 48:00Receiver sender. Okay. And then proceed
  894. 48:02forward. Okay. Yeah. So without wasting
  895. 48:05much time, let's start and let's
  896. 48:07proceed. And also also you know uh if
  897. 48:10you like the video then you can
  898. 48:12subscribe my channel. Okay. Hit the like
  899. 48:14button, subscribe my channel. Okay.
  900. 48:16Yeah. Also you can thank me. Fine. Okay.
  901. 48:20So yeah let's start. Let's go. Fine. So
  902. 48:23let's start with our account entity.
  903. 48:26Okay. So
  904. 48:28entity dot
  905. 48:31account. Yeah. Okay. So now entity and
  906. 48:39table.
  907. 48:40So
  908. 48:42name is accounts. Okay. And then Lombok
  909. 48:47annotations add data at all arcs and add
  910. 48:50no arcs constructor. Fine. Now what are
  911. 48:54my fields? Okay. So at first private
  912. 49:00string id. Okay. And the ID is
  913. 49:05not identity but
  914. 49:08it should be UYU ID. Okay. Yeah. Next is
  915. 49:13my account number. Okay. So a string
  916. 49:16account number. Okay. Then private
  917. 49:21string account holder name.
  918. 49:25Okay. Then what?
  919. 49:29Email. Okay. And then uh yeah so private
  920. 49:36a string phone. Okay. And then account
  921. 49:40type. Okay. So account type. Okay. And
  922. 49:46account type. So we have you know few
  923. 49:49string values like uh you know savings
  924. 49:52account, current account, fixed deposit.
  925. 49:54Okay. So let's declare it as enum. Okay.
  926. 49:59So enum and we have few string values
  927. 50:02fine later on we'll create okay or let's
  928. 50:05create it right now. So in the entity
  929. 50:09java and enum
  930. 50:12account type okay yeah next field is
  931. 50:17another enum we need to create for
  932. 50:21status
  933. 50:22account
  934. 50:24status. Okay and status. So account
  935. 50:28status means you know active. Okay.
  936. 50:31Blogged or flagged. Okay. So for that
  937. 50:35too let me create enum.
  938. 50:37Okay. Yeah. Now the next field we need
  939. 50:42to add is
  940. 50:45private and uh balance. Okay. So it
  941. 50:48should be big decimal and balance. And
  942. 50:51then also you know uh account should
  943. 50:56have
  944. 50:57big decimal and
  945. 51:00it should have daily
  946. 51:02what transaction limit.
  947. 51:06Yes or no? Yes.
  948. 51:08So daily transaction limit. Okay. And
  949. 51:12then we have you know our local date
  950. 51:16time.
  951. 51:18local
  952. 51:20date time. Okay. Created at
  953. 51:24similarly private local date time and
  954. 51:27updated at. Okay. Now let's add few
  955. 51:31annotations.
  956. 51:33So for account number it should be uh
  957. 51:37nullable false and
  958. 51:40should be unique. Okay. So unique true.
  959. 51:43Fine. Okay. Now for the account holder
  960. 51:46name column nullable false. Okay that's
  961. 51:49it. And uh for the email same thing let
  962. 51:54me just copy and paste column nullable
  963. 51:55false for the phone number same thing.
  964. 51:58Okay enum and nullable false. Okay same
  965. 52:02thing for our second enum that is at
  966. 52:06enumerated and type a string column
  967. 52:09nullable false. Okay. And yeah here in
  968. 52:13the balance we need to add you know
  969. 52:16precision and scale. Okay. So first
  970. 52:18property is nable false and then
  971. 52:21precision uh 12. Okay. Let me just
  972. 52:26modify to 15. Okay. Same thing same
  973. 52:30thing for the daily transition limit.
  974. 52:32Okay. So yeah and created at so at
  975. 52:36creation time stamp. Add creation time
  976. 52:39stamp. And for this add update time
  977. 52:42stamp. Okay. Yeah. Fine. So our account
  978. 52:47entity is done. Now let's complete our
  979. 52:51enum part. Okay. So account status and
  980. 52:54account type. Okay. So what are the
  981. 52:57account status values? Okay. So it is
  982. 53:01active. Okay. Account status active or
  983. 53:04uh account blocked.
  984. 53:07Yes. or account closed. Yeah. Okay. And
  985. 53:12also let me write the comments. You know
  986. 53:14account
  987. 53:16life cycle is status. See comments are
  988. 53:20really important in my project videos.
  989. 53:22Okay. In future uh in coming few minutes
  990. 53:25I'm going to show you the entire code
  991. 53:28flow. Okay. In the comments so that you
  992. 53:32can implement at your own first. Okay.
  993. 53:34Fine. So now the next is what account
  994. 53:39type. Okay. So what are the account
  995. 53:42types? The first is savings.
  996. 53:46Okay. Then uh savings account and then
  997. 53:51current account. Okay. And also let's
  998. 53:55add fixed deposit.
  999. 53:59Yes. Got it. Yeah. Now, now watch next
  1000. 54:04is our
  1001. 54:06DTO. Okay, so we have you know create
  1002. 54:11account request
  1003. 54:13and in response what we'll get. So
  1004. 54:18account
  1005. 54:20response. Okay. So let's add the fields
  1006. 54:24in these two details. Okay. First let me
  1007. 54:26add add data. then add
  1008. 54:30no arcs and add all arcs.
  1009. 54:34Okay, now let me just put them side by
  1010. 54:38side. Okay, account here and my create
  1011. 54:41account request. Okay, so what are the
  1012. 54:44fields I need to create an account?
  1013. 54:46Okay, so first I need this account
  1014. 54:49holder name. Okay.
  1015. 54:53And then
  1016. 54:54next is I need email and phone. Okay.
  1017. 54:58Email, phone.
  1018. 55:01Fine. And then what? Then uh account
  1019. 55:06type.
  1020. 55:08Okay.
  1021. 55:10And one more field. What? Private
  1022. 55:14big decimal. No, not balance.
  1023. 55:17But uh let me rename it as initial
  1024. 55:22uh better initial deposit.
  1025. 55:25Yeah, because once you go to the bank
  1026. 55:28and once you create a new account. Okay.
  1027. 55:30So the bank executive will ask you for
  1028. 55:33initial deposit.
  1029. 55:35Yes. Okay. So now let me add you know
  1030. 55:39the validations first at not blank.
  1031. 55:42Okay. And if it is blank then we'll
  1032. 55:45display a message like account
  1033. 55:49holder name is required. Okay. And
  1034. 55:54similarly for the email at not blank
  1035. 55:59else email is required also also let's
  1036. 56:03check the email format. Okay. So
  1037. 56:07you know
  1038. 56:09invalid email format.
  1039. 56:13Okay. And phone number. Okay. So, same
  1040. 56:16thing not blank.
  1041. 56:19And message that phone is required.
  1042. 56:26Okay. Then next is account type. Okay.
  1043. 56:30So, not null.
  1044. 56:32Not null. And
  1045. 56:35message will display that account type
  1046. 56:39is required. And finally finally we need
  1047. 56:43to add two more annotations here. So
  1048. 56:46first is at not null. Okay we'll display
  1049. 56:50a message
  1050. 56:52that uh initial deposit
  1051. 56:56is
  1052. 56:59is required.
  1053. 57:02Okay. And also what we want we want our
  1054. 57:07deposit in positive. Okay. Should not be
  1055. 57:11in negative. Yeah, definitely balance
  1056. 57:13should be in positive not the negative.
  1057. 57:15Okay. So at positive. Okay. And if
  1058. 57:20suppose you try to hit you try to send
  1059. 57:24the request with negative balance or
  1060. 57:26negative initial deposit then it should
  1061. 57:29show the error like initial deposit
  1062. 57:34must be
  1063. 57:37positive.
  1064. 57:39Yes.
  1065. 57:42create a point. Okay. Yeah. So this is
  1066. 57:45what my uh first create account request
  1067. 57:48DTO. Next in response what all fields
  1068. 57:51we'll get. So I guess we need all the
  1069. 57:55fields. Okay. Let me just directly copy
  1070. 57:57and paste here.
  1071. 58:00Fine. And uh let me just you know
  1072. 58:06remove all these
  1073. 58:09annotations and validations.
  1074. 58:13Okay.
  1075. 58:16Yeah.
  1076. 58:18So
  1077. 58:25fine. So I need ID, account number,
  1078. 58:28account holder name, email, phone and
  1079. 58:31account type, status, balance, daily
  1080. 58:34transaction limit, created at and okay,
  1081. 58:36let me remove updated at. I don't need
  1082. 58:39this.
  1083. 58:41Okay, also these imports statements.
  1084. 58:46Yeah, so our you know uh DTO part is
  1085. 58:49done. Okay, now let me create the full
  1086. 58:51skeleton. Okay. So, first controller dot
  1087. 58:55account controller. Okay. And then
  1088. 59:01next is our service dot
  1089. 59:05account service. Okay. And and what our
  1090. 59:13you know repository dot
  1091. 59:17account repository
  1092. 59:20and it should be interface. Okay.
  1093. 59:24Extends jpa repo.
  1094. 59:27Okay. Account and string. Yeah.
  1095. 59:30Definitely of type is string because our
  1096. 59:33id of type is string. Okay. Yeah. The
  1097. 59:36next is
  1098. 59:39um also also let me you know
  1099. 59:44consumer class. Okay. So account event
  1100. 59:47consumer
  1101. 59:49yes consume the events
  1102. 59:52um the events like we have discussed in
  1103. 59:54the HLD architecture that transaction
  1104. 59:57service. Okay. So our transaction
  1105. 1:00:00service publish the event what
  1106. 1:00:03transaction dot initiated.
  1107. 1:00:07Okay. And that event consumed by our
  1108. 1:00:11account event consumer.
  1109. 1:00:15Okay. So that it hits a method which
  1110. 1:00:20method
  1111. 1:00:22deduct
  1112. 1:00:24balance.
  1113. 1:00:26Okay. which we are going to implement in
  1114. 1:00:28our
  1115. 1:00:30account service. Okay. All the you know
  1116. 1:00:34money movement method is going to
  1117. 1:00:36implement in this deduct balance credit
  1118. 1:00:41you know and uh uh receiver refund
  1119. 1:00:45everything else. Okay. Yeah. So that's
  1120. 1:00:49it. Okay. Fine. Next is uh account
  1121. 1:00:54controller. Okay. and
  1122. 1:00:58got it.
  1123. 1:01:00Okay. So at first rest controller and
  1124. 1:01:05request mapping. Okay. API
  1125. 1:01:09and V1
  1126. 1:01:12and
  1127. 1:01:13accounts
  1128. 1:01:16then SLF 4J. Okay. And now let me
  1129. 1:01:22private final account
  1130. 1:01:26service. Okay. For that let me also add
  1131. 1:01:29one more annotation that is required
  1132. 1:01:32asks constructor.
  1133. 1:01:35Okay. Yeah.
  1134. 1:01:37Now let's start adding the endpoints.
  1135. 1:01:41Okay. So what are the endpoints we need
  1136. 1:01:42to add here? First is create account.
  1137. 1:01:46Okay. Then get account. Okay. Get
  1138. 1:01:50balance.
  1139. 1:01:52Fine. Next is our block account. Yes,
  1140. 1:01:56block account. And then our saga is step
  1141. 1:02:01number one.
  1142. 1:02:04Okay. That is our um deduct balance.
  1143. 1:02:12Okay. And then and then what?
  1144. 1:02:16Um,
  1145. 1:02:18credit
  1146. 1:02:19credit balance. Okay, that means uh
  1147. 1:02:24what? Receiver. Okay, so credit
  1148. 1:02:28receiver,
  1149. 1:02:30credit sender. Okay, that means refund.
  1150. 1:02:36So this is I guess uh you know saga step
  1151. 1:02:40number I guess uh four. Yeah. So these
  1152. 1:02:46all endpoints we need to add and
  1153. 1:02:50implement it in the our account service.
  1154. 1:02:54Okay.
  1155. 1:02:56Yeah. So also need to consume two events
  1156. 1:03:00from fraud detection
  1157. 1:03:02and uh from
  1158. 1:03:04transaction service. Okay. So let's do
  1159. 1:03:08it. Let's implement it and then let's
  1160. 1:03:10quickly finish it. Okay. Fine. So public
  1161. 1:03:15response entity. Okay. And uh I'm
  1162. 1:03:20returning the what account response
  1163. 1:03:22account
  1164. 1:03:25response. And first is my create
  1165. 1:03:29account.
  1166. 1:03:31Okay. And at valid.
  1167. 1:03:35Okay. At valid. Okay. And at request
  1168. 1:03:40body. Let me pass the create account
  1169. 1:03:43request and let's keep it short request.
  1170. 1:03:48Okay.
  1171. 1:03:51Yeah. So
  1172. 1:03:54fine.
  1173. 1:03:56Return
  1174. 1:03:57response entity. Okay. And dot status
  1175. 1:04:02http. Okay. Status dot created
  1176. 1:04:08dot body. And let me call the method
  1177. 1:04:13account service dot create account.
  1178. 1:04:16Okay, which we are going to implement in
  1179. 1:04:19the account service class. Okay. And let
  1180. 1:04:23me pass this request here.
  1181. 1:04:27Okay. Yeah, it is what? Post mapping.
  1182. 1:04:31Post mapping. Okay. Next method is what?
  1183. 1:04:35public
  1184. 1:04:38and response entity account response.
  1185. 1:04:43Okay. And what? Get account.
  1186. 1:04:48Okay. Get account.
  1187. 1:04:51And get account at path variable. Okay.
  1188. 1:04:56By
  1189. 1:04:58account number.
  1190. 1:05:02Okay.
  1191. 1:05:04So
  1192. 1:05:06return
  1193. 1:05:07response
  1194. 1:05:09entity dot okay and account service dot
  1195. 1:05:15get account oops get account
  1196. 1:05:19and let me pass the account number okay
  1197. 1:05:23and it is my get mapping okay
  1198. 1:05:29and
  1199. 1:05:32this is what my account
  1200. 1:05:36number. Yeah. Okay. Fine.
  1201. 1:05:40So the next method is our
  1202. 1:05:45public also. Just let me you know copy
  1203. 1:05:49paste this one.
  1204. 1:05:51So
  1205. 1:05:53it should be get balance.
  1206. 1:05:57Okay. And get balance by account number.
  1207. 1:06:00Okay. It is fine. Get balance.
  1208. 1:06:04Okay. And here in the mapping balance.
  1209. 1:06:10Yeah. Fine. Also also here I'm getting
  1210. 1:06:14the balance. Okay. So big decimal.
  1211. 1:06:18Okay. Fine. Now comes our block account.
  1212. 1:06:23Okay. So public
  1213. 1:06:26response entity.
  1214. 1:06:29Okay. and a string. Yeah. And block
  1215. 1:06:35account.
  1216. 1:06:37Okay. So by same thing add path variable
  1217. 1:06:42string account number. Yes.
  1218. 1:06:45And then then what? Account service dot
  1219. 1:06:51block
  1220. 1:06:54account. Okay. Let me pass the account
  1221. 1:06:57number and we'll return
  1222. 1:07:00response entity dot okay
  1223. 1:07:05and account blocked
  1224. 1:07:09successfully. Yeah, here the mapping.
  1225. 1:07:13Okay, tell me uh which mapping I need to
  1226. 1:07:17put here.
  1227. 1:07:19Yes, get. No, not get. It should be put
  1228. 1:07:24mapping. Okay.
  1229. 1:07:26And
  1230. 1:07:30uh it is let me pass the account number.
  1231. 1:07:35Okay. And block.
  1232. 1:07:39Yeah. Next is next. What? Next is our
  1233. 1:07:44saga step number one. Okay. Saga step
  1234. 1:07:48one. Fine.
  1235. 1:07:51Deduct balance. Okay. also called by
  1236. 1:07:57transaction
  1237. 1:08:00service when
  1238. 1:08:03transaction service when
  1239. 1:08:06yes tell me when transfer is initiated
  1240. 1:08:13okay yeah got it that's why I told you
  1241. 1:08:18the comments are really important in my
  1242. 1:08:20videos so public and
  1243. 1:08:25response entity.
  1244. 1:08:28Okay,
  1245. 1:08:30type a string and deduct balance. Okay,
  1246. 1:08:36and need to pass two things obviously.
  1247. 1:08:39So, first I need to pass the account
  1248. 1:08:41number and definitely the balance. Okay,
  1249. 1:08:44the amount. So, add request param
  1250. 1:08:47request param. Okay, big decimal amount.
  1251. 1:08:50Fine.
  1252. 1:08:53and account service dot deduct balance.
  1253. 1:09:01Okay. Uh let me pass the account number
  1254. 1:09:03and
  1255. 1:09:04amount here. And then return
  1256. 1:09:10response entity dot okay amount. Okay.
  1257. 1:09:14Amount. Okay.
  1258. 1:09:17Or I can say balance deducted
  1259. 1:09:21successfully.
  1260. 1:09:23Okay.
  1261. 1:09:25Put mapping and
  1262. 1:09:29here account number
  1263. 1:09:32to pass. Okay.
  1264. 1:09:36And deduct.
  1265. 1:09:38Fine. Okay. Okay. Okay. Now the
  1266. 1:09:41important one that is our
  1267. 1:09:45saga step
  1268. 1:09:49uh four h that is compensating. Okay. So
  1269. 1:09:55compensating
  1270. 1:09:57and
  1271. 1:09:59transaction
  1272. 1:10:02endpoint fine and it is called
  1273. 1:10:07by
  1274. 1:10:09transaction service.
  1275. 1:10:13Okay. So um listen to me here
  1276. 1:10:17compensating transaction endpoint. Okay.
  1277. 1:10:20So either we'll create two separate
  1278. 1:10:23methods. Okay. So credit receiver
  1279. 1:10:29and you know refund.
  1280. 1:10:32Okay. So definitely it is you know uh we
  1281. 1:10:35are crediting sender or we'll handle
  1282. 1:10:41both in one that is credit balance.
  1283. 1:10:47Okay. and we'll handle it in our
  1284. 1:10:49transaction
  1285. 1:10:50uh service.
  1286. 1:10:52Yes. Okay. So, called by transaction
  1287. 1:10:57service in two scenarios. Okay.
  1288. 1:11:05What are they? The first one is my
  1289. 1:11:09fraud.
  1290. 1:11:11Fraud detected.
  1291. 1:11:14Okay. So I need to refund sender.
  1292. 1:11:20Okay, that means I'll undo
  1293. 1:11:24a step one. Okay, second thing
  1294. 1:11:29transaction
  1295. 1:11:31completed.
  1296. 1:11:33Okay, so
  1297. 1:11:35I'll credit
  1298. 1:11:38receiver. Okay, fraud that means refund.
  1299. 1:11:41Transaction completed that means credit
  1300. 1:11:43receiver. Okay. Fine.
  1301. 1:11:46So now
  1302. 1:11:49public
  1303. 1:11:50response entity. Okay. And a string
  1304. 1:11:57credit balance. Okay.
  1305. 1:12:02Now add path variable account number and
  1306. 1:12:07big decimal amount. Fine. So account
  1307. 1:12:12service dot
  1308. 1:12:14credit balance. Okay. And account number
  1309. 1:12:20and amount.
  1310. 1:12:22Okay. And then return
  1311. 1:12:26response entity
  1312. 1:12:29dot. Okay.
  1313. 1:12:32And what
  1314. 1:12:35balance
  1315. 1:12:37credited
  1316. 1:12:39successfully.
  1317. 1:12:41Okay. The endpoint is again put mapping.
  1318. 1:12:49Okay. Account
  1319. 1:12:54number
  1320. 1:12:56and credit. Okay. So these are our
  1321. 1:13:00endpoints.
  1322. 1:13:02We need to implement it. Okay. So kindly
  1323. 1:13:06pay attention here on my account
  1324. 1:13:10service. Okay, let's go for it. So
  1325. 1:13:17service and then SLF 4J. Okay, then
  1326. 1:13:24private
  1327. 1:13:25final account repository. Okay, so for
  1328. 1:13:30that let me also add required arcs
  1329. 1:13:35constructor. Okay,
  1330. 1:13:38fine. So our first endpoint is public
  1331. 1:13:42and I'm returning account response and
  1332. 1:13:46create account. Okay, what I'm getting
  1333. 1:13:50I'm getting the request create account
  1334. 1:13:52request and uh let's keep it short
  1335. 1:13:56request. Okay, first let me add the
  1336. 1:13:59login. So info log.info info and
  1337. 1:14:04I am creating account
  1338. 1:14:08for
  1339. 1:14:11okay and let me pass the request dot get
  1340. 1:14:16email okay now first let me check
  1341. 1:14:21whether account is already exist or not
  1342. 1:14:24in my account repository okay so account
  1343. 1:14:27dot
  1344. 1:14:29exist by email. Okay. So, I need to
  1345. 1:14:35create this method in my account
  1346. 1:14:36repository. Okay.
  1347. 1:14:40Account repository. Account repository.
  1348. 1:14:43Fine. And boolean
  1349. 1:14:47exist by email. And I'm passing the
  1350. 1:14:50string email. Okay. Back to our account
  1351. 1:14:54service.
  1352. 1:14:56Fine. And
  1353. 1:14:59um let me pass the get email. Okay. So
  1354. 1:15:04if it is true then let's throw new
  1355. 1:15:08runtime exception and account already
  1356. 1:15:13exist
  1357. 1:15:15for email. Okay. And our request dot get
  1358. 1:15:21email.
  1359. 1:15:22If not then uh then then what?
  1360. 1:15:27So if not then first let me create
  1361. 1:15:31account object.
  1362. 1:15:33Okay. So you can create in two ways
  1363. 1:15:36either by new operator account account
  1364. 1:15:39uh equals new account or else using the
  1365. 1:15:43builder. Okay. So just you need to add
  1366. 1:15:46here add builder annotation.
  1367. 1:15:50Okay. and then account account equals
  1368. 1:15:54account dot
  1369. 1:15:57builder. Okay. And then all the fields
  1370. 1:15:59will populate here. So you need to just
  1371. 1:16:01set the values like account holder name.
  1372. 1:16:04Okay. So what you are getting from here
  1373. 1:16:07request dot get account holder name.
  1374. 1:16:09Okay. Like this in all the fields. Okay.
  1375. 1:16:12But for now let me just keep the simple
  1376. 1:16:14one. Okay. So account new account and
  1377. 1:16:18then set the values also let me remove
  1378. 1:16:22this. Okay no use fine and yeah
  1379. 1:16:29so let me just set the values account
  1380. 1:16:33dot set holder name and request dot get
  1381. 1:16:38holder name. Next is account dot
  1382. 1:16:42set email. Okay. Get email. Fine.
  1383. 1:16:48And uh you know what else?
  1384. 1:16:52Email, phone, account type and initial
  1385. 1:16:55deposit.
  1386. 1:16:56Then account dot set phone.
  1387. 1:17:01Okay. So yeah, get phone and then
  1388. 1:17:06account dot set account type. Okay.
  1389. 1:17:11Account type. So I'm getting the account
  1390. 1:17:14type. Okay. Also status. So account dot
  1391. 1:17:19set you know uh set status. So status
  1392. 1:17:25should be active. Okay. So account
  1393. 1:17:27status dotactive. Fine. And then finally
  1394. 1:17:31uh account dot we need to set the
  1395. 1:17:34balance. Okay. So the balance set
  1396. 1:17:38balance should be the initial deposit.
  1397. 1:17:42Yeah, definitely the initial deposit is
  1398. 1:17:44only our balance. So request dot
  1399. 1:17:48get initial deposit. Okay. And now now
  1400. 1:17:53our important logic account dot set
  1401. 1:17:57account number. Okay. Now I cannot do
  1402. 1:18:01like this account dot get account
  1403. 1:18:03number. No, we need to generate the
  1404. 1:18:07account number.
  1405. 1:18:09Yes or no? So just look here. We need to
  1406. 1:18:14generate
  1407. 1:18:16uh account number because we have the
  1408. 1:18:19specifications.
  1409. 1:18:20Okay. Like account number should be
  1410. 1:18:23first unique.
  1411. 1:18:25Second thing is must be
  1412. 1:18:29uh of 12 digits.
  1413. 1:18:32Yeah. So for that we need to write a
  1414. 1:18:36separate logic. Okay.
  1415. 1:18:39Fine. Let me just you know add here
  1416. 1:18:44generate
  1417. 1:18:46account number. Okay. And we'll
  1418. 1:18:49implement this method. Fine. Okay. So
  1419. 1:18:52now I want you to answer me for our next
  1420. 1:18:55field that is account dot set daily
  1421. 1:18:59transition limit. Yeah. So now tell me
  1422. 1:19:03uh what will be my user who is creating
  1423. 1:19:07a new account
  1424. 1:19:09transaction limit. What should I write
  1425. 1:19:11here? Okay. So now pay attention here.
  1426. 1:19:15Well, it depends on account type. We
  1427. 1:19:19have three types of account. Savings,
  1428. 1:19:21current and fixed deposit. And it
  1429. 1:19:23differs just like if a person is
  1430. 1:19:26creating an account and uh it's saving
  1431. 1:19:30account. Okay. Savings account. Then his
  1432. 1:19:34transition limit may be 100,000.
  1433. 1:19:37Yeah. And rest for uh current account or
  1434. 1:19:41uh you know let's say fixed deposit.
  1435. 1:19:44We'll set our daily transaction limit as
  1436. 1:19:47let's say 500,000.
  1437. 1:19:50Yes or no? So request dot you know first
  1438. 1:19:54let me get the account type okay and if
  1439. 1:19:58it is equals savings
  1440. 1:20:02okay then new big decimal and uh yeah
  1441. 1:20:09uh the daily transaction limit is
  1442. 1:20:10100,000
  1443. 1:20:13okay
  1444. 1:20:14else
  1445. 1:20:17okay
  1446. 1:20:19else what new big decimal for our uh you
  1447. 1:20:23know fixed deposit and current account
  1448. 1:20:26the daily transaction limit is 500,000.
  1449. 1:20:30Yes. Okay. Fine. Now let me account and
  1450. 1:20:35saved account equals account repository.
  1451. 1:20:39Okay. Saved. And also let me just add
  1452. 1:20:42the login that is account created.
  1453. 1:20:48Okay. and
  1454. 1:20:50saved account dot get account
  1455. 1:20:55number. Okay. And let me return the you
  1456. 1:20:59know now I need to return account
  1457. 1:21:02response. Okay. But I'm getting here
  1458. 1:21:05account. Okay. So I need to convert it.
  1459. 1:21:08So for that let me create a method map
  1460. 1:21:11to
  1461. 1:21:13response.
  1462. 1:21:14Okay. And let me pass the saved account.
  1463. 1:21:19Okay.
  1464. 1:21:21Yeah.
  1465. 1:21:23Now quickly let me just
  1466. 1:21:27private and need to return the account
  1467. 1:21:31response and map to response. Okay fine.
  1468. 1:21:35So account
  1469. 1:21:37response response
  1470. 1:21:42equals new account response. Okay. and
  1471. 1:21:44then just set the values.
  1472. 1:21:47Okay. in the response object.
  1473. 1:21:51Fine. Okay. So, just like response dot
  1474. 1:21:56set.
  1475. 1:21:57Okay. I guess let me Yeah. So, I haven't
  1476. 1:22:01mentioned the Lombok
  1477. 1:22:03at data at all arcs at no args. Okay.
  1478. 1:22:08Fine. Now, set ID. Okay. So, what I'm
  1479. 1:22:15getting account ID. Similarly for all
  1480. 1:22:17the fields. Okay. So let me just do fast
  1481. 1:22:20forward. Okay. And then return response.
  1482. 1:22:27Yeah. Fine. Okay. Now we are going to
  1483. 1:22:30implement one of the most important
  1484. 1:22:32method that is generate account number.
  1485. 1:22:37Okay. So private string and we going to
  1486. 1:22:41generate unique 12digit account number.
  1487. 1:22:45But how? Can you tell me any guesses? So
  1488. 1:22:49first let me take secure random. Okay.
  1489. 1:22:53Private
  1490. 1:22:55static
  1491. 1:22:57secure random. Okay.
  1492. 1:23:01Equals secure random. Fine. And now let
  1493. 1:23:06me open the dowhile loop. Okay. So first
  1494. 1:23:09let me also take you know my variable in
  1495. 1:23:12which I'm going to store my account
  1496. 1:23:14number. Okay. And then do while loop.
  1497. 1:23:18Yes.
  1498. 1:23:23Okay. So now uh let me first generate a
  1499. 1:23:28unit uh random number. Okay. Here is a
  1500. 1:23:32you know tricky part. So secure random
  1501. 1:23:35my variable and dot next long and let me
  1502. 1:23:39just set the upper limit. Okay. So my
  1503. 1:23:43upper limit is 1. Okay. And 2 3 4 5 6 7
  1504. 1:23:508 9 10 11 12 13.
  1505. 1:23:55Okay. Yeah. Now look at here. So you
  1506. 1:23:57might be thinking that I have set my
  1507. 1:24:01upper limit, set my bound
  1508. 1:24:04as this number that is 1 2 3
  1509. 1:24:094 5 6 7 8 9 10 11 12 13. Okay, that is
  1510. 1:24:14correct because this line, you know,
  1511. 1:24:17this line generates
  1512. 1:24:20a random numbers from 0 to uh this
  1513. 1:24:26number minus one that is 999 until 12
  1514. 1:24:29digits. Okay. Yeah, definitely inclusive
  1515. 1:24:33and this is exclusive. Okay. Now there
  1516. 1:24:37is one issue you might be thinking that
  1517. 1:24:39why from zero to uh you know this uh
  1518. 1:24:43last 12-digit number as you mentioned
  1519. 1:24:46that we need a count number is specific
  1520. 1:24:5112digit number and unique.
  1521. 1:24:55So you should have to set the range from
  1522. 1:25:00you know 1 2 3 4 5 6 7 8 9 10 11 12 to
  1523. 1:25:06this last 12-digit number.
  1524. 1:25:10Okay, then only we'll get only 12digit
  1525. 1:25:14number.
  1526. 1:25:16Okay. And for the unique we'll uh check
  1527. 1:25:19in the database.
  1528. 1:25:21Yeah, you're correct. But what I'm
  1529. 1:25:24thinking is so let's say this line
  1530. 1:25:27generates the number as 1 2 3 4 5. Yeah,
  1531. 1:25:33possible. So it can generate any number
  1532. 1:25:36from zero to last 12-digit number. Let's
  1533. 1:25:40say this number.
  1534. 1:25:42So this is not a 12digit number. But it
  1535. 1:25:46is specific that we only need
  1536. 1:25:5112 dual digit number and should be
  1537. 1:25:52unique. So how about let's convert it.
  1538. 1:25:57Yes. So
  1539. 1:26:001 2 3 4 5 and put the zeros. Okay.
  1540. 1:26:06Remaining seven zeros. So 1 2 3 4 5 6 7.
  1541. 1:26:12it becomes my 12digit
  1542. 1:26:15number.
  1543. 1:26:17Yes or no? So 1 2 3 4 5 6 7 8 9 10 11
  1544. 1:26:2212. Similarly, if suppose it generates
  1545. 1:26:25uh you know 1 2 so 1 2 3 4 5 6 7 8 9 10.
  1546. 1:26:36Okay. And for the uniqueness we are
  1547. 1:26:39going to check in the our repo rep
  1548. 1:26:41repository database.
  1549. 1:26:44Yeah. So that's why this is what our
  1550. 1:26:47logic. Okay. Let's write it. Let's uh
  1551. 1:26:49you know code the complete logic. Okay.
  1552. 1:26:54Fine. So now my account number equals
  1553. 1:26:58Okay. Uh let me format it. String dot
  1554. 1:27:02format. Now let me explain to you. So
  1555. 1:27:06format starts. So this is a percentage
  1556. 1:27:09that means format start. Now I need to
  1557. 1:27:12replace with the zeros zero. Now I need
  1558. 1:27:1612digit number 12. Okay. And d for the
  1559. 1:27:19decimal integer.
  1560. 1:27:22Yes or no?
  1561. 1:27:24See how I'm explaining line by line,
  1562. 1:27:26word by word. Okay. So percent means
  1563. 1:27:29format starts. Zero means replacing with
  1564. 1:27:32zeros. 12. Okay, need 12-digit you know
  1565. 1:27:37uh account number 12digit number and D
  1566. 1:27:41means decimal integer. Okay, fine. Now
  1567. 1:27:44here while so account repository dot
  1568. 1:27:50exist by account
  1569. 1:27:53number. Okay. And we'll pass the account
  1570. 1:27:56number. Okay. So yeah this account
  1571. 1:28:01number.
  1572. 1:28:03Okay. what it means? Let me explain you.
  1573. 1:28:06First, let me create this method in our
  1574. 1:28:08repository. Account repository. Okay.
  1575. 1:28:12And boolean.
  1576. 1:28:16Fine. And I'm getting the account
  1577. 1:28:18number.
  1578. 1:28:20Okay. Yeah. So now just
  1579. 1:28:24Okay. So look at here. What we are
  1580. 1:28:26checking in this condition that
  1581. 1:28:30is there any user available with the
  1582. 1:28:34same account number which generated
  1583. 1:28:37here. Okay. So let's say this is my you
  1584. 1:28:40know user uh database and there are few
  1585. 1:28:44users already registered. Okay. So fine
  1586. 1:28:49and this is what account number and few
  1587. 1:28:52us are already registered. Okay. with
  1588. 1:28:54the account number let's say 0 0 0 till
  1589. 1:28:571 2 3 4 5 and uh 0 0 4 5 6 whatever till
  1590. 1:29:0312 digit and you know just like that.
  1591. 1:29:06Now suppose a new user came create
  1592. 1:29:09account. Okay, create account and then
  1593. 1:29:12finally generate account. So this method
  1594. 1:29:14called control come here comes here
  1595. 1:29:16comes here and it generates
  1596. 1:29:19a random account number. Let's say 1 2 3
  1597. 1:29:234 5 a random number. Okay. So now it
  1598. 1:29:27converted to
  1599. 1:29:303 4 5 6 7 and 1 2 3 4 5. Now with this
  1600. 1:29:35account number there is already a record
  1601. 1:29:39exist in our database.
  1602. 1:29:43That is what we are checking here. If it
  1603. 1:29:46is exist then continue the loop.
  1604. 1:29:50Generate another number. Generate
  1605. 1:29:52another number.
  1606. 1:29:54Once this condition failed there is no
  1607. 1:29:56any entry in our database. That means
  1608. 1:29:59that account number is unique one. So
  1609. 1:30:01that is assigned to that particular
  1610. 1:30:04user.
  1611. 1:30:06Getting my point? Yes or no? Okay. Fine.
  1612. 1:30:10So here and then
  1613. 1:30:13we are returning the account number.
  1614. 1:30:18Yes, understood the concept how we have
  1615. 1:30:21implemented and how we have generated.
  1616. 1:30:24Okay. So also let me write the comment
  1617. 1:30:26generate unique 12
  1618. 1:30:31digit account number.
  1619. 1:30:36Yeah. Okay.
  1620. 1:30:38Fine. Now let's implement our next
  1621. 1:30:41methods. Okay. So get account get
  1622. 1:30:44balance. Okay. Let me just implement it
  1623. 1:30:46quickly and then we'll move to our uh
  1624. 1:30:49saga methods. Okay.
  1625. 1:30:52So
  1626. 1:30:54public
  1627. 1:30:56account response and get account. Okay,
  1628. 1:31:03the string account number.
  1629. 1:31:06Okay, now first let me get the account.
  1630. 1:31:09So account
  1631. 1:31:14account equals
  1632. 1:31:18um account repository dot find by
  1633. 1:31:23account number. Okay. So we need to
  1634. 1:31:26create this method to account repository
  1635. 1:31:30and yeah
  1636. 1:31:33so optional.
  1637. 1:31:36Okay.
  1638. 1:31:38and account find by account number
  1639. 1:31:43and I'm getting the
  1640. 1:31:46account number.
  1641. 1:31:49Okay.
  1642. 1:31:51Yeah. Now comes here. Let me pass the
  1643. 1:31:56account number or else throw
  1644. 1:32:02new runtime exception
  1645. 1:32:07account not found.
  1646. 1:32:11Yes. Yeah. Now so that's it and we'll
  1647. 1:32:15return map to response account. Okay.
  1648. 1:32:18Yeah.
  1649. 1:32:20Now similarly um let me just copy and
  1650. 1:32:24paste for our get balance. Okay. So get
  1651. 1:32:28balance
  1652. 1:32:31and this is my
  1653. 1:32:34well I'm returning the big decimal.
  1654. 1:32:37Okay.
  1655. 1:32:38Okay. First I got my account and then
  1656. 1:32:42return
  1657. 1:32:44account dot get balance.
  1658. 1:32:48Okay.
  1659. 1:32:49Mhm. Yeah. Now let's implement our next
  1660. 1:32:54that is block account which is uh called
  1661. 1:32:58by fraud detection. Okay. So public void
  1662. 1:33:04block account.
  1663. 1:33:07Okay. And
  1664. 1:33:09a string account number.
  1665. 1:33:14Fine.
  1666. 1:33:16Okay. and called
  1667. 1:33:21uh what?
  1668. 1:33:24Okay. So, block account
  1669. 1:33:29and
  1670. 1:33:31called by
  1671. 1:33:34prod detection
  1672. 1:33:37service via
  1673. 1:33:40Kafka. H okay.
  1674. 1:33:44Okay.
  1675. 1:33:47So yeah also let me just quickly you
  1676. 1:33:51know get account by account number.
  1677. 1:33:57Okay
  1678. 1:33:59comments are must yes and get
  1679. 1:34:04account
  1680. 1:34:05balance.
  1681. 1:34:07Fine called by fraud detection service.
  1682. 1:34:10Okay, definitely because once fraud
  1683. 1:34:14detected
  1684. 1:34:15then
  1685. 1:34:17this service gets called. Okay, so first
  1686. 1:34:21let me add the login. Okay, and it's
  1687. 1:34:24like I'm blocking account.
  1688. 1:34:29Okay,
  1689. 1:34:32I'm blocking the account. Okay, and
  1690. 1:34:35account number. Fine. Then first let me
  1691. 1:34:38get the account. Okay, let me just copy
  1692. 1:34:42that you know the complete thing.
  1693. 1:34:47I'm getting the account using account
  1694. 1:34:49number. Okay, got the account and let me
  1695. 1:34:52just set the status account dot you know
  1696. 1:34:56set status as account dot you know
  1697. 1:34:59status do.blogged. Okay. And at the time
  1698. 1:35:02of transfer we'll check that account
  1699. 1:35:05must be in active state. Okay. Yeah. So
  1700. 1:35:10let me just save it. Account repository
  1701. 1:35:13save and log dot info account blocked
  1702. 1:35:18account number. Yes. Okay. Yeah. Now now
  1703. 1:35:23what? So now next is
  1704. 1:35:28uh
  1705. 1:35:29h
  1706. 1:35:32deduct balance.
  1707. 1:35:35Okay, deduct
  1708. 1:35:38balance and
  1709. 1:35:41I'm getting account number and big
  1710. 1:35:46decimal
  1711. 1:35:48amount.
  1712. 1:35:51Okay. Mhm.
  1713. 1:35:54So now
  1714. 1:35:57deduct balance from
  1715. 1:36:01sender
  1716. 1:36:03account
  1717. 1:36:04and it is called by
  1718. 1:36:08transaction service.
  1719. 1:36:12Yes or no? Yes.
  1720. 1:36:15Fine. So log dot info and I am deducting
  1721. 1:36:20balance. Okay. So deducting balance
  1722. 1:36:25and from account.
  1723. 1:36:28Okay. So deducting balance that is
  1724. 1:36:31amount
  1725. 1:36:33H. Okay.
  1726. 1:36:36Now let me get that account first.
  1727. 1:36:39Yeah. So
  1728. 1:36:42let me get the account. Okay. Got it.
  1729. 1:36:45And now let's check if if what if
  1730. 1:36:50account
  1731. 1:36:51dot get status
  1732. 1:36:56is
  1733. 1:36:58not active.
  1734. 1:37:00If the status is not active then
  1735. 1:37:06throw runtime exception that account is
  1736. 1:37:09not active. Okay. And account number.
  1737. 1:37:14Yes. Then let's check the balance. Okay.
  1738. 1:37:18Because we need to add both. Fine. Some
  1739. 1:37:22of you might forget to check the status.
  1740. 1:37:25Yeah. That's why status is the most
  1741. 1:37:27important field. Okay. Yes. So now once
  1742. 1:37:31active then we'll check the balance. Uh
  1743. 1:37:34account dot
  1744. 1:37:36get balance dot compare to compare to.
  1745. 1:37:43Okay. amount
  1746. 1:37:45and less than zero.
  1747. 1:37:48Less than zero. Then here
  1748. 1:37:54row new
  1749. 1:37:56runtime exception that insufficient
  1750. 1:37:59funds for account. Yeah. Okay. And then
  1751. 1:38:04account dot set balance. Okay. We need
  1752. 1:38:08to set the balance. What? account dot
  1753. 1:38:11get balance dots subtract.
  1754. 1:38:15Okay.
  1755. 1:38:19Subtract amount.
  1756. 1:38:22Fine. And then let me save it.
  1757. 1:38:25Repository and then log dot info. So
  1758. 1:38:29balance balance updated
  1759. 1:38:34and new
  1760. 1:38:36balance
  1761. 1:38:38is
  1762. 1:38:40account dot get balance.
  1763. 1:38:45Yes. Okay. Okay. Okay. Now let's
  1764. 1:38:48implement our last method that is
  1765. 1:38:52uh yeah credit balance. Okay.
  1766. 1:38:57So public void and credit balance
  1767. 1:39:04a string account
  1768. 1:39:07number and big decimal
  1769. 1:39:13amount.
  1770. 1:39:17Okay.
  1771. 1:39:19Yeah. So now comments are most
  1772. 1:39:23important. So credit balance and called
  1773. 1:39:28by
  1774. 1:39:30transaction
  1775. 1:39:32service via Kafka. Okay, we need to also
  1776. 1:39:36you know handle it in uh our transaction
  1777. 1:39:39service. This is you know the heart of
  1778. 1:39:43our banking system. Please do not miss
  1779. 1:39:45the service method implementation.
  1780. 1:39:48Everything goes here. Okay. And our
  1781. 1:39:50fraud detection. Okay. Yeah. So let me
  1782. 1:39:55just add some loggings log.info and
  1783. 1:39:59I am crediting
  1784. 1:40:02what
  1785. 1:40:04uh two
  1786. 1:40:07account
  1787. 1:40:11fine and crediting this amount to this
  1788. 1:40:15account.
  1789. 1:40:17Okay. This can be anyone. Fine. Yeah. So
  1790. 1:40:20first let me let me get that.
  1791. 1:40:27Okay.
  1792. 1:40:29Yeah. And then I need to add. Okay. So
  1793. 1:40:32account dot set balance. Okay. Then
  1794. 1:40:39account dot get balance. And we need to
  1795. 1:40:42dot add amount.
  1796. 1:40:45Yes. And then account repository dot
  1797. 1:40:48save and log dot info. So balance
  1798. 1:40:54credited.
  1799. 1:40:56Okay. And new balance
  1800. 1:41:00account dot get balance. Yeah. So this
  1801. 1:41:04is what our uh you know completed
  1802. 1:41:08everything all the method implementation
  1803. 1:41:12done. Yeah. account controller.
  1804. 1:41:15Yes. And now now let's move to our
  1805. 1:41:20account event consumer
  1806. 1:41:22where we are going to consume
  1807. 1:41:25transaction completed event and fraud
  1808. 1:41:29detection event.
  1809. 1:41:32Okay. Yeah. To block the account or to
  1810. 1:41:35credit the balance. Yeah. Okay.
  1811. 1:41:38Important one. So let's start add
  1812. 1:41:41service and at SLF 4J. Fine. Now here we
  1813. 1:41:47are consuming two events. The first one
  1814. 1:41:50is public void and consume
  1815. 1:41:55transaction completed.
  1816. 1:41:58Okay. and add payload and map
  1817. 1:42:05a string object.
  1818. 1:42:09Okay. And payload.
  1819. 1:42:13Yes. Now
  1820. 1:42:16comments are consume what? Transaction
  1821. 1:42:20dot completed. Okay. Yeah.
  1822. 1:42:23Completed event from Kafka. And also I
  1823. 1:42:28want you to tell me that what it means
  1824. 1:42:31like what we are doing here
  1825. 1:42:34transaction completed means what? Okay.
  1826. 1:42:38So here look at here transaction
  1827. 1:42:40completed means
  1828. 1:42:42everything is done and no fraud detected
  1829. 1:42:46and now finally we are
  1830. 1:42:49crediting to receiver. Yes or no? Yeah.
  1831. 1:42:54Okay.
  1832. 1:42:55So here
  1833. 1:42:58credits
  1834. 1:43:00receiver account H. Now let me open my
  1835. 1:43:05try catch. And
  1836. 1:43:09here
  1837. 1:43:11let me first get the
  1838. 1:43:15receiver account equals
  1839. 1:43:19payload dot get
  1840. 1:43:24receiver account
  1841. 1:43:27number.
  1842. 1:43:29Okay.
  1843. 1:43:31Yeah. Let me type cast it the string
  1844. 1:43:36and and what big decimal.
  1845. 1:43:41Okay. And amount.
  1846. 1:43:43So
  1847. 1:43:45new big decimal. Okay. And then payload
  1848. 1:43:50dot get amount dot to string. Yeah.
  1849. 1:43:55And then let me first add the login that
  1850. 1:43:58we are crediting
  1851. 1:44:01account.
  1852. 1:44:03Okay.
  1853. 1:44:05And amount.
  1854. 1:44:09Fine.
  1855. 1:44:11So receiver account. And this is amount.
  1856. 1:44:15Got it? Okay. Now what we need? We need
  1857. 1:44:19to call that method. Okay. So account
  1858. 1:44:22service first. Let me get that private
  1859. 1:44:26final account service and account
  1860. 1:44:29service. Okay, for that let me add
  1861. 1:44:33required asks constructor. Okay, now
  1862. 1:44:37I need to credit. Okay, so account
  1863. 1:44:40service dot we already created a method
  1864. 1:44:43in the account service.
  1865. 1:44:45Okay, if you remember just now few
  1866. 1:44:47minutes before credit balance. Okay,
  1867. 1:44:51same thing. And let me pass the account
  1868. 1:44:54and amount. Okay,
  1869. 1:44:58that's it. And in our exception, let me
  1870. 1:45:01just add log error.
  1871. 1:45:05Okay, and error
  1872. 1:45:08crediting account.
  1873. 1:45:12Okay. E dot get message. H. Yeah. Now
  1874. 1:45:18add Kafka listener and topics. So
  1875. 1:45:24transaction dot completed.
  1876. 1:45:27Yeah, that's what we mentioned here in
  1877. 1:45:30the comments. Yeah, and the group we are
  1878. 1:45:35going to handle
  1879. 1:45:38uh in our where uh in our uh application
  1880. 1:45:43dot yiml file. Okay, properties file
  1881. 1:45:46because we are going to consume two
  1882. 1:45:51events from two different services.
  1883. 1:45:55Okay, so let's keep a single group for
  1884. 1:45:58both of them. Yeah, fine. Now the next
  1885. 1:46:00is next event we are consuming that is
  1886. 1:46:04public void consume
  1887. 1:46:07prod.
  1888. 1:46:10Okay, because we have one more method in
  1889. 1:46:12our account service that is
  1890. 1:46:15uh block account. Okay, so once fraud is
  1891. 1:46:18detected, we need to consume that and we
  1892. 1:46:21need to block account. Okay, payload
  1893. 1:46:25and and what h
  1894. 1:46:29uh let me open my try catch. Okay,
  1895. 1:46:35fine also.
  1896. 1:46:38Yeah. So at first uh
  1897. 1:46:43comments yeah
  1898. 1:46:46comments are most important. So consume
  1899. 1:46:50fraud dot detected
  1900. 1:46:52event
  1901. 1:46:54from Kafka and it blocks
  1902. 1:47:00h blocks the
  1903. 1:47:03flagged account. H okay. So first let me
  1904. 1:47:08get that. So a string account
  1905. 1:47:11number equals
  1906. 1:47:14payload dot get
  1907. 1:47:18account number. Okay. So
  1908. 1:47:22let me type casted a string
  1909. 1:47:26and and what let me add the login
  1910. 1:47:29log.info info that prod detected and uh
  1911. 1:47:35I'm blocking the account.
  1912. 1:47:38Okay.
  1913. 1:47:43Account number. Fine. Okay. And then let
  1914. 1:47:47me call account service dot blog
  1915. 1:47:50account. Pass the account number. Yeah.
  1916. 1:47:54In the catch block log dot error.
  1917. 1:47:58Okay. and error blocking account E.get
  1918. 1:48:02message.
  1919. 1:48:04Yeah. At Kafka listener and topics
  1920. 1:48:10what
  1921. 1:48:11fraud dot detected.
  1922. 1:48:15Yeah. So I guess my account service is
  1923. 1:48:19about to finish. Okay. Just one thing
  1924. 1:48:22remaining that is application dot you
  1925. 1:48:24know properties file. So controller
  1926. 1:48:27DTO's and all the entities enum
  1927. 1:48:30repository
  1928. 1:48:32and service event consumer and service.
  1929. 1:48:34Fine. Now let's configure our
  1930. 1:48:36properties.
  1931. 1:48:38So spring dot
  1932. 1:48:41application dot name. Okay. So account
  1933. 1:48:46service and then data source.
  1934. 1:48:51Okay.
  1935. 1:48:53So URL JDBC
  1936. 1:48:56MySQL.
  1937. 1:48:58Okay. And localhost 3306.
  1938. 1:49:02Fine. And let's create our first
  1939. 1:49:06database for our account service. Okay.
  1940. 1:49:10So let's say account DB. Okay. Also
  1941. 1:49:13let's uh add a property create database
  1942. 1:49:18if not
  1943. 1:49:20not exist
  1944. 1:49:23equals true.
  1945. 1:49:26Okay.
  1946. 1:49:28Yeah. Then username. So my username is
  1947. 1:49:33root
  1948. 1:49:35password. My password is you know root.
  1949. 1:49:38You can just enter your own uh MySQL
  1950. 1:49:41password. Okay. and driver
  1951. 1:49:44class name that is com dot MySQL dot CJ
  1952. 1:49:50dot
  1953. 1:49:52uh JDBC dot driver.
  1954. 1:49:58Okay fine. Now next is JPA
  1955. 1:50:02hibernate and DDL auto. So update. Okay.
  1956. 1:50:09and then show SQL
  1957. 1:50:13true fine then dialect. Okay. So
  1958. 1:50:18properties dot hibernate
  1959. 1:50:22dot dialect. Okay. So
  1960. 1:50:26just go to this uh you know search and
  1961. 1:50:31classes type my SQL
  1962. 1:50:35dialect. Click here and this is the you
  1963. 1:50:39know MySQL dialect class file. Okay. So
  1964. 1:50:44copy full path or dot hibernate dialect
  1965. 1:50:47dot MySQL dialect. Okay. Close this.
  1966. 1:50:53Paste it here. Dot MySQL
  1967. 1:50:57dialect. H. Okay. Fine. Now our Kafka
  1968. 1:51:01properties. So Kafka dot
  1969. 1:51:05bootstrap
  1970. 1:51:07servers
  1971. 1:51:09localhost
  1972. 1:51:119092.
  1973. 1:51:12Okay. Then consumer.
  1974. 1:51:16Okay. So group ID. Yes. So let's say
  1975. 1:51:21group ID. Let's keep it as account
  1976. 1:51:24service group. Okay. A single group. We
  1977. 1:51:28are consuming two events.
  1978. 1:51:31Fine. Then auto
  1979. 1:51:35offset reset.
  1980. 1:51:39So earliest
  1981. 1:51:42H. Okay. And then key value D
  1982. 1:51:45serializer. Okay. So
  1983. 1:51:51key D serializer. Okay. It is
  1984. 1:51:54org.apache.
  1985. 1:51:57Kafka common. Okay. Then serialization
  1986. 1:52:03dot string
  1987. 1:52:06d serializer.
  1988. 1:52:10Fine. Similarly, value d serializer.
  1989. 1:52:12Okay. Key d serializer and value
  1990. 1:52:16d serializer.
  1991. 1:52:19Fine. So it is spring framework or dot
  1992. 1:52:23spring
  1993. 1:52:24framework.
  1994. 1:52:27Okay. dot kafka
  1995. 1:52:30dots support
  1996. 1:52:32dot serializer dot json d serializer.
  1997. 1:52:39Yes. Okay. Then properties
  1998. 1:52:43then spring
  1999. 1:52:46json.
  2000. 1:52:49Okay. Then
  2001. 1:52:51trusted then packages.
  2002. 1:52:55Okay. So yeah and
  2003. 1:53:00use
  2004. 1:53:02type
  2005. 1:53:04headers
  2006. 1:53:06let me set it as false
  2007. 1:53:09and payload package value
  2008. 1:53:15default.
  2009. 1:53:17Okay type. Okay. So our payload
  2010. 1:53:23you know of type map.
  2011. 1:53:26Okay. So packages java dot util dot
  2012. 1:53:32hashmap.
  2013. 1:53:34Fine. Okay. Now producer.
  2014. 1:53:39Yes. Producer.
  2015. 1:53:43Okay. Let me just copy paste these two.
  2016. 1:53:46Okay. So producer
  2017. 1:53:50now here it should be key serializer
  2018. 1:53:53instead of d serializer. Okay.
  2019. 1:53:57And here to a string serializer.
  2020. 1:54:01Oh JSON
  2021. 1:54:04d serializer. Uh sorry serializer.
  2022. 1:54:08Okay fine. Now port.
  2023. 1:54:11So
  2024. 1:54:16here server dot port it is running on
  2025. 1:54:218081
  2026. 1:54:22and
  2027. 1:54:24management then endpoints then
  2028. 1:54:29web.
  2029. 1:54:31Okay then exposure
  2030. 1:54:35and include what?
  2031. 1:54:39Health info.
  2032. 1:54:42Okay. Fine. So this is what our account
  2033. 1:54:45service is completed. Okay. Account
  2034. 1:54:48service is completed. Everything is
  2035. 1:54:50done. Yeah. And all our methods. Now
  2036. 1:54:56comes our next
  2037. 1:54:59crucial service that is transaction
  2038. 1:55:03service. The heart of our banking
  2039. 1:55:05system. Okay. Yeah. So without wasting
  2040. 1:55:09much time, let's start. Let's go. Okay.
  2041. 1:55:13So let's start with our transaction
  2042. 1:55:16entity.
  2043. 1:55:17Okay.
  2044. 1:55:19Transaction
  2045. 1:55:21entity. Fine. And
  2046. 1:55:25entity then table
  2047. 1:55:29name
  2048. 1:55:31transactions.
  2049. 1:55:33Fine. Then my Lombok annotations at all
  2050. 1:55:38arcs at no arcs. Fine. Now what all
  2051. 1:55:42fields we should add in our transaction
  2052. 1:55:45entity. So the first is private string
  2053. 1:55:49ID.
  2054. 1:55:51Okay. ID and should be UU ID. UU ID.
  2055. 1:55:57Okay. Fine. Now next we need to add uh
  2056. 1:56:02both user account number. Okay. So
  2057. 1:56:05private string first my sender account
  2058. 1:56:10number. Okay. Then private string and
  2059. 1:56:15receiver
  2060. 1:56:17account number.
  2061. 1:56:20Okay fine. Then comes my uh obviously
  2062. 1:56:26amount. So big decimal amount. Then we
  2063. 1:56:30have
  2064. 1:56:31uh
  2065. 1:56:33you know what type. Okay. So transaction
  2066. 1:56:39type
  2067. 1:56:40and we are going to create a enum for
  2068. 1:56:44that because we have a bunch of values.
  2069. 1:56:47Let me just create it. Okay. So Java
  2070. 1:56:53enum. Okay. transaction type.
  2071. 1:56:57Fine. And and what one more enum will
  2072. 1:57:02create that is transaction status.
  2073. 1:57:08Okay. Status.
  2074. 1:57:10Fine. So let me also create that.
  2075. 1:57:16Okay.
  2076. 1:57:18Fine. Now next let me add uh
  2077. 1:57:22description.
  2078. 1:57:25Okay then uh yeah so a string and if
  2079. 1:57:30transition got failed then failure
  2080. 1:57:35reason
  2081. 1:57:36obviously then private string reference
  2082. 1:57:41number. Okay.
  2083. 1:57:44Reference number fine. And finally our
  2084. 1:57:49two fields that is local date time
  2085. 1:57:53created at
  2086. 1:57:55and private local date time updated at.
  2087. 1:58:01No not updated at instead we'll write it
  2088. 1:58:05here as completed at.
  2089. 1:58:11Yeah. Transaction completed should not
  2090. 1:58:14be updated. Yes or no. Now let's add you
  2091. 1:58:18know few validations. So
  2092. 1:58:22column nullable
  2093. 1:58:24false. Okay
  2094. 1:58:27fine. And same thing nullable false. For
  2095. 1:58:30amount I need to add two more properties
  2096. 1:58:33that is precision.
  2097. 1:58:35So let's keep it as 15 and scale two.
  2098. 1:58:38Okay. Now transaction type. Okay. So it
  2099. 1:58:41is enumerated string and column nullable
  2100. 1:58:46false. Same thing goes with my another
  2101. 1:58:48enum. Okay. And description. Okay.
  2102. 1:58:54Yeah. Created at at creation timestamp.
  2103. 1:58:58Fine. Okay. Now let's you know add the
  2104. 1:59:03fields in our
  2105. 1:59:05enums. Okay. So our transaction entity
  2106. 1:59:08is completed. Fine. transaction status.
  2107. 1:59:11Yeah, this one is important. So, first
  2108. 1:59:14let me add the comments and also show
  2109. 1:59:19you the life cycle flow. Okay, so
  2110. 1:59:23transaction life cycle flow that is just
  2111. 1:59:28just pay attention here. First is
  2112. 1:59:30pending. Okay, from pending to
  2113. 1:59:34processing, okay, and at last completed.
  2114. 1:59:39Okay. So this case happens in case of
  2115. 1:59:46clean
  2116. 1:59:47transaction. Yes or no? So once the
  2117. 1:59:50transaction is clean, nothing fraud,
  2118. 1:59:53nothing suspicious activity detected. So
  2119. 1:59:56directly from uh pending processing and
  2120. 2:00:00then completed
  2121. 2:00:03you know money
  2122. 2:00:05credit
  2123. 2:00:06to
  2124. 2:00:08receiver. Yeah. Okay. Fine. The next is
  2125. 2:00:13our
  2126. 2:00:15pending processing and if something
  2127. 2:00:20suspicious found. Okay. So our next
  2128. 2:00:23status is pending verification.
  2129. 2:00:28Okay. And suspicious
  2130. 2:00:33detected. Yes or no? Yeah. And if
  2131. 2:00:36suspicious detected then bank needs to
  2132. 2:00:40verify with the user. Yes or no? So if
  2133. 2:00:44user verified then we'll complete the
  2134. 2:00:48transaction. Completed.
  2135. 2:00:50Okay. verified.
  2136. 2:00:53Yeah. OTP. Okay. Phone call and other
  2137. 2:00:57medium. And if not verified.
  2138. 2:01:01Okay. So if verified and if not
  2139. 2:01:04verified, okay, then we will flag the
  2140. 2:01:09transaction and we will block the
  2141. 2:01:12account. Okay. Saga. Saga
  2142. 2:01:16refund.
  2143. 2:01:18Yes or no? Definitely we need to refund
  2144. 2:01:21to the sender back now if the
  2145. 2:01:24transaction is failed you know
  2146. 2:01:26processing failed. Okay. So yeah it
  2147. 2:01:30comes here these two inside our
  2148. 2:01:33verification
  2149. 2:01:35and yeah flagged.
  2150. 2:01:39Okay already mentioned. So these are our
  2151. 2:01:42status and flow. Fine. So pending then
  2152. 2:01:47processing then pending
  2153. 2:01:51verification.
  2154. 2:01:54Okay. Then
  2155. 2:01:56completed. Okay. Then failed. Then
  2156. 2:02:02flagged. Yes or no. Okay. Fine. Now next
  2157. 2:02:07comes our transaction type. So you'll
  2158. 2:02:10know that transaction type deposit you
  2159. 2:02:14know withdrawal
  2160. 2:02:17fine
  2161. 2:02:19and
  2162. 2:02:22uh you know payment
  2163. 2:02:24okay and transfer
  2164. 2:02:27yeah for transaction type okay so here
  2165. 2:02:31is our entity part is completed now
  2166. 2:02:34let's
  2167. 2:02:36implement our DTO so DTO dot But now I
  2168. 2:02:39need to uh put the transfer request.
  2169. 2:02:44Okay. So transfer
  2170. 2:02:47request. Okay. And in response
  2171. 2:02:52what transaction response.
  2172. 2:02:56Yeah.
  2173. 2:02:58Fine. Okay. So now where is my
  2174. 2:03:01transaction entity? Let me put them side
  2175. 2:03:03by side as I need to add the fields from
  2176. 2:03:06that two. Yeah, transfer request first.
  2177. 2:03:10Let me add Lombog data. All arcs, no
  2178. 2:03:14arcs.
  2179. 2:03:16Okay,
  2180. 2:03:17so first I need what to initiate the
  2181. 2:03:21transfer. I need my sender account
  2182. 2:03:24number.
  2183. 2:03:26Okay, I need my receiver account number
  2184. 2:03:32and amount.
  2185. 2:03:34Definitely I need amount
  2186. 2:03:37and let's add description.
  2187. 2:03:42Okay, fine. Yeah. So at not blank. Okay.
  2188. 2:03:50And uh if it is blank then we'll display
  2189. 2:03:53a message that is sender
  2190. 2:03:57account number is required.
  2191. 2:04:02Yes. Okay.
  2192. 2:04:04Similarly, let me just
  2193. 2:04:07copy this
  2194. 2:04:10and here
  2195. 2:04:13receiver account number is required in
  2196. 2:04:15case of amount not null. Okay. Message
  2197. 2:04:22uh amount is required. Okay. And also
  2198. 2:04:28amount should be in positive. Okay. So
  2199. 2:04:32message
  2200. 2:04:34and amount
  2201. 2:04:37must be positive.
  2202. 2:04:41Yes. Fine. Okay.
  2203. 2:04:45Next is our transaction response.
  2204. 2:04:51Okay. So first add data. Okay. Then add
  2205. 2:04:59all arcs. at no hearts.
  2206. 2:05:02Okay. Now in response, let me just take
  2207. 2:05:06all of them.
  2208. 2:05:09Okay. Yeah. So let me remove
  2209. 2:05:15all these annotations.
  2210. 2:05:19Okay. I don't need them.
  2211. 2:05:26Okay. Fine. ID. Sender. Account number.
  2212. 2:05:29receiver amount type status description
  2213. 2:05:31failure reference number created at and
  2214. 2:05:36what
  2215. 2:05:37completed at. Okay, now let me build the
  2216. 2:05:42skeleton. Okay, so quickly first
  2217. 2:05:47controller and transaction
  2218. 2:05:51controller.
  2219. 2:05:52Yeah.
  2220. 2:05:54Then service
  2221. 2:05:57transaction
  2222. 2:05:59service. Okay. Then repository
  2223. 2:06:04dot
  2224. 2:06:06transaction
  2225. 2:06:08repository.
  2226. 2:06:10Okay. Extends JPA
  2227. 2:06:15repo. Okay.
  2228. 2:06:17And what? Oh, one second. One second. It
  2229. 2:06:21should be
  2230. 2:06:23interface.
  2231. 2:06:25Okay. Yeah. So, transaction.
  2232. 2:06:31Okay. And
  2233. 2:06:34here a string. Yeah.
  2234. 2:06:38Next is our client.
  2235. 2:06:41Okay. Client dot account service client.
  2236. 2:06:47Fine. Uh also I need the radius here too
  2237. 2:06:52because I need my OTP to be stored in
  2238. 2:06:58the radius.
  2239. 2:07:00Okay. And uh I guess we have not added
  2240. 2:07:04the radius dependency here.
  2241. 2:07:08Yeah, let me check open F. No, fine.
  2242. 2:07:12We'll add it uh once we'll start coding
  2243. 2:07:15our you know uh that verify OTP and uh
  2244. 2:07:19fraud detection part. Okay. But for now
  2245. 2:07:22let's keep as it is. Okay. And what else
  2246. 2:07:27remaining? Repository service entity
  2247. 2:07:29DTO.
  2248. 2:07:33Okay. So config dot radius
  2249. 2:07:38config H. Yeah.
  2250. 2:07:41Fine. So now let's start adding our
  2251. 2:07:45endpoints. Okay. So rest controller and
  2252. 2:07:50request
  2253. 2:07:51mapping. Okay.
  2254. 2:07:54API
  2255. 2:07:56v1 then
  2256. 2:07:59oops where I'm writing transactions.
  2257. 2:08:04Okay. Then add slf 4j. Okay. Also, let
  2258. 2:08:10me just take account service.
  2259. 2:08:14Yeah,
  2260. 2:08:16account service. Account service.
  2261. 2:08:19Oh, sorry. Transaction service. I
  2262. 2:08:22forgot. Transaction
  2263. 2:08:24service.
  2264. 2:08:26Okay, transaction service. Okay, for
  2265. 2:08:28that I need to add required arcs
  2266. 2:08:31constructor. Fine. Now, let's add here
  2267. 2:08:34endpoints. forget one thing to create
  2268. 2:08:38one class. Okay, you know in the service
  2269. 2:08:42the actual decider the actual decider
  2270. 2:08:45class. Okay, that is my transaction
  2271. 2:08:50uh event consumer
  2272. 2:08:54H here only I'm going to consume the
  2273. 2:08:58event
  2274. 2:09:00okay and then proceed according to that.
  2275. 2:09:03Yeah. So now again let's continue with
  2276. 2:09:07our transaction controller. Okay. Fine.
  2277. 2:09:10Okay. So public and then uh response
  2278. 2:09:17response entity. Okay. I am returning
  2279. 2:09:21what transaction response.
  2280. 2:09:24Okay. And our first endpoint is transfer
  2281. 2:09:30at valid. Fine. and add request body.
  2282. 2:09:37Okay. And transfer request
  2283. 2:09:41request.
  2284. 2:09:45Fine. Yeah.
  2285. 2:09:47And
  2286. 2:09:49here I am returning what? Response
  2287. 2:09:54entity dot
  2288. 2:09:57status. HTTP
  2289. 2:10:00status dot
  2290. 2:10:03you know created okay dot body and let
  2291. 2:10:09me call our transaction
  2292. 2:10:12service dot
  2293. 2:10:15transfer and I'll pass the request okay
  2294. 2:10:22it is my post mapping okay oops post
  2295. 2:10:27mapping mapping
  2296. 2:10:29and
  2297. 2:10:32transfer.
  2298. 2:10:34Okay, the next is our public and
  2299. 2:10:38response entity returning the
  2300. 2:10:41transaction response and get
  2301. 2:10:44transaction.
  2302. 2:10:46Okay, I'm getting the transaction
  2303. 2:10:50using my transaction ID. Transaction ID.
  2304. 2:10:55Okay, fine. So return response entity
  2305. 2:11:02okay dot okay and my transaction service
  2306. 2:11:08dot get transaction let me pass the
  2307. 2:11:13transaction
  2308. 2:11:14ID okay
  2309. 2:11:18and this is get mapping okay transaction
  2310. 2:11:23ID fine now let me just copy copy and
  2311. 2:11:29paste it here. So the next is get
  2312. 2:11:33transaction
  2313. 2:11:35history. Okay. And
  2314. 2:11:38I'll get the transaction history
  2315. 2:11:40definitely using user account number.
  2316. 2:11:45Okay. So user account number and here to
  2317. 2:11:51transaction service get transaction
  2318. 2:11:54history.
  2319. 2:11:56Let me pass account number
  2320. 2:12:01here too. Account number and
  2321. 2:12:06account.
  2322. 2:12:08Yeah. Okay. The next comes our OTP
  2323. 2:12:11verification endpoint.
  2324. 2:12:14Okay. Important one. So this is what I'm
  2325. 2:12:17talking about. Public and response
  2326. 2:12:21entity. Okay.
  2327. 2:12:24in return 1 second 1 second so here it
  2328. 2:12:29should be list
  2329. 2:12:32okay because I'm getting
  2330. 2:12:36uh history transaction history based on
  2331. 2:12:38account number so I'll get the list of
  2332. 2:12:43transaction for this account number def
  2333. 2:12:46so definitely uh it is the list of
  2334. 2:12:49transaction response
  2335. 2:12:52okay Yeah, fine. Now let's come to here
  2336. 2:12:56response entity and transaction response
  2337. 2:13:00and verify
  2338. 2:13:02OTP.
  2339. 2:13:03Okay. Or uh yeah verify OTP and add path
  2340. 2:13:09variable.
  2341. 2:13:11So the first is no not a string account
  2342. 2:13:16number transaction ID. Okay. and second
  2343. 2:13:22is request param.
  2344. 2:13:25Okay. And a string OTP.
  2345. 2:13:31Fine. So
  2346. 2:13:33also let me just add the loggings log
  2347. 2:13:36dot info that OTP
  2348. 2:13:41and verification
  2349. 2:13:44request
  2350. 2:13:47transaction.
  2351. 2:13:49Okay. and
  2352. 2:13:52transaction ID. Yeah. And return
  2353. 2:13:57response entity.
  2354. 2:13:59Okay. Dot. Okay.
  2355. 2:14:03Transaction service dot verify
  2356. 2:14:09OTP.
  2357. 2:14:10Okay. And let me pass
  2358. 2:14:14transaction ID and OTP.
  2359. 2:14:20Fine.
  2360. 2:14:23Post mapping
  2361. 2:14:26H. Okay. And here
  2362. 2:14:30it is transaction
  2363. 2:14:34ID. Okay. And verify. Okay. So these are
  2364. 2:14:40all our endpoints. Fine. Now let's
  2365. 2:14:44implement these all one by one. Okay.
  2366. 2:14:46And uh I want you to keep an eye on
  2367. 2:14:52verify OTP and my transfer.
  2368. 2:14:56Okay. Endpoints. Fine. So my transaction
  2369. 2:15:00service
  2370. 2:15:02and add service at SLF 4J. Okay. And now
  2371. 2:15:09let me take private final and
  2372. 2:15:13transaction repository. Okay,
  2373. 2:15:16transaction repository. So for that let
  2374. 2:15:20me add one more annotation that is
  2375. 2:15:23required ask arxs constructor. Now let's
  2376. 2:15:26create our Kafka topic variables. Okay
  2377. 2:15:31like transaction initiated, transaction
  2378. 2:15:33completed, transaction refunded. Okay.
  2379. 2:15:37So private static final a string and
  2380. 2:15:45transaction
  2381. 2:15:47initiated
  2382. 2:15:49topic definitely we need
  2383. 2:15:54transaction
  2384. 2:15:55dot initiated.
  2385. 2:15:58Okay. And now let me just
  2386. 2:16:04copy and paste.
  2387. 2:16:06Okay.
  2388. 2:16:08Fine.
  2389. 2:16:10Yeah. So the second one is transaction
  2390. 2:16:14dot
  2391. 2:16:16completed and transaction dot refunded
  2392. 2:16:23here too. Transaction dot completed
  2393. 2:16:28and transaction dot refunded.
  2394. 2:16:32Okay. Fine. Yeah. So now let's implement
  2395. 2:16:37our first method that is transaction.
  2396. 2:16:42Okay. And response and
  2397. 2:16:46method name is transfer. Yeah, I'm
  2398. 2:16:49getting transfer request.
  2399. 2:16:53Transfer request and request. Okay, the
  2400. 2:16:57comments are most important.
  2401. 2:17:00So it is our saga step number one.
  2402. 2:17:04Okay. Initiate
  2403. 2:17:08transfer. Fine. And deducts from sender
  2404. 2:17:15via fain client. Okay. Then saves
  2405. 2:17:22transaction
  2406. 2:17:24as processing.
  2407. 2:17:27Fine.
  2408. 2:17:28and then publish
  2409. 2:17:32event to Kafka for fraud check.
  2410. 2:17:38Okay,
  2411. 2:17:40fine. And then returns.
  2412. 2:17:43See why I'm writing these comments?
  2413. 2:17:46Because I want you to implement first at
  2414. 2:17:49your own by just reading these comments.
  2415. 2:17:53Pause the video, okay? and try to
  2416. 2:17:56implement at your own first. Step number
  2417. 2:17:58one, initiate transfer. Then deduct
  2418. 2:18:01balance via FIN. Okay. Account service
  2419. 2:18:03client. F client. Then uh
  2420. 2:18:07what? Save transition as processing.
  2421. 2:18:10Okay. Repository we have. Fine.
  2422. 2:18:13Okay. And then publish event to Kafka.
  2423. 2:18:17Okay. So Kafka template and then return.
  2424. 2:18:20Okay. Let's implement it one by one all
  2425. 2:18:24the steps. So
  2426. 2:18:26first let me add some bloggings that
  2427. 2:18:31saga start. Okay. And transfer from this
  2428. 2:18:37account to this account and this much is
  2429. 2:18:42the amount. So from request dot sender
  2430. 2:18:47to uh receiver. So get receiver and
  2431. 2:18:51amount.
  2432. 2:18:53Okay. Now
  2433. 2:18:56um deduct from sender. Okay. So via f
  2434. 2:19:00client account service client. Okay. And
  2435. 2:19:04uh you all know that we have deduct
  2436. 2:19:08method in our account service main java
  2437. 2:19:12service and account service account
  2438. 2:19:15controller. Actually I need direct
  2439. 2:19:18balance. Yeah. So you just come here and
  2440. 2:19:22my transaction service account service
  2441. 2:19:24client. Yeah.
  2442. 2:19:27In this client, let me just
  2443. 2:19:31you know returning the string. Okay.
  2444. 2:19:35A string and entire method
  2445. 2:19:39deduct balance.
  2446. 2:19:42Fine. And full path put mapping.
  2447. 2:19:46Oh 1 second. So it should be interface.
  2448. 2:19:50Yeah.
  2449. 2:19:52So put mapping
  2450. 2:19:54fine and the entire path.
  2451. 2:19:59Okay.
  2452. 2:20:00Fine.
  2453. 2:20:02Oops.
  2454. 2:20:06And
  2455. 2:20:08here
  2456. 2:20:10our account number and deduct.
  2457. 2:20:16Okay. Yeah. Done. And here
  2458. 2:20:22faint client
  2459. 2:20:24then
  2460. 2:20:25name. So from account service and URL.
  2461. 2:20:32Okay. So what
  2462. 2:20:37account dot service dot URL?
  2463. 2:20:42Okay. That's it. Yes or no? and
  2464. 2:20:46semicolon I'm missing. Okay, back to our
  2465. 2:20:50account service transaction service.
  2466. 2:20:53Okay, and here
  2467. 2:20:56let me what
  2468. 2:20:59saga is step number one deduct
  2469. 2:21:06from
  2470. 2:21:08sender. Yes. So also let me just get the
  2471. 2:21:13object private final account service
  2472. 2:21:18client and account service client
  2473. 2:21:23in the account service client we have
  2474. 2:21:24just now created
  2475. 2:21:28okay dot deduct balance okay and let me
  2476. 2:21:32pass so we need to deduct from sender
  2477. 2:21:34okay so request dot get sender account
  2478. 2:21:38number and amount So request dot get
  2479. 2:21:42amount.
  2480. 2:21:45Yes, that's it. Okay.
  2481. 2:21:49Yeah. Fine. Now next step is save
  2482. 2:21:52transaction as processing. Okay. So
  2483. 2:21:56transaction.
  2484. 2:21:59Okay.
  2485. 2:22:02Transaction.
  2486. 2:22:05Fine.
  2487. 2:22:06And transaction equals new transaction.
  2488. 2:22:12And now what?
  2489. 2:22:15Let's set the properties set the you
  2490. 2:22:17know fields
  2491. 2:22:19values. So transaction dot set and
  2492. 2:22:24sender account number. Okay. So request
  2493. 2:22:27dot get sender account number. Similarly
  2494. 2:22:30transaction dot receiver get receiver
  2495. 2:22:33and then uh amount. Okay. Then type.
  2496. 2:22:38Okay. So, transaction dot set type.
  2497. 2:22:42Okay. So,
  2498. 2:22:45let it be transfer. Okay. And status.
  2499. 2:22:50Okay. So, transition dot set status. I
  2500. 2:22:55have mentioned here processing. Okay.
  2501. 2:22:57So, because currently it is uh you know
  2502. 2:23:00in the processing state.
  2503. 2:23:02Okay. Fine.
  2504. 2:23:05And then also transaction dot
  2505. 2:23:10set description get description.
  2506. 2:23:14Yes. And reference number also. So set
  2507. 2:23:19reference number. So let me just
  2508. 2:23:22generate it. UID dot random do.2.
  2509. 2:23:27Okay. Now let's save. So transaction and
  2510. 2:23:33saved transaction equals
  2511. 2:23:36transaction repository dot save and
  2512. 2:23:41transaction.
  2513. 2:23:43Yes, also blog dot info
  2514. 2:23:48and transaction saved as processing.
  2515. 2:23:55Fine. and saved
  2516. 2:23:59transaction dot get ID H. Now our next
  2517. 2:24:05step that is publish okay publish event
  2518. 2:24:09to Kafka.
  2519. 2:24:11So we need to publish initiated event.
  2520. 2:24:14Here
  2521. 2:24:16what you know uh we are doing the transa
  2522. 2:24:19transaction has been initiated.
  2523. 2:24:22Okay. Deduct balance just initiated.
  2524. 2:24:25Okay. processing. So we need to you know
  2525. 2:24:29publish the initiated event. For that I
  2526. 2:24:32have already created oh not created fine
  2527. 2:24:35let me create that too. So event dot
  2528. 2:24:40transaction
  2529. 2:24:42initiated event.
  2530. 2:24:45Okay. Add data
  2531. 2:24:49at all arcs. No arcs.
  2532. 2:24:53Fine. So let me just add the values
  2533. 2:24:59uh sorry fields that is private string
  2534. 2:25:02first transaction ID okay second is uh a
  2535. 2:25:08string
  2536. 2:25:09sender
  2537. 2:25:11account number.
  2538. 2:25:15Okay,
  2539. 2:25:17next is private string
  2540. 2:25:21uh receiver account number then okay big
  2541. 2:25:25decimal amount and finally let me add
  2542. 2:25:29description also
  2543. 2:25:33okay yeah back to our service and here
  2544. 2:25:37let me just you know get that
  2545. 2:25:40transaction initiated event okay event
  2546. 2:25:45equals
  2547. 2:25:47new transaction initiated event and let
  2548. 2:25:50me set the values.
  2549. 2:25:52Okay, so my save transaction let me get
  2550. 2:25:55that and set here.
  2551. 2:25:58Okay.
  2552. 2:26:00Dot get id first is ID only. Right.
  2553. 2:26:05ID account amount and the description.
  2554. 2:26:07Okay.
  2555. 2:26:10So save transaction dot sender account.
  2556. 2:26:14Save transaction dot receiver.
  2557. 2:26:18Okay. Then uh amount. Okay. And then
  2558. 2:26:22description. Okay. Fine. Then now let me
  2559. 2:26:27you know send. So I need to get the
  2560. 2:26:31Kafka template
  2561. 2:26:34private final
  2562. 2:26:37Kafka template. Okay. Here
  2563. 2:26:42object H Kafka template
  2564. 2:26:46dot send dot send. Okay. and the event
  2565. 2:26:51topic is transaction initiated event.
  2566. 2:26:56Okay, fine.
  2567. 2:26:58Then saved transaction.get ID and event.
  2568. 2:27:03Then let me just add log.info
  2569. 2:27:07and uh our
  2570. 2:27:10saga is step number two. Okay. So fine
  2571. 2:27:16this is what our
  2572. 2:27:19saga is step number two. Okay publish
  2573. 2:27:24for fraud
  2574. 2:27:27check.
  2575. 2:27:29So saga is step number two that is
  2576. 2:27:33transaction
  2577. 2:27:35initiated
  2578. 2:27:37event
  2579. 2:27:39published.
  2580. 2:27:42Yeah.
  2581. 2:27:46Saved transaction dot get ID and I need
  2582. 2:27:51to return what I'm returning. I'm
  2583. 2:27:53returning the transaction response.
  2584. 2:27:56Okay. But I have transaction. Okay. So I
  2585. 2:28:00need to convert it map
  2586. 2:28:03to
  2587. 2:28:05uh response. Let me pass saved
  2588. 2:28:08transaction. Okay. Quickly let me create
  2589. 2:28:12this method returning the transaction
  2590. 2:28:15response map to response. Okay. Also let
  2591. 2:28:18me rename it as transaction. Fine. Now
  2592. 2:28:23uh let me just take transition response
  2593. 2:28:28response new transition response and
  2594. 2:28:31then set the values. So response
  2595. 2:28:36dot set id transaction dot get ID. Okay.
  2596. 2:28:40Similarly with all the fields. So let me
  2597. 2:28:42just do fast forward. Okay. Fine. And
  2598. 2:28:45then return response. Okay. So our
  2599. 2:28:49transfer method is implemented. Okay.
  2600. 2:28:53Returning the transaction response. Now
  2601. 2:28:55let's implement other endpoints. Get
  2602. 2:28:59transaction. Get transaction history.
  2603. 2:29:01Okay. Don't think about verify OTP.
  2604. 2:29:04Okay. Why? Because we are going to
  2605. 2:29:07implement this endpoint at last.
  2606. 2:29:12Why? See here the name indicating that
  2607. 2:29:15verify OTP
  2608. 2:29:18that means at last once uh my
  2609. 2:29:22transaction initiated. Okay. Then fraud
  2610. 2:29:24detection service does his check. Okay.
  2611. 2:29:28Detected some suspicious activity. then
  2612. 2:29:30my notification service. Okay. Then um
  2613. 2:29:35sends the OTP notification and finally
  2614. 2:29:39we will verify the OTP by entering the
  2615. 2:29:43OTP. If it is verified then okay. If not
  2616. 2:29:46verified then proceed forward. Yes or
  2617. 2:29:50no? That's why I'm telling you this is
  2618. 2:29:53the most complex. Okay. And uh the most
  2619. 2:29:59crucial part heart of banking system
  2620. 2:30:03center point of banking system. So
  2621. 2:30:05please do not miss a single part of our
  2622. 2:30:09transaction service till we completes.
  2623. 2:30:13Okay. So let's implement our next
  2624. 2:30:15endpoint that is get transaction. Fine.
  2625. 2:30:18And then get transaction history. Okay.
  2626. 2:30:21So
  2627. 2:30:23yeah here public
  2628. 2:30:28okay and I'm returning transaction
  2629. 2:30:31response get transaction
  2630. 2:30:35okay and what I'm getting I'm getting
  2631. 2:30:39the transaction ID
  2632. 2:30:43fine okay okay so first let me get the
  2633. 2:30:47transaction
  2634. 2:30:49okay
  2635. 2:30:50Um
  2636. 2:30:52yeah. So transaction also also directly
  2637. 2:30:57let me pass return
  2638. 2:31:00map to response. Okay. And transaction
  2639. 2:31:04repository dot find by ID. Okay.
  2640. 2:31:10Find by ID. Okay. and
  2641. 2:31:17dot
  2642. 2:31:19or else throw.
  2643. 2:31:22And new
  2644. 2:31:24runtime exception
  2645. 2:31:28that is
  2646. 2:31:33transaction
  2647. 2:31:35not found.
  2648. 2:31:38Okay.
  2649. 2:31:40transaction ID. That's it. Done. Okay.
  2650. 2:31:45Next is our get transaction history
  2651. 2:31:51public. And I'm returning the list of
  2652. 2:31:56transaction response
  2653. 2:31:59transaction.
  2654. 2:32:01One second. Yeah. Response and get
  2655. 2:32:07transaction
  2656. 2:32:09history.
  2657. 2:32:11Okay. And I'm getting the account
  2658. 2:32:14number. Yeah. So
  2659. 2:32:18in this method we need to create a query
  2660. 2:32:22method. We need to query my database my
  2661. 2:32:25repository. Okay. So what return and
  2662. 2:32:29transaction repository
  2663. 2:32:32then I need history the complete
  2664. 2:32:36transaction history for a particular
  2665. 2:32:39user okay whose account number is this
  2666. 2:32:43okay so
  2667. 2:32:46it's like
  2668. 2:32:48find by find by
  2669. 2:32:53transaction history
  2670. 2:32:55okay so Yeah. Find by sender account
  2671. 2:33:01number.
  2672. 2:33:02Okay. And uh then order by order by
  2673. 2:33:10created at
  2674. 2:33:12descending. Yes. Comes on the top. Okay.
  2675. 2:33:16Recent one. And we'll pass the account
  2676. 2:33:19number here. Okay. Fine. Let's do it.
  2677. 2:33:23So my transaction repository transaction
  2678. 2:33:28repository
  2679. 2:33:30and here
  2680. 2:33:32list.
  2681. 2:33:34Okay. Of
  2682. 2:33:37transaction.
  2683. 2:33:39One second. Let me import it. Okay. And
  2684. 2:33:44find by
  2685. 2:33:47sender account number. Okay. and order
  2686. 2:33:54order by created at
  2687. 2:33:58dc
  2688. 2:34:00a string and account number.
  2689. 2:34:06Yes. Okay.
  2690. 2:34:09Fine. Let me just copy that.
  2691. 2:34:13And here
  2692. 2:34:16dot find by sender account number order
  2693. 2:34:20by created at dsc
  2694. 2:34:23and I'm passing account number dot
  2695. 2:34:27stream dot map okay this
  2696. 2:34:32map to response okay dot collect and to
  2697. 2:34:37list
  2698. 2:34:41okay fine
  2699. 2:34:42Done. Yeah. Now everything is done.
  2700. 2:34:46Okay. Uh regarding our endpoints.
  2701. 2:34:51Fine. So
  2702. 2:34:53transfer get transaction get transaction
  2703. 2:34:56history. Okay. Don't think about verify
  2704. 2:34:59OTP for now. We'll implement but at last
  2705. 2:35:02I already told you. Yeah. After
  2706. 2:35:05notification service. So I am taking you
  2707. 2:35:08with the flow.
  2708. 2:35:10Okay. The flow is The flow is uh
  2709. 2:35:13currently
  2710. 2:35:15currently
  2711. 2:35:17my user. Okay. My user initiated
  2712. 2:35:22a transaction
  2713. 2:35:24and we have published a event. That's
  2714. 2:35:27it. That is my current flow.
  2715. 2:35:30Okay. Like this.
  2716. 2:35:33My user initiated a transaction. That's
  2717. 2:35:36it.
  2718. 2:35:38Okay. Next is transaction service
  2719. 2:35:42published. So my fraud detection service
  2720. 2:35:45consume this event and start checking.
  2721. 2:35:49So next we need to jump to our fraud
  2722. 2:35:52detection service.
  2723. 2:35:55So let's do it
  2724. 2:35:58you know so what else remaining which is
  2725. 2:36:00independent.
  2726. 2:36:02Okay. So my account service client
  2727. 2:36:07radius config at uh later we'll just see
  2728. 2:36:10controller okay response request is done
  2729. 2:36:15everything is done initiated
  2730. 2:36:17repository
  2731. 2:36:19okay the one thing remaining that is my
  2732. 2:36:22application yml so let's do it you know
  2733. 2:36:25uh quickly and then we'll jump directly
  2734. 2:36:27into our next fraud detection service
  2735. 2:36:30okay fine so Spring
  2736. 2:36:34application
  2737. 2:36:36name
  2738. 2:36:38transaction
  2739. 2:36:40service.
  2740. 2:36:41Okay. Then data source
  2741. 2:36:45URL. So URL is JDBC
  2742. 2:36:50MySQL
  2743. 2:36:52and
  2744. 2:36:53localhost 3306
  2745. 2:36:56and
  2746. 2:36:58transaction DB. Okay. Another database.
  2747. 2:37:02Let me add a property create
  2748. 2:37:06database if not exist equals true. Okay.
  2749. 2:37:12Then my username root my password root.
  2750. 2:37:18You can enter your own username password
  2751. 2:37:22driver class name that is com dot mysql
  2752. 2:37:27dot cj dot
  2753. 2:37:30jdbc dot driver. Okay. Then jpa
  2754. 2:37:37then hibernate
  2755. 2:37:39ddl auto
  2756. 2:37:42update.
  2757. 2:37:44Then what? Show SQL. So true. Then
  2758. 2:37:51properties.
  2759. 2:37:53Okay. Then uh what? Hibernate.
  2760. 2:37:58Okay. Dot dialect.
  2761. 2:38:02Fine. So we have already added dialect
  2762. 2:38:06here in our application
  2763. 2:38:10yml of account service. Okay. Let me
  2764. 2:38:13directly copy and paste.
  2765. 2:38:16Okay. Or else just go to this search and
  2766. 2:38:20classes. Type MySQL
  2767. 2:38:24dialect. Click on this class and copy
  2768. 2:38:28the entire path. Org.hibernate
  2769. 2:38:31dot dialect dot MySQL dialect. Okay. And
  2770. 2:38:36paste it here. Fine. Next is my Kafka
  2771. 2:38:40properties. Kafka dot bootstrap
  2772. 2:38:45servers. Okay. So localhost
  2773. 2:38:509092.
  2774. 2:38:52Fine. Then consumer. So I've already
  2775. 2:38:55added in my account service. Let me
  2776. 2:38:57directly copy and paste consumer and
  2777. 2:39:01producer
  2778. 2:39:03you know till producer.
  2779. 2:39:06Okay.
  2780. 2:39:07Fine. Yeah. Okay. Next, next comes our
  2781. 2:39:14server port. Okay. 8082.
  2782. 2:39:18Fine. And then our uh faint client
  2783. 2:39:24properties. So account service URL.
  2784. 2:39:29Okay. On which URL? My account service
  2785. 2:39:31is running. So account service URL and
  2786. 2:39:35HTTP
  2787. 2:39:37localhost
  2788. 2:39:3980
  2789. 2:39:4281. Okay. And finally my actuator
  2790. 2:39:47property
  2791. 2:39:49management
  2792. 2:39:51then endpoints
  2793. 2:39:54web
  2794. 2:39:56exposure
  2795. 2:39:59include
  2796. 2:40:02health and info done. So now in this
  2797. 2:40:06what else is remaining only one thing
  2798. 2:40:08remaining that is our verify OTP. Okay.
  2799. 2:40:12So I want you to visualize the flow.
  2800. 2:40:16Okay. The flow is transaction service.
  2801. 2:40:20Fine. So just just visualize that uh
  2802. 2:40:24there is some user sitting and uh just
  2803. 2:40:27click on the send money transaction
  2804. 2:40:29initiated according to our code
  2805. 2:40:31initiated initiated status is uh
  2806. 2:40:34processing and we have published that
  2807. 2:40:37event to Kafka.
  2808. 2:40:40Now the flow will go to my fraud
  2809. 2:40:43detection service because fraud
  2810. 2:40:46detection service going to consume this
  2811. 2:40:49event and start checking the transaction
  2812. 2:40:53for any suspicious activity. Okay. So
  2813. 2:40:56let's code our fraud detection service
  2814. 2:41:00first. Let me
  2815. 2:41:03uh you know service and
  2816. 2:41:07fraud
  2817. 2:41:09detection event consumer
  2818. 2:41:13h consumer event consumer okay let's
  2819. 2:41:17consume that yeah
  2820. 2:41:20you know see this is luxury what I'm
  2821. 2:41:23teaching you this is luxury
  2822. 2:41:26I'm teaching you in a flow I can also do
  2823. 2:41:29like you know uh this is my transaction
  2824. 2:41:31service here is my controller let's
  2825. 2:41:33implement that
  2826. 2:41:36but if I'll follow that process then
  2827. 2:41:39nothing will gets into your head nothing
  2828. 2:41:42you'll ask me like why we are uh you
  2829. 2:41:45know verifying the OTP first where from
  2830. 2:41:47where my OTP is coming okay then uh you
  2831. 2:41:52know uh why we are doing this fraud
  2832. 2:41:54detection service consuming event at
  2833. 2:41:56last it should be at the first that is
  2834. 2:41:59why I'm going with the flow my user
  2835. 2:42:03initiated. Next is transaction service
  2836. 2:42:06consuming. Okay. Yeah. So it is public
  2837. 2:42:11void and consume
  2838. 2:42:15transaction
  2839. 2:42:17initiated.
  2840. 2:42:19Yeah. And payload.
  2841. 2:42:22Okay. Payload map.
  2842. 2:42:27Fine. a string
  2843. 2:42:31object and payload.
  2844. 2:42:36Okay,
  2845. 2:42:38fine. So now first let me add some
  2846. 2:42:42loggings. Okay. Log dot info and
  2847. 2:42:49what received
  2848. 2:42:52transaction
  2849. 2:42:54for fraud check.
  2850. 2:42:58Okay.
  2851. 2:43:00Yeah. And payload dot get transaction
  2852. 2:43:04ID. Okay. Now let me open my try catch.
  2853. 2:43:10Okay. Here. And uh
  2854. 2:43:15okay let me so also let me create fraud
  2855. 2:43:18detection service.
  2856. 2:43:22Fraud detection service. Okay fine.
  2857. 2:43:29And
  2858. 2:43:30here
  2859. 2:43:33private final
  2860. 2:43:36fraud detection service. Fraud detection
  2861. 2:43:38service.
  2862. 2:43:40Add required asks in that we are going
  2863. 2:43:44to create one method that is check
  2864. 2:43:48transaction.
  2865. 2:43:51Okay. We'll pass the payload.
  2866. 2:43:54Okay. And this check transaction is
  2867. 2:43:57responsible to do the checks for this
  2868. 2:44:00transaction. I'm getting the payload for
  2869. 2:44:03okay from my transaction.initiated
  2870. 2:44:06Initiated event at Kafka listener
  2871. 2:44:11topic is what? H transaction dot
  2872. 2:44:17initiated.
  2873. 2:44:19Okay. And group ID
  2874. 2:44:23fraud
  2875. 2:44:25detection
  2876. 2:44:28group.
  2877. 2:44:30Yes or no? Yes. Also let me add the
  2878. 2:44:34comments that is
  2879. 2:44:39oops one second.
  2880. 2:44:43Yeah. So
  2881. 2:44:46listens to
  2882. 2:44:49transaction dot initiated
  2883. 2:44:53topic.
  2884. 2:44:56Okay. And every transaction
  2885. 2:45:00goes
  2886. 2:45:02through
  2887. 2:45:05fraud
  2888. 2:45:07check
  2889. 2:45:09before
  2890. 2:45:11completing
  2891. 2:45:13yes or no. Okay. Yeah. Now let me create
  2892. 2:45:17this uh method check transaction in our
  2893. 2:45:20fraud detection service. So
  2894. 2:45:24service then
  2895. 2:45:27sl 4j
  2896. 2:45:30h and public void check transaction I'm
  2897. 2:45:35getting the payload right
  2898. 2:45:38so
  2899. 2:45:40map string payload okay so at first one
  2900. 2:45:47second okay
  2901. 2:45:51fine So at first let me get my
  2902. 2:45:54transaction ID. Okay, transaction ID
  2903. 2:45:58payload dot get transaction ID and then
  2904. 2:46:02let me get account number.
  2905. 2:46:07Okay, so
  2906. 2:46:10let me just copy and paste and here
  2907. 2:46:14my sender account number.
  2908. 2:46:19Yes. Okay. And I need amount. So big
  2909. 2:46:23decimal and amount equals new big
  2910. 2:46:28decimal. Fine. And payload dot get
  2911. 2:46:34amount dot to a string. Okay. Now also I
  2912. 2:46:39need to fetch the real balance.
  2913. 2:46:45Okay. balance
  2914. 2:46:47from account service.
  2915. 2:46:51Okay. So if you remember in the account
  2916. 2:46:54service we have one more method that is
  2917. 2:46:59get balance. Okay. So that's why in the
  2918. 2:47:02fraud detection service I need to fetch
  2919. 2:47:04the balance. Okay. Now why I need it?
  2920. 2:47:08Because for the fraud check. Okay.
  2921. 2:47:11Suppose if uh any suspicious or uh any
  2922. 2:47:14three times five times you know uh the
  2923. 2:47:18amount initiated from the sender's
  2924. 2:47:21account so I need to check okay this is
  2925. 2:47:24what the balance and uh 90% or five
  2926. 2:47:26times of the balance is being initiated
  2927. 2:47:29so there is something suspicious so I
  2928. 2:47:32need to check with the user yes or no
  2929. 2:47:35yeah so so let's fetch it and uh how to
  2930. 2:47:38fetch it via faint client
  2931. 2:47:41So
  2932. 2:47:43here client dot account
  2933. 2:47:48service client. Okay. And interface.
  2934. 2:47:52Fine. So my account service controller.
  2935. 2:47:57Okay. You just come here and here.
  2936. 2:48:02Now
  2937. 2:48:05get balance. Yeah. So big decimal. Okay.
  2938. 2:48:09Big decimal. And here get balance.
  2939. 2:48:14Fine. Now
  2940. 2:48:19get mapping. Okay. And my full path API
  2941. 2:48:26v1 accounts.
  2942. 2:48:30And
  2943. 2:48:34what account number and balance?
  2944. 2:48:40Okay. Done. Also fe client
  2945. 2:48:45name is from account service.
  2946. 2:48:49Okay. And
  2947. 2:48:52URL
  2948. 2:48:54is
  2949. 2:48:56what? account dot service dot URL.
  2950. 2:49:02Yeah,
  2951. 2:49:04let's get back to our uh notification uh
  2952. 2:49:07sorry fraud detection service.
  2953. 2:49:10So my yeah fraud detection service and
  2954. 2:49:14let me also
  2955. 2:49:17first take the object of that. So
  2956. 2:49:19private final account
  2957. 2:49:22service client.
  2958. 2:49:24Okay, also for that I need to add
  2959. 2:49:28required arcs constructor.
  2960. 2:49:31Now let me get the balance.
  2961. 2:49:34Okay, so big decimal and sender balance
  2962. 2:49:40equal
  2963. 2:49:41account serviceclient dot get balance
  2964. 2:49:43and
  2965. 2:49:45I'm passing the account number. Okay,
  2966. 2:49:49fine. Now next log dot info and checking
  2967. 2:49:57transaction.
  2968. 2:50:00Okay. Account.
  2969. 2:50:04Okay.
  2970. 2:50:06Amount
  2971. 2:50:08and balance.
  2972. 2:50:11H fine. So transaction transaction ID
  2973. 2:50:15account number amount amount and balance
  2974. 2:50:19sender balance. Fine. Now I need to
  2975. 2:50:24perform
  2976. 2:50:26fraud checks or perform suspicious
  2977. 2:50:29activity whatever.
  2978. 2:50:32Okay. And let me pass account number
  2979. 2:50:36amount and sender balance.
  2980. 2:50:40Okay. And let me return.
  2981. 2:50:45Okay. So let me return you know if fraud
  2982. 2:50:51detected. So I'll return true or false
  2983. 2:50:54that means boolean. Oh let me do one
  2984. 2:50:57thing. Let me create a model. Okay. Here
  2985. 2:51:00in uh itself
  2986. 2:51:02model
  2987. 2:51:04dot
  2988. 2:51:06fraud check result. Yes.
  2989. 2:51:11at data at all arcs no arcs in that let
  2990. 2:51:18me add private boolean
  2991. 2:51:22fraud and private string reason H this
  2992. 2:51:28is good this is the best one okay
  2993. 2:51:33and here I'm returning the fraud
  2994. 2:51:37check result
  2995. 2:51:40and result.
  2996. 2:51:42Okay,
  2997. 2:51:44fine. So, fraud check result contains is
  2998. 2:51:48fraud in boolean. If it is fraud, yes or
  2999. 2:51:51no. And if it is fraud, then reason of
  3000. 2:51:54that. Yeah. So, I'm returning the entire
  3001. 2:51:57object. Fine. It contains everything.
  3002. 2:52:01H this is good. Fine. And then we'll
  3003. 2:52:04check if result
  3004. 2:52:08okay dot is fraud
  3005. 2:52:12then then what any suspicious activity
  3006. 2:52:17detected.
  3007. 2:52:19Okay then what? So log dot info and
  3008. 2:52:24first suspicious
  3009. 2:52:28activity detected.
  3010. 2:52:31Okay. And where in account?
  3011. 2:52:37Okay.
  3012. 2:52:41And reason.
  3013. 2:52:44Okay. What is the reason? Yes.
  3014. 2:52:47Now requesting OTP verification.
  3015. 2:52:52Fine. we need uh to request an OTP
  3016. 2:52:57and ask user to enter is this is you
  3017. 2:53:01only or some other fraudster is doing
  3018. 2:53:04something else. Okay. So account account
  3019. 2:53:08number and reason is result dot get
  3020. 2:53:13reason. Fine. Now we are going to
  3021. 2:53:17publish an event. Which event? Tell me
  3022. 2:53:21which event. So we are inside result dot
  3023. 2:53:25is fraud condition that means we have
  3024. 2:53:29detected something suspicious.
  3025. 2:53:32So which event we are going to publish
  3026. 2:53:35that is verification
  3027. 2:53:39required.
  3028. 2:53:41Yes or no? So we need to verify with the
  3029. 2:53:44user that is it you who initiated this
  3030. 2:53:48transaction? Yes or no? Yeah, in case if
  3031. 2:53:53our fraud detection service detected
  3032. 2:53:57something suspicious,
  3033. 2:53:59in that case we need to
  3034. 2:54:01uh publish this event verification dot
  3035. 2:54:06required.
  3036. 2:54:08Yeah. Now my transaction service consume
  3037. 2:54:12this event. My transaction service gets
  3038. 2:54:14to know that okay fraud detection
  3039. 2:54:17service detected something suspicious.
  3040. 2:54:20So now let's consume that.
  3041. 2:54:24Okay fine. Now uh we have discussed that
  3042. 2:54:28we need to verify the user how via OTP.
  3043. 2:54:35Yes. So my uh transaction service
  3044. 2:54:37consume this event and
  3045. 2:54:41generate OTP.
  3046. 2:54:44Yes. Generate OTP. Fine. And then again
  3047. 2:54:49publish
  3048. 2:54:52event. Which event? OTP dot generated.
  3049. 2:54:58Okay. Yeah. So this is what our event.
  3050. 2:55:03Now
  3051. 2:55:04this event is going to consume by my
  3052. 2:55:09notification service.
  3053. 2:55:12Why? Because see anyhow
  3054. 2:55:17we need to notify to the user then only
  3055. 2:55:20user can add the OTP. Yes or no? If
  3056. 2:55:24verification is required if bank needs
  3057. 2:55:27to verify the user then bank will send
  3058. 2:55:30the OTP. How? Via SMS via email. Okay.
  3059. 2:55:37So once OTP generated now my
  3060. 2:55:40notification service consume
  3061. 2:55:43this event.
  3062. 2:55:45Okay and call API which API verify OTP.
  3063. 2:55:53If you remember you know we have
  3064. 2:55:57discussed that in our transaction
  3065. 2:56:01controller
  3066. 2:56:02uh this verify OTP. I told you that we
  3067. 2:56:07are going to code this uh endpoint at
  3068. 2:56:10the end. So here we are going to verify
  3069. 2:56:13the OTP whatever OTP our system
  3070. 2:56:16generated and whatever OTP my user
  3071. 2:56:19entered. If yes then proceed with the
  3072. 2:56:22transaction. Okay. And if no then then
  3073. 2:56:26what? Then block the account flag the
  3074. 2:56:31transaction.
  3075. 2:56:33Understood? So this is our entire flow
  3076. 2:56:36and we are going to code it step by step
  3077. 2:56:40and that is why I haven't coded this
  3078. 2:56:46verify OTP yes or no okay yeah let's
  3079. 2:56:50start coding the remaining part so now
  3080. 2:56:56is fraud detected okay suspicious
  3081. 2:56:58activity detected okay so let me
  3082. 2:57:02uh string
  3083. 2:57:04object and
  3084. 2:57:07verification verification event. We are
  3085. 2:57:10going to publish new hashmap.
  3086. 2:57:14Okay. Then verification event. First let
  3087. 2:57:17me put the transaction ID. Okay. Then
  3088. 2:57:20verification event. Let me put the
  3089. 2:57:22account number. Okay. And then amount.
  3090. 2:57:25Okay. That's good. And verification
  3091. 2:57:28event dot let me put the reason. Okay. I
  3092. 2:57:32need the reason. Fine. Reason and result
  3093. 2:57:38dot get reason. Fine. So,
  3094. 2:57:44okay. Okay. Okay. So I need to create my
  3095. 2:57:47topic variable private static final
  3096. 2:57:53a string and
  3097. 2:57:56verification
  3098. 2:58:00you know required
  3099. 2:58:04topic.
  3100. 2:58:07So verification.
  3101. 2:58:10Okay. Verification dot required.
  3102. 2:58:16Yes. Okay. Yeah. Let me just copy this.
  3103. 2:58:20And now I'm going to send. Okay. I need
  3104. 2:58:24that too. Private
  3105. 2:58:27final Kafka
  3106. 2:58:29template.
  3107. 2:58:31Okay. a string object and
  3108. 2:58:36Kafka template.
  3109. 2:58:39Okay,
  3110. 2:58:41so Kafka template dot send and
  3111. 2:58:44verification required topic and also
  3112. 2:58:50transaction ID. Yeah,
  3113. 2:58:54good good. Okay, so this is our first
  3114. 2:58:57case. If result dot is fraud. Okay. If
  3115. 2:59:01anything detected else if nothing
  3116. 2:59:04detected then what? Then clean proceed
  3117. 2:59:07with the transaction. Okay. So that
  3118. 2:59:10means transaction is clean. Fine. So log
  3119. 2:59:15dot info and my transaction clean. Okay.
  3120. 2:59:22So here map. Okay. and uh transaction
  3121. 2:59:30clean event.
  3122. 2:59:33Okay,
  3123. 2:59:37fine. So clean event let me put the
  3124. 2:59:41transaction ID. Okay. And uh transaction
  3125. 2:59:45clean event dot let me put is fraud uh
  3126. 2:59:49you know value. So is fraud
  3127. 2:59:55that is false.
  3128. 2:59:57Okay. And transaction
  3129. 3:00:01dotput and reason as null. Yeah. If
  3130. 3:00:06everything is clean then no reason.
  3131. 3:00:10Now let me just Kafka template dot send.
  3132. 3:00:13So also let me you know create the
  3133. 3:00:15variable for that.
  3134. 3:00:18Okay. So
  3135. 3:00:23h
  3136. 3:00:26fraud check
  3137. 3:00:30clean result
  3138. 3:00:35topic. Okay.
  3139. 3:00:38So
  3140. 3:00:42uh fraud dot check. Clean.
  3141. 3:00:48Yes.
  3142. 3:00:51Let me just
  3143. 3:00:54uh you know
  3144. 3:00:58send.
  3145. 3:01:00Okay. And transaction ID and transaction
  3146. 3:01:05clean event. Yeah. So this is done.
  3147. 3:01:12Okay.
  3148. 3:01:13Uh and now we need to implement this
  3149. 3:01:17method perform fraud checks. Okay. So we
  3150. 3:01:20are going to perform generally three uh
  3151. 3:01:24fraud checks three patterns. Okay. And
  3152. 3:01:28uh yeah so that's it. Proceed according
  3153. 3:01:31to that. So let's implement one by one.
  3154. 3:01:34So private okay and I'm returning fraud
  3155. 3:01:39check result. Okay. perform fraud check
  3156. 3:01:43and account number, amount and sender
  3157. 3:01:45balance.
  3158. 3:01:46So, private fraud check result perform
  3159. 3:01:50fraud check. Okay. And a string account
  3160. 3:01:55number then big decimal amount and then
  3161. 3:02:01big decimal
  3162. 3:02:03sender balance.
  3163. 3:02:06Okay. Fine. Now I want you all to focus
  3164. 3:02:11on my screen.
  3165. 3:02:13Okay.
  3166. 3:02:15Yeah. Just look at here. So in this
  3167. 3:02:19fraud check we are going to generally
  3168. 3:02:22perform uh three checks or I can say
  3169. 3:02:26three patterns.
  3170. 3:02:29Yes. The first pattern is velocity
  3171. 3:02:33check.
  3172. 3:02:34Velocity check. Okay. Because as we
  3173. 3:02:38discussed that you know fraudster
  3174. 3:02:41fraudster don't withdraw manually.
  3175. 3:02:45Yeah. Instead what they'll do is they
  3176. 3:02:48run a script and which fires multiple
  3177. 3:02:53transaction in seconds.
  3178. 3:02:56Yes or no? Yeah. So what we're going to
  3179. 3:02:59check is
  3180. 3:03:01um if suppose we detected let's say five
  3181. 3:03:05transaction or 10 transaction maybe 20
  3182. 3:03:08transaction in 1 minute
  3183. 3:03:11okay 60 seconds. So let's take the least
  3184. 3:03:15one five transaction if it detected
  3185. 3:03:18then we'll detect
  3186. 3:03:22that as suspicious and that two in the
  3187. 3:03:2660 seconds because generally normal user
  3188. 3:03:30won't do it. Okay. Now the fact is see
  3189. 3:03:34we are not blocking the account.
  3190. 3:03:37It is just a suspicious activity
  3191. 3:03:40detected. Yeah. So what we need to do is
  3192. 3:03:43we need to get back to the user. Yes.
  3193. 3:03:47And uh ask user for the verification via
  3194. 3:03:51OTP. Is this you? If it is then let's
  3195. 3:03:54proceed. No worries.
  3196. 3:03:57Yes or no? But there is another case.
  3197. 3:04:00Okay. And that comes our you know uh
  3198. 3:04:03second and third pattern. Fine. So yeah
  3199. 3:04:07the second pattern is let's say a user
  3200. 3:04:11has initiated a transaction okay and
  3201. 3:04:15that transaction is three times or five
  3202. 3:04:20times
  3203. 3:04:22of his average transaction he usually
  3204. 3:04:27make.
  3205. 3:04:29So what my second pattern will do is
  3206. 3:04:32first we'll get the average transactions
  3207. 3:04:37of that particular user.
  3208. 3:04:39Okay, let's say 50
  3209. 3:04:43$45. Okay, or in any currency. Fine. And
  3210. 3:04:48uh let's say $100 65 35 10 120 56 and so
  3211. 3:04:56on. Okay. So we'll calculate the average
  3212. 3:05:00and then
  3213. 3:05:02uh on any day suppose my user initiated
  3214. 3:05:06a transaction of 10,000
  3215. 3:05:1012,000
  3216. 3:05:12okay 5,000
  3217. 3:05:1515,000 so that is quite you know
  3218. 3:05:20suspicious
  3219. 3:05:21marked
  3220. 3:05:24okay and we'll transfer
  3221. 3:05:26that uh you know request to our
  3222. 3:05:29verification window. Please verify the
  3223. 3:05:32user that the uh you know transaction
  3224. 3:05:36initiated by our genuine user or some
  3225. 3:05:40fraud. Okay. Because we have detected
  3226. 3:05:42you know unusual
  3227. 3:05:44uh bigger amount transactions.
  3228. 3:05:48Yes or no? And our pattern number three
  3229. 3:05:52is uh you know similar to the second
  3230. 3:05:54pattern that is uh balance uh 90% or
  3231. 3:05:5850%. Okay. So balance check that means
  3232. 3:06:02if suppose a user initiated a transfer
  3233. 3:06:04okay and uh that transaction is 90%
  3234. 3:06:10okay of
  3235. 3:06:12user's balance. Okay. So that is you
  3236. 3:06:16know suspicious.
  3237. 3:06:18Okay. Yeah. So let's implement it and uh
  3238. 3:06:24our
  3239. 3:06:26pattern number one that is
  3240. 3:06:29velocity check.
  3241. 3:06:32Okay. Also we need three variables you
  3242. 3:06:35know because uh we need to what uh we
  3243. 3:06:39need to just tell our methods that
  3244. 3:06:45uh these are the fixed values. If
  3245. 3:06:48exceeded then make it suspicious. Okay,
  3246. 3:06:51I mean to say let's say in case of
  3247. 3:06:53velocity check if suppose user
  3248. 3:06:58initiated five transaction. Okay, five
  3249. 3:07:01transaction in 60 seconds. So this five
  3250. 3:07:04we need to give it explicitly.
  3251. 3:07:07Okay, we can give any number five 6 7.
  3252. 3:07:10So we'll handle it from our resources
  3253. 3:07:14application yml. Okay. Similarly, if
  3254. 3:07:17suppose uh transition is three times or
  3255. 3:07:20five times greater, okay, then mark it
  3256. 3:07:23as a suspicious. So three or five we
  3257. 3:07:26need to give via variable. Okay.
  3258. 3:07:30And similarly 90% or 95%. Okay. Yeah. So
  3259. 3:07:38let's do it. The first is our uh you
  3260. 3:07:42know velocity check. If also let me
  3261. 3:07:46create a method velocity
  3262. 3:07:49or
  3263. 3:07:51is
  3264. 3:07:53velocity
  3265. 3:07:56exceeded.
  3266. 3:07:58Okay. And let me pass the account
  3267. 3:08:01number.
  3268. 3:08:02Fine. Then I'll return new fraud check
  3269. 3:08:07result. Okay. And fraud check result
  3270. 3:08:09contains two field that is fraud. Yes,
  3271. 3:08:12it is fraud. Okay. Or maybe suspicious.
  3272. 3:08:16Fine. So, we have already named it as a
  3273. 3:08:18fraud. Okay. Let's keep it. It might be.
  3274. 3:08:22Okay. Yeah. And the reason is too many
  3275. 3:08:28transactions
  3276. 3:08:30in
  3277. 3:08:3260 seconds.
  3278. 3:08:35Yes. Okay.
  3279. 3:08:39and
  3280. 3:08:41velocity
  3281. 3:08:44limit
  3282. 3:08:46exceeded.
  3283. 3:08:49Okay.
  3284. 3:08:52H yes. Similarly the next pattern is our
  3285. 3:08:57uh
  3286. 3:09:00pattern number two that is amount check.
  3287. 3:09:06F
  3288. 3:09:09is amount
  3289. 3:09:13suspicious. Okay.
  3290. 3:09:16And let me pass account number and
  3291. 3:09:19amount.
  3292. 3:09:21Okay. So this two method will implement
  3293. 3:09:24in that we are going to check. Okay.
  3294. 3:09:28Like uh we'll find out the average.
  3295. 3:09:31Okay. And everything else. So we'll
  3296. 3:09:34return new. Let me just copy and
  3297. 3:09:39paste it here.
  3298. 3:09:41Okay. And uh the fraud is true. The
  3299. 3:09:44reason is what
  3300. 3:09:47unusual
  3301. 3:09:50transaction amount.
  3302. 3:09:53Okay.
  3303. 3:09:55And
  3304. 3:09:57exceeds
  3305. 3:09:59let's say three times 3 X.
  3306. 3:10:04Okay. your
  3307. 3:10:06average.
  3308. 3:10:08Okay. Fine. And our pattern number three
  3309. 3:10:15that is
  3310. 3:10:18balance check. Okay.
  3311. 3:10:22Fine. So if transaction transaction
  3312. 3:10:26amount is 90%. Okay. So let's say sender
  3313. 3:10:30balance dot compare to. Okay. And big
  3314. 3:10:36decimal big decimal
  3315. 3:10:39dot zero H. Yeah. Okay. Greater than
  3316. 3:10:45zero
  3317. 3:10:47and
  3318. 3:10:50and is balance
  3319. 3:10:54check failed. Okay. So this is two a
  3320. 3:10:58method will create. Let me pass sender
  3321. 3:11:01balance and amount.
  3322. 3:11:04Okay. So if it is then we'll return new
  3323. 3:11:09and same thing
  3324. 3:11:12h just
  3325. 3:11:15the reason is
  3326. 3:11:17what the reason transaction
  3327. 3:11:20exceeds
  3328. 3:11:2290%
  3329. 3:11:25of account balance.
  3330. 3:11:29Yeah. Okay. Now let's implement one by
  3331. 3:11:32one. Okay. And also also if uh nothing
  3332. 3:11:37gets satisfied. Okay. All get failed
  3333. 3:11:40that means transition is clean. Okay. So
  3334. 3:11:43return new
  3335. 3:11:46fraud check result false and null.
  3336. 3:11:51Yes. Okay. So fraud is uh you know false
  3337. 3:11:56no fraud and there is no reason okay
  3338. 3:12:00okay fine let's implement one by one so
  3339. 3:12:03is velocity exceeded
  3340. 3:12:06okay
  3341. 3:12:07private boolean is velocity exceeded and
  3342. 3:12:12uh I'm getting a string account
  3343. 3:12:17number
  3344. 3:12:19okay so we going to use the radius Yes.
  3345. 3:12:23Yes or no? Yeah. So that is the best way
  3346. 3:12:26to keep the count a string key. Okay.
  3347. 3:12:32So first let's create our key as fraud
  3348. 3:12:36and velocity. Okay. And account number
  3349. 3:12:41fine. And then count. So we'll pass the
  3350. 3:12:46key. Okay. First let me get the radius
  3351. 3:12:48template.
  3352. 3:12:50private final radius template.
  3353. 3:12:55Okay. And a string string radius
  3354. 3:13:00template.
  3355. 3:13:02Okay. And
  3356. 3:13:05so here radius template dot ops for
  3357. 3:13:08value. Okay. And dot increment increment
  3358. 3:13:12key. Okay. So if user initiated one
  3359. 3:13:16transaction increment one then two then
  3360. 3:13:19three then four then five and from sixth
  3361. 3:13:21flagged need to check the user but in 60
  3362. 3:13:25seconds. Okay. So how to check
  3363. 3:13:30uh we are going to set the expiry time
  3364. 3:13:33as 60cond. Okay. Because see user can
  3365. 3:13:36make multiple transaction in uh you know
  3366. 3:13:39first transaction in first minute and
  3367. 3:13:42then second minute and then uh after 2
  3368. 3:13:44hours that is okay but in 60 seconds
  3369. 3:13:47continuously that is suspicious. Okay.
  3370. 3:13:50So if we'll check if count not equals
  3371. 3:13:55not equals null. Okay. And and
  3372. 3:14:00count
  3373. 3:14:02equals 1.
  3374. 3:14:05Okay, that means radius template dot
  3375. 3:14:08expire. Fine. Let's expire. Okay. And uh
  3376. 3:14:13this is key 60 and in seconds. Okay.
  3377. 3:14:20Fine.
  3378. 3:14:22Yes. Yeah.
  3379. 3:14:24Also some loggings log.info
  3380. 3:14:28and velocity
  3381. 3:14:31velocity check
  3382. 3:14:34amount.
  3383. 3:14:36Okay. Count
  3384. 3:14:40fine. Okay. Amount. No. Here account.
  3385. 3:14:46Yeah. Account number. Okay. Then count.
  3386. 3:14:50Okay. Count. And yeah, the next is count
  3387. 3:14:56this by this. Okay, so we need to
  3388. 3:15:00provide what we need to provide, we need
  3389. 3:15:02to provide uh on which count we need to
  3390. 3:15:06flag. Okay, for that let's create the
  3391. 3:15:09variable and handle it via application
  3392. 3:15:12yiml. Uh yeah, yl int max
  3393. 3:15:17transactions
  3394. 3:15:18per minute.
  3395. 3:15:21Okay. And add value.
  3396. 3:15:26Okay.
  3397. 3:15:29Yeah.
  3398. 3:15:31So fraud dot max transactions
  3399. 3:15:38per minute.
  3400. 3:15:42Okay. And also let me handle it
  3401. 3:15:48resources. And here
  3402. 3:15:51fraud
  3403. 3:15:53dot max transaction per minute. Okay. So
  3404. 3:15:57we are allowing five. Yeah. Five
  3405. 3:16:00transaction my user can do per minute.
  3406. 3:16:03Okay. And from the very sixth
  3407. 3:16:05transaction immediately you will get uh
  3408. 3:16:09you know OTP. And if it is uh genuine
  3409. 3:16:13then you can just verify and proceed
  3410. 3:16:14with the transaction else
  3411. 3:16:17get the refund back fraud detection
  3412. 3:16:19service and here we'll provide that
  3413. 3:16:22variable max transaction per minute.
  3414. 3:16:24Okay. And then we are returning count
  3415. 3:16:28first count not equal
  3416. 3:16:31null. Okay. And and
  3417. 3:16:36what
  3418. 3:16:37count greater than if count greater than
  3419. 3:16:41max transaction per minute 6 7 8 9 10
  3420. 3:16:44whatever then yeah it uh it hits true
  3421. 3:16:47and uh fine too many transactions okay
  3422. 3:16:52next is is amount suspicious account
  3423. 3:16:54number and amount I'm getting let's
  3424. 3:16:57implement this too private
  3425. 3:16:59boolean
  3426. 3:17:01is amount suspicious string string
  3427. 3:17:04account number and big decimal
  3428. 3:17:10amount.
  3429. 3:17:11So first let me you know
  3430. 3:17:15just set the key. So average key okay
  3431. 3:17:19because see here
  3432. 3:17:22this is uh is amount suspicious. So what
  3433. 3:17:26we're doing we are first checking the
  3434. 3:17:31amount the initiated transaction is
  3435. 3:17:35uh three times of average. So first we
  3436. 3:17:39need to get the average average key
  3437. 3:17:42first let me you know just set it. So
  3438. 3:17:44let's say fraud and
  3439. 3:17:48average
  3440. 3:17:50amount. Okay. and account number. And
  3441. 3:17:53also let me pass a string
  3442. 3:17:58average. Okay. Radius template dot ops
  3443. 3:18:02for value. Okay. And dot get what key
  3444. 3:18:08average key H. Got it. Fine. Now, now
  3445. 3:18:13first let me pre-check that if coming as
  3446. 3:18:17null then uh it is safe. radius template
  3447. 3:18:21dot ops for value dot will set our key
  3448. 3:18:26and amount dot to string. Okay. And
  3449. 3:18:30we'll return it as false.
  3450. 3:18:33Yeah. Okay. All good.
  3451. 3:18:38Fine. And then uh we need to get the
  3452. 3:18:42average. Okay. So big decimal and
  3453. 3:18:47average amount equals new big decimal.
  3454. 3:18:52Okay.
  3455. 3:18:53Average str.
  3456. 3:18:56Fine. And then also let me get the
  3457. 3:19:00threshold
  3458. 3:19:02big decimal. And this is what our
  3459. 3:19:05threshold. Okay. Threshold means average
  3460. 3:19:09amount dot multiply. Okay. and multiply
  3461. 3:19:14with what? So multiply with what? Uh
  3462. 3:19:17again private
  3463. 3:19:20double and
  3464. 3:19:22suspicious
  3465. 3:19:25amount
  3466. 3:19:27multiplier.
  3467. 3:19:30Okay. And here add value
  3468. 3:19:36find
  3469. 3:19:39dot
  3470. 3:19:41suspicious
  3471. 3:19:45amount
  3472. 3:19:47multiplier.
  3473. 3:19:50Okay, let me just handle it right away
  3474. 3:19:56here.
  3475. 3:19:57suspicious amount multiplier which is uh
  3476. 3:20:01h if the amount is let's say five times
  3477. 3:20:05okay five times if the initiated amount
  3478. 3:20:07is five times of average then we will
  3479. 3:20:11you know
  3480. 3:20:13uh mark it as suspicious. So average
  3481. 3:20:15amount
  3482. 3:20:18okay multiply big decimal dot value of
  3483. 3:20:23and suspicious amount multiplier
  3484. 3:20:27okay
  3485. 3:20:30correct correct
  3486. 3:20:32and then we will update
  3487. 3:20:36running average. So how to update big
  3488. 3:20:41decimal
  3489. 3:20:43new average
  3490. 3:20:46equals average amount dot add amount.
  3491. 3:20:52Okay. Dot divide divide what? Big
  3492. 3:20:56decimal.
  3493. 3:20:58Okay. Big decimal dot value of two H.
  3494. 3:21:04And the scale is two. and rounding mode
  3495. 3:21:09half up. Half up. Okay, fine. And then
  3496. 3:21:14radius radius template dot ops for
  3497. 3:21:18value. So we need to set it set. Okay.
  3498. 3:21:22And
  3499. 3:21:24is new average dot to a string. Yes.
  3500. 3:21:29Some loggings log.info and so amount
  3501. 3:21:32check. Okay. amount.
  3502. 3:21:37Fine. And then threshold.
  3503. 3:21:44Uh
  3504. 3:21:46threshold. Okay.
  3505. 3:21:49And what? Suspicious.
  3506. 3:21:54Fine. So amount is amount. Threshold.
  3507. 3:21:59Threshold. And suspicious is we need to
  3508. 3:22:02compare. Okay. So amount
  3509. 3:22:05amount dot compare to with threshold
  3510. 3:22:09okay greater than zero.
  3511. 3:22:12Okay whatever comes and finally we will
  3512. 3:22:16return amount dot compare to threshold
  3513. 3:22:21greater than zero.
  3514. 3:22:24Yes fine. This is what our is amount
  3515. 3:22:28suspicious pattern. Okay. Next one. So
  3516. 3:22:32the last one is is balance check field.
  3517. 3:22:36Okay. And I'm getting sender balance and
  3518. 3:22:38amount. Okay. So private
  3519. 3:22:44private and
  3520. 3:22:47boolean
  3521. 3:22:48is balance check field
  3522. 3:22:51big decimal
  3523. 3:22:53center balance and amount. Here what we
  3524. 3:22:56are checking that if transaction amount
  3525. 3:23:00you know is uh 90% of balance.
  3526. 3:23:05Okay. So 90% of balance we need to
  3527. 3:23:08multiply balance dot multiply
  3528. 3:23:13and uh 90%. Okay. So this is what in a
  3529. 3:23:16variable we'll get just like uh
  3530. 3:23:18suspicious amount multiplier and
  3531. 3:23:20whatever. Okay. and then uh yeah we'll
  3532. 3:23:24uh compare it.
  3533. 3:23:26Okay. So,
  3534. 3:23:29big decimal. Okay. And maximum allowed.
  3535. 3:23:33Maximum allowed equals
  3536. 3:23:37the balance I'm getting.
  3537. 3:23:40Okay. Center balance
  3538. 3:23:44dot multiply H. And
  3539. 3:23:49our third variable
  3540. 3:23:531 second. multiplier.
  3541. 3:23:56Okay. Private double. And this is max
  3542. 3:24:02balance
  3543. 3:24:04percentage.
  3544. 3:24:07Okay.
  3545. 3:24:09Double max balance percentage. Okay. And
  3546. 3:24:12here add
  3547. 3:24:14value.
  3548. 3:24:18Fine. fraud dot max
  3549. 3:24:22balance
  3550. 3:24:24percentage.
  3551. 3:24:26Fine. Let me handle it.
  3552. 3:24:32Okay. And 90%. Okay. So 0.90.
  3553. 3:24:37Okay. We'll multiply it by this number.
  3554. 3:24:42Yes. So,
  3555. 3:24:46oh, once what?
  3556. 3:24:50Yeah.
  3557. 3:24:52Okay. So, sender balance dot multiply
  3558. 3:24:57and big decimal dot value of and
  3559. 3:25:02whatever just now created max balance
  3560. 3:25:05percentage
  3561. 3:25:07H. So, this is what max allowed.
  3562. 3:25:10Okay. Yeah. Now log dot info and balance
  3563. 3:25:16check
  3564. 3:25:18amount.
  3565. 3:25:22Okay.
  3566. 3:25:24And max allowed.
  3567. 3:25:27Fine. And suspicious.
  3568. 3:25:32Yes or no?
  3569. 3:25:35Okay.
  3570. 3:25:37Fine. So amount is amount max allowed is
  3571. 3:25:42max allowed and suspicious is let's
  3572. 3:25:45compare it. So amount dot compare to max
  3573. 3:25:49allowed greater than zero. Yeah. And
  3574. 3:25:51that two we need to return. So amount
  3575. 3:25:54dot compare to max allowed greater than
  3576. 3:25:59zero.
  3577. 3:26:02Yes. Fine. So this is our pattern number
  3578. 3:26:05three implementation. Okay. So, here is
  3579. 3:26:08our fraud detection service completed.
  3580. 3:26:11Fine. Now, now uh we are on our second
  3581. 3:26:14stage. Okay. The first stage is
  3582. 3:26:18you know transaction service user
  3583. 3:26:20initiated this transaction and publish
  3584. 3:26:23the event transaction initiated topic.
  3585. 3:26:26This is consumed by our fraud detection.
  3586. 3:26:29H fraud detection here.
  3587. 3:26:33Okay. Consumed transaction.initiated
  3588. 3:26:35initiated and checks the transaction.
  3589. 3:26:38Fine. Here in the service checking the
  3590. 3:26:40transaction. Okay. Now if something got
  3591. 3:26:44flagged and result dot is fraud gets
  3592. 3:26:48true. Okay. Among these three patterns
  3593. 3:26:50something got flagged and result. Fraud
  3594. 3:26:53gets true. Then here comes and here my
  3595. 3:26:56fraud detection again publishing an
  3596. 3:26:58event which is verification required.
  3597. 3:27:03Verification required. And that is going
  3598. 3:27:06to consume by our again transaction
  3599. 3:27:09service. So now
  3600. 3:27:12let's come here and let's consume that.
  3601. 3:27:16Yes. Okay. Let's do that. See how you
  3602. 3:27:19know the flow is going. That is the pure
  3603. 3:27:22luxury. Okay. For that uh you can
  3604. 3:27:25subscribe my channel. Yeah. Okay. Let's
  3605. 3:27:28do it. And also if you want to thank me
  3606. 3:27:31then uh there is a button just adjacent
  3607. 3:27:34to like or share button you can just tap
  3608. 3:27:37on that and you can thank me. Okay fine.
  3609. 3:27:41So let's proceed with our event
  3610. 3:27:44consumer. Okay
  3611. 3:27:46public
  3612. 3:27:48void and consume what verification
  3613. 3:27:54required.
  3614. 3:27:56Okay. And add payload
  3615. 3:28:00map.
  3616. 3:28:02Yeah.
  3617. 3:28:04A string object and
  3618. 3:28:08payload.
  3619. 3:28:11Okay. Fine. So now what we are consuming
  3620. 3:28:15fraud detection service. Okay. And
  3621. 3:28:20if fraud is detected then we need to
  3622. 3:28:23verify verify required topic and it is
  3623. 3:28:26verification dot required. Okay we need
  3624. 3:28:30to verify and
  3625. 3:28:32uh via OTP. Yeah. So first we need to
  3626. 3:28:36generate OTP.
  3627. 3:28:39Okay. Yeah.
  3628. 3:28:43Also let me just write the comments as
  3629. 3:28:47consume
  3630. 3:28:49verification dot required. Okay. And uh
  3631. 3:28:55generate OTP
  3632. 3:28:58and
  3633. 3:29:00ask user to
  3634. 3:29:03verify. Okay.
  3635. 3:29:07Fine.
  3636. 3:29:08Now let me open my try catch.
  3637. 3:29:13Okay. And first let me get transaction
  3638. 3:29:18ID. Transaction ID equals
  3639. 3:29:22Okay. Fine. Payload that uh get
  3640. 3:29:24transaction ID. Then uh I need account
  3641. 3:29:28number.
  3642. 3:29:30Account number.
  3643. 3:29:33Okay. Fine. And then I need reason.
  3644. 3:29:39Okay. Yeah.
  3645. 3:29:43So log info. Okay. One second. Let me
  3646. 3:29:47add the annotation
  3647. 3:29:49at service at slf4j.
  3648. 3:29:53Yeah. Okay.
  3649. 3:29:55log dot
  3650. 3:29:58info and
  3651. 3:30:01verification
  3652. 3:30:04required.
  3653. 3:30:06Okay.
  3654. 3:30:07Transaction
  3655. 3:30:10and uh reason.
  3656. 3:30:14So
  3657. 3:30:16what transaction ID and reason. Okay.
  3658. 3:30:21Now first let me get the transaction.
  3659. 3:30:25Okay. So transaction and
  3660. 3:30:31transaction equals transaction
  3661. 3:30:33repository. Okay. So for that private
  3662. 3:30:38final
  3663. 3:30:39and transaction
  3664. 3:30:45transaction repository.
  3665. 3:30:48Okay. Also let me add required asks
  3666. 3:30:52constructor. Fine. So transaction
  3667. 3:30:55repository dot find by ID. We have the
  3668. 3:30:59ID. Okay. Transaction ID. Let me pass
  3669. 3:31:01it.
  3670. 3:31:03Dot or else throw
  3671. 3:31:08new runtime exception.
  3672. 3:31:10Okay. And
  3673. 3:31:13transaction not found.
  3674. 3:31:17Okay. transaction ID.
  3675. 3:31:21Fine.
  3676. 3:31:23Now, now what? Now we need to add an
  3677. 3:31:27item potency guard. Okay. So, what is
  3678. 3:31:31that? uh item potency guard because in
  3679. 3:31:36order to prevent
  3680. 3:31:41two time
  3681. 3:31:43credit
  3682. 3:31:46to my
  3683. 3:31:49receiver or to my sender.
  3684. 3:31:55Yes. So see we are uh you know verifying
  3685. 3:32:02the user
  3686. 3:32:04only if the status is in processing.
  3687. 3:32:11If the transaction status is in
  3688. 3:32:13processing, if suppose my status is not
  3689. 3:32:17processing that means either either uh
  3690. 3:32:23you know transaction has been already
  3691. 3:32:25completed
  3692. 3:32:26or the transaction has been flagged
  3693. 3:32:31that means you know uh blocked out.
  3694. 3:32:34Okay. So the status should be in the
  3695. 3:32:36processing
  3696. 3:32:38otherwise there is chance of twice
  3697. 3:32:41credit to my receiver or sender. Okay
  3698. 3:32:45fine. I hope you got the point. So
  3699. 3:32:49let me just add that check. Okay.
  3700. 3:32:55Yeah. So if
  3701. 3:32:58transaction
  3702. 3:33:01dot get status
  3703. 3:33:05not equals
  3704. 3:33:08not equals processing. Okay. In that
  3705. 3:33:12case we need to send first warning.
  3706. 3:33:16Okay. uh transaction
  3707. 3:33:21not
  3708. 3:33:23processing
  3709. 3:33:26skipping
  3710. 3:33:29okay and transaction ID fine and from
  3711. 3:33:32here we'll return
  3712. 3:33:36okay
  3713. 3:33:38next let's go forward okay so if it is
  3714. 3:33:41processing then uh we need to generate
  3715. 3:33:44generate sixdigit
  3716. 3:33:48OTP. Okay. Yeah. So, a string OTP equals
  3717. 3:33:54a string dot format. Okay. And uh
  3718. 3:34:01formatting starts fine.
  3719. 3:34:04and uh 06 you know length is uh six
  3720. 3:34:07digit and then d that means decimal
  3721. 3:34:11integer and uh what math dot random
  3722. 3:34:18okay and times 900,000
  3723. 3:34:23okay plus
  3724. 3:34:27100,000 okay
  3725. 3:34:31fine okay and uh also
  3726. 3:34:37int.
  3727. 3:34:38Okay,
  3728. 3:34:41fine. So I got my sixdigit OTP. Now I
  3729. 3:34:46need to store OTP in radius.
  3730. 3:34:51Okay. And uh I'll put my OTP expiry
  3731. 3:34:57expires in 5 minutes. Let me first you
  3732. 3:35:02know set up the key OTP key equals and
  3733. 3:35:08verification
  3734. 3:35:11OTP. Okay. Then what? Then transaction
  3735. 3:35:16ID. Okay. And then radius template. So I
  3736. 3:35:22also need here private final radius
  3737. 3:35:27template. One second. We haven't added
  3738. 3:35:32uh radius dependency in our transaction
  3739. 3:35:34service.
  3740. 3:35:36Okay.
  3741. 3:35:41I guess no. Yeah. Not. So first let me
  3742. 3:35:45add
  3743. 3:35:48in the fraud detection. We have yes we
  3744. 3:35:50have spring data radius. Okay. Let me
  3745. 3:35:53just copy
  3746. 3:35:56and
  3747. 3:35:59paste it here.
  3748. 3:36:03Yeah,
  3749. 3:36:04fine.
  3750. 3:36:08Okay,
  3751. 3:36:10let it reload.
  3752. 3:36:13Yeah, done. So now back to our event
  3753. 3:36:16consumer and radius template.
  3754. 3:36:23Okay, radius template. Fine.
  3755. 3:36:28Let me get that radius template.
  3756. 3:36:31Okay. Dot opts for value. Okay. And dot
  3757. 3:36:36set
  3758. 3:36:38what? OTP key. OTP. Okay. And expiry.
  3759. 3:36:44So, let me also set the OTP expiry
  3760. 3:36:48variable. private
  3761. 3:36:51static final long and OTP
  3762. 3:36:57expiry
  3763. 3:37:00minutes.
  3764. 3:37:01Okay. Equals five.
  3765. 3:37:05Fine. So here reduce template set OTP
  3766. 3:37:09key OTP and OTP expiry minutes and in
  3767. 3:37:15minutes. Okay.
  3768. 3:37:18Yeah, fine. And now we need to update it
  3769. 3:37:22status.
  3770. 3:37:24Okay, because we have added transaction
  3771. 3:37:26status processing to pending
  3772. 3:37:29verification.
  3773. 3:37:31Yes, that's uh what we have discussed.
  3774. 3:37:35Yeah, see how the flow is going. Okay,
  3775. 3:37:38so transaction
  3776. 3:37:41dot set status as pending verification.
  3777. 3:37:47Okay. And then we need to save it. So,
  3778. 3:37:49transaction repository save. Okay. And
  3779. 3:37:53then log dot info.
  3780. 3:37:57Okay. And OTP generated
  3781. 3:38:01for
  3782. 3:38:03transaction
  3783. 3:38:06and expires.
  3784. 3:38:09Okay. Expires in this much minute. Okay.
  3785. 3:38:15So transaction ID and OTP expiry
  3786. 3:38:19minutes. Fine. Now I need to what? I
  3787. 3:38:24need to notify
  3788. 3:38:26notify
  3789. 3:38:29user. Okay. Yes or no? So once once my
  3790. 3:38:34bank system
  3791. 3:38:37okay generates
  3792. 3:38:40OTP what will be the next step?
  3793. 3:38:45user
  3794. 3:38:46gets the OTP on his phone
  3795. 3:38:50via SMS or
  3796. 3:38:54email.
  3797. 3:38:56Yes or no? So we need to uh notify to
  3798. 3:39:01the user because OTP generated. How will
  3799. 3:39:04notify? We are going to publish
  3800. 3:39:09an event.
  3801. 3:39:12Okay, event like uh transaction
  3802. 3:39:16OTP generated
  3803. 3:39:19and that event is going to consume
  3804. 3:39:22by our notification service
  3805. 3:39:27and notification service calls verify
  3806. 3:39:29OTP which we have created
  3807. 3:39:34uh in our transaction controller. This
  3808. 3:39:36one
  3809. 3:39:37verify OTP
  3810. 3:39:40getting a point. Yes or no? Okay. Yes.
  3811. 3:39:44Fine. So let's do it. Uh okay.
  3812. 3:39:50Transaction event consumer notify user.
  3813. 3:39:55So let me just put the values map and
  3814. 3:40:01okay
  3815. 3:40:03let me rename my variable name OTP
  3816. 3:40:06event.
  3817. 3:40:08Now the first thing let me put as OTP
  3818. 3:40:11event dot put
  3819. 3:40:16and transaction ID. Okay, transaction ID
  3820. 3:40:20then uh account number. Okay, fine. Then
  3821. 3:40:24reason. Okay. Fine. And then I need to
  3822. 3:40:27put OTP also. Okay. Yeah. OTP. Okay. And
  3823. 3:40:32also amount. Okay. OTP event dot
  3824. 3:40:38put. Okay. And amount.
  3825. 3:40:44Fine.
  3826. 3:40:47payload dot
  3827. 3:40:50get
  3828. 3:40:52amount.
  3829. 3:40:55Okay. Yes. So then next Kafka. Okay. Let
  3830. 3:41:01me also get that
  3831. 3:41:03private final Kafka
  3832. 3:41:07template
  3833. 3:41:09string object.
  3834. 3:41:13Kafka template. Let me just
  3835. 3:41:17you know
  3836. 3:41:19Kafka template dot send.
  3837. 3:41:22Okay. And uh
  3838. 3:41:26Okay. So
  3839. 3:41:30h
  3840. 3:41:32private
  3841. 3:41:35static final a string and
  3842. 3:41:41transaction
  3843. 3:41:44OTP
  3844. 3:41:47generated
  3845. 3:41:50topic. Okay. So transaction
  3846. 3:41:54OTP dot
  3847. 3:41:56generated
  3848. 3:41:59let me copy it.
  3849. 3:42:03Fine. And then transaction ID and
  3850. 3:42:08OTP event
  3851. 3:42:11H. Yeah.
  3852. 3:42:13In the catch block, let me just add log
  3853. 3:42:17dot error.
  3854. 3:42:19Okay. And here
  3855. 3:42:24error handling
  3856. 3:42:27verification
  3857. 3:42:30required.
  3858. 3:42:32Okay.
  3859. 3:42:35And e dot get message.
  3860. 3:42:38Yeah. So this is what yes or no. Yeah.
  3861. 3:42:42Understood. Uh OTP generated and event
  3862. 3:42:46published. Now this this OTP generated
  3863. 3:42:49event is going to consume by our
  3864. 3:42:53notification. Okay. And then calls this
  3865. 3:42:56method.
  3866. 3:43:00This method
  3867. 3:43:02okay fine let's do it.
  3868. 3:43:06So my notification service yeah src main
  3869. 3:43:12java. Okay. Let me quickly create
  3870. 3:43:17service dot
  3871. 3:43:19notification
  3872. 3:43:21service
  3873. 3:43:23and add slj
  3874. 3:43:27at
  3875. 3:43:29service. Okay. Yeah. Now what public
  3876. 3:43:34void and consume
  3877. 3:43:37OTP
  3878. 3:43:39generated.
  3879. 3:43:41Okay. add payload.
  3880. 3:43:45Okay. And map
  3881. 3:43:49a string object and payload.
  3882. 3:43:55Yeah.
  3883. 3:43:58Fine. Yeah. Now let me open my try
  3884. 3:44:01catch. Okay. And here a string first.
  3885. 3:44:06Let me get account number. Okay. string
  3886. 3:44:10account
  3887. 3:44:12number. Okay, account number. Then let
  3888. 3:44:15me get the OTP. Okay, OTP equals
  3889. 3:44:20payload dot get
  3890. 3:44:25and OTP
  3891. 3:44:28fine. And let me type cast it.
  3892. 3:44:32Okay. And then let me get the
  3893. 3:44:36transaction ID. Okay, transaction ID and
  3894. 3:44:41then let me get the amount.
  3895. 3:44:46Okay, so payload dot get amount dot to a
  3896. 3:44:53string. Okay, and then reason.
  3897. 3:45:00Okay, so reason H. Yeah, now uh send
  3898. 3:45:07alert. Okay. So we'll implement this
  3899. 3:45:10method. Okay. And the job of this method
  3900. 3:45:14is to send the alert to my user. Okay.
  3901. 3:45:19And in this method we have you know few
  3902. 3:45:22parameters. First is subject. Okay. So
  3903. 3:45:26subject should be transaction
  3904. 3:45:31verification
  3905. 3:45:33required.
  3906. 3:45:35Okay. Verification required.
  3907. 3:45:38Yeah. And message. So message string
  3908. 3:45:44format. Okay. And suspicious.
  3909. 3:45:48Okay. Suspicious
  3910. 3:45:52activity
  3911. 3:45:54detected.
  3912. 3:45:56Yes. On your account.
  3913. 3:46:00H.
  3914. 3:46:01Okay.
  3915. 3:46:03and
  3916. 3:46:07reason.
  3917. 3:46:09So reason is what percent s h okay and
  3918. 3:46:16then then what
  3919. 3:46:19then
  3920. 3:46:22a transaction
  3921. 3:46:24of percent s is pending
  3922. 3:46:30verification.
  3923. 3:46:32Okay. Yes or no?
  3924. 3:46:35And and also about expiry. So
  3925. 3:46:42your OTP is
  3926. 3:46:48percent
  3927. 3:46:49s and valid for 5 minutes.
  3928. 3:46:57Yes.
  3929. 3:46:58And
  3930. 3:47:00uh what? Yeah. So also if this wasn't
  3931. 3:47:07you.
  3932. 3:47:09Okay. Then
  3933. 3:47:12ignore
  3934. 3:47:13this message.
  3935. 3:47:16H. This is good. Yeah.
  3936. 3:47:20Okay. And in the catch block log dot
  3937. 3:47:25error
  3938. 3:47:27and
  3939. 3:47:30error sending OTP
  3940. 3:47:34notification.
  3941. 3:47:37Okay.
  3942. 3:47:39Fine. Uh notification.
  3943. 3:47:45Yeah. Okay. Now uh we need to you know
  3944. 3:47:50create this method send alert. Okay. So
  3945. 3:47:55private
  3946. 3:47:58private void send alert. Okay. And I'm
  3947. 3:48:03taking subject
  3948. 3:48:06and a string message.
  3949. 3:48:08Okay. Uh also also let me add one more
  3950. 3:48:12thing that is account number.
  3951. 3:48:16Yeah. Okay. So here
  3952. 3:48:20a string account
  3953. 3:48:24number H. Now it is good. Yeah. Okay. So
  3954. 3:48:29we'll implement this method. Okay. Later
  3955. 3:48:31on. First let's complete the other
  3956. 3:48:33parts. Okay. So in this method we are
  3957. 3:48:37going to add you know the code to send
  3958. 3:48:42the alerts to the user. Okay. Maybe it
  3959. 3:48:46is uh credit alert, debit alert, fraud
  3960. 3:48:50alert, suspicious activity detector
  3961. 3:48:53alert, OTP alert. Okay. So alerts fine.
  3962. 3:48:56So just one method for all. Yeah. Okay.
  3963. 3:49:01Also let me add at Kafka listener
  3964. 3:49:05annotation. Okay. And uh the topic is
  3965. 3:49:10yeah transaction.
  3966. 3:49:13Ootp.enerated.
  3967. 3:49:14generated.
  3968. 3:49:16Okay. Yeah. Now tell me where are we in
  3969. 3:49:19our flow? So I guess we are in our last
  3970. 3:49:22step. Okay. So I want you all to focus
  3971. 3:49:26here that is
  3972. 3:49:29our notification service is consuming
  3973. 3:49:33what this uh transaction OTP generated.
  3974. 3:49:38That means what that means is user
  3975. 3:49:40notified.
  3976. 3:49:42Our user
  3977. 3:49:44notified
  3978. 3:49:46with
  3979. 3:49:48OTP.
  3980. 3:49:49The next thing is user needs to verify
  3981. 3:49:54the transaction.
  3982. 3:49:58Okay. And uh to do that he needs to
  3983. 3:50:03enter the OTP
  3984. 3:50:06and we'll match it with our stored OTP.
  3985. 3:50:12Okay. So first thing is verify. How to
  3986. 3:50:15verify? Simple. We have already created
  3987. 3:50:18a method here uh you know transaction
  3988. 3:50:22controller and our endpoint that is
  3989. 3:50:25verify OTP. Now
  3990. 3:50:28at this stage we need to implement this
  3991. 3:50:33method yes or no. So this is why you
  3992. 3:50:37know I told you the flow is really
  3993. 3:50:39important in this project and that's
  3994. 3:50:42what I want to make you feel how to
  3995. 3:50:45start coding and go with the flow
  3996. 3:50:49otherwise you know it will really become
  3997. 3:50:51a mess. Okay. So yeah also here in the
  3998. 3:50:57transaction event consumer we have
  3999. 3:51:00consumed
  4000. 3:51:02verification required. Okay. So, Kafka
  4001. 3:51:05listener and topic
  4002. 3:51:10verification dot required. Fine. Okay.
  4003. 3:51:14So, now let's do our uh let's implement
  4004. 3:51:17this verify OTP and transaction ID and
  4005. 3:51:20OTP. Okay.
  4006. 3:51:24Public transaction. Okay. Response and
  4007. 3:51:29verify OTP. Fine. a string and
  4008. 3:51:33transaction ID and a string OTP. Okay.
  4009. 3:51:39Now, first let me add some loggings that
  4010. 3:51:42uh OTP
  4011. 3:51:43verification for the transaction.
  4012. 3:51:49Okay. And transaction ID. Okay. Now
  4013. 3:51:52first uh let me get the transaction
  4014. 3:51:55transaction. Okay. Using ID. So
  4015. 3:51:57transaction repository dotfind by ID.
  4016. 3:51:59Let me pass the transaction ID and or
  4017. 3:52:01else through. Okay. New runtime
  4018. 3:52:04exception. New runtime exception. Okay.
  4019. 3:52:08And transaction not found. Okay. Yes.
  4020. 3:52:14And transaction ID. Yeah. Now the next
  4021. 3:52:17thing is we need to get the OTP stored
  4022. 3:52:22OTP. Then only we can you know compare
  4023. 3:52:24it with our uh user entered OTP. So
  4024. 3:52:27first let me you know set up the key. So
  4025. 3:52:30OTP key equals okay what was the key?
  4026. 3:52:33Yeah this is the key at the time we have
  4027. 3:52:35generated our OTP and stored the OTP in
  4028. 3:52:37our radius. You can see set okay so this
  4029. 3:52:42is my key and uh
  4030. 3:52:45fine and now let me get the stored OTP
  4031. 3:52:50which is radius template. So I guess we
  4032. 3:52:52haven't you know imported that.
  4033. 3:52:56So private final and uh radius template.
  4034. 3:53:02Okay. A string a string and radius
  4035. 3:53:05template.
  4036. 3:53:07Okay fine. The next thing is radius
  4037. 3:53:10template dot ops forvalue dot get. Okay.
  4038. 3:53:12Because we need to get and we'll pass
  4039. 3:53:14the key. So here I'm getting the stored
  4040. 3:53:16OTP.
  4041. 3:53:18Okay. And expiry time is 5 minutes. Now
  4042. 3:53:21we need to check if stored OTP is null
  4043. 3:53:24coming as null that means that means OTP
  4044. 3:53:27already expired. Okay. So in that case
  4045. 3:53:30what we need to do is we need to
  4046. 3:53:31compensate. Okay. And uh okay first let
  4047. 3:53:35me you know log dot warning. Okay. And
  4048. 3:53:38OTP expired for transaction
  4049. 3:53:43and transaction ID.
  4050. 3:53:46Fine. And then we will compensate
  4051. 3:53:50transaction.
  4052. 3:53:51Okay. Let me pass the transaction. Okay.
  4053. 3:53:55And uh then what? Return map to response
  4054. 3:53:59and transaction.
  4055. 3:54:02Yes or no. Yeah. Also let me just pass
  4056. 3:54:06some message that OTP expired. OTP
  4057. 3:54:10expired. Okay. And transaction
  4058. 3:54:14cancelled.
  4059. 3:54:16Fine and amount refunded. Okay. Because
  4060. 3:54:20see we are you know verifying the
  4061. 3:54:23transaction because we have detected
  4062. 3:54:25something suspicious that is why cancel
  4063. 3:54:28and amount refunded. Okay. Second case
  4064. 3:54:31if uh stored OTP not equals to the enter
  4065. 3:54:35OTP. Okay. That means user entered wrong
  4066. 3:54:38OTP. Okay. Suspicious. Fine. So stored
  4067. 3:54:41OTP and not fine. So what we'll do is we
  4068. 3:54:47will you know block account and refund
  4069. 3:54:51and log dot warning. So wrong wrong OTP.
  4070. 3:54:57Okay. And blocking account and
  4071. 3:55:01refunding. Yeah. Transaction ID. Okay.
  4072. 3:55:05So first radius template dotdelete.
  4073. 3:55:07Okay. In this case if OTP entered wrong
  4074. 3:55:09then first we'll delete. Okay. And let
  4075. 3:55:11me pass the OTP key and then block
  4076. 3:55:14account. Okay. And compensate.
  4077. 3:55:19Okay. Let me pass the transaction and uh
  4078. 3:55:23wrong OTP received. Okay. Or let's say
  4079. 3:55:27wrong OTP entered. Yeah. So transaction
  4080. 3:55:32cancelled.
  4081. 3:55:34Okay.
  4082. 3:55:36And uh
  4083. 3:55:39account
  4084. 3:55:41blocked for security.
  4085. 3:55:44Yes. Fine. And then we'll return map to
  4086. 3:55:47response and uh yeah transaction. Fine.
  4087. 3:55:51Else else what? Else OTP. Correct. Okay.
  4088. 3:55:55Then we need to complete the
  4089. 3:55:58transaction. So log dot info and uh you
  4090. 3:56:03know OTP verified. Yes. Completing
  4091. 3:56:08transaction.
  4092. 3:56:10Okay. And uh transaction ID. Fine. So we
  4093. 3:56:15need to first radius template dotdelete
  4094. 3:56:17OTP key and then complete
  4095. 3:56:20transaction that means we need to credit
  4096. 3:56:22to our receiver okay let me pass the
  4097. 3:56:25transaction okay that's it and return
  4098. 3:56:28map to response transaction so we need
  4099. 3:56:30to implement these three methods okay I
  4100. 3:56:33told you uh once we'll uh verify the OTP
  4101. 3:56:35then u further we'll have three cases
  4102. 3:56:38okay so these are our three cases in
  4103. 3:56:40case OTP expired in case wrong OTP in
  4104. 3:56:42case correct OTP fine so quickly you
  4105. 3:56:45know let's implement one by one first
  4106. 3:56:47compensate transaction okay so private
  4107. 3:56:50void and compensate transaction I'm
  4108. 3:56:53getting transaction transaction and a
  4109. 3:56:55string message or maybe reason yeah okay
  4110. 3:57:00now log dot warning okay and saga
  4111. 3:57:04compensation
  4112. 3:57:06yes refunding okay refunding
  4113. 3:57:12okay and amount
  4114. 3:57:14Yeah.
  4115. 3:57:17Transaction dot get sender account
  4116. 3:57:20number H. And amount is what?
  4117. 3:57:22Transaction dot get amount. Okay. Next
  4118. 3:57:25is uh we need to credit we need to
  4119. 3:57:27credit money back to sender. Okay. And
  4120. 3:57:32synchronously. Okay. So
  4121. 3:57:36fine synchronously. So how to do it? Uh
  4122. 3:57:40we will not do it. Actually our faint
  4123. 3:57:42client will do it. Okay. Because you
  4124. 3:57:45know credit balance. Okay. Our account
  4125. 3:57:48service has one method we have created
  4126. 3:57:50that is our yeah this one credit
  4127. 3:57:53balance. Okay. So first where is our f
  4128. 3:57:55client? My account controller comes here
  4129. 3:57:57and transaction service. Yeah
  4130. 3:58:01I'm just returning the string. Okay. And
  4131. 3:58:05credit balance. Yes. Copy and paste it
  4132. 3:58:08here. Okay. put mapping the entire path
  4133. 3:58:11that means API v1 accounts.
  4134. 3:58:16Okay. And account number credit.
  4135. 3:58:20Okay, that's it. Now back to our uh
  4136. 3:58:24transaction service.
  4137. 3:58:26Okay. And uh yeah, here. So also let me
  4138. 3:58:30just get it. Okay, already there. Fine.
  4139. 3:58:33No worries. So credit money back to our
  4140. 3:58:36sender. H account service client dot
  4141. 3:58:39credit balance. Okay. And credit balance
  4142. 3:58:41to you know back to sender. So
  4143. 3:58:43transaction dot get sender account
  4144. 3:58:44number and how much amount? Yeah this
  4145. 3:58:46much. Okay that's it. Now I need to
  4146. 3:58:49change first the status. So transaction
  4147. 3:58:51status dot set uh dot set status as
  4148. 3:58:55flagged. Yes or no? Okay. Flagged. Fine.
  4149. 3:59:00And also let me you know transition dot
  4150. 3:59:03set failure reason. you know we have one
  4151. 3:59:05field in the transition entity as
  4152. 3:59:06failure reason so you know what is the
  4153. 3:59:09reason uh I'm getting the reason okay
  4154. 3:59:12and
  4155. 3:59:15so saga
  4156. 3:59:17okay compensation
  4157. 3:59:20executed
  4158. 3:59:22and amount
  4159. 3:59:25refunded at
  4160. 3:59:28what
  4161. 3:59:30local date time dot now okay and now Let
  4162. 3:59:34me save the transaction once saved and
  4163. 3:59:39publish
  4164. 3:59:40refund
  4165. 3:59:42event. Okay. Why? Because notification
  4166. 3:59:46service will alert user that uh uh you
  4167. 3:59:50know that uh the refund has been
  4168. 3:59:54received just know because we need to
  4169. 3:59:56notify user for every money movement.
  4170. 3:59:59Okay. So you know money credited back to
  4171. 4:00:03the sender. So definitely we need to
  4172. 4:00:05notify. Okay. Now let me take map and
  4173. 4:00:08what we need to put object refund event
  4174. 4:00:13equals new hashmap. Okay. And then
  4175. 4:00:16refund event dotput.
  4176. 4:00:19Okay. First transaction id. Okay.
  4177. 4:00:24Fine. And uh then what? So refund event
  4178. 4:00:27dotput
  4179. 4:00:29sender account number. Okay. So yeah.
  4180. 4:00:33Then what? Refund dot put and uh amount.
  4181. 4:00:38Okay. So transaction dot get amount.
  4182. 4:00:41Okay. And refund event dotput
  4183. 4:00:44reason. Okay. Fine. Then Kafka template
  4184. 4:00:49dot send. And uh we have one topic.
  4185. 4:00:54Yeah. Yeah. this one refunded topic
  4186. 4:00:56transaction. Refunded. Okay.
  4187. 4:01:00Fine. And then transaction dot get ID
  4188. 4:01:04and refund event also log dot info and
  4189. 4:01:09saga compensation
  4190. 4:01:12complete. Okay. And refunded to what
  4191. 4:01:19transaction dot get amount. Okay.
  4192. 4:01:24and transaction
  4193. 4:01:26dot get
  4194. 4:01:29sender account number.
  4195. 4:01:32Yes. So this is our uh you know
  4196. 4:01:35compensate transaction method is
  4197. 4:01:36implemented successfully. Next method
  4198. 4:01:38that is block account and compensate.
  4199. 4:01:41Okay. Compensate. Fine. Let's implement
  4200. 4:01:44it. I'm getting the okay transaction
  4201. 4:01:46fine. So private and void
  4202. 4:01:51transaction. Okay. transaction and a
  4203. 4:01:54string reason. So here in this we need
  4204. 4:01:58not to do okay much just we need to
  4205. 4:02:00publish fraud.detected detected event.
  4206. 4:02:03Okay. So, publish fraud dot detected.
  4207. 4:02:08Okay. And account
  4208. 4:02:12account
  4209. 4:02:15service will block account. Okay. So,
  4210. 4:02:20map. Okay. And here let me rename my
  4211. 4:02:23event variable that is fraud event.
  4212. 4:02:26Okay. First let me just you know fraud
  4213. 4:02:30event dot put transaction id. Okay let
  4214. 4:02:33me directly copy paste. Fine. And then
  4215. 4:02:36uh account number. Okay. So fraud event
  4216. 4:02:39dot put account number. Okay. So
  4217. 4:02:44transaction dot get sender account
  4218. 4:02:46number. Fine. And then reason. So
  4219. 4:02:50reason. And here fraud event. Okay. And
  4220. 4:02:54uh uh yeah that's it. Now Kafka template
  4221. 4:02:58dot send. Okay. And uh so I guess we
  4222. 4:03:02haven't created fraud detected. Okay.
  4223. 4:03:04Let me create that too. Private static
  4224. 4:03:07final string fraud detected topic.
  4225. 4:03:13Okay. So fraud
  4226. 4:03:15dot detected.
  4227. 4:03:18Yes.
  4228. 4:03:20Let me just copy it. Okay. and uh paste
  4229. 4:03:23it here.
  4230. 4:03:25And then what? H so transaction dot get
  4231. 4:03:31uh sender account number and fraud
  4232. 4:03:34event.
  4233. 4:03:36Yeah. Log dot warning. Okay. And uh
  4234. 4:03:42fraud dot detected published.
  4235. 4:03:47Fine. and
  4236. 4:03:50account
  4237. 4:03:53will be blocked.
  4238. 4:03:57Kindly
  4239. 4:03:59contact to your bank.
  4240. 4:04:03Fine. So transaction dot get sender
  4241. 4:04:05account number. Okay. And then what we
  4242. 4:04:09need to do? Yeah. So we need to now saga
  4243. 4:04:16compensation. H. Okay. And refund
  4244. 4:04:20sender. Okay. And then we'll call
  4245. 4:04:22compensate transaction transaction and
  4246. 4:04:24reason. Yeah. So this is good. Yes. So
  4247. 4:04:27if if you know uh something suspicious
  4248. 4:04:30activity detected and wrong OTP. So in
  4249. 4:04:33that case we are blocking the account.
  4250. 4:04:35Okay. And uh going forward in the
  4251. 4:04:37blocking account and compensate first we
  4252. 4:04:39have published this event. Okay. And if
  4253. 4:04:42you remember that our account service
  4254. 4:04:44has already a method. The method which
  4255. 4:04:46method my account service already
  4256. 4:04:48consuming fraud dot detected?
  4257. 4:04:52Yes or no? Consume fraud detected
  4258. 4:04:53method. Okay. It is blocking the
  4259. 4:04:55account. Block account here and here we
  4260. 4:04:56are blocking the account. After that
  4261. 4:04:58user will not able to uh initiate any
  4262. 4:05:02transaction. Okay. And then finally
  4263. 4:05:04finally after that we are compensating.
  4264. 4:05:07Okay. So once blocked and then finally
  4265. 4:05:09referred to the sender. So this is our
  4266. 4:05:11block account and uh compensate
  4267. 4:05:13implementation. Okay. Now the next and
  4268. 4:05:15last one is we need to complete the
  4269. 4:05:17transaction. That means we need to
  4270. 4:05:18credit to our receiver. Okay. So private
  4271. 4:05:22void and complete transaction and I'm
  4272. 4:05:25getting just transaction transaction.
  4273. 4:05:27Okay. So first let me set the status as
  4274. 4:05:31set uh status as completed. Okay. And
  4275. 4:05:35then I also need to set the completed at
  4276. 4:05:40local date time. Okay. dot set completed
  4277. 4:05:42at if you remember we have added one
  4278. 4:05:44field in the transaction that is
  4279. 4:05:46completed at. Okay. So you know
  4280. 4:05:50completed at local time dot now and then
  4281. 4:05:53we are you know saving in our repo
  4282. 4:05:56transaction. Okay. And then finally
  4283. 4:06:01uh we'll publish the event which event
  4284. 4:06:04transaction completed event. So look at
  4285. 4:06:07here in the event package we have
  4286. 4:06:10already created one event transaction
  4287. 4:06:11initiated one more event let me create
  4288. 4:06:14okay that is transaction completed event
  4289. 4:06:19okay and at data at all arcs at no arcs
  4290. 4:06:24fine so the fields I'm going to add in
  4291. 4:06:27this is a string okay private a string
  4292. 4:06:32and transaction ID okay then private a
  4293. 4:06:36string string sender account number
  4294. 4:06:40then private a string and uh receiver
  4295. 4:06:45account number.
  4296. 4:06:48Okay, account number.
  4297. 4:06:52Fine. And next is uh obviously private
  4298. 4:06:55big decimal and amount and then private
  4299. 4:07:00string description.
  4300. 4:07:03Okay, this is it. Let me just get the
  4301. 4:07:07transaction completed event object.
  4302. 4:07:08Okay. So, transaction completed event.
  4303. 4:07:13Okay. And completed event equals
  4304. 4:07:15transaction new transaction completed
  4305. 4:07:18event. In this let me set the values.
  4306. 4:07:20So, transaction dot uh get id. Okay.
  4307. 4:07:24Then transaction dot get sender account
  4308. 4:07:27number. Then uh transaction dot
  4309. 4:07:30receiver. Then transaction dot amount.
  4310. 4:07:33then transaction dot get description.
  4311. 4:07:37Okay. And Kafka template dot send. Okay.
  4312. 4:07:41We have already added this uh topic
  4313. 4:07:43variable that is transaction completed
  4314. 4:07:45event. Only thing remaining. Okay. Yeah.
  4315. 4:07:48So now transaction completed event and
  4316. 4:07:52uh transaction.get ID and completed
  4317. 4:07:54event. Now saga completed. So log.info
  4318. 4:07:58saga complete. Okay. and transaction
  4319. 4:08:05completed. Yes, transaction dot get ID.
  4320. 4:08:09Okay, our first part is completed and uh
  4321. 4:08:12now let's start the second part. Okay,
  4322. 4:08:14so I guess you all might be thinking
  4323. 4:08:16that uh we have implemented a lot
  4324. 4:08:17methods. Okay, consumed a lot uh events
  4325. 4:08:20and still you are seeing the second part
  4326. 4:08:22is remaining. Okay, so what's that?
  4327. 4:08:24Yeah. So I want you all to remind uh one
  4328. 4:08:27thing that uh yeah so user initiated the
  4329. 4:08:30transfer okay transaction and uh we have
  4330. 4:08:32published transaction initiated topic
  4331. 4:08:34and uh our fraud detection service
  4332. 4:08:37consume this event and starts checking
  4333. 4:08:38the transaction. Okay now I just want
  4334. 4:08:41you all to focus on my screen and line
  4335. 4:08:43number 55 or 53. Okay. If result dot is
  4336. 4:08:46fraud if fraud detected suspicious
  4337. 4:08:48activity detected. Okay then we start
  4338. 4:08:50the verification. So till this point
  4339. 4:08:52what we have done is regarding this
  4340. 4:08:55verification started verification then
  4341. 4:08:58we have uh implemented the method to
  4342. 4:09:00generate OTP then that event is consumed
  4343. 4:09:03by notification okay then verify OTP
  4344. 4:09:05based on verification we have
  4345. 4:09:06implemented uh whether need to
  4346. 4:09:07compensate or complete or block okay but
  4347. 4:09:10if result dot is fraud uh is false
  4348. 4:09:15that means everything is clean there is
  4349. 4:09:17no fraud detected okay so control comes
  4350. 4:09:19here line number 69 transaction clean
  4351. 4:09:22that means uh another event published
  4352. 4:09:25fraud check result clean. Okay. So yeah
  4353. 4:09:29fraud check clean in that case we need
  4354. 4:09:31to directly uh you know credit the money
  4355. 4:09:35to the receiver. Okay. So that too we
  4356. 4:09:37need to consume event in our transaction
  4357. 4:09:39service. This is what our last thing.
  4358. 4:09:41Okay. Transaction event consumer.
  4359. 4:09:44Okay. Yeah. So if fraud detection uh
  4360. 4:09:48fails to detect any fraud any suspicious
  4361. 4:09:51then we have published clean event. So
  4362. 4:09:53we need to consume this. Okay. What's
  4363. 4:09:56that? Fraud.check. Okay. Fine. And
  4364. 4:09:59transaction event consumer. Fine. And
  4365. 4:10:01public void. Okay. Consume fraud check
  4366. 4:10:06clean. Okay. Result
  4367. 4:10:11and add payload.
  4368. 4:10:14Fine. map
  4369. 4:10:17a string object payload.
  4370. 4:10:20Okay. Also at Kafka listener and
  4371. 4:10:26topic fraud dot check dot clean. Yeah.
  4372. 4:10:31Let's finish it quickly and wrap our
  4373. 4:10:33transaction
  4374. 4:10:35uh what transaction service. So first
  4375. 4:10:37let me open my try catch. Okay.
  4376. 4:10:42And uh then first let me get my
  4377. 4:10:44transaction ID. Transaction ID equals
  4378. 4:10:49payload dot 1 second. So yeah, let me
  4379. 4:10:53directly copy paste. Okay. Transaction
  4380. 4:10:57ID H. Okay.
  4381. 4:11:02Okay. Fine. And now next just we need to
  4382. 4:11:06call uh a method. We need to create one
  4383. 4:11:08method in our transaction service. Why?
  4384. 4:11:10Because see here uh we are consuming
  4385. 4:11:13fraud check result clean. Okay,
  4386. 4:11:15fraud.clean that means everything is
  4387. 4:11:17clean. We need to credit to the
  4388. 4:11:18receiver. Okay, that means we need to
  4389. 4:11:21call this method complete transaction.
  4390. 4:11:24Yeah, because this is only crediting uh
  4391. 4:11:26to the receiver. Okay, transaction
  4392. 4:11:28status completed but it is private how
  4393. 4:11:30to call it. So for that you know let me
  4394. 4:11:34just
  4395. 4:11:35first uh get private final transaction
  4396. 4:11:40service transaction service. Okay. And
  4397. 4:11:43here let me call transaction service dot
  4398. 4:11:46process
  4399. 4:11:48fraud check
  4400. 4:11:51or process clean result.
  4401. 4:11:54Okay. And I'm passing the transaction
  4402. 4:11:56ID. Okay. in log dot error and error
  4403. 4:12:03processing fraud check result
  4404. 4:12:08E dot get message. Okay. Now let me
  4405. 4:12:12quickly create this method to here.
  4406. 4:12:15Okay. Public void. Okay. And getting the
  4407. 4:12:20transaction
  4408. 4:12:22ID. Okay. Now first let me get the
  4409. 4:12:25transaction. Okay. Using the ID. So
  4410. 4:12:28better to directly Yeah. Copy. Okay.
  4411. 4:12:34Fine. Then we need to add uh item
  4412. 4:12:36potency guard. Okay. In order to prevent
  4413. 4:12:39the duplicate events. Okay. Just like we
  4414. 4:12:41have added in our this uh verification
  4415. 4:12:44required event. Yeah. This one. Okay. So
  4416. 4:12:49yes, paste it here. Fine. And then
  4417. 4:12:50directly call complete transaction and
  4418. 4:12:53pass the transaction. Yes. Yeah.
  4419. 4:12:57um transaction id okay
  4420. 4:13:01fine so whenever the request comes that
  4421. 4:13:04uh whenever the fraud detected service
  4422. 4:13:06gives the green signal to our
  4423. 4:13:08transaction okay here I'm consuming
  4424. 4:13:10fraud check clean and from here I'm
  4425. 4:13:12calling this method and this method is
  4426. 4:13:15finally completing our transaction
  4427. 4:13:17crediting money to our receiver fully
  4428. 4:13:19completed our transaction service is
  4429. 4:13:21fully completed okay and uh our fraud
  4430. 4:13:25detection service. Okay. Account service
  4431. 4:13:28uh client. Okay. Fraud check and event
  4432. 4:13:31consumer and fraud detection. Fine. So
  4433. 4:13:33here too everything is done. Only one
  4434. 4:13:35thing remaining that is our application.
  4435. 4:13:36YML. Let me quickly uh complete that.
  4436. 4:13:40Yeah. We have added you know few
  4437. 4:13:42properties for our fraud max transaction
  4438. 4:13:44suspicious amount multiplier and max
  4439. 4:13:46balance percentage. Okay. Fine. And
  4440. 4:13:50here. So let me start
  4441. 4:13:53application name. So it is fraud
  4442. 4:13:56detection service. Okay. And then data
  4443. 4:14:01radius. Okay. Host port. One second.
  4444. 4:14:07Radius host and port. Okay. So host is
  4445. 4:14:09our local host and port is 6379 6379.
  4446. 4:14:14Also also in our transaction service
  4447. 4:14:18uh application YAML properties file.
  4448. 4:14:22I guess we haven't added the radius
  4449. 4:14:24properties. No, we need to add it. Why?
  4450. 4:14:27Because we have used the radius,
  4451. 4:14:30you know, created uh the OTP stored OTP.
  4452. 4:14:33Okay. Yeah. So, let's add here too.
  4453. 4:14:36Okay. And
  4454. 4:14:39data radius
  4455. 4:14:42host local host. Oops. And port 6379.
  4456. 4:14:49H. Now, it is good. Okay. Back to our
  4457. 4:14:52fraud detection property file. Yeah. And
  4458. 4:14:55uh then our Kafka properties. Okay. So,
  4459. 4:14:57let me directly copy and paste from my
  4460. 4:15:01Kafka and till producer.
  4461. 4:15:05Okay. Back to our flaw detection and
  4462. 4:15:08yes, done fine. Then watch server
  4463. 4:15:12dot port 8084.
  4464. 4:15:15Okay. We do have this account service
  4465. 4:15:18client. So, we need to add the
  4466. 4:15:20properties.
  4467. 4:15:21Okay. account
  4468. 4:15:24you know service URL for
  4469. 4:15:28fain client
  4470. 4:15:32okay and what's that account dos service
  4471. 4:15:36URL
  4472. 4:15:38yes http
  4473. 4:15:40and localhost
  4474. 4:15:438081 okay on this uh address my account
  4475. 4:15:46service is running fine and fraud
  4476. 4:15:49detection is already there we have added
  4477. 4:15:52while coding and then management. Okay.
  4478. 4:15:56Endpoints then web exposure.
  4479. 4:16:01Okay.
  4480. 4:16:03Then include health and info. So
  4481. 4:16:07everything is done in our fraud
  4482. 4:16:08detection. Now only thing remaining that
  4483. 4:16:10is our notification service and we need
  4484. 4:16:12to consume few more events also. We need
  4485. 4:16:15to implement this send alert method.
  4486. 4:16:17Okay. So first event we have implemented
  4487. 4:16:19uh sorry consumed that OTP generated.
  4488. 4:16:22Next we need to consume our you know
  4489. 4:16:24debit alert credit alert yes or no. So
  4490. 4:16:27once money debited so debit alert
  4491. 4:16:30credited credit alert okay and uh for
  4492. 4:16:34the Razer pay side yeah Razer payment
  4493. 4:16:36gateway external payments yes or no once
  4494. 4:16:39you know uh using our bank application
  4495. 4:16:42you are paying to some external
  4496. 4:16:44merchants just like Amazon. Okay. So at
  4497. 4:16:47that point our payment gateway comes
  4498. 4:16:48into the picture. Okay. And for that two
  4499. 4:16:51we need to uh set up and we have already
  4500. 4:16:53one service that is you know our payment
  4501. 4:16:55service. Where is that? Where is that?
  4502. 4:16:58Uh yeah this one. Okay. So payment
  4503. 4:17:02success alert payment failure alert.
  4504. 4:17:05Okay. So for all these alert we need to
  4505. 4:17:07consume the events here and notify user.
  4506. 4:17:10Okay. Yeah. So quickly first let's
  4507. 4:17:13complete our payment service and then
  4508. 4:17:14finally we'll come up here and consume
  4509. 4:17:17all the uh alert events and implement
  4510. 4:17:20this method. Which one? Our send alert.
  4511. 4:17:23Okay. Yeah. So now now next thing is
  4512. 4:17:27let's start our final thing. Not final
  4513. 4:17:31second last. Okay. Payment service.
  4514. 4:17:33Okay. Okay. So let's start with our
  4515. 4:17:36payment entity.
  4516. 4:17:39Okay. payment and now entity.
  4517. 4:17:46Okay,
  4518. 4:17:48then
  4519. 4:17:50table
  4520. 4:17:52name. So, payments
  4521. 4:17:56and add data add no args and all args.
  4522. 4:18:01Fine. Now, let's add the fields. So
  4523. 4:18:04first is private string id and my id
  4524. 4:18:09should be what at generated
  4525. 4:18:14value
  4526. 4:18:16strategy and uyu ID. Okay. Yeah. Next.
  4527. 4:18:21So we going to use the razer pay. Okay.
  4528. 4:18:24So for that let me create a variables
  4529. 4:18:28for order ID and payment ID. So, Razer
  4530. 4:18:32Pay order ID and private
  4531. 4:18:37string Razer Pay payment ID.
  4532. 4:18:42Yeah, fine. Now, uh I need a account
  4533. 4:18:47number. So, private
  4534. 4:18:50account number as we already fetching
  4535. 4:18:53you know using the payload. Okay. Column
  4536. 4:18:57and null label false. The next is I need
  4537. 4:19:02big decimal
  4538. 4:19:05and amount.
  4539. 4:19:09Next, let me add uh what? Currency.
  4540. 4:19:13So, currency.
  4541. 4:19:15Okay. Yeah. And now private
  4542. 4:19:20payment status.
  4543. 4:19:23Okay. Yeah. So we'll create a enum for
  4544. 4:19:26that you know because we have bunch of
  4545. 4:19:28string values.
  4546. 4:19:30So
  4547. 4:19:32entity and
  4548. 4:19:34you know enum
  4549. 4:19:37payment status. Yeah fine. Later on
  4550. 4:19:41we'll add the fields. Okay. Then private
  4551. 4:19:46string
  4552. 4:19:47description. Okay. Then private string
  4553. 4:19:53failure reason. Okay. Payment failure
  4554. 4:19:55reason. And then private
  4555. 4:19:59local date time. Okay. Uh created at
  4556. 4:20:07and our last field that is local date
  4557. 4:20:10time updated at.
  4558. 4:20:14Okay. So add update timestamp
  4559. 4:20:19and add creation timestamp.
  4560. 4:20:23Okay. Yeah. Then uh payment status.
  4561. 4:20:26Okay. So this is my enum enumerated of
  4562. 4:20:30type string. Fine. And then uh for this
  4563. 4:20:35column nullable false. Yeah. Okay. For
  4564. 4:20:40this two nullable false. And let me add
  4565. 4:20:42precision that is uh 15 and scale two.
  4566. 4:20:47Okay. Yeah. So it is done.
  4567. 4:20:51Now let me add the fields for our enum
  4568. 4:20:54that is payment status.
  4569. 4:20:56So status can be you know created. Okay.
  4570. 4:21:01And then pending okay or completed or
  4571. 4:21:07failed. and
  4572. 4:21:10uh refunded. Yes, definitely. Yeah.
  4573. 4:21:15Okay. Now, uh let me just add the DTO
  4574. 4:21:22dot
  4575. 4:21:24create
  4576. 4:21:27you know payment
  4577. 4:21:29request.
  4578. 4:21:31Okay.
  4579. 4:21:32And uh in response what we'll get. So,
  4580. 4:21:38payment response
  4581. 4:21:41or I can just add order payment order
  4582. 4:21:46response. Yeah. Now, let's add the
  4583. 4:21:50fields here. Okay.
  4584. 4:21:53So, payment and
  4585. 4:21:57fine. So, at first add
  4586. 4:22:01data and add no arcs and all arcs. Okay.
  4587. 4:22:07So now what I need what all fields I
  4588. 4:22:10need. So I need first account number.
  4589. 4:22:15Okay. And then I need amount.
  4590. 4:22:20Okay. And finally let me add the
  4591. 4:22:23description.
  4592. 4:22:27Okay. Yeah. So add not blank
  4593. 4:22:33and Okay.
  4594. 4:22:35And if it is blank then we'll display a
  4595. 4:22:38message that account number is required.
  4596. 4:22:44Okay. Then at not null. Okay.
  4597. 4:22:51Else will display a message amount is
  4598. 4:22:54required also amount must be in
  4599. 4:22:57positive.
  4600. 4:22:59So positive message is amount
  4601. 4:23:05must be positive. Okay. Yeah, that's it.
  4602. 4:23:10Now, now let's add the fields here in
  4603. 4:23:14the response. First, let me take the
  4604. 4:23:20payment ID. Okay. Then uh yeah, Razer
  4605. 4:23:24Pay order ID. Okay. in response. Fine.
  4606. 4:23:30And then amount. Okay.
  4607. 4:23:34Yeah. And uh Yeah. Then
  4608. 4:23:39currency.
  4609. 4:23:41Okay. Currency status. Okay. So
  4610. 4:23:48instead of enum here, let's you know uh
  4611. 4:23:53set the variable as a string. Okay.
  4612. 4:23:55because we can set it as a string value.
  4613. 4:23:59Yeah. Fine. Also one more thing uh we
  4614. 4:24:04need that is
  4615. 4:24:07private a string and
  4616. 4:24:11razor pay
  4617. 4:24:13razer pay key ID. Okay.
  4618. 4:24:18Fine.
  4619. 4:24:20Add data and add all arcs. Add no arcs.
  4620. 4:24:25Okay. So this is what our DTO has done.
  4621. 4:24:28Now let me just build the entire
  4622. 4:24:30skeleton. So first configuration we can
  4623. 4:24:34just add. Okay. Configuration dot
  4624. 4:24:39cross origin config
  4625. 4:24:42because we need to run our you know
  4626. 4:24:44front end files and need the permission.
  4627. 4:24:48Okay. Then only we can uh make the real
  4628. 4:24:51payment in our own banking page. Okay.
  4629. 4:24:55Then uh what our controller dot payment
  4630. 4:25:01controller. Okay. And then our
  4631. 4:25:06service dot
  4632. 4:25:08payment service. Okay. And then our
  4633. 4:25:15repository dot
  4634. 4:25:17payment
  4635. 4:25:20repository.
  4636. 4:25:22Okay. interface extends
  4637. 4:25:26JPA repo.
  4638. 4:25:30Okay. And
  4639. 4:25:35payment.
  4640. 4:25:38Okay. A string.
  4641. 4:25:42Fine. And uh uh what else? Yeah, that's
  4642. 4:25:47it. Okay. So add rest controller
  4643. 4:25:54at request mapping. Okay. API v1.
  4644. 4:26:02Fine. API1 and
  4645. 4:26:05payments.
  4646. 4:26:07Yeah. Okay. at SLF4J
  4647. 4:26:12H and then uh private final
  4648. 4:26:18payment service payment service. So for
  4649. 4:26:21that I need to add required arcs
  4650. 4:26:24constructor.
  4651. 4:26:26Okay. Now you know there are two
  4652. 4:26:30important endpoints. First is create
  4653. 4:26:33order. Okay. So once a user click on the
  4654. 4:26:36send money at the bank page create order
  4655. 4:26:40fine and the next thing is web hook.
  4656. 4:26:46Okay if you heard about once the status
  4657. 4:26:48changes so web hook is inbuilt with the
  4658. 4:26:51events if the status you know if the
  4659. 4:26:53payment successful web hook captured
  4660. 4:26:56that success event and then update the
  4661. 4:27:00back end. Okay so I'll show you. Okay,
  4662. 4:27:04in the web hook fine once we'll set up
  4663. 4:27:06our Razer Pay account. So our first
  4664. 4:27:09endpoint is public. Okay, and response
  4665. 4:27:13entity I'm returning the payment order
  4666. 4:27:17response. Okay, our DTO and create
  4667. 4:27:23payment order.
  4668. 4:27:27Okay, fine.
  4669. 4:27:30And add valid. Okay. Add request body
  4670. 4:27:37and create.
  4671. 4:27:40Okay. Payment request request.
  4672. 4:27:45Okay.
  4673. 4:27:48So,
  4674. 4:27:51return
  4675. 4:27:53response entity dot status. HTTP status.
  4676. 4:28:00Okay. dot created
  4677. 4:28:04dot body. Okay. And payment service dot
  4678. 4:28:10create
  4679. 4:28:13payment order. Let me pass the request.
  4680. 4:28:18Okay.
  4681. 4:28:20It is my post mapping
  4682. 4:28:24and
  4683. 4:28:25create
  4684. 4:28:27order.
  4685. 4:28:29Okay. Yeah. The next is our public and
  4686. 4:28:35response entity.
  4687. 4:28:38Okay. Of type a string and handle
  4688. 4:28:43web hook.
  4689. 4:28:44Okay. So add request body
  4690. 4:28:49and uh let me take a map a string object
  4691. 4:28:54and payload. Okay. Fine. Okay, we'll
  4692. 4:28:58fetch it. So here payment service dot
  4693. 4:29:05handle web hook. Okay, we'll pass the
  4694. 4:29:09payload and
  4695. 4:29:12return
  4696. 4:29:14response entity dot okay and web hook
  4697. 4:29:23processed
  4698. 4:29:26H. Yeah. So here it is to post mapping
  4699. 4:29:33and
  4700. 4:29:35web hook. Okay. Fine. Also let me just
  4701. 4:29:40write Razer Pay
  4702. 4:29:43web hook endpoint. Fine. Now let's
  4703. 4:29:47implement. So all of your focus should
  4704. 4:29:50be on my payment service. Okay. Yeah.
  4705. 4:29:53important one
  4706. 4:29:55service at SLF 4J. Okay.
  4707. 4:30:01And
  4708. 4:30:03private final.
  4709. 4:30:06So payment repository. Okay. For that
  4710. 4:30:10let me add required arcs constructor.
  4711. 4:30:13Now let me also create our you know
  4712. 4:30:17Kafka
  4713. 4:30:18topic variable. Okay. a static final a
  4714. 4:30:23string and payment
  4715. 4:30:28completed
  4716. 4:30:31topic. Okay.
  4717. 4:30:33So payment dot completed
  4718. 4:30:37and similarly
  4719. 4:30:41similarly our failed.
  4720. 4:30:43So payment
  4721. 4:30:46failed topic payment dot
  4722. 4:30:50failed. Okay fine.
  4723. 4:30:54Now yeah important one payment.
  4724. 4:30:59Okay order response
  4725. 4:31:03and create payment order. This is what
  4726. 4:31:06our first method we need to implement.
  4727. 4:31:08And I'm getting the create payment
  4728. 4:31:10request.
  4729. 4:31:11Okay. create payment request and
  4730. 4:31:14request.
  4731. 4:31:17Okay,
  4732. 4:31:19one second. Yeah,
  4733. 4:31:23fine. So now let me add here comments
  4734. 4:31:31that uh you know create
  4735. 4:31:34razor payment
  4736. 4:31:37order and the flow flow is like first
  4737. 4:31:44need to create order in Razer Pay okay
  4738. 4:31:48or whatever our uh you know payment
  4739. 4:31:51gateway then we need to save the payment
  4740. 4:31:55that's why
  4741. 4:31:57we have added our MySQL dependency in
  4742. 4:32:00this. So payment record in DB okay then
  4743. 4:32:04third is we need to return order details
  4744. 4:32:09to front end
  4745. 4:32:12okay and then
  4746. 4:32:15fourth is front end shows
  4747. 4:32:19Razer Pay checkout page. Yeah, on the
  4748. 4:32:24check out page only we'll uh make the
  4749. 4:32:26payment. And then fifth is user pays.
  4750. 4:32:31Okay. And sixth is then razor pay calls
  4751. 4:32:37what? We hook. I told you web hook is
  4752. 4:32:39what status. Okay. It has the events
  4753. 4:32:43after user pays whether it is success or
  4754. 4:32:45failed. We hbook captured that. Okay.
  4755. 4:32:48Fine. So this is one you know uh
  4756. 4:32:50complete flow. I told you my comments
  4757. 4:32:53are really important. I'm going to show
  4758. 4:32:54you the entire flow so that you can if
  4759. 4:32:58you can then you can code at your own at
  4760. 4:33:00first otherwise video is there I'm
  4761. 4:33:02coding. Yeah. Okay. So let's start with
  4762. 4:33:05our uh some login. Okay. At first what
  4763. 4:33:08we need to do is first in our flow it is
  4764. 4:33:11create order in Razer Pay. Yeah. So
  4765. 4:33:15creating payment order for account.
  4766. 4:33:21Okay.
  4767. 4:33:23And
  4768. 4:33:25amount.
  4769. 4:33:26Yeah. So I'm getting request dot get
  4770. 4:33:30account number. Okay. And similarly
  4771. 4:33:33request
  4772. 4:33:35request dot get amount. Okay. Fine. The
  4773. 4:33:38next thing is let me get my Razer Pay
  4774. 4:33:41client. Okay. So, Razer Pay client.
  4775. 4:33:46Okay. Razer pay client equals new Razer
  4776. 4:33:50Pay client. Fine. So, now we need to
  4777. 4:33:52pass few things here. Okay. Look at
  4778. 4:33:55here.
  4779. 4:33:57So, at first we need to pass here my
  4780. 4:33:59Razer Pay key ID. Okay. And second thing
  4781. 4:34:02is I need to pass Razer Pay key secret.
  4782. 4:34:07Yeah. So from where we'll get it these
  4783. 4:34:10two things
  4784. 4:34:12once we'll set up our Razer Pay payment
  4785. 4:34:15gateway. Okay, I'll show you. Okay, at
  4786. 4:34:18that time and we'll generate our unique
  4787. 4:34:21key ID and key secret. Okay. Yeah. So
  4788. 4:34:26you know with these uh two fields we'll
  4789. 4:34:30able to make our real you know transfer
  4790. 4:34:33real payments. Okay. And then we'll uh
  4791. 4:34:36directly copy and paste it into our uh
  4792. 4:34:38you know properties file and we'll
  4793. 4:34:40handle it here using our variables.
  4794. 4:34:43Yeah. So let's do that. Okay. Let me
  4795. 4:34:48create two variables for that. Private
  4796. 4:34:51string and key id. Okay. And private
  4797. 4:34:55string key secret. Okay. So add value H.
  4798. 4:35:02Okay.
  4799. 4:35:04and
  4800. 4:35:06Razer pay dot key id h and similarly
  4801. 4:35:15what razor pay dot key secret h okay
  4802. 4:35:19fine let me pass both of them here so
  4803. 4:35:24key id and
  4804. 4:35:26key secret okay fine now the next thing
  4805. 4:35:30is also
  4806. 4:35:32uh why I'm getting here some uh you know
  4807. 4:35:36error. Uh okay fine. So I need to you
  4808. 4:35:40know throws razor pay
  4809. 4:35:43exception. Okay. Also in the controller
  4810. 4:35:48method throws razor pay exception. Okay
  4811. 4:35:54fine. H yeah. Now the next thing is I
  4812. 4:35:58need to convert my you know amount into
  4813. 4:36:00the smaller one. Okay. convert my
  4814. 4:36:03currency into the smaller one. Let's say
  4815. 4:36:05just look at here. So suppose if I'm
  4816. 4:36:08using USD okay so I need to convert it
  4817. 4:36:11into cents. Okay. So one USD
  4818. 4:36:15is how much cents? 100
  4819. 4:36:18cents. Okay. So I need to multiply
  4820. 4:36:22you know uh by 100.
  4821. 4:36:28Yes or no? Yeah. And uh let's say I'm
  4822. 4:36:32using INR
  4823. 4:36:34okay Indian rupees okay so I need to
  4824. 4:36:36convert it into what the smaller one is
  4825. 4:36:39pes yeah so yeah same thing 1 INR equals
  4826. 4:36:44100 fine similarly whatever currency you
  4827. 4:36:48have you can just proceed with that okay
  4828. 4:36:51so let me now
  4829. 4:36:55you know just
  4830. 4:36:58code that So converted amount okay and
  4831. 4:37:04uh int converted amount
  4832. 4:37:09okay equals what first let me get the
  4833. 4:37:12amount request dot get
  4834. 4:37:16uh amount okay and then dot multiply
  4835. 4:37:19what big decimal dot value of and
  4836. 4:37:24multiply with 100 dot int value okay
  4837. 4:37:29Yeah. So this is now my final converted
  4838. 4:37:31amount. Okay. I need to put it uh in uh
  4839. 4:37:34into my order request. Yeah. Fine. So my
  4840. 4:37:39JSON object. Let's create our order
  4841. 4:37:41request. Order request
  4842. 4:37:45equals new JSON object. Okay. And let's
  4843. 4:37:48put few things in our this request.
  4844. 4:37:51Okay. Order request. Okay. As the name
  4845. 4:37:53indicating order request. So first let
  4846. 4:37:56me put my amount obviously. Okay. And uh
  4847. 4:38:00then okay currency. Okay. USD or INR.
  4848. 4:38:03Okay. Fine. Okay. Let me put the USD.
  4849. 4:38:07Fine. And uh then finally our receipt. H
  4850. 4:38:12order
  4851. 4:38:14request dot put H. And our receipt ID.
  4852. 4:38:20Okay. Receipt. So
  4853. 4:38:25let's say receipt ID. Okay. So we need
  4854. 4:38:28to generate a unique and random id.
  4855. 4:38:32Okay, for that yeah so one question for
  4856. 4:38:35you. Okay, let me generate using uu ID
  4857. 4:38:38dot random UU ID dot2 string. Okay, but
  4858. 4:38:41there might be possible not practically.
  4859. 4:38:43Okay, it's a lot of combinations but
  4860. 4:38:45theoretically you know it can generate
  4861. 4:38:49um same UU ID.
  4862. 4:38:53I know it's not practically possible lot
  4863. 4:38:55of combinations. Okay. But theoretically
  4864. 4:38:57it is possible. Okay. So for that you
  4865. 4:39:00know one solution. Let's you know uh add
  4866. 4:39:06what's that? So we can also concatenate
  4867. 4:39:09our
  4868. 4:39:11uh
  4869. 4:39:12system dot current times. Okay.
  4870. 4:39:18Then UID. Okay. And then dot will
  4871. 4:39:22replace. Okay. So
  4872. 4:39:26replace hyphen.
  4873. 4:39:29Yeah. Okay. And dot substring 0 comma
  4874. 4:39:3510.
  4875. 4:39:37Okay. Yeah. Why I'm doing this? Why I'm
  4876. 4:39:41doing this? Because just look at here.
  4877. 4:39:44So
  4878. 4:39:46you know our receipt ID should not
  4879. 4:39:49exceed 30 characters.
  4880. 4:39:52Okay. And here I'll get something like
  4881. 4:39:55uh you know sum 8 9 e b okay for hyphen
  4882. 4:40:02uh a 29 b something like that okay our
  4883. 4:40:06uh random ID so I'm replacing hyphen
  4884. 4:40:10okay and then restricting it to 10 okay
  4885. 4:40:14yeah so that will be you know kind of
  4886. 4:40:17our unique receipt ID okay fine let's
  4887. 4:40:20proceed with that Okay, next thing is
  4888. 4:40:24what?
  4889. 4:40:26Uh, I need to just, you know, get the
  4890. 4:40:28order. So, or I can just write Razer Pay
  4891. 4:40:33Razer Pay order. Okay. Equals I have,
  4892. 4:40:37you know, Razer Pay client
  4893. 4:40:39from the Razer Pay client dot orders
  4894. 4:40:43dot, you know, create.
  4895. 4:40:46Okay. And let me pass this order
  4896. 4:40:49request.
  4897. 4:40:50H. Okay. Fine. And also now let me just
  4898. 4:40:54add some login that our you know Razer
  4899. 4:40:57Pay order created. Razer Pay order
  4900. 4:41:01created. Okay. And also let me just you
  4901. 4:41:06know send the ID Razer Pay order dot get
  4902. 4:41:11ID dot to a string.
  4903. 4:41:15Okay fine. So our first thing is done.
  4904. 4:41:18First job is done. Okay. create order in
  4905. 4:41:20Razer Pay. That is done. Now the next
  4906. 4:41:23thing is save payment
  4907. 4:41:26uh record in database. Okay fine. So
  4908. 4:41:29let's do that.
  4909. 4:41:31Save payment record H. Okay. So let me
  4910. 4:41:36get that payment. Okay. Our entity
  4911. 4:41:40payment
  4912. 4:41:42equals new and payment. Fine. Okay. And
  4913. 4:41:47then let's uh set the values. So at very
  4914. 4:41:50first thing let me set my Razer Pay
  4915. 4:41:52order ID. Okay, Razer Pay order ID.
  4916. 4:41:56Okay, same thing.
  4917. 4:42:00Fine. Get ID dot to string. Okay, and
  4918. 4:42:03then let me just set the account number.
  4919. 4:42:06Set account number. Okay, I'm getting in
  4920. 4:42:09our request dot get account number.
  4921. 4:42:12Okay, then uh what amount? Okay,
  4922. 4:42:16obviously. And then uh currency. So
  4923. 4:42:19payment dot set currency USD okay or INR
  4924. 4:42:23okay fine and uh then payment dot yeah
  4925. 4:42:28also status so it is created okay and
  4926. 4:42:33then finally let me also set my
  4927. 4:42:35description okay so description okay
  4928. 4:42:38payment uh sorry request dot get
  4929. 4:42:41description yeah now let me save it
  4930. 4:42:45payment uh you know repository dots save
  4931. 4:42:48payment payment and
  4932. 4:42:51I'm getting payment saved payment. Okay,
  4933. 4:42:57fine. Now I'm returning payment order
  4934. 4:43:01response. Okay, let me just put it here.
  4935. 4:43:05Okay, and
  4936. 4:43:07need to return payment order response.
  4937. 4:43:09So
  4938. 4:43:10return new payment order response. The
  4939. 4:43:14first field is payment ID. Okay. So from
  4940. 4:43:18the save payment, let me set it. So get
  4941. 4:43:22ID. Okay. Next is our Razer Pay order
  4942. 4:43:25ID. So yeah, this is
  4943. 4:43:30Razer Pay order ID. Okay. Next is our
  4944. 4:43:34amount. So from the request, let me set
  4945. 4:43:36it amount. Okay. And then next is our
  4946. 4:43:40currency. Okay. So USD INR. Okay. And
  4947. 4:43:46yeah uh one more thing you have to write
  4948. 4:43:48it one one currency either USD okay or
  4949. 4:43:52INR I'm just writing for both okay or
  4950. 4:43:55for any of the user USD INR euros
  4951. 4:43:59whatever pounds whatever okay you just
  4952. 4:44:01have to write it uh one currency not you
  4953. 4:44:05know multiple like this USD INR okay or
  4954. 4:44:08uh separated by you know slash no USD
  4955. 4:44:12okay USD INR okay INR
  4956. 4:44:15Okay. Fine. GBP and whatever
  4957. 4:44:19fine. Okay. Yeah. And the next thing is
  4958. 4:44:23status. So my status is created. And the
  4959. 4:44:26last thing is Razer Pay key ID. Okay. So
  4960. 4:44:29ID which I'm getting from the Razer Pay.
  4961. 4:44:32Let me set it. Okay. Razer Pay key ID.
  4962. 4:44:35And that is done. Okay. Done. Okay. Let
  4963. 4:44:38me just close this. And uh with this we
  4964. 4:44:43have completed our first method that is
  4965. 4:44:46our create payment order. Fine. Next
  4966. 4:44:49method come ups that is our web hook. Hm
  4967. 4:44:52handle web hook. Yeah. So remember one
  4968. 4:44:55thing. Okay. One note point
  4969. 4:44:58H. So for the real payments you know
  4970. 4:45:02payments okay web hook is not mandatory
  4971. 4:45:06but it is recommended. Okay. and most
  4972. 4:45:09important functionality because you know
  4973. 4:45:12payment gateways like uh stripe okay or
  4974. 4:45:16razor pay we are using so you know they
  4975. 4:45:19have web hook and what web hook does is
  4976. 4:45:23it capture events
  4977. 4:45:26you know so web hook contains you know
  4978. 4:45:28around 100 plus events okay for all the
  4979. 4:45:31payment related events like if payment
  4980. 4:45:34is failed so web hook has the event
  4981. 4:45:37payment failed Okay, payment success,
  4982. 4:45:39order created, order you know cancelled,
  4983. 4:45:42payment pending, whatever 100 plus
  4984. 4:45:45events.
  4985. 4:45:47Okay, so whatever happens in the you
  4986. 4:45:49know at the time of checkout let's say
  4987. 4:45:52you have purchased something uh from
  4988. 4:45:53Amazon and uh here is my checkout page
  4989. 4:45:56and let's say payment failed.
  4990. 4:46:00So our web hook captured that event and
  4991. 4:46:03notify to our back end.
  4992. 4:46:07Why? Because in the back end we have
  4993. 4:46:09returned a method to handle uh you know
  4994. 4:46:13failure events like you know in coming
  4995. 4:46:16few minutes we'll uh write we'll
  4996. 4:46:18implement the method handle payment
  4997. 4:46:20failure.
  4998. 4:46:22Okay. And let's say if suppose payment
  4999. 4:46:25got successful. So first web hook
  5000. 4:46:28capture that event. Yeah we see we need
  5001. 4:46:31something from the payment gateway side.
  5002. 4:46:34This is another resource. This is not a
  5003. 4:46:36part of our uh code, not a part of our
  5004. 4:46:39digital banking system. Payment gateway
  5005. 4:46:41is another you know resource, another
  5006. 4:46:43company.
  5007. 4:46:45So payment gateway provides a web hook
  5008. 4:46:48which capture the events okay on the
  5009. 4:46:51front end side and notify to our back
  5010. 4:46:54end so that we can you know uh take
  5011. 4:46:58action after that. If failed then what?
  5012. 4:47:03If success then what we just need our
  5013. 4:47:06back end just need our banking system
  5014. 4:47:08just need uh that web hook notify us
  5015. 4:47:12okay and then finally we'll uh proceed
  5016. 4:47:15forward according to that okay as per
  5017. 4:47:17our code yeah so that is what and yeah
  5018. 4:47:21definitely I'll show you we'll set up
  5019. 4:47:23our web hook okay I'll show you the all
  5020. 4:47:25the events okay while setting up uh in
  5021. 4:47:28our testing part okay yeah so fine
  5022. 4:47:33Let's first code our you know web hook
  5023. 4:47:36handle webbook method and then we'll uh
  5024. 4:47:39also implement the payment success and
  5025. 4:47:42payment failure events. Okay. Yeah.
  5026. 4:47:45Let's proceed. So public and what it is
  5027. 4:47:51handle web hook. Okay.
  5028. 4:47:54void and handle web hook map
  5029. 4:48:01a string object
  5030. 4:48:06payload. Yeah.
  5031. 4:48:08Now log dot info. Okay. So here first
  5032. 4:48:14whatever payment status okay that failed
  5033. 4:48:18dot success. So here received
  5034. 4:48:21Razer Pay
  5035. 4:48:23web hook. Okay. And payload dot get
  5036. 4:48:30event.
  5037. 4:48:32Yes. Okay. Now a string event equals
  5038. 4:48:39let me just
  5039. 4:48:41copy this payload dot
  5040. 4:48:45get event and type casted. Fine. And now
  5041. 4:48:51if if just listen to me, okay, pay
  5042. 4:48:54attention here. Payment dot there is one
  5043. 4:48:58event captured. Okay. So, payment dot
  5044. 4:49:01captured
  5045. 4:49:03dot equals
  5046. 4:49:06this event.
  5047. 4:49:08If it is then our we need to handle
  5048. 4:49:12payment payment
  5049. 4:49:16success. Okay, that is what you know uh
  5050. 4:49:18payment successful.
  5051. 4:49:20Yeah. So, let me create another method
  5052. 4:49:22for that and we'll handle the payment
  5053. 4:49:25success.
  5054. 4:49:27else if
  5055. 4:49:31our payment dot failed.
  5056. 4:49:35Okay, there is one more event. I'll show
  5057. 4:49:37you the list of events. Okay, equals
  5058. 4:49:41event.
  5059. 4:49:43Okay, then uh we'll handle our payment
  5060. 4:49:49failure.
  5061. 4:49:50Okay, and we'll pass the payload. Yeah.
  5062. 4:49:54Okay, fine. So now let's implement these
  5063. 4:49:58two method. Handle payment success.
  5064. 4:50:01Okay. Private void handle payment
  5065. 4:50:05success. Okay. And let me open my try
  5066. 4:50:08catch.
  5067. 4:50:11So first I need to extract the data from
  5068. 4:50:14the payload. Okay. So how to do it? Map
  5069. 4:50:19and a string object. Okay. and payment
  5070. 4:50:27data equals let me create one more
  5071. 4:50:30method
  5072. 4:50:32extract
  5073. 4:50:34payment data okay and I'll pass the
  5074. 4:50:38payload okay we'll implement this method
  5075. 4:50:40and we'll extract the data fine then
  5076. 4:50:44from that data I need few things just
  5077. 4:50:46like order ID so payment
  5078. 4:50:51you
  5079. 4:50:53payment data. There's payment data.
  5080. 4:50:56Okay. Extracted one. And dot get
  5081. 4:51:01what?
  5082. 4:51:02Order ID. Yeah. Fine. Okay. And the same
  5083. 4:51:07way how I'm writing.
  5084. 4:51:09Okay. A string. Fine. One second.
  5085. 4:51:14Payment. Okay. Here to payment.
  5086. 4:51:18Fine. And also I need a payment id.
  5087. 4:51:24Okay. So from the payment data okay dot
  5088. 4:51:28get
  5089. 4:51:29fine and id also let me type cast
  5090. 4:51:36a string. Yes. Okay. Fine. So now let me
  5091. 4:51:40get the payment and using order ID.
  5092. 4:51:44Okay. So, payment and payment equals
  5093. 4:51:50payment repository dot
  5094. 4:51:54find by Razer Pay. Razer
  5095. 4:52:00uh yeah, Razer Pay order ID. Okay. And
  5096. 4:52:05let me pass the order ID. Okay. Find by
  5097. 4:52:08Razer Pay order ID. So, let's create
  5098. 4:52:10this method in our payment repository.
  5099. 4:52:14So optional
  5100. 4:52:17and
  5101. 4:52:18payment
  5102. 4:52:20and I'm passing the order id. Okay. So
  5103. 4:52:26dot or else throw and new runtime
  5104. 4:52:33exception what payment not
  5105. 4:52:40found for order. Okay. See because
  5106. 4:52:45uh as we have already written in the
  5107. 4:52:47flow create order in Razer Pay and then
  5108. 4:52:50save payment record return order. Okay.
  5109. 4:52:54So at the time of uh you know handling
  5110. 4:52:56the success payment we need to get by
  5111. 4:53:02order ID. Okay. Payment not found for
  5112. 4:53:05order.
  5113. 4:53:07Okay. and
  5114. 4:53:10order ID.
  5115. 4:53:12Okay, if yes, then first we'll set the
  5116. 4:53:16payment ID. Okay, so set Razer Pay
  5117. 4:53:19payment ID which is payment ID. Okay,
  5118. 4:53:22and then we need to set the status
  5119. 4:53:25payment dot set status as completed.
  5120. 4:53:30H because you know we are handling the
  5121. 4:53:32payment success. So it only triggers
  5122. 4:53:36when our web hook which is a integrated
  5123. 4:53:40you know uh functionality of razer pay.
  5124. 4:53:43So it captured success payment okay its
  5125. 4:53:45own headache and then we are just
  5126. 4:53:47handling the payment success okay to
  5127. 4:53:51proceed forward
  5128. 4:53:53and then we'll save that saved fine then
  5129. 4:53:57now publish payment
  5130. 4:54:01completed event to Kafka
  5131. 4:54:06okay
  5132. 4:54:08yeah so map
  5133. 4:54:11and a string
  5134. 4:54:14object event equals new hashmap.
  5135. 4:54:20Okay. And then what we need to put so
  5136. 4:54:24first let's put the payment ID. Okay. So
  5137. 4:54:31payment dot get ID. Yeah. And then let's
  5138. 4:54:36put our
  5139. 4:54:38account number. So yeah from the same
  5140. 4:54:43thing payment dot get account number
  5141. 4:54:47and then let's put
  5142. 4:54:51uh what
  5143. 4:54:53event doput
  5144. 4:54:56um okay
  5145. 4:55:00payment payment
  5146. 4:55:02where is that yeah
  5147. 4:55:06amount yeah okay
  5148. 4:55:10So
  5149. 4:55:12amount and
  5150. 4:55:14yes get amount and one more thing. Okay.
  5151. 4:55:18So one more thing
  5152. 4:55:24Razer Pay payment ID. Okay. This one.
  5153. 4:55:29So event dot put
  5154. 4:55:34and Razer Pay payment ID.
  5155. 4:55:38This is our payment ID. Okay. And then
  5156. 4:55:42Kafka dot
  5157. 4:55:46Okay. I guess uh yeah,
  5158. 4:55:50private final Kafka
  5159. 4:55:54and template string
  5160. 4:55:57object
  5161. 4:55:59Kafka template. Okay.
  5162. 4:56:03Then yeah, Kafka
  5163. 4:56:07template dot send. Okay. So, payment
  5164. 4:56:13completed topic.
  5165. 4:56:16Okay. Then payment dot get id
  5166. 4:56:21get ID and what event.
  5167. 4:56:27Okay. and log.info
  5168. 4:56:30our payment
  5169. 4:56:33completed
  5170. 4:56:36and payment dot get
  5171. 4:56:40ID.
  5172. 4:56:42Okay. Yeah. And log dot error. So error
  5173. 4:56:50handling
  5174. 4:56:52payment success
  5175. 4:56:55e dot get message.
  5176. 4:56:59Fine. Done. Now let's handle our payment
  5177. 4:57:03failure. Okay. So private void handle
  5178. 4:57:09payment failure.
  5179. 4:57:11Okay. And
  5180. 4:57:13fine. So same thing. Let me first open
  5181. 4:57:17try and catch. Now let me copy few
  5182. 4:57:22things. First let me same thing extract
  5183. 4:57:25the payment data. Okay. And then uh yeah
  5184. 4:57:30also I need order ID. Okay. Failure or
  5185. 4:57:34success I need order ID. Okay. First
  5186. 4:57:37order created. Okay. Then uh yeah also I
  5187. 4:57:41need my payment by order ID. Okay. Then
  5188. 4:57:48I need to set the status.
  5189. 4:57:52Okay. So
  5190. 4:57:55no I don't need this payment ID. Okay.
  5191. 4:57:58Because payment failed. So just this
  5192. 4:58:03two.
  5193. 4:58:04Okay. And also I have one more field.
  5194. 4:58:08Okay. H failure reason. Okay. So,
  5195. 4:58:12payment status as failed
  5196. 4:58:16and payment dot set failure reason.
  5197. 4:58:22Okay. Payment failed via
  5198. 4:58:27Razer Pay. Okay. And we'll save it and
  5199. 4:58:32then we'll publish. Okay. So let me just
  5200. 4:58:35copy this and
  5201. 4:58:38let me just check. So event payment ID,
  5202. 4:58:42account number, amount. Okay. And here
  5203. 4:58:47reason. Okay. So reason is uh same thing
  5204. 4:58:52we can uh
  5205. 4:58:55add payment field via Razer Pay. Yeah.
  5206. 4:58:59Okay. And then then what? Kafka template
  5207. 4:59:06dot send
  5208. 4:59:09here it should be failed. Okay.
  5209. 4:59:13Yeah. Failed topic.
  5210. 4:59:18Okay. And get ID event.
  5211. 4:59:23Yeah. Log dot warning and payment
  5212. 4:59:29failed.
  5213. 4:59:31Okay. Payment dot get ID.
  5214. 4:59:36Got it.
  5215. 4:59:38Log dot error. Okay. So, error handling
  5216. 4:59:45payment
  5217. 4:59:47failure.
  5218. 4:59:50Yes. E dot get message. Fine. Now only
  5219. 4:59:54one thing remaining that is extract
  5220. 4:59:56payment data. Okay. Okay. Fine. So
  5221. 5:00:00nothing big deal. Let me just implement
  5222. 5:00:03it. Private and returning the map string
  5223. 5:00:08object. Okay.
  5224. 5:00:10Extract payment data H. So map and a
  5225. 5:00:16string
  5226. 5:00:19a string
  5227. 5:00:21object. Okay. And let it be entity.
  5228. 5:00:26Okay. Fine. uh equals
  5229. 5:00:31payload dot get okay the entire payload
  5230. 5:00:36and I'll type cast it as
  5231. 5:00:40map
  5232. 5:00:42and yeah a string object
  5233. 5:00:46okay then what then map a string object
  5234. 5:00:51and I need the wrapper
  5235. 5:00:54okay so
  5236. 5:00:56wrapper Or I can just write payment
  5237. 5:01:01wrapper equals
  5238. 5:01:03okay entity from the entity let me get
  5239. 5:01:07the payment
  5240. 5:01:11okay and I'll type cast it as map okay
  5241. 5:01:18okay and then finally let me return
  5242. 5:01:22what payment wrapper dot get
  5243. 5:01:27entity entity. Okay. Yeah. Entity
  5244. 5:01:31and uh then type cast it as Okay. Fine.
  5245. 5:01:36So
  5246. 5:01:38I got my you know extracted data done.
  5247. 5:01:42So this is done. We have implemented the
  5248. 5:01:46entire order. Okay. Order done. saved
  5249. 5:01:49and then handle status, payment success,
  5250. 5:01:52payment failure, handle web hook is all
  5251. 5:01:56done. Yeah. Okay. Now, now what? Now,
  5252. 5:02:01let me just add the configurations. So,
  5253. 5:02:04add configuration.
  5254. 5:02:07Okay.
  5255. 5:02:09Public web MVC configure. Okay. So now
  5256. 5:02:15return new web MVC configur inside
  5257. 5:02:21uh you know we'll override that method.
  5258. 5:02:24So public okay and yeah definitely
  5259. 5:02:29add cross origin mappings. Okay. Add
  5260. 5:02:33override.
  5261. 5:02:35Okay. And then registry dot add
  5262. 5:02:39mappings. Here we have added what? API.
  5263. 5:02:43Yeah. Dot allowed origins.
  5264. 5:02:47So yeah. And then dot allowed methods.
  5265. 5:02:52Get
  5266. 5:02:54and post put delete. Okay. Allowed
  5267. 5:02:58headers. Okay.
  5268. 5:03:02And
  5269. 5:03:04uh yeah, that's it. Fine.
  5270. 5:03:09Okay. Done.
  5271. 5:03:12Also
  5272. 5:03:14at bin H.
  5273. 5:03:19Yeah.
  5274. 5:03:20Done. Now only one thing remaining that
  5275. 5:03:23is our properties file. Let's do it.
  5276. 5:03:27Okay. Fine. So spring application
  5277. 5:03:32name
  5278. 5:03:34payment service. Okay. Then data source.
  5279. 5:03:39Okay. So just let me copy paste from my
  5280. 5:03:44account service. Okay. I have yeah this
  5281. 5:03:47one. Okay. Till dialect.
  5282. 5:03:52Okay.
  5283. 5:03:54So
  5284. 5:03:56and here I need another database. Okay.
  5285. 5:04:01See how many database we are using.
  5286. 5:04:04Okay. And everything
  5287. 5:04:07fine. JPA hibernate dialect. Okay. Now
  5288. 5:04:10my Kafka properties. So that too. Let me
  5289. 5:04:16just
  5290. 5:04:18get it. One second. So we have
  5291. 5:04:24uh published. Yes, just published. Just
  5292. 5:04:27published. Okay. If just published then
  5293. 5:04:30we don't need consumer.
  5294. 5:04:33So we just need this producer.
  5295. 5:04:36Okay. And where is my payment?
  5296. 5:04:42So first I need my bootstrap
  5297. 5:04:47servers localhost
  5298. 5:04:499092
  5299. 5:04:52and then just producer
  5300. 5:04:55fine
  5301. 5:04:57server
  5302. 5:04:58dot port 8083.
  5303. 5:05:03Okay. Yeah. Three is missing. Okay.
  5304. 5:05:06Fine. Now our Razer Pay configuration.
  5305. 5:05:11So razor pay
  5306. 5:05:15config
  5307. 5:05:17duration.
  5308. 5:05:19Okay. So what we have you know just
  5309. 5:05:24added the variables razer pay dot key ID
  5310. 5:05:28and key secret.
  5311. 5:05:31Okay. Razer pay.
  5312. 5:05:35So Razer Pay dot key ID. Okay. So you
  5313. 5:05:40know it's like some uh R Z P and
  5314. 5:05:45something like fine and then uh key
  5315. 5:05:50secret. Okay. And uh then our you know
  5316. 5:05:55what
  5317. 5:05:57web hook
  5318. 5:05:58and
  5319. 5:06:00secret. Okay. Yeah. Next is yeah simple
  5320. 5:06:05management.
  5321. 5:06:06Okay. Then endpoints
  5322. 5:06:09web
  5323. 5:06:11exposure
  5324. 5:06:14include
  5325. 5:06:15health
  5326. 5:06:17and info. Okay. Fine. So this is what
  5327. 5:06:22completed each and everything. Okay. Now
  5328. 5:06:26only our last thing remaining that is
  5329. 5:06:30what our API gateway need to set the
  5330. 5:06:35routing and
  5331. 5:06:37uh configuration for rate limiting.
  5332. 5:06:41Okay. Yeah. So without wasting much time
  5333. 5:06:44let's start and let's go. Okay. So let's
  5334. 5:06:47start with our API gateway all the
  5335. 5:06:49routings and uh configurations. Okay. So
  5336. 5:06:53at first let me code my rate limiter
  5337. 5:06:55config.
  5338. 5:06:59Rate limiter config. Okay.
  5339. 5:07:05Configuration.
  5340. 5:07:08Fine. Public and key resolver. Key
  5341. 5:07:13resolver.
  5342. 5:07:14Okay. Key resolver.
  5343. 5:07:17Then return exchange.
  5344. 5:07:21Okay.
  5345. 5:07:22Then mono dot just
  5346. 5:07:27exchange dot get request dot get remote
  5347. 5:07:33address. Okay. Then dot get address and
  5348. 5:07:36dot host host address.
  5349. 5:07:40Yeah.
  5350. 5:07:41Okay.
  5351. 5:07:43At bin. That's it. And now let's add the
  5352. 5:07:48routings in our application dotl.
  5353. 5:07:52So spring application
  5354. 5:07:56name api
  5355. 5:07:59gateway. Okay. And then data
  5356. 5:08:04radius host. So local host and
  5357. 5:08:12local host and port 6379.
  5358. 5:08:17Yeah. And then what? Cloud
  5359. 5:08:22gateway
  5360. 5:08:24and routes.
  5361. 5:08:27Okay. Yeah. Now let's start. So account
  5362. 5:08:33service
  5363. 5:08:35routes. Okay.
  5364. 5:08:39One second.
  5365. 5:08:42Okay. Fine.
  5366. 5:08:45Yeah.
  5367. 5:08:47So now
  5368. 5:08:50ID
  5369. 5:08:52account
  5370. 5:08:54service. Okay. Then URI. So HTTP
  5371. 5:09:00localhost
  5372. 5:09:02and 80 81. and then predicates.
  5373. 5:09:09So
  5374. 5:09:11path. Okay. So path is what? API v1 and
  5375. 5:09:18accounts. Yeah. Okay. Fine. Then
  5376. 5:09:21filters.
  5377. 5:09:23Okay. So yeah, filters.
  5378. 5:09:27Okay.
  5379. 5:09:29name is
  5380. 5:09:31request
  5381. 5:09:33rate
  5382. 5:09:34limiter.
  5383. 5:09:36Okay. And
  5384. 5:09:39arcs radius
  5385. 5:09:42rate
  5386. 5:09:44limiter and replenish rate. Okay.
  5387. 5:09:52Rate. Okay. Let me keep it as 10.
  5388. 5:09:56Okay. also the burst capacity.
  5389. 5:09:59So rate limiter
  5390. 5:10:03and
  5391. 5:10:04burst capacity
  5392. 5:10:1020. Fine. Okay. Now the same thing goes
  5393. 5:10:18with our transaction service. Okay.
  5394. 5:10:23Uh yeah
  5395. 5:10:26fine. So here
  5396. 5:10:29transaction service routes.
  5397. 5:10:33Okay. And
  5398. 5:10:36transaction service localhost 8082
  5399. 5:10:42API v1
  5400. 5:10:46transactions.
  5401. 5:10:47Fine. And yeah, next is our payment
  5402. 5:10:52service. Okay.
  5403. 5:10:55So,
  5404. 5:10:57okay.
  5405. 5:10:59Here payment service routes
  5406. 5:11:03and payment service
  5407. 5:11:078083
  5408. 5:11:08API v1 payments.
  5409. 5:11:13Okay. One second.
  5410. 5:11:17uh in our Java.
  5411. 5:11:22Okay, fine. API v1 payments.
  5412. 5:11:26Yeah. Okay, that's it.
  5413. 5:11:30Uh also
  5414. 5:11:32payment service. Fine. So let me just
  5415. 5:11:35modify this as five and 10 H. Now it is
  5416. 5:11:41good. Okay. So now this will be our
  5417. 5:11:45entry point. So server.port 8080. Okay.
  5418. 5:11:498080
  5419. 5:11:51and then
  5420. 5:11:53management then endpoints
  5421. 5:11:57web
  5422. 5:12:00exposure.
  5423. 5:12:02Okay. Include here health info and
  5424. 5:12:08gateway.
  5425. 5:12:12Okay. Yeah. Health info and gateway.
  5426. 5:12:17Okay. This is done. Now what else
  5427. 5:12:19remaining is uh I guess in our
  5428. 5:12:22notification service
  5429. 5:12:25uh yeah notification service. Okay. So I
  5430. 5:12:28told you that uh you know we have
  5431. 5:12:31consumed we have already consumed our
  5432. 5:12:33OTP generated event. Okay. And uh also
  5433. 5:12:38we have created send alert method. Okay,
  5434. 5:12:41you can see this.
  5435. 5:12:43Yeah, this one. Now, uh we need to also
  5436. 5:12:47consume few more methods. What methods?
  5437. 5:12:49So, you know, uh if suppose transaction
  5438. 5:12:53transaction is completed.
  5439. 5:12:56Okay. So, in that case we need to
  5440. 5:12:59consume that uh you know the completed
  5441. 5:13:02event and need to update or notify to
  5442. 5:13:05the user. Yeah. So in that case we need
  5443. 5:13:10to notify both the user sender and
  5444. 5:13:13receiver that uh you know some x amount
  5445. 5:13:17debited. Okay. And some x amount
  5446. 5:13:21credited.
  5447. 5:13:22Yes or no? Yeah. So we need to you know
  5448. 5:13:25just notify the debit alert credit
  5449. 5:13:27alert. Okay. Second thing is if suppose
  5450. 5:13:30fraud is detected, if suppose any
  5451. 5:13:32suspicious activity detected then in
  5452. 5:13:35that case too we need to notify to the
  5453. 5:13:37user.
  5454. 5:13:38Okay fine. Uh third case is um you know
  5455. 5:13:43in case of Razer Pay Razer Pay or I'm
  5456. 5:13:46talking about external payments. Okay.
  5457. 5:13:49Suppose you have purchased something
  5458. 5:13:50from the Amazon.
  5459. 5:13:52Okay. Or you know whatever website.
  5460. 5:13:54Okay. And uh once you click on the check
  5461. 5:13:57out button okay so it will take you on
  5462. 5:14:00some check out page banking page okay
  5463. 5:14:02and something got failed there something
  5464. 5:14:04got failed or the bank you know uh the
  5465. 5:14:07payment got success okay so we also need
  5466. 5:14:11to handle that case
  5467. 5:14:14you know that is what the external
  5468. 5:14:15payment suppose you are paying to some
  5469. 5:14:17external merchants okay so we also need
  5470. 5:14:21to handle payment success and handle
  5471. 5:14:24payment failure. Okay. Yeah. So I
  5472. 5:14:27already told you that we need to inform
  5473. 5:14:29user each and every money moment where
  5474. 5:14:32his money is going and that is what the
  5475. 5:14:34real banking application do. Okay. Yeah.
  5476. 5:14:37So you know that is quite most important
  5477. 5:14:40and uh yeah we can't left it. So let's
  5478. 5:14:43implement that too. Okay.
  5479. 5:14:46Yeah.
  5480. 5:14:49So at first we have consumed OTP
  5481. 5:14:52generated. Okay. The next is public
  5482. 5:14:54void. Yeah. Any guesses? Okay. Consume
  5483. 5:14:58transaction
  5484. 5:15:00completed.
  5485. 5:15:02Fine. Add payload.
  5486. 5:15:05Okay. And map. Okay. Let me just copy
  5487. 5:15:09and paste. Okay.
  5488. 5:15:12Fine.
  5489. 5:15:15Yeah. Okay. And uh
  5490. 5:15:20here this is at Kafka listener. Okay.
  5491. 5:15:24Topic is what h in our transaction
  5492. 5:15:28service. Okay. Transaction service
  5493. 5:15:31and src main service. Transaction
  5494. 5:15:36service. Okay. Um yeah. Can you see this
  5495. 5:15:39transaction initiated topic transaction
  5496. 5:15:42completed topic? Okay. If transaction is
  5497. 5:15:45completed then we need to you know
  5498. 5:15:47consume this event and notify both the
  5499. 5:15:50users. Okay. So back to our notification
  5500. 5:15:54service and topic is our transaction dot
  5501. 5:15:57completed. Okay. Now let me open my try
  5502. 5:16:01catch.
  5503. 5:16:02Okay
  5504. 5:16:04fine. And first let me you know get my
  5505. 5:16:10sender account. Okay. sender account
  5506. 5:16:14equals
  5507. 5:16:17payload dot get
  5508. 5:16:20sender
  5509. 5:16:22account number.
  5510. 5:16:24Oh yeah. Okay. And also let me type cast
  5511. 5:16:28it a string. Fine. Okay. Next is
  5512. 5:16:34what? Receiver. Same thing with a
  5513. 5:16:37receiver. receiver account equals
  5514. 5:16:40payload dot get and receiver account
  5515. 5:16:46number. Okay,
  5516. 5:16:50fine.
  5517. 5:16:52H yeah. So let me do the same thing. Let
  5518. 5:16:55me type cast it. Okay. And third thing I
  5519. 5:16:59need what? I need the amount. Okay. So a
  5520. 5:17:03string amount equals
  5521. 5:17:06payload dot get okay and amount dot to a
  5522. 5:17:13string.
  5523. 5:17:14Yeah. Okay. Fine. Now let me call this
  5524. 5:17:18method. Okay. Send alert. So send alert.
  5525. 5:17:24Okay. And what I'm passing first first
  5526. 5:17:28let me also write comments debit alert.
  5527. 5:17:33Okay. So in the debit alert first let me
  5528. 5:17:35pass the sender account. Okay. Then I'm
  5529. 5:17:38accepting subject. Okay. So subject is
  5530. 5:17:41let's say debit alert. Okay. And finally
  5531. 5:17:45message. Okay. So first let me format a
  5532. 5:17:49string dot format. Okay. And then then
  5533. 5:17:54what? So percent s percent s
  5534. 5:17:58debited
  5535. 5:17:59h from account which account
  5536. 5:18:05okay account and percent s okay so uh
  5537. 5:18:12percent s debited okay that means amount
  5538. 5:18:15debited from account sender account okay
  5539. 5:18:19h yeah yeah
  5540. 5:18:21fine sounds good and Now credit alert.
  5541. 5:18:27So similarly, okay, let me just copy
  5542. 5:18:30this and paste it here. Instead of
  5543. 5:18:33sender, it is now receiver and
  5544. 5:18:38it is credit alert. Okay. And percent is
  5545. 5:18:43now it is credited from account and it
  5546. 5:18:47is
  5547. 5:18:49receiver H. Okay. Yeah. Done. And in the
  5548. 5:18:55catch block log dot
  5549. 5:18:58error and error sending transaction
  5550. 5:19:03notification. Okay. Notification. Fine.
  5551. 5:19:08Yeah. And e dot
  5552. 5:19:11uh get message. Okay. Done. Yeah. Done.
  5553. 5:19:15Next thing let's consume our fraud
  5554. 5:19:18detected. Okay. So public void and
  5555. 5:19:21consume fraud detected.
  5556. 5:19:25Yeah. Add payload and again let me just
  5557. 5:19:31directly copy this from here and paste
  5558. 5:19:35it here. Okay. Now add Kafka listener
  5559. 5:19:40and what's the topic? So the topic is
  5560. 5:19:44fraud.detected. Okay. Yeah. Fraud dot
  5561. 5:19:48detected. Where am I? Notification
  5562. 5:19:51service. And here
  5563. 5:19:54topics fraud dot detected. Okay.
  5564. 5:19:58Fine. Now here to let me open first my
  5565. 5:20:02try catch and Okay. So first let me get
  5566. 5:20:08the account number. Okay. Payload dot
  5567. 5:20:13get
  5568. 5:20:15account number. Okay. Let me type cast
  5569. 5:20:18it
  5570. 5:20:20fine.
  5571. 5:20:22Okay. Then also I want reason. Okay.
  5572. 5:20:28Because see if fraud detected then uh
  5573. 5:20:32where is my fraud detection? Yeah it is
  5574. 5:20:34main Java and model. In the model we
  5575. 5:20:38have two fields that is fraud and
  5576. 5:20:39reason. Okay. So I need that too.
  5577. 5:20:43notification service and uh payload dot
  5578. 5:20:47get
  5579. 5:20:49reason. Okay. And this is what my string
  5580. 5:20:55h okay fine now again let me just call
  5581. 5:20:59send alert. Okay. And here let me pass
  5582. 5:21:01the account number. My subject is let's
  5583. 5:21:05say account. Okay. or uh suspicious
  5584. 5:21:11activity
  5585. 5:21:13you know
  5586. 5:21:15detected.
  5587. 5:21:17Okay. And then a string dot format
  5588. 5:21:22H one second. Yeah. So the message will
  5589. 5:21:27write as your account you know percent s
  5590. 5:21:33has been blocked.
  5591. 5:21:36Okay. And
  5592. 5:21:42next is this is what reason. Okay. And
  5593. 5:21:47percent s
  5594. 5:21:49percent s m. Okay. and
  5595. 5:21:56and what please
  5596. 5:22:00contact
  5597. 5:22:02your bank immediately. Okay. So
  5598. 5:22:10yeah fine. Okay. So
  5599. 5:22:17it is your account. Okay. Account number
  5600. 5:22:20and reason. Re reason. Yes.
  5601. 5:22:25Okay, that's it. And in our catch block
  5602. 5:22:29log dot error and error sending fraud
  5603. 5:22:35alert
  5604. 5:22:37e dot get message.
  5605. 5:22:41Okay, it's done. Fine. Next is we are
  5606. 5:22:44consuming our refunded event. Okay, if
  5607. 5:22:47you know uh something got failed and our
  5608. 5:22:50bank process the refund you know refund
  5609. 5:22:54process let me you know consume that
  5610. 5:22:58okay public void consume
  5611. 5:23:03and transaction
  5612. 5:23:05refunded
  5613. 5:23:07okay
  5614. 5:23:09then I'm getting the payload
  5615. 5:23:14yeah Okay,
  5616. 5:23:17here at Kafka listener. Okay, what's the
  5617. 5:23:21topic? Transaction service and yeah,
  5618. 5:23:25transaction dot refunded. H okay.
  5619. 5:23:30Notification service and
  5620. 5:23:33topic
  5621. 5:23:35transaction dotreunded. Okay, fine. Let
  5622. 5:23:37me open my try catch. Okay. And here. So
  5623. 5:23:45let me get my first sender account.
  5624. 5:23:47Okay. Already the code is there. Just
  5625. 5:23:49need to copy
  5626. 5:23:51get sender account. Okay. H then uh I
  5627. 5:23:56need amount. Okay. Refund. So you know I
  5628. 5:24:01need the amount.
  5629. 5:24:03Okay. I'm getting it. And then
  5630. 5:24:07uh refund. Okay. So also I need reason.
  5631. 5:24:11Okay. reason I'm getting okay I got it
  5632. 5:24:15fine now let me call send alert again
  5633. 5:24:18and first my sender account okay the
  5634. 5:24:22subject I put as refund and processed
  5635. 5:24:28okay and message string dot format
  5636. 5:24:33okay so your transaction of percent s
  5637. 5:24:40was cancelled
  5638. 5:24:42Okay.
  5639. 5:24:45And
  5640. 5:24:46transaction cancelled. Okay. And percent
  5641. 5:24:49s has been
  5642. 5:24:52refunded
  5643. 5:24:54to account percent s. Okay. And what? So
  5644. 5:25:00your transaction of
  5645. 5:25:03uh one second. What is that?
  5646. 5:25:07Transaction of percentile was canceled.
  5647. 5:25:09And okay percent s
  5648. 5:25:13has been refunded to percent s
  5649. 5:25:16h
  5650. 5:25:18also also let me just you know
  5651. 5:25:22uh yeah let me give the reason two so
  5652. 5:25:28percent s
  5653. 5:25:30okay yeah now it is fine
  5654. 5:25:35so there are total four fields we need
  5655. 5:25:38to fill Okay. So your transaction of
  5656. 5:25:42amount. Okay. And reason is reason.
  5657. 5:25:46Okay. Then percent as has been refunded.
  5658. 5:25:48Okay. So that to amount. Okay. And
  5659. 5:25:52refunded to account sender account.
  5660. 5:25:55Okay. Done. Yeah. Now in our catch block
  5661. 5:25:59log dot error and error sending
  5662. 5:26:06refund notification.
  5663. 5:26:10Okay. E dot get message.
  5664. 5:26:16Yes. Done. Next is next two more uh you
  5665. 5:26:21know we need to consume two more events.
  5666. 5:26:23Okay. So that two of our payment service
  5667. 5:26:28first is public void and consume payment
  5668. 5:26:33completed.
  5669. 5:26:35Okay. So yeah same thing at payload
  5670. 5:26:40payload
  5671. 5:26:42H. Yeah.
  5672. 5:26:45Okay. And at Kafka listener. So we
  5673. 5:26:51already seen we coded our payment
  5674. 5:26:54service just few minutes before. Okay.
  5675. 5:26:58And our payment service payment service.
  5676. 5:27:01Yeah. Payment completed and payment
  5677. 5:27:04failed. So payment dot completed. Okay.
  5678. 5:27:08Fine. And in coming few minutes we are
  5679. 5:27:10going to test it. Okay. Real money uh
  5680. 5:27:14testing. Okay. So topic and payment dot
  5681. 5:27:18completed. now.
  5682. 5:27:21Okay. And what I need? So, first I need
  5683. 5:27:26account number. Okay. I already have
  5684. 5:27:28already coded here. Uh, not here. Not
  5685. 5:27:31here. Yeah, here.
  5686. 5:27:33Account number. Okay. And then I need
  5687. 5:27:38amount. Okay. From here. I get it.
  5688. 5:27:43I got it. Okay. Fine. Now, let me call
  5689. 5:27:46the send alert method. Okay. And let me
  5690. 5:27:49pass account number. Okay. And then the
  5691. 5:27:52subject, let me keep it as payment
  5692. 5:27:58successful. Okay. And then string dot
  5693. 5:28:03format. Okay. The message is payment of
  5694. 5:28:09percent is completed. Okay.
  5695. 5:28:13And
  5696. 5:28:15then then what? So I also need to you
  5697. 5:28:19know just display razor pay id okay and
  5698. 5:28:25that to percent s okay fine
  5699. 5:28:29yeah so
  5700. 5:28:32um payment of percent s okay so payment
  5701. 5:28:35of amount and razer pay id okay so that
  5702. 5:28:40to let me get it from payload okay so
  5703. 5:28:43payload dot get and razer pay. Okay.
  5704. 5:28:47What's that?
  5705. 5:28:49Payment. Payment service
  5706. 5:28:53entity. Okay.
  5707. 5:28:56Razer Pay payment ID. Okay. Fine. Back
  5708. 5:29:00to our notification service and Razer
  5709. 5:29:04Pay payment ID.
  5710. 5:29:06Yeah,
  5711. 5:29:09looks good. Now log dot error in the
  5712. 5:29:13exception. Okay. Error sending
  5713. 5:29:19error sending payment notification.
  5714. 5:29:24Okay. And e do.get message. Fine.
  5715. 5:29:28Similarly, let me also consume you know
  5716. 5:29:30payment failed. Okay. In uh payment
  5717. 5:29:34gateway side if something got failed.
  5718. 5:29:35Okay. So that two we are handling. Okay.
  5719. 5:29:38So public void consume
  5720. 5:29:42payment
  5721. 5:29:44failed.
  5722. 5:29:46Okay. And payload.
  5723. 5:29:49So
  5724. 5:29:51okay fine. Thank you for autopop
  5725. 5:29:55populating. Okay. Add kafka listener.
  5726. 5:29:59What's the you know
  5727. 5:30:02topic name? Payment service. And here we
  5728. 5:30:05are payment dot failed.
  5729. 5:30:09Okay.
  5730. 5:30:11Notification service and
  5731. 5:30:14topics
  5732. 5:30:16payment dot failed. Yeah. Try catch.
  5733. 5:30:21Okay. Exception
  5734. 5:30:24and
  5735. 5:30:27yeah. So now in this two let me directly
  5736. 5:30:31copy and paste both of these fields
  5737. 5:30:33account number and amount. Okay. done.
  5738. 5:30:38And then uh send alert. Okay, I'm
  5739. 5:30:42passing account number. Okay, in this
  5740. 5:30:44case, subject is my payment and failed.
  5741. 5:30:49Okay, and uh also one more thing. Yeah.
  5742. 5:30:54So, a string dot format. Yeah. And uh
  5743. 5:31:01your payment of percent s
  5744. 5:31:06could could not be
  5745. 5:31:09could not be processed. Okay.
  5746. 5:31:17And
  5747. 5:31:19then what? Please try again our
  5748. 5:31:24contact support.
  5749. 5:31:29Fine. Yeah, that will be good. And we
  5750. 5:31:32have you know your payment of okay
  5751. 5:31:35amount. That's it. Could not be
  5752. 5:31:37processed. Please try again or contact
  5753. 5:31:39support. Okay. in the catch block log
  5754. 5:31:42dot
  5755. 5:31:44error and
  5756. 5:31:47error
  5757. 5:31:50sending.
  5758. 5:31:53Okay, payment failure.
  5759. 5:31:59Yeah, we need to specify
  5760. 5:32:01and notification
  5761. 5:32:04e dot get message. Okay, so it is done.
  5762. 5:32:07We have consumed all our you know uh
  5763. 5:32:11events.
  5764. 5:32:12Yeah. The first thing is OTP generated.
  5765. 5:32:15Okay. Find and then uh what
  5766. 5:32:20transaction completed debit alert credit
  5767. 5:32:22alert and then if fraud detected that
  5768. 5:32:24two we have consumed and then refunded
  5769. 5:32:27also we have consumed payment completed
  5770. 5:32:30and payment failed. Fine. So in each
  5771. 5:32:33method we are you know calling one
  5772. 5:32:35method that is send alert. Okay, because
  5773. 5:32:37this method is only responsible to send
  5774. 5:32:39alert and notify my user. Okay, so for
  5775. 5:32:42now let me take all the alerts and
  5776. 5:32:44notification in my logs my log terminal.
  5777. 5:32:47Okay, because uh as our current focus
  5778. 5:32:50should be on end to end testing of our
  5779. 5:32:53digital banking system application.
  5780. 5:32:55Okay, we need to test the important
  5781. 5:32:57functionality. Okay, most importantly
  5782. 5:33:00you know transfer method. Okay. And then
  5783. 5:33:02what uh in the transaction service we
  5784. 5:33:05have written you know verify OTP method.
  5785. 5:33:08Okay. Before that fraud detection in
  5786. 5:33:10real time. Okay. And uh you know OTP
  5787. 5:33:14generated. Okay. Fine. And uh our
  5788. 5:33:17notification service consume that and it
  5789. 5:33:20will call verify OTP. Fine. And then you
  5790. 5:33:23know refund process and uh properly
  5791. 5:33:26implemented saga implementation. Okay.
  5792. 5:33:29saga pattern and uh compensating. Okay,
  5793. 5:33:32block and compensating and you know
  5794. 5:33:35completing the transaction. Okay, so
  5795. 5:33:38these are what our important
  5796. 5:33:40functionality we need to test it out
  5797. 5:33:42first. Okay, and we need to make sure
  5798. 5:33:43that none of these broke. Okay, if any
  5799. 5:33:46one of these will broke then we need to
  5800. 5:33:48rectify there itself. Okay, once it is
  5801. 5:33:51confirmed that our digital banking
  5802. 5:33:54system ready to move to the production.
  5803. 5:33:56Okay, then we'll implement this
  5804. 5:33:58functionality. Okay, send alert. See,
  5805. 5:34:00this is not important one. Anyway, we
  5806. 5:34:02can take alerts in our logs. Okay, later
  5807. 5:34:05on we can just implement you know SMS
  5808. 5:34:09via Twilio API. Okay, which enables to
  5809. 5:34:13you know uh send the SMS on our WhatsApp
  5810. 5:34:16and uh you know SMS on phone and uh then
  5811. 5:34:19we'll implement you know Java mail.
  5812. 5:34:21Okay. To receive the, you know,
  5813. 5:34:23notification on our mail. Fine. So,
  5814. 5:34:26yeah, our current focus should be on end
  5815. 5:34:28to end testing. Okay. And I recommend
  5816. 5:34:30you not to miss a single second uh of
  5817. 5:34:33our testing part. Yeah, that's it. So,
  5818. 5:34:36let's you know take the alerts in our
  5819. 5:34:39logs and then finally move to our most
  5820. 5:34:41crucial part that is testing. Okay.
  5821. 5:34:44Yeah, let's go. Okay. So log dot info
  5822. 5:34:48and
  5823. 5:34:51okay fine then log dot info. Okay. So
  5824. 5:34:57account
  5825. 5:34:59account number H. Then log dot info.
  5826. 5:35:04Okay. So subject.
  5827. 5:35:07Yeah.
  5828. 5:35:09Uh subject. Okay. Fine. And then log dot
  5829. 5:35:13info message. Okay. And finally
  5830. 5:35:17log.info.
  5831. 5:35:19Let me close it. Okay. Yeah. Okay. Fine.
  5832. 5:35:23So I'm accepting you know all the
  5833. 5:35:26notification alerts in my logs. Okay.
  5834. 5:35:29Okay. Fine. Fine. Fine. For now. This is
  5835. 5:35:31good. Okay. And let's shift all the
  5836. 5:35:34focus should be on our testing part.
  5837. 5:35:37Okay. Yeah. Fine. So before we start
  5838. 5:35:40testing, let me just check all the
  5839. 5:35:43files. Okay. whether uh any of the file
  5840. 5:35:45remain untouched. Okay. So I guess uh
  5841. 5:35:48you know our application Yeah. Okay. So
  5842. 5:35:52application do yiml of our uh
  5843. 5:35:54notification service is incomplete. Let
  5844. 5:35:57us just complete this two. Okay. So
  5845. 5:36:01spring application okay dot name. So it
  5846. 5:36:05is notification
  5847. 5:36:07and service. Fine.
  5848. 5:36:11And then Kafka properties Kafka. Okay.
  5849. 5:36:15Then bootstrap
  5850. 5:36:18servers. Fine. So local host 9092.
  5851. 5:36:24Okay. And then uh let us directly copy
  5852. 5:36:30paste you know the entire consumer and
  5853. 5:36:34producer. Okay. from my transaction
  5854. 5:36:37service or any other service properties
  5855. 5:36:40file you can just copy. Okay. Yeah.
  5856. 5:36:44Done. Okay. The next thing is we just
  5857. 5:36:47need to set the port number. Okay. So my
  5858. 5:36:52applications uh notification service
  5859. 5:36:55should run on the port 8085. Okay. And
  5860. 5:36:58then management dot endpoints dot you
  5861. 5:37:04know web dot exposure and include. So
  5862. 5:37:10health and info.
  5863. 5:37:13Okay fine. Yeah. So now I guess
  5864. 5:37:16everything is done and we are good to go
  5865. 5:37:18for our testing part. So first let me
  5866. 5:37:22close all my services. Okay, let me just
  5867. 5:37:27close all the tabs. Yeah. Okay. So, at
  5868. 5:37:30very first thing what we need to do is
  5869. 5:37:32just pay attention here. What we need to
  5870. 5:37:34do is
  5871. 5:37:36first thing is uh we need to check our
  5872. 5:37:39data flow.
  5873. 5:37:42Okay. Or I can say infrastructure.
  5874. 5:37:45Yeah. That means uh whether our um you
  5875. 5:37:49know services is running or not. Okay.
  5876. 5:37:51Our data services I'm talking about.
  5877. 5:37:53Okay. So you know Radius, Kafka,
  5878. 5:37:58Zookeeper, MySQL.
  5879. 5:38:01Okay. Yeah. Okay. And the second thing
  5880. 5:38:05is um you know we are going to set up
  5881. 5:38:12our Razer Pay
  5882. 5:38:15payment gateway account and we'll get
  5883. 5:38:19key ID and
  5884. 5:38:23key secret.
  5885. 5:38:25Okay. and we'll you know add both of
  5886. 5:38:30these in our payment service
  5887. 5:38:34you know properties file. Okay. Yeah.
  5888. 5:38:37And third thing is
  5889. 5:38:40third thing is what we need to do is we
  5890. 5:38:43need to run the services one by one.
  5891. 5:38:46Okay. Account service you know uh API
  5892. 5:38:49gateway fraud detection notification
  5893. 5:38:51payment service. Okay. Transaction
  5894. 5:38:54service. Fine. And then finally we'll
  5895. 5:38:56open our postman. Okay. And we'll test
  5896. 5:38:59all our you know internal payments and
  5897. 5:39:01uh endpoints one by one. Okay. We'll
  5898. 5:39:03verify and we'll verif uh verify the
  5899. 5:39:06alerts everything else. Okay. And at
  5900. 5:39:09last we'll verify our you know external
  5901. 5:39:11payments that is our Razer Pay site. So
  5902. 5:39:14ready to go. Okay. We are good to go.
  5903. 5:39:17Let me just
  5904. 5:39:20start. Okay. The very first thing is let
  5905. 5:39:22me you know open my Docker. Okay. We
  5906. 5:39:24have already done setting up all the
  5907. 5:39:27environments at the starting of the
  5908. 5:39:28video. Okay, my banking system and
  5909. 5:39:31Kafka, Radius, Zookeeper is up and
  5910. 5:39:34running beautifully. Okay, and the
  5911. 5:39:36fourth service is MySQL. Okay, so MySQL
  5912. 5:39:39I already installed on my local machine.
  5913. 5:39:41So yeah, definitely that to my up and
  5914. 5:39:43running. Next thing is let me go to my
  5915. 5:39:45you know browser and let's set up our
  5916. 5:39:48payment gateway account. Okay. Yeah.
  5917. 5:39:51Okay. So here's my browser and you just
  5918. 5:39:54need to type here Razerpay. Okay, Google
  5919. 5:39:58it and click on the very first link that
  5920. 5:40:00is razor.com. Okay, you can just check
  5921. 5:40:04out the website. Fine. The very first
  5922. 5:40:07thing we need to do is we need to sign
  5923. 5:40:09up. Okay, so just click on the top right
  5924. 5:40:12button, sign up button. Okay, and yeah,
  5925. 5:40:14we'll land here on the sign up page.
  5926. 5:40:16Fine. Now uh
  5927. 5:40:20you know you'll be asked to enter few
  5928. 5:40:24basic details like uh email okay and uh
  5929. 5:40:28phone number you know whatever name and
  5930. 5:40:31everything else okay and at last you
  5931. 5:40:35know the you know payment gateway ask
  5932. 5:40:38you for your bank account details bank
  5933. 5:40:41account details okay in order to collect
  5934. 5:40:44the payments from other users
  5935. 5:40:48Okay. Yeah, definitely. So, bank account
  5936. 5:40:51details and then just click on the next
  5937. 5:40:53next next and you'll land on the you
  5938. 5:40:56know uh dashboard. Okay. Fine. So, I
  5939. 5:41:00already signed up. So, let me just
  5940. 5:41:02directly log into my account. Okay. So
  5941. 5:41:06once you logged into your account and
  5942. 5:41:08you land here okay on the homepage you
  5943. 5:41:11can see there are a lot of options
  5944. 5:41:12payment links payment you know pages
  5945. 5:41:15payment uh razor pay.m me okay link
  5946. 5:41:18invoices payment button and other
  5947. 5:41:20options fine so what you need to do is
  5948. 5:41:24just you know you can see here account
  5949. 5:41:26and settings okay click on this button
  5950. 5:41:29and you land here on the account and uh
  5951. 5:41:32product settings page fine under website
  5952. 5:41:36and app settings. There's a you know
  5953. 5:41:38link API keys. Just click on it. Okay.
  5954. 5:41:41And you land here. Yeah. So you can see
  5955. 5:41:45there are two options website and API
  5956. 5:41:48keys and web hooks. Okay. Yeah. So at
  5957. 5:41:52first here under website and API keys
  5958. 5:41:55you can just first uh if you have then
  5959. 5:41:58you can just add your website or app.
  5960. 5:42:00Okay. And second is API key and
  5961. 5:42:04integration. Okay. So you know you can
  5962. 5:42:07see I already generated one API key.
  5963. 5:42:09Okay. That is key ID and key secret.
  5964. 5:42:12Okay. In case you know you are if you
  5965. 5:42:14are new to the this uh Razer Pay payment
  5966. 5:42:16gateway then you can just click on the
  5967. 5:42:19button. Okay. And generate a new key ID
  5968. 5:42:22and key secret. Okay. API keys
  5969. 5:42:24credentials. Fine. Okay. And uh this is
  5970. 5:42:29what you know we'll get our key ID key
  5971. 5:42:31secret and once yeah once generated just
  5972. 5:42:34save that into your you know secure
  5973. 5:42:36place in your uh you know file system.
  5974. 5:42:39Okay. Because we need them in our
  5975. 5:42:42payment service. Okay. Yeah. So where we
  5976. 5:42:45need payment service src main resources
  5977. 5:42:49application yiml and yeah here can you
  5978. 5:42:52see we have already added the properties
  5979. 5:42:55razer pick key id and key secret
  5980. 5:42:59okay fine yeah okay so this is what our
  5981. 5:43:03uh you know websites and API keys fine
  5982. 5:43:07next is our web hooks okay so can you
  5983. 5:43:11see here is one button add new web hook.
  5984. 5:43:15Okay, just click on that. Okay, and uh
  5985. 5:43:19yeah, I want all of you to focus on this
  5986. 5:43:22thing active events. Okay, I already
  5987. 5:43:25told you that webbook has the you know
  5988. 5:43:28hundreds of events.
  5989. 5:43:30Okay, my web hook capture the event and
  5990. 5:43:34notify to my back end. Okay, so suppose
  5991. 5:43:37you know suppose there is a user. Okay.
  5992. 5:43:41And uh my user let's say this is my
  5993. 5:43:44user. Okay. And user have purchased
  5994. 5:43:46something from Amazon. Okay. Click on
  5995. 5:43:48the checkout page. Once check out page
  5996. 5:43:51you know this is what my checkout page
  5997. 5:43:53and uh you know enter all the bank
  5998. 5:43:56credentials everything else. Fine. And
  5999. 5:43:59something got failed here.
  6000. 5:44:01Okay. Something got failed from my you
  6001. 5:44:04know that Razer Pay payment gateway
  6002. 5:44:06site. Okay. So my web hook. Okay, with
  6003. 5:44:10the help of web hook, you know what
  6004. 5:44:13he'll do is he will capture that failed
  6005. 5:44:16event. Okay, because my web hook has lot
  6006. 5:44:21of events, you know, mentioned here. So,
  6007. 5:44:24let me just zoom it. Yeah, can you see
  6008. 5:44:27payment events? So, under payment
  6009. 5:44:28events, payment unauthorized,
  6010. 5:44:31payment.failed. So, we'll just check it.
  6011. 5:44:34Okay, payment.aptured. Okay, if payment
  6012. 5:44:36is successfully done, then
  6013. 5:44:38payment.captured captured is you know uh
  6014. 5:44:41is captured by my web hook. Okay. And
  6015. 5:44:44notify to my back end. Then back end
  6016. 5:44:48will uh proceed forward as per our code
  6017. 5:44:50what uh what we have you know written.
  6018. 5:44:53Okay. Next is payment dispute created.
  6019. 5:44:57Payment dispute won lost. Okay. And then
  6020. 5:45:00order events. Order paid. order
  6021. 5:45:03notification delivered, failed, invoice,
  6022. 5:45:05subscription events, active, pending,
  6023. 5:45:08halted, charged, okay, settlements, QR
  6024. 5:45:11events, fund accounts, events, refund
  6025. 5:45:13events, transfer accounts. So, lot of
  6026. 5:45:16events, okay? Almost you know 100 plus.
  6027. 5:45:19So, we don't need to take care because
  6028. 5:45:21see Razer Pay is another party. It's not
  6029. 5:45:24a part of our bank. Okay? So if suppose
  6030. 5:45:27my user is paying something you know uh
  6031. 5:45:29someone to the external merchants to
  6032. 5:45:32Amazon okay or uh to some other uh you
  6033. 5:45:35know on Airbnb or whatever to external
  6034. 5:45:38payments okay so there is someone
  6035. 5:45:41payment gateway okay now if something
  6036. 5:45:44got happened captured whatever okay so
  6037. 5:45:47we need someone to capture that and
  6038. 5:45:50notify to our back end whatever happened
  6039. 5:45:53on the you know front side on the
  6040. 5:45:56payment gateway side. So that is what
  6041. 5:45:58our web hook setup will do for us. Web
  6042. 5:46:02hook is not mandatory. Okay. Yeah. But
  6043. 5:46:06it is recommended. Okay. It is not
  6044. 5:46:08mandatory for the real payments. Fine.
  6045. 5:46:11But it is recommended. Okay. because uh
  6046. 5:46:15you know the payment gateway also has
  6047. 5:46:17their internal handling process for the
  6048. 5:46:20failure and uh for the you know success
  6049. 5:46:25okay like uh once payment got successful
  6050. 5:46:28so they'll redirect on some other
  6051. 5:46:29website okay or on other page or if
  6052. 5:46:32something got failed then they'll ask
  6053. 5:46:35user to retry okay and the third part is
  6054. 5:46:38currently we can't set up our web hook
  6055. 5:46:42okay because you can See here it is
  6056. 5:46:44asking us webbook URL and HTTPS URL is
  6057. 5:46:48recommended. Okay. So the very first
  6058. 5:46:51thing okay we need what we need domain
  6059. 5:46:54name. Okay. Domain
  6060. 5:46:57name let's say
  6061. 5:47:00uh our you know digital banking
  6062. 5:47:03system.com.
  6063. 5:47:05Okay. And and in actual this is not
  6064. 5:47:09enough. Okay. what we need to enter
  6065. 5:47:12here. Just listen to me. So, first once
  6066. 5:47:15we'll uh get our domain name dbs.com/
  6067. 5:47:19our payment
  6068. 5:47:22service
  6069. 5:47:24you know base URL pattern.
  6070. 5:47:28Okay. So in our controller you know we
  6071. 5:47:31have just uh added our URL pattern in
  6072. 5:47:33the request mapping. Okay. So let's say
  6073. 5:47:36this is our domain name. So DBS
  6074. 5:47:39okay.com/appi
  6075. 5:47:42you know v1 and
  6076. 5:47:45payments yeah this is only okay let me
  6077. 5:47:49check it so where is our payment okay
  6078. 5:47:53first java controller payment controller
  6079. 5:47:57yeah this one API v1 payments
  6080. 5:48:02this is what we need to enter okay fine
  6081. 5:48:05so this is what We need to enter and our
  6082. 5:48:09entire URL is this dbs.com. Okay,
  6083. 5:48:12whatever domain name /api v1 and
  6084. 5:48:16payments and this is complete thing we
  6085. 5:48:18need to enter here. Okay, but
  6086. 5:48:20unfortunately we don't have our domain
  6087. 5:48:22name. Okay, fine. So one thing for you,
  6088. 5:48:26okay, one homework for you that uh you
  6089. 5:48:28can just you know complete the project
  6090. 5:48:30and host this project. Okay, even on the
  6091. 5:48:33free tier and then try web hook. I want
  6092. 5:48:37you to try. Okay, and next thing is
  6093. 5:48:42Okay, next thing is secret. Okay, so
  6094. 5:48:44just add you know some uh strong secret
  6095. 5:48:47just like uh we used to add in our JWT
  6096. 5:48:51you know token. So also mentioned here
  6097. 5:48:54that we strongly recommend adding
  6098. 5:48:56secrets for security. Okay, then alert
  6099. 5:48:58email. Okay. And next thing is what? So
  6100. 5:49:04whatever events we have handled. Okay.
  6101. 5:49:07So we have handled payment failed and
  6102. 5:49:09payment capture just check it. Okay. Or
  6103. 5:49:12whatever you know you just uh need to
  6104. 5:49:14check. Just you know have the proper
  6105. 5:49:17handling code in the back end. Okay. And
  6106. 5:49:21create web hook.
  6107. 5:49:23So it will you know uh create a web hook
  6108. 5:49:27and whatever secret you have given here
  6109. 5:49:30just copy that secret and paste it into
  6110. 5:49:35your application yml here web hook
  6111. 5:49:38secret.
  6112. 5:49:39Yeah. So this is you know kind of our uh
  6113. 5:49:43razor pay website a uh sorry API keys
  6114. 5:49:47integration and webbook integration is
  6115. 5:49:49done. we are all good to take you know
  6116. 5:49:54uh payments from the user also one last
  6117. 5:49:58thing that is uh you can see our current
  6118. 5:50:00mode is test mode okay can you see this
  6119. 5:50:03test mode okay test mode so yeah no real
  6120. 5:50:08money moves for now okay so why because
  6121. 5:50:12you know currently we are testing our
  6122. 5:50:13application okay once will uh you know
  6123. 5:50:16once our application is tested
  6124. 5:50:18thoroughly it is confirmed that we can
  6125. 5:50:20move our application to the production
  6126. 5:50:22then we'll uh toggle it and change it to
  6127. 5:50:25the production. Okay. Now important
  6128. 5:50:28thing is once you'll change it to the
  6129. 5:50:30production you need to generate a new
  6130. 5:50:33API key and that two for the production.
  6131. 5:50:37Okay. So the current API key uh API keys
  6132. 5:50:41are for the testing test uh test mode.
  6133. 5:50:45Okay. So these API key will not work
  6134. 5:50:47there. Okay. Once you'll generate the
  6135. 5:50:50API key for uh you know production that
  6136. 5:50:55works as your real payment okay that
  6137. 5:50:58takes your real payment. Okay. So for
  6138. 5:50:59that too you know uh they have a few
  6139. 5:51:02requirement. The first requirement is
  6140. 5:51:04your bank details should be verified.
  6141. 5:51:08Okay. Second thing is you should have a
  6142. 5:51:10proper you know website hosted on a you
  6143. 5:51:13know some domain.
  6144. 5:51:16Yeah definitely. Okay. Then only they'll
  6145. 5:51:18allow you to put their uh API key and
  6146. 5:51:21key ID and key secret on you know your
  6147. 5:51:23website. Okay. Fine. Yeah. Same thing
  6148. 5:51:26with the test mode. Okay. Just uh we'll
  6149. 5:51:29do the you know money transfer
  6150. 5:51:31everything will handle success and
  6151. 5:51:32failure. Okay. But there is no real
  6152. 5:51:35money moment happens here. Okay. Yeah.
  6153. 5:51:38And also I just already told you what
  6154. 5:51:40you need to do that. Yeah. Okay. Fine.
  6155. 5:51:42So now our Razer Pay payment setup is uh
  6156. 5:51:47all done. Okay, we are good to go to
  6157. 5:51:50start all our you know microservices. So
  6158. 5:51:53now let's start our you know all the
  6159. 5:51:55microservices one by one. Fine. So let
  6160. 5:51:58me start with API gateway and yeah one
  6161. 5:52:00more thing one more thing. So make sure
  6162. 5:52:02that you have updated all the values you
  6163. 5:52:05know in our uh account service
  6164. 5:52:08application.
  6165. 5:52:10Okay what values? So values
  6166. 5:52:14uh of MySQL
  6167. 5:52:18username and password.
  6168. 5:52:22Okay, because I updated it. Okay, and
  6169. 5:52:24second thing is you know make sure that
  6170. 5:52:27you have you know set the proper key ID
  6171. 5:52:32and key secret what we have just now
  6172. 5:52:35fetched okay from the Razer P. Yeah. Uh
  6173. 5:52:39okay fine. And also third thing is
  6174. 5:52:43uh add enable fain client annotation.
  6175. 5:52:48Okay. Yeah.
  6176. 5:52:50Fine. Now let me start my you know all
  6177. 5:52:54the microservices. So let's start with
  6178. 5:52:57our API gateway. Okay. Uh
  6179. 5:53:04API gateway. Okay. And run. Yeah. So,
  6180. 5:53:11okay, my API gateway service is
  6181. 5:53:16you know started. Okay. And I guess
  6182. 5:53:20running on the port 8080.
  6183. 5:53:23Okay. Fine. Yeah. So,
  6184. 5:53:28all looks good. Okay. In the application
  6185. 5:53:31yml.
  6186. 5:53:34One second. 1 second.
  6187. 5:53:37Oh, okay. Okay. Okay. Okay. Let me
  6188. 5:53:39terminate it. Okay.
  6189. 5:53:41Fine.
  6190. 5:53:43Yeah. So, close all. And here it should
  6191. 5:53:47be rate
  6192. 5:53:50limiter dot replenish rate and dot burst
  6193. 5:53:54capacity. Okay. Instead of hyphen.
  6194. 5:53:58Okay. Dot. Yeah.
  6195. 5:54:02H because see we are allowing you know
  6196. 5:54:06uh at most 10 request and burst capacity
  6197. 5:54:11is 20 request okay in order to prevent
  6198. 5:54:14our application from attackers. Okay. So
  6199. 5:54:16that they you know can't able to make uh
  6200. 5:54:205,000 or 6,000 request in one go. Okay.
  6201. 5:54:24That is what you know why we have just
  6202. 5:54:26put the rate limiter. Okay. Yeah. Now it
  6203. 5:54:28is good. So just you know uh update your
  6204. 5:54:32application yml too. Okay. And now again
  6205. 5:54:35let me restart.
  6206. 5:54:38See uh so you know
  6207. 5:54:41that is what the benefit of uh testing
  6208. 5:54:44part. Okay. Because we'll get to know
  6209. 5:54:47where we can commit you know the
  6210. 5:54:49mistake. Okay. And will rectify that
  6211. 5:54:52itself. Yeah. Okay. It started. And then
  6212. 5:54:57let me now start my account service.
  6213. 5:55:01Okay. So Java and account service. Okay.
  6214. 5:55:04Fine.
  6215. 5:55:06Run. Also let me parallelly check the
  6216. 5:55:11application. YML. Okay. So my account
  6217. 5:55:14service is running on the port 8081. And
  6218. 5:55:18yeah. So I want you know all of you to
  6219. 5:55:21focus on my screen. Okay. And look at
  6220. 5:55:25here
  6221. 5:55:26in the Kafka properties we have group
  6222. 5:55:28ID. Okay. So make sure that whatever
  6223. 5:55:31group ID you have you know uh kept
  6224. 5:55:36in one service. Okay. That should not be
  6225. 5:55:40repeat in another.
  6226. 5:55:43Okay. So for account service our group
  6227. 5:55:45ID is you know account service group.
  6228. 5:55:48Yeah. And it is running. Yeah. It
  6229. 5:55:51started my application. Okay. Fine.
  6230. 5:55:54Okay. Next is let me start my
  6231. 5:55:57transaction service. Okay. Transaction.
  6232. 5:56:00Okay. First thing is make sure that you
  6233. 5:56:04have added this uh enable f client
  6234. 5:56:07annotation.
  6235. 5:56:09Okay. Yeah. Second thing is in the
  6236. 5:56:12resources
  6237. 5:56:14and yeah can you see this in the
  6238. 5:56:18transaction service application yiml.
  6239. 5:56:21Okay. group ID is same as
  6240. 5:56:24of account service. Okay. So here we
  6241. 5:56:29should have to update you know
  6242. 5:56:31transaction service group.
  6243. 5:56:35Yeah fine. Now it is uh fine else you'll
  6244. 5:56:40face the error. Okay. while testing
  6245. 5:56:45run
  6246. 5:56:47and yeah now my you know transaction
  6247. 5:56:51service is running on the port I guess
  6248. 5:56:548082
  6249. 5:56:57okay yeah
  6250. 5:57:00so
  6251. 5:57:01you know let it run and then uh after
  6252. 5:57:05that we'll start our fraud detection
  6253. 5:57:08service okay fraud detection service
  6254. 5:57:11fine
  6255. 5:57:13So okay it started fine great then fraud
  6256. 5:57:17detection service. Okay you should you
  6257. 5:57:19know add this uh enable fe clients and
  6258. 5:57:22in the resources let me first check.
  6259. 5:57:26Yeah can you see this here too here to
  6260. 5:57:29account service group. Okay fraud
  6261. 5:57:33service group.
  6262. 5:57:35Okay now let me just hit the run.
  6263. 5:57:40Okay. Yeah. Next thing is uh let's start
  6264. 5:57:44our notification service.
  6265. 5:57:47So
  6266. 5:57:49you know notification and
  6267. 5:57:52in the resources
  6268. 5:57:54can you see this because you know we
  6269. 5:57:57have just copied this code from consumer
  6270. 5:58:00till producer. Okay but we forget to
  6271. 5:58:03update this uh group.
  6272. 5:58:07Okay so let's modify it. Notification.
  6273. 5:58:12Okay. Notification
  6274. 5:58:14service group. Yeah. Okay. So, my fraud
  6275. 5:58:18detection service is up and running.
  6276. 5:58:20Now, let me just hit run. Okay. And
  6277. 5:58:26notification service started. Okay. And
  6278. 5:58:29next is our payment service. Okay. So,
  6279. 5:58:34payment service. Fine. and resources
  6280. 5:58:38application yml and here yeah fine no
  6281. 5:58:42consumer so let me start my payment
  6282. 5:58:44service okay
  6283. 5:58:47and
  6284. 5:58:50started on the port I guess 8083
  6285. 5:58:56yeah so
  6286. 5:59:11Yeah.
  6287. 5:59:13On port 8083.
  6288. 5:59:15Okay. Fine. Now let's test our you know
  6289. 5:59:19all the endpoints of our digital banking
  6290. 5:59:22system. Yeah. So for that I already
  6291. 5:59:25opened my Postman. Okay. And the very
  6292. 5:59:29first thing is what we need to do. The
  6293. 5:59:32first thing is we need to create sender
  6294. 5:59:34and receiver account. Okay. So let me
  6295. 5:59:39just go to my account service.
  6296. 5:59:42Okay. Controller account controller.
  6297. 5:59:44Okay. And here API v1 accounts. Okay.
  6298. 5:59:51Fine. And create account. Create account
  6299. 5:59:54request. Yeah. So, HTTP
  6300. 6:00:00localhost
  6301. 6:00:028080.
  6302. 6:00:04Okay. Yeah. All request through gateway
  6303. 6:00:08and then API accounts. That's it. Post
  6304. 6:00:11mapping body. Okay. Raw and
  6305. 6:00:17JSON. Fine. The first is my in the
  6306. 6:00:21request account holder name. Okay. So
  6307. 6:00:25let's say John Doe. Okay. Next is email,
  6308. 6:00:30phone, account type, and initial
  6309. 6:00:32deposit.
  6310. 6:00:34Okay. So, email. Okay. So, let's say
  6311. 6:00:40John at
  6312. 6:00:42testmail.com.
  6313. 6:00:44Okay. Next is our phone. Okay. So
  6314. 6:00:509 9999 99999.
  6315. 6:00:55Okay. Yeah.
  6316. 6:00:57And then account type.
  6317. 6:01:02Okay. So let's say savings.
  6318. 6:01:06Okay. And finally initial deposit.
  6319. 6:01:11Okay. So initial deposit uh let's say
  6320. 6:01:1510,000.
  6321. 6:01:17Okay. Fine. Now let me send the request
  6322. 6:01:20and yeah sending request.
  6323. 6:01:24My account is going to create. Yeah
  6324. 6:01:27created. So phone number account type
  6325. 6:01:30savings status and I want you all to
  6326. 6:01:33focus on this field account number.
  6327. 6:01:37Yeah. So if you remember how we have
  6328. 6:01:40implemented our account number you know.
  6329. 6:01:44So it should be 12 digit unique.
  6330. 6:01:48Yes. And then we have formatted like a
  6331. 6:01:51string. Okay. And inside uh percent then
  6332. 6:01:56replace with zero. Okay. Then of 12
  6333. 6:01:59digit. Okay. And then decimal integer.
  6334. 6:02:02And then here is my random number.
  6335. 6:02:05Remember? Yeah. So this is how you know
  6336. 6:02:09it is our code is perfectly generating
  6337. 6:02:12the 12digit number. Similarly let me
  6338. 6:02:17create the receiver. So let's treat it
  6339. 6:02:19as a sender. And now receiver. So same
  6340. 6:02:23thing. Okay. And post mapping. Okay.
  6341. 6:02:27Body raw text JSON. Let me just copy
  6342. 6:02:33and paste it here. Okay. paste. Fine.
  6343. 6:02:37So, let's say Jane. Okay. And
  6344. 6:02:43Jane. Fine. Phone number. Let me replace
  6345. 6:02:46it with, you know, 88 888
  6346. 6:02:5088 88 88 88 888. Okay. And initial
  6347. 6:02:55deposit, let's say, um, what? 6,000. H.
  6348. 6:03:01Okay. Send it. Yeah. So
  6349. 6:03:06okay done. Now also let me you know
  6350. 6:03:10check the balance. Okay we have that you
  6351. 6:03:14know get balance. Okay using account
  6352. 6:03:16number/balance.
  6353. 6:03:19Okay fine. So
  6354. 6:03:23API accounts and using account number.
  6355. 6:03:27So let me just you know
  6356. 6:03:30paste here account number and
  6357. 6:03:34balance. Okay. So I'm expecting 10,000.
  6358. 6:03:38Okay. This is of uh sender balance
  6359. 6:03:41sender account number. So yeah 10,000.
  6360. 6:03:45So now next thing is let's transfer.
  6361. 6:03:48Okay. The first thing is happy path. H.
  6362. 6:03:51So where is my transaction service?
  6363. 6:03:55Transaction
  6364. 6:03:57controller. Transaction controller.
  6365. 6:03:59Okay. And transfer.
  6366. 6:04:03Okay. Transfer request. Sender account
  6367. 6:04:06number. Okay. Receiver account number.
  6368. 6:04:09I'm transferring amount and description.
  6369. 6:04:13Okay. Fine. And here API v1 transaction
  6370. 6:04:17transfer. Okay. So next is
  6371. 6:04:22you know API v1
  6372. 6:04:25transactions.
  6373. 6:04:27Okay. And
  6374. 6:04:30transfer
  6375. 6:04:32it is post mapping body raw
  6376. 6:04:36JSON. Okay. And the first is what?
  6377. 6:04:43Sender account number.
  6378. 6:04:46H which is sender account number which
  6379. 6:04:49is this.
  6380. 6:04:51Okay.
  6381. 6:04:54Second is my
  6382. 6:04:56receiver account number. Okay. So
  6383. 6:05:01receiver is
  6384. 6:05:03yeah this is
  6385. 6:05:07okay and then amount. Okay. So amount
  6386. 6:05:11let's say what 600. Okay. And
  6387. 6:05:18description.
  6388. 6:05:20Okay. So, description. Let's say test
  6389. 6:05:26transfer.
  6390. 6:05:28Uh okay. Fine. So, first let's consider
  6391. 6:05:32our happy path. Okay. Nothing fraud is
  6392. 6:05:34detected. And let's you know sender
  6393. 6:05:38initiate the you know transaction of
  6394. 6:05:41600. Okay. Let me send it. So
  6395. 6:05:45okay sending request and yeah can you
  6396. 6:05:48see status is pending and this is what
  6397. 6:05:51my ID
  6398. 6:05:53okay sender account receiver account
  6399. 6:05:56fine now I want all of you to focus on
  6400. 6:06:00my logs
  6401. 6:06:02okay first transaction logs okay so
  6402. 6:06:05transaction logs started here you know
  6403. 6:06:09saga is step number two okay step number
  6404. 6:06:11one is Yeah. Saga start. Okay. Transfer.
  6405. 6:06:18Fine. And also let's go here. Okay.
  6406. 6:06:22Service. Transaction service.
  6407. 6:06:24Fine.
  6408. 6:06:26And where is our transfer? Yeah. So this
  6409. 6:06:28is what transfer. And first thing is
  6410. 6:06:31deduct from sender. Okay. So let me just
  6411. 6:06:33check my sender balance. Okay. Initially
  6412. 6:06:3610,000 but now it should be 9.4K. Yeah.
  6413. 6:06:40Can you see? 9,400. Okay. Fine. And then
  6414. 6:06:44transaction created, saved and published
  6415. 6:06:48event. Transaction initiated.
  6416. 6:06:51Okay. This event
  6417. 6:06:54consumed by our fraud detection. Fraud
  6418. 6:06:57detection. Fraud detection.
  6419. 6:07:00Okay. Fraud detection service. H. Where
  6420. 6:07:05is my Yeah. Fraud detection service
  6421. 6:07:09consumed. Okay. this event and call this
  6422. 6:07:14check transaction. Check transaction.
  6423. 6:07:17Done. Done. Done. And nothing fraud is
  6424. 6:07:20detected. Okay. And
  6425. 6:07:23comes outside of the if statement. And
  6426. 6:07:25here fraud check clean. That means
  6427. 6:07:29everything is clean. Complete the
  6428. 6:07:31transaction. Okay. So this event is
  6429. 6:07:34going to consumed by again my
  6430. 6:07:36transaction service.
  6431. 6:07:39Okay. So
  6432. 6:07:43hm where is that? Uh yeah fraud check
  6433. 6:07:47clean which is calling process clean
  6434. 6:07:50result and complete transaction.
  6435. 6:07:54Okay transaction dot completed topic
  6436. 6:07:59H. Okay and transaction completed is
  6437. 6:08:03consumed by my next is notification.
  6438. 6:08:07Notification. Notification.
  6439. 6:08:10Okay. So,
  6440. 6:08:13transaction completed and
  6441. 6:08:16debit alert. Credit alert. Okay. So, now
  6442. 6:08:19just focus on notification and yeah, can
  6443. 6:08:22you just look at this
  6444. 6:08:24debit alert? Okay. This is my sender
  6445. 6:08:28account number, credit alert and
  6446. 6:08:31receiver account number. 600 debited
  6447. 6:08:34from 600 credited uh sorry credited
  6448. 6:08:40here it should be two okay yeah mistake
  6449. 6:08:42so no worries created to uh this account
  6450. 6:08:46okay fine done so this is the happy path
  6451. 6:08:50now let's uh you know add a fraud in
  6452. 6:08:54this okay so which fraud let me just add
  6453. 6:08:58uh velocity fraud H that means uh let's
  6454. 6:09:03say I'm the fraudster and uh you know I
  6455. 6:09:07have ran a script
  6456. 6:09:10okay and that script fires fires you
  6457. 6:09:14know six transaction six transaction
  6458. 6:09:17immediately in uh less than 10 seconds.
  6459. 6:09:22Okay, maybe you know uh the fraudster
  6460. 6:09:25you know just run the script and that
  6461. 6:09:28fires 500 transactions. Okay, 50
  6462. 6:09:31transaction in in a few seconds. Okay,
  6463. 6:09:33so let's take six transaction in uh 10
  6464. 6:09:36seconds or maybe in 6 seconds. Fine. So,
  6465. 6:09:40let me just do that. Okay, fine. Let me
  6466. 6:09:44go to my Okay. Uh
  6467. 6:09:53yeah, Postman. And this is what the
  6468. 6:09:56transfer. Okay. So, let me just hit six
  6469. 6:09:59times. Okay. 1 2 3 4 5 6. Okay. Fine.
  6470. 6:10:09Now transaction service. And
  6471. 6:10:14here
  6472. 6:10:16it is, you know. Can you see this?
  6473. 6:10:201 2 3 four times. Okay.
  6474. 6:10:24And
  6475. 6:10:29finally, yeah, that's what I'm looking
  6476. 6:10:31for. OTP generated for transaction.
  6477. 6:10:34Okay, so just look at here. Every time
  6478. 6:10:37you know we initiate a transaction, my
  6479. 6:10:39fraud detection service will check it.
  6480. 6:10:42Okay, we'll check it and
  6481. 6:10:45it will check all three fraud. Okay. But
  6482. 6:10:49we have now you know explicitly that
  6483. 6:10:52added a fraud. Okay. And that two
  6484. 6:10:55velocity exceeded fraud. Yes or no? The
  6485. 6:10:58too many transaction in 60 seconds. So
  6486. 6:11:01we have you know quickly just uh you
  6487. 6:11:05know made six or more than five
  6488. 6:11:07transactions in few seconds. So
  6489. 6:11:11you know it just hit the count which uh
  6490. 6:11:16becomes greater than uh this maximum
  6491. 6:11:19value allowed. Okay, which we have
  6492. 6:11:21already set it as five.
  6493. 6:11:24Okay, that's why we have you know just
  6494. 6:11:27uh make six transaction quickly. Okay.
  6495. 6:11:31So yeah definitely fraud is detected and
  6496. 6:11:35verification required topic is you know
  6497. 6:11:39sent. Now this verification required
  6498. 6:11:42topic that means verification is
  6499. 6:11:44required. So in that case we need to
  6500. 6:11:46generate OTP and uh who's going to
  6501. 6:11:50generate OTP? My transaction service
  6502. 6:11:52event consumer. Okay. So here
  6503. 6:11:58OTP generator. Okay, can you see in the
  6504. 6:12:00transaction service logs OTP generated?
  6505. 6:12:05Okay, and once OTP generated
  6506. 6:12:09you know uh
  6507. 6:12:12OTP generated event okay I publish this
  6508. 6:12:15and this is going to consume by my
  6509. 6:12:18notification service
  6510. 6:12:20OTP generated
  6511. 6:12:22okay here I'm displaying this
  6512. 6:12:26notification
  6513. 6:12:28Error
  6514. 6:12:31sending OTP notification
  6515. 6:12:34format a specifier.
  6516. 6:12:36Okay.
  6517. 6:12:39Oh, one second. One second. Mistake.
  6518. 6:12:41Mistake. H we haven't you know completed
  6519. 6:12:45this. So suspicious activity detected on
  6520. 6:12:47your account. Reason is reason. Then a
  6521. 6:12:52transaction of what amount
  6522. 6:12:56is pending verification. Your OTP is
  6523. 6:13:00OTP. Okay. Wait for 5 minutes. Okay. And
  6524. 6:13:06yeah, that's it. Okay. Fine. So again,
  6525. 6:13:10let me you know restart it.
  6526. 6:13:14Okay.
  6527. 6:13:17Okay. So notification service and
  6528. 6:13:22stop and rerun. Okay, because see we
  6529. 6:13:24haven't completed it. Okay, so
  6530. 6:13:27definitely format a specify error. Okay,
  6531. 6:13:31so first let it you know rerun.
  6532. 6:13:36Okay fine. So now now what? Now let me
  6533. 6:13:42just do again. Okay, let me
  6534. 6:13:46again
  6535. 6:13:47just commit a fraud. Okay, so 1 2 3 4 5
  6536. 6:13:556. Okay, some fraudster is trying to you
  6537. 6:13:59know uh drain the counts running the run
  6538. 6:14:01the script and initiated few transition
  6539. 6:14:04in 60 seconds. Fine. Now same thing
  6540. 6:14:08happened. The fluke goes like uh yeah
  6541. 6:14:11can you see this suspicious activity
  6542. 6:14:14detected on your account. Okay on the
  6543. 6:14:17sixth transaction. Okay reason too many
  6544. 6:14:20transition in 60 seconds velocity
  6545. 6:14:22exceeded.
  6546. 6:14:24Okay transition of 600 is pending
  6547. 6:14:26verification. Okay because see now bank
  6548. 6:14:29detected that uh you know on this
  6549. 6:14:32account continuously transition is
  6550. 6:14:35happening. So they put on this
  6551. 6:14:37verification and your OTP is this valid
  6552. 6:14:41for 5 minute. If this wasn't you, ignore
  6553. 6:14:44this message. Okay, fine. So
  6554. 6:14:49you know
  6555. 6:14:51uh yeah,
  6556. 6:14:53let me just copy this message. Okay, and
  6557. 6:14:57let me hit the API. Which API?
  6558. 6:15:01Our transaction controller. and this
  6559. 6:15:05verify OTP. Okay, this API
  6560. 6:15:09in the request param let me pass this.
  6561. 6:15:13Okay, fine. My postman
  6562. 6:15:16and transaction.
  6563. 6:15:19Fine.
  6564. 6:15:20Transaction ID. Okay, verify
  6565. 6:15:25transaction ID is what? This is my
  6566. 6:15:28transaction ID. Okay, let me just
  6567. 6:15:34put that.
  6568. 6:15:37Okay, and verify.
  6569. 6:15:40Fine. And then request param. Okay. So,
  6570. 6:15:44question mark. Fine. Then OTP equals
  6571. 6:15:49what is the OTP? 242990.
  6572. 6:15:52242990.
  6573. 6:15:53Okay. Fine. And post mapping. Okay. So,
  6574. 6:15:57send it. And can you see this status is
  6575. 6:16:01completed.
  6576. 6:16:03Okay, that means genuine.
  6577. 6:16:06Genuine. Okay. So now your job is to
  6578. 6:16:09test it with you know wrong OTP. Let's
  6579. 6:16:12say 1 2 3 4 5 6. Okay. And expired OTP.
  6580. 6:16:17Fine. So we have provided for all the
  6581. 6:16:20you know things. Right. So in our
  6582. 6:16:24transaction service
  6583. 6:16:26uh
  6584. 6:16:28you know here block account block and
  6585. 6:16:32compensate refund. Okay. Okay. Yeah. So
  6586. 6:16:36in case of OTP expired in case of wrong
  6587. 6:16:40OTP entered in case of you know else
  6588. 6:16:43there's uh correct OTP. Okay. So you can
  6589. 6:16:46just try these two. Okay. In this case,
  6590. 6:16:49you know, uh user will get refund.
  6591. 6:16:54Okay. Fine. Yeah. Simple. You can try.
  6592. 6:16:57Yeah, you can just try. Fine. Okay. Now,
  6593. 6:17:00let's move to our next part. Okay. See,
  6594. 6:17:03this is what our first part is done.
  6595. 6:17:06Okay. So, every bank system has you know
  6596. 6:17:08two parts. Okay. Same as ours. So, first
  6597. 6:17:11is our internal payments. Fine. Internal
  6598. 6:17:14payments just like we did. Okay. Second
  6599. 6:17:16is our external payments. Yeah. So for
  6600. 6:17:21this we have you know set up our Razer
  6601. 6:17:25Pay uh account.
  6602. 6:17:28Okay. I told you suppose if you have
  6603. 6:17:31purchased something from Amazon. Okay.
  6604. 6:17:33External payments. Okay. Or any other
  6605. 6:17:35website. Yeah. So to the checkout page,
  6606. 6:17:38payment gateway and success or failure.
  6607. 6:17:41Yeah. Let's do that. Okay. Fine. So now
  6608. 6:17:46let's do that and okay. Okay. So for uh
  6609. 6:17:51our external payments I have created
  6610. 6:17:53yeah a simple uh page front end page.
  6611. 6:17:56Okay. Let me just uh go to my file
  6612. 6:17:59explorer.
  6613. 6:18:01Okay. And yeah this is payment. Let me
  6614. 6:18:05just copy
  6615. 6:18:07aspath
  6616. 6:18:10and my browser. and then paste it here.
  6617. 6:18:16So
  6618. 6:18:19yeah, banking payment demo. Okay, so you
  6619. 6:18:24know, let me just write the account
  6620. 6:18:26number here. Okay, or account number
  6621. 6:18:30sending to my receiver account. Okay,
  6622. 6:18:34receiver account number. And here, let
  6623. 6:18:37me just take in dollars. Okay, fine. So
  6624. 6:18:41pay now. Can you see? Creating payment
  6625. 6:18:44order. No key passed.
  6626. 6:18:48Okay.
  6627. 6:18:49Let me go to my code.
  6628. 6:18:54Uh length must Oh, one second. One
  6629. 6:18:57second. I remember
  6630. 6:18:59what we have done. Okay. So, in our
  6631. 6:19:02payment service,
  6632. 6:19:04uh yeah, can you see? I told you here in
  6633. 6:19:07the currency, you should have to put
  6634. 6:19:09just one. Okay, let me put the USD.
  6635. 6:19:12Okay, USD. USD.
  6636. 6:19:17Okay. And US dollar. Okay. Fine. So, you
  6637. 6:19:21can just put uh whatever currency INR,
  6638. 6:19:24GBP, whatever. Okay. Let me put the USD.
  6639. 6:19:28Okay. Fine. And uh then again rerun my
  6640. 6:19:35you know
  6641. 6:19:37payment service. Okay.
  6642. 6:19:41Fine.
  6643. 6:19:42Okay. And we are just about to, you
  6644. 6:19:45know, finish.
  6645. 6:19:48And uh Okay. Running on the port 8083.
  6646. 6:19:53Fine.
  6647. 6:19:56Okay.
  6648. 6:20:04Yeah. So, back to our browser and $10
  6649. 6:20:08pay now. Creating payment order and
  6650. 6:20:12yeah, can you see? So,
  6651. 6:20:16$10.
  6652. 6:20:18Okay, I'm paying and yeah, so let me
  6653. 6:20:22just add the, you know, sample card.
  6654. 6:20:26Okay, so let's say 2 1 3 2 Okay. Okay. 1
  6655. 6:20:312 3 4 21 2 1 4 3 you know 3 2 4 1. Okay.
  6656. 6:20:38Whatever. Fine. And uh expired date
  6657. 6:20:41let's say you know 6 27. Okay. And uh
  6658. 6:20:46CVB 1 2 3. Okay. And continue. Fine.
  6659. 6:20:50Maybe later you can just save it. And
  6660. 6:20:53now this is what our you know banking
  6661. 6:20:55system. Okay. Paying $10 now. Yeah. Can
  6662. 6:20:59you see this page? Okay. So now Razer
  6663. 6:21:03Pay is asking us that uh you know you
  6664. 6:21:06want to proceed as success or failure.
  6665. 6:21:10Okay. Because you know we are testing in
  6666. 6:21:12our testing mode and it is better to
  6667. 6:21:14test both cases. Okay. Fine. And
  6668. 6:21:18obviously we are handling both. Okay.
  6669. 6:21:20Yeah. So let's do the success part.
  6670. 6:21:23Okay. Just click on it and uh then okay
  6671. 6:21:27banking system proceed confirming
  6672. 6:21:30payment. Okay. And then
  6673. 6:21:34it generates what you know 3 2 1. Yeah.
  6674. 6:21:38Can you see this payment id pay
  6675. 6:21:41underscore?
  6676. 6:21:43Yeah. And in case of failure it will not
  6677. 6:21:47generate that. Okay. Fine. So this is
  6678. 6:21:50what you know our entire testing we have
  6679. 6:21:53done. Okay. And here is our you know
  6680. 6:21:57entire digital banking system also. Uh
  6681. 6:22:00we need to add few more things. Okay.
  6682. 6:22:02Few more services. Okay. Few more you
  6683. 6:22:04know fraud detection patterns and Kafka
  6684. 6:22:07streams and everything else. Okay. So
  6685. 6:22:09definitely fine. This is what the basic
  6686. 6:22:12architecture how it works. Okay. You
  6687. 6:22:14know and uh how our fraud detection
  6688. 6:22:16works. Okay. Also if you have any more
  6689. 6:22:19request that uh what you want me to
  6690. 6:22:22upload the next project then please
  6691. 6:22:24comment me down. Okay. Also if you
  6692. 6:22:27haven't subscribed then please subscribe
  6693. 6:22:29my channel. Okay. You can thank me.
  6694. 6:22:31Okay. Subscribe like. Okay. Hit the like
  6695. 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.