feat: add razorpay

This commit is contained in:
2025-04-17 11:29:03 +05:30
parent c00055f466
commit b5d5cd6ab1
6 changed files with 209 additions and 41 deletions

View File

@@ -0,0 +1,23 @@
import Razorpay from "razorpay";
const razorpay = new Razorpay({
key_id: "rzp_test_1SbLmNX2nCKRZA",
key_secret: "8CTcXrodJqKQ3cfmic84Ffdl",
});
export async function POST(req) {
try {
const body = await req.json(); // Parse the request body
const { amount, currency } = body;
const order = await razorpay.orders.create({
amount,
currency,
});
return new Response(JSON.stringify(order), { status: 200 });
} catch (error) {
console.error("Error creating Razorpay order:", error);
return new Response(JSON.stringify({ error: "Failed to create Razorpay order" }), { status: 500 });
}
}

View File

@@ -0,0 +1,23 @@
const crypto = require("crypto");
export default async function handler(req, res) {
if (req.method === "POST") {
const { razorpay_order_id, razorpay_payment_id, razorpay_signature } =
req.body;
const body = razorpay_order_id + "|" + razorpay_payment_id;
const expectedSignature = crypto
.createHmac("sha256", "8CTcXrodJqKQ3cfmic84Ffdl")
.update(body.toString())
.digest("hex");
if (expectedSignature === razorpay_signature) {
res.status(200).json({ success: true });
} else {
res.status(400).json({ success: false });
}
} else {
res.status(405).json({ error: "Method not allowed" });
}
}