I am trying to integrate Razorpay in my nuxt app. For that, I installed razorpay dependency using npm i razorpay
My index.js files starts with
const functions = require('firebase-functions')
const Razorpay = require('razorpay')
const admin = require('firebase-admin')
const crypto = require('crypto')
But after writing the function(basic helloWorld function) and deploying it gave me an error unable to deploy function. But when I commented below line the helloWorld function deployed successfully.
//const Razorpay = require('razorpay')
Again I uncommented above line and it still gives me error unable to deploy.
Version info
Node v12.18.3
Firebase v8.16.2
My Dependencies
"dependencies": {
"@nuxtjs/axios": "^5.12.2",
"@nuxtjs/pwa": "^3.0.2",
"cookieparser": "^0.1.0",
"core-js": "^3.6.5",
"firebase": "^8.2.0",
"js-cookie": "^2.2.1",
"jwt-decode": "^3.1.2",
"nuxt": "^2.14.6",
"nuxt-buefy": "^0.4.3",
"razorpay": "^2.0.6",
"uuid": "^8.3.2",
"vuexfire": "^3.2.5"
},
Please note that you will need to put the following in the Firebase Cloud Function to integrate the Razorpray:
const Razorpay = require("razorpay");
var key_id = "YOUR_RAZORPAY_KEY_ID";
var key_secret = "YOUR_RAZORPAY_KEY_SECRET";
var instance = new Razorpay({
key_id: key_id,
key_secret: key_secret
});
You need to follow the next steps to integrate it:
Please have a look into the following Medium tutorial for better understanding and this GitHub Repository for a code example.
********** UPDATE **********
Regarding Cors error, please make sure the following:
const cors = require('cors')({origin: true});
exports.createPayment = functions.https.onRequest(async (req, res) => {
cors(req, res, () => {
// your function body here - use the provided req and res from cors
})
});