Last active
May 9, 2021 07:16
-
-
Save piyushgarg-dev/eee86e6749d0e91de5d6158a39f2eae6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { request, response } = require('express'); | |
const express = require('express'); | |
const Razorpay = require('razorpay'); | |
const app = express(); | |
const PORT = 8000; | |
app.use(express.static('./public')); | |
app.use(express.json()); | |
app.post('/order', async (request, response) => { | |
const amount = request.body.amount; | |
if (!amount) return response.json({ message: 'Please provide amount' }) | |
// Create a razorpayInstance | |
const razorpayInstance = new Razorpay({ | |
key_id: '<YOUR_KEY_ID_HERE>', | |
key_secret: '<YOUR_SECRET_HERE>', | |
}); | |
const paymentOptions = { | |
amount: amount * 100, | |
currency: 'INR', | |
receipt: '#1', | |
}; | |
const razorpayOrder = await razorpayInstance.orders.create(paymentOptions); | |
return response.json({ | |
message: 'success', | |
order: razorpayOrder | |
}); | |
}); | |
app.listen(PORT, () => console.log(`Express server started at PORT:${PORT}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment