From 82e193eb5d0934e1e008622266f72fb8b635cde6 Mon Sep 17 00:00:00 2001 From: Harsh Mahadev Duche Date: Fri, 19 Jul 2024 20:52:39 +0530 Subject: [PATCH] added simulated-bankapi & Some Bug fixes --- apps/bank-webhook/package.json | 4 +- apps/bank-webhook/src/index.ts | 13 +++-- apps/simulatad-bankapi/package.json | 20 ++++++++ apps/simulatad-bankapi/src/index.ts | 42 ++++++++++++++++ apps/user-app/app/layout.tsx | 2 +- apps/user-app/app/lib/actions/Transactions.ts | 2 +- apps/user-app/components/AddMoney.tsx | 20 ++++++-- apps/user-app/components/OnRampTrans.tsx | 3 +- package-lock.json | 49 +++++++++++++++++++ packages/db/prisma/seed.ts | 8 +-- 10 files changed, 146 insertions(+), 17 deletions(-) create mode 100644 apps/simulatad-bankapi/package.json create mode 100644 apps/simulatad-bankapi/src/index.ts diff --git a/apps/bank-webhook/package.json b/apps/bank-webhook/package.json index 4492888..2a60cfd 100644 --- a/apps/bank-webhook/package.json +++ b/apps/bank-webhook/package.json @@ -3,7 +3,8 @@ "version": "1.0.0", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "dev": "esbuild src/index.ts --bundle --platform=node --outdir=dist && node dist/index.js" }, "keywords": [], "author": "", @@ -12,6 +13,7 @@ "dependencies": { "@repo/db": "*", "@types/express": "^4.17.21", + "cors": "^2.8.5", "express": "^4.19.2", "prisma": "^5.17.0" }, diff --git a/apps/bank-webhook/src/index.ts b/apps/bank-webhook/src/index.ts index d38067f..816abe1 100644 --- a/apps/bank-webhook/src/index.ts +++ b/apps/bank-webhook/src/index.ts @@ -1,21 +1,24 @@ import express from 'express'; import db from "@repo/db/client"; +var cors = require('cors') const app = express(); +app.use(express.json()); +app.use(cors()) app.post("/hdfcwebhook", async(req, res)=>{ const paymentInformation = { token: req.body.token, - userId: req.body.user_identifier, + userId: req.body.userId, amount: req.body.amount, } - + console.log(paymentInformation.userId) try{ await db.$transaction([ - db.balance.update({ + db.balance.updateMany({ where:{ - userId: paymentInformation.userId + userId: Number(paymentInformation.userId) }, data:{ amount: { @@ -23,7 +26,7 @@ app.post("/hdfcwebhook", async(req, res)=>{ } } }), - db.onRampTransaction.update({ + db.onRampTransaction.updateMany({ where:{ token: paymentInformation.token }, diff --git a/apps/simulatad-bankapi/package.json b/apps/simulatad-bankapi/package.json new file mode 100644 index 0000000..d1af712 --- /dev/null +++ b/apps/simulatad-bankapi/package.json @@ -0,0 +1,20 @@ +{ + "name": "simulatad-bankapi", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "dev": "esbuild src/index.ts --bundle --platform=node --outdir=dist && node dist/index.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "express": "^4.19.2", + "uuid": "^10.0.0" + }, + "devDependencies": { + "@types/uuid": "^10.0.0" + } +} diff --git a/apps/simulatad-bankapi/src/index.ts b/apps/simulatad-bankapi/src/index.ts new file mode 100644 index 0000000..eb21ca0 --- /dev/null +++ b/apps/simulatad-bankapi/src/index.ts @@ -0,0 +1,42 @@ + +import axios from 'axios'; +import express from 'express'; +import { v4 as uuidv4 } from 'uuid'; +const app = express(); +var cors = require('cors') +app.use(express.json()); +app.use(cors()) +app.post("/api/v1/hdfc/transfer", async(req, res) => { + + const token = uuidv4(); + console.log(token); + console.log(req.body); + // webhook request + try{ + const transferStatusChange = await axios.post("http://localhost:3300/hdfcwebhook", { + token:req.body.token, + userId: req.body.userId, + amount: req.body.amount + }) + + if(transferStatusChange.status === 200){ + res.status(200).json({ + message: "Transfer Completed" + }) + } + else{ + res.status(411).json({ + message: "Error while processing transfer" + }) + } +}catch(e){ + console.error(e); + res.status(411).json({ + message: "Error while processing transfer" + }) +} +}) + +app.listen(3301, ()=>{ + console.log("Server started at 3301"); +}) \ No newline at end of file diff --git a/apps/user-app/app/layout.tsx b/apps/user-app/app/layout.tsx index c02e87d..7146cdc 100644 --- a/apps/user-app/app/layout.tsx +++ b/apps/user-app/app/layout.tsx @@ -7,7 +7,7 @@ import { AppbarClient } from "../components/AppbarClient"; const inter = Inter({ subsets: ["latin"] }); export const metadata: Metadata = { - title: "Wallet", + title: "theWallet", description: "Simple wallet app", }; diff --git a/apps/user-app/app/lib/actions/Transactions.ts b/apps/user-app/app/lib/actions/Transactions.ts index d04a4f7..22e8c58 100644 --- a/apps/user-app/app/lib/actions/Transactions.ts +++ b/apps/user-app/app/lib/actions/Transactions.ts @@ -22,6 +22,6 @@ export async function createOnRampTransactions({amount, provider}:{amount:number }) return { message: "Transaction initiated", - transaction + token:transaction.token }; } \ No newline at end of file diff --git a/apps/user-app/components/AddMoney.tsx b/apps/user-app/components/AddMoney.tsx index 27d2d1b..b6b8a23 100644 --- a/apps/user-app/components/AddMoney.tsx +++ b/apps/user-app/components/AddMoney.tsx @@ -7,6 +7,7 @@ import { Select } from "./ui/select" import { useState } from "react" import axios from "axios" import { createOnRampTransactions } from "../app/lib/actions/Transactions" +import { useSession } from "next-auth/react" const SUPPORTED_BANKS = [{ name: "HDFC Bank", @@ -17,9 +18,11 @@ const SUPPORTED_BANKS = [{ }]; export default function AddMoney() { + const session = useSession(); const [redirectUrl, setRedirectUrl] = useState(SUPPORTED_BANKS[0]?.redirectUrl); const [amount, setAmount] = useState(0); const [provider, setProvider] = useState(SUPPORTED_BANKS[0]?.name) + console.log() return( @@ -43,10 +46,19 @@ export default function AddMoney() { value: x.name }))} />
- diff --git a/apps/user-app/components/OnRampTrans.tsx b/apps/user-app/components/OnRampTrans.tsx index 9ba306f..f8ed381 100644 --- a/apps/user-app/components/OnRampTrans.tsx +++ b/apps/user-app/components/OnRampTrans.tsx @@ -43,7 +43,8 @@ export default function OnRampTransCard({
Received INR - + + {t.status}
diff --git a/package-lock.json b/package-lock.json index 631248f..ee29d29 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,7 @@ "dependencies": { "@repo/db": "*", "@types/express": "^4.17.21", + "cors": "^2.8.5", "express": "^4.19.2", "prisma": "^5.17.0" }, @@ -146,6 +147,30 @@ "typescript": "^5.3.3" } }, + "apps/simulatad-bankapi": { + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "express": "^4.19.2", + "uuid": "^10.0.0" + }, + "devDependencies": { + "@types/uuid": "^10.0.0" + } + }, + "apps/simulatad-bankapi/node_modules/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "apps/user-app": { "name": "docs", "version": "1.0.0", @@ -3108,6 +3133,13 @@ "integrity": "sha512-iEN8J0BoMnsWBqjVbWH/c0G0Hh7O21lpR2/+PrvAVgWdzL7eexIFm4JN/Wn10PTcmNdtS6U67r499mlWMXOxNw==", "dev": true }, + "node_modules/@types/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "7.3.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.3.1.tgz", @@ -4699,6 +4731,19 @@ "url": "https://opencollective.com/core-js" } }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -11029,6 +11074,10 @@ "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" }, + "node_modules/simulatad-bankapi": { + "resolved": "apps/simulatad-bankapi", + "link": true + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", diff --git a/packages/db/prisma/seed.ts b/packages/db/prisma/seed.ts index 52b4c8e..e13913b 100644 --- a/packages/db/prisma/seed.ts +++ b/packages/db/prisma/seed.ts @@ -10,11 +10,11 @@ const harsh = await prisma.user.upsert({ update: {}, create: { number: "1111111111", - password: await bcrypt.hash("demouser", 10), + password: await bcrypt.hash("harsh", 10), name: "harsh", Balance:{ create:{ - amount: 20000, + amount: 40000, locked: 0 } }, @@ -38,11 +38,11 @@ const archit = await prisma.user.upsert({ update: {}, create: { number: "2222222222", - password: await bcrypt.hash("demouser2", 10), + password: await bcrypt.hash("archit", 10), name: "archit", Balance:{ create:{ - amount: 20000, + amount: 40000, locked: 0 } },