Skip to content

Instantly share code, notes, and snippets.

@piyushgarg-dev
Last active May 9, 2021 07:16
Show Gist options
  • Save piyushgarg-dev/eee86e6749d0e91de5d6158a39f2eae6 to your computer and use it in GitHub Desktop.
Save piyushgarg-dev/eee86e6749d0e91de5d6158a39f2eae6 to your computer and use it in GitHub Desktop.
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