Skip to content

Commit

Permalink
added simulated-bankapi & Some Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ducheharsh committed Jul 19, 2024
1 parent 8836269 commit 82e193e
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 17 deletions.
4 changes: 3 additions & 1 deletion apps/bank-webhook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand All @@ -12,6 +13,7 @@
"dependencies": {
"@repo/db": "*",
"@types/express": "^4.17.21",
"cors": "^2.8.5",
"express": "^4.19.2",
"prisma": "^5.17.0"
},
Expand Down
13 changes: 8 additions & 5 deletions apps/bank-webhook/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
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: {
increment: paymentInformation.amount
}
}
}),
db.onRampTransaction.update({
db.onRampTransaction.updateMany({
where:{
token: paymentInformation.token
},
Expand Down
20 changes: 20 additions & 0 deletions apps/simulatad-bankapi/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
42 changes: 42 additions & 0 deletions apps/simulatad-bankapi/src/index.ts
Original file line number Diff line number Diff line change
@@ -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");
})
2 changes: 1 addition & 1 deletion apps/user-app/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};

Expand Down
2 changes: 1 addition & 1 deletion apps/user-app/app/lib/actions/Transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export async function createOnRampTransactions({amount, provider}:{amount:number
})
return {
message: "Transaction initiated",
transaction
token:transaction.token
};
}
20 changes: 16 additions & 4 deletions apps/user-app/components/AddMoney.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
<Card className='mt-6 w-[35vw] h-fit'>
<CardHeader>
Expand All @@ -43,10 +46,19 @@ export default function AddMoney() {
value: x.name
}))} />
<div className="mt-6">
<Button onClick={async()=>{
window.location.href = redirectUrl || "";
const res = await createOnRampTransactions({amount, provider: provider || ""})
alert(res.message);
<Button onClick={async()=>{
const res = await createOnRampTransactions({amount, provider: provider || ""}).then((res)=>{
axios.post("http://localhost:3301/api/v1/hdfc/transfer", {
amount,
userId:session.data?.user?.id,
token:res.token
}).then((BankRequest)=>{
BankRequest.data.message === "Transfer Completed" ? alert("Money added successfully") : alert("Error while adding money")
})

})


}}>
Add Money
</Button>
Expand Down
3 changes: 2 additions & 1 deletion apps/user-app/components/OnRampTrans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export default function OnRampTransCard({
<div>
<div className="text-sm">
Received INR


{t.status}
</div>

<div className="text-slate-600 text-xs">
Expand Down
49 changes: 49 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/db/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
Expand All @@ -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
}
},
Expand Down

0 comments on commit 82e193e

Please sign in to comment.