TypeError: Cannot read properties of undefined (reading 'create') in flutterwave-node-v3 library

134 Views Asked by At

Hello Stack Overflow community,

I'm facing an issue while using the flutterwave-node-v3 library in my Node.js project. I'm trying to create an order using the flw.orders.create method, but I keep getting the following error: TypeError: Cannot read properties of undefined (reading 'create') at checkout (C:\Users\kv4biz\Desktop\mojoyOnline\Ecommerce(backend)\controller\paymentCtrl.js:16:34)

Here's the relevant part of my paymentCtrl.js file:

const Flutterwave = require("flutterwave-node-v3");
require("dotenv").config();
const flw = new Flutterwave(
  process.env.FLW_PUBLIC_KEY,
  process.env.FLW_SECRET_KEY
);

const checkout = async (req, res) => {
  const { amount } = req.body;
  const option = {
  amount: amount * 100,
  currency: "NGN",
  redirect_url: "YOUR_REDIRECT_URL",
  payment_options: "card,mobilemoney,ussd",
};
const order = await flw.orders.create(option); // This line causes the error
  res.json({
   success: true,
   order,
  });
};

// ... other functions ...

module.exports = {
 checkout,
 paymentVerification,

};

I have confirmed that the flutterwave-node-v3 package is installed, and I have set the correct FLW_PUBLIC_KEY and FLW_SECRET_KEY in my environment variables.

Can anyone please help me understand why I'm getting this error and how to fix it? I'd appreciate any insights or suggestions to resolve this issue.

Thank you!

0

There are 0 best solutions below