-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_payment.js
More file actions
executable file
·40 lines (37 loc) · 923 Bytes
/
Copy pathcreate_payment.js
File metadata and controls
executable file
·40 lines (37 loc) · 923 Bytes
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
const express = require ('express');
const Razorpay = require ('razorpay');
const bodyParser = require ('body-parser');
// razorpay instance
const razorpay = new Razorpay ({
key_id: 'rzp_test_Sih1MBM2KDbgmA',
key_secret: 'mudKbxfk2RwKAXefp4q5m3uR',
});
// express app instance
const app = express ();
app.use (bodyParser.json ());
PORT = 4000;
app.listen (PORT, () => {
console.log (`API listening on PORT ${PORT} `);
});
app.use(cors({
origin: '*'
}));
app.post ('/api/payments', async (req, res) => {
console.log(req)
const amount = req.body.amount;
const currency = req.body.currency;
console.log ('service');
// Create a new Razorpay order
try {
const order = await razorpay.orders.create ({
amount: amount,
currency: currency,
});
console.log(order)
res.json ({order});
} catch (err) {
console.log (err);
}
});
// Export the Express API
module.exports = app;