Skip to content

Commit

Permalink
fix payment api
Browse files Browse the repository at this point in the history
  • Loading branch information
AVtheking committed Nov 22, 2023
1 parent 4cc53db commit 2d84ca2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
9 changes: 4 additions & 5 deletions controllers/payment_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions routes/paymentRouter.js
Original file line number Diff line number Diff line change
@@ -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;
module.exports = paymentRouter;
2 changes: 1 addition & 1 deletion views/makePayment.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2d84ca2

Please sign in to comment.