From 2d84ca23f02efcaa485c0c39941f04cda7ebc507 Mon Sep 17 00:00:00 2001 From: Ankit Varshney Date: Wed, 22 Nov 2023 17:31:11 +0530 Subject: [PATCH] fix payment api --- controllers/payment_controller.js | 9 ++++----- index.js | 3 +++ routes/paymentRouter.js | 9 ++++----- views/makePayment.ejs | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/controllers/payment_controller.js b/controllers/payment_controller.js index 38a8b46..e9c5f43 100644 --- a/controllers/payment_controller.js +++ b/controllers/payment_controller.js @@ -22,8 +22,7 @@ const paymentCtrl = { key_id: process.env.KEY_ID, key_secret: process.env.KEY_SECRET, }); - // // console.log(razorpayInstance); - // console.log(process.env.KEY_SECRET); + const options = { amount: amount * 100, currency: "INR", @@ -50,9 +49,9 @@ const paymentCtrl = { checkPayment: async (req, res, next) => { try { - // console.log("inside checkPayment"); - // console.log(`req.body.order_id is ${req.body.order_id}`) - // console.log(`req.body.payment_id is ${req.body.payment_id}`) + console.log("inside checkPayment"); + console.log(`req.body.order_id is ${req.body.order_id}`) + console.log(`req.body.payment_id is ${req.body.payment_id}`) const courseid = req.params.courseId; const result = await courseIdSchema.validateAsync({ params: courseid }); const courseId = result.params; diff --git a/index.js b/index.js index c98d796..e4d3e9e 100644 --- a/index.js +++ b/index.js @@ -34,6 +34,9 @@ app.set("view engine", "ejs"); app.get("/upload", async (req, res) => { res.render("upload"); }); +app.get("/payment", async (req, res) => { + res.render("makePayment"); +}); app.use(express.urlencoded({ extended: false })); app.use(express.json()); app.use(errorMiddleware); diff --git a/routes/paymentRouter.js b/routes/paymentRouter.js index 0efb167..8cfa206 100644 --- a/routes/paymentRouter.js +++ b/routes/paymentRouter.js @@ -1,15 +1,14 @@ const express = require("express"); const paymentRouter = express.Router(); -const {paymentCtrl} = require("../controllers"); +const { paymentCtrl } = require("../controllers"); const { auth } = require("../middlewares"); - // paymentRouter.get("/payment", (req, res)=>{ // res.render("makePayment") // }) -paymentRouter.post("/createOrder" , auth,paymentCtrl.createOrder) +paymentRouter.post("/createOrder/:courseId",auth, paymentCtrl.createOrder); -paymentRouter.post("/checkPayment/:courseId",auth,paymentCtrl.checkPayment) +paymentRouter.post("/checkPayment/:courseId",auth, paymentCtrl.checkPayment); -module.exports = paymentRouter; \ No newline at end of file +module.exports = paymentRouter; diff --git a/views/makePayment.ejs b/views/makePayment.ejs index 197bb72..3ee8f48 100644 --- a/views/makePayment.ejs +++ b/views/makePayment.ejs @@ -48,7 +48,7 @@ "currency": "INR", "order_id": "" + res.order_id + "", "handler": function (response) { - alert("Payment Success"); + // alert("Payment Success"); console.log(response); $.ajax({ url: "/checkPayment",