-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaymentController.js
61 lines (50 loc) · 1.52 KB
/
paymentController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const Razorpay = require('razorpay');
const { RAZORPAY_ID_KEY, RAZORPAY_SECRET_KEY } = process.env;
const razorpayInstance = new Razorpay({
key_id: RAZORPAY_ID_KEY,
key_secret: RAZORPAY_SECRET_KEY
});
const renderProductPage = async(req,res)=>{
try {
res.sendFile(__dirname+"/services.html");
} catch (error) {
console.log(error.message);
}
}
const createOrder = async(req,res)=>{
try {
const amount = req.body.amount*100
const options = {
amount: amount,
currency: 'INR',
receipt: '[email protected]'
}
razorpayInstance.orders.create(options,
(err, order)=>{
if(!err){
res.status(200).send({
success:true,
msg:'Order Created',
order_id:order.id,
amount:amount,
key_id:RAZORPAY_ID_KEY,
product_name:req.body.name,
description:req.body.description,
contact:"8567345632",
name: "Anuj Sharma",
email: "[email protected]"
});
}
else{
res.status(400).send({success:false,msg:'Something went wrong!'});
}
}
);
} catch (error) {
console.log(error.message);
}
}
module.exports = {
renderProductPage,
createOrder
}