Hello Community,
I'm facing an issue while using the Razorpay NPM package in a Google Cloud Function. When calling the create order function using the Razorpay instance, the function throws the following error:
error creating order TypeError: Cannot read properties of undefined (reading 'error')
at normalizeError (/workspace/node_modules/razorpay/dist/api.js:41:22)
at bound (node:domain:432:15)
at runBound (node:domain:443:12)
at tryCatcher (/workspace/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/workspace/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/workspace/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/workspace/node_modules/bluebird/js/release/promise.js:649:10)
...
Environment:
Node.js version: (mention your Node.js version, e.g., v20.0.0)
Razorpay NPM package version: (mention your package version, e.g., 2.9.2 or 2.9.5)
Running in: Google Cloud Functions
Thank you for the help!
Hi @Accredian,
Welcome to Google Cloud Community!
It seems that your Google Cloud Function is experiencing the error "Cannot read properties of undefined (reading 'error')" when invoking razorpay.orders.create(). This usually occurs because of wrong API credentials, network problems, or an unforeseen API response.
Here are some Quick Fix that might help:
const razorpay = new Razorpay({
key_id: process.env.RAZORPAY_KEY_ID,
key_secret: process.env.RAZORPAY_KEY_SECRET
});
const order = await razorpay.orders.create({
amount: 50000, // in paise (₹500)
currency: "INR",
receipt: "order_rcptid_11"
});
try {
const order = await razorpay.orders.create(orderDetails);
console.log("Order Created:", order);
} catch (error) {
console.error("Error:", error.response?.data || error);
}
npm install razorpay@latest
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.