Skip to content

Commit

Permalink
Changes: bank webhook - include failure status
Browse files Browse the repository at this point in the history
  • Loading branch information
sudhanshugautam2911 committed Nov 6, 2024
1 parent 824886c commit 6901818
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions apps/bank-webhook/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,52 @@ app.post("/hdfcWebhook", async (req, res) => {
const paymentInformation: {
token: string;
userId: string;
amount: string
amount: string;
status: string;
} = {
token: req.body.token,
userId: req.body.user_identifier,
amount: req.body.amount
amount: req.body.amount,
status: req.body.status
};

try {
await db.$transaction([
db.balance.updateMany({
where: {
userId: Number(paymentInformation.userId)
},
data: {
amount: {
increment: Number(paymentInformation.amount)
if (status == 'success') {
await db.$transaction([
db.balance.updateMany({
where: {
userId: Number(paymentInformation.userId)
},
data: {
amount: {
increment: Number(paymentInformation.amount)
}
}
}
}),
}),
db.onRampTransaction.updateMany({
where: {
token: paymentInformation.token
},
data: {
status: "Success",
}
})
]);
} else {
db.onRampTransaction.updateMany({
where: {
token: paymentInformation.token
},
},
data: {
status: "Success",
status: "Failure",
}
})
]);
}

res.json({
message: "Captured"
})
} catch(e) {
} catch (e) {
console.error(e);
res.status(411).json({
message: "Error while processing webhook"
Expand Down

0 comments on commit 6901818

Please sign in to comment.