Skip to content

Finish onramps

Course: PayTM Part-2 - chapter 2

Right now, we’re able to see the onramp transactions that have been seeded.

We don’t see any new ones though

Clicking on this button should initiate a new entry in the onRampTransactions table, that is eventually fulfilled by the bank-webhook module

Let’s implement this feature via a server action

  • Create a new action in lib/actions/createOnrampTransaction.ts
"use server";
import prisma from "@repo/db/client";
import { getServerSession } from "next-auth";
import { authOptions } from "../auth";
export async function createOnRampTransaction(provider: string, amount: number) {
// Ideally the token should come from the banking provider (hdfc/axis)
const session = await getServerSession(authOptions);
if (!session?.user || !session.user?.id) {
return {
message: "Unauthenticated request"
}
}
const token = (Math.random() * 1000).toString();
await prisma.onRampTransaction.create({
data: {
provider,
status: "Processing",
startTime: new Date(),
token: token,
userId: Number(session?.user?.id),
amount: amount * 100
}
});
return {
message: "Done"
}
}
  • Call the action when the button is pressed (AddMoneyCard)
$1b

Notice more balances getting added , but the balance will remain the same. This is because the bank hasn’t yet approved the txn

  • cd apps/bank-webhook

  • npm run dev (If it fails, try installing esbuild)

  • In another terminal, get the token for one of the onRamp transactions by running npx prisma studio in packages/db

  • Simulate a hdfcBank transaction POST http://localhost:3003/hdfcWebhook

{
"token": "970.4572088875194",
"user_identifier": 1,
"amount": "210"
}

💡 Do you really need the amount/user id to come from the hdfc bank server? Or is the token enough?