I am using razorpay api as a payment gateway for my shopping website and I am stuck at creating multiple orders
it works perfectly fine when I order single product but when I try to checkout from cart where there are multiple product added, I get stuck about what to do for amount and description field because it sends array of product while its send single product when its ordered directly.
app.post("/payment", async (req, res) => {
try {
const { product } = req.body;
console.log("product");
const amount = product.price * 100;
const currency = "INR";
const receipt = product.id;
const notes = { desc: product.desc };
instance.orders.create({ amount, currency, receipt, notes }),
(err, order) => {
if (error) {
return res.status(500).json({ err });
}
return res.status(200).json({ order });
};
} catch (err) {
console.log(err);
}
res.json(res);
});
when I order directly
{
b_name: "siyaram",
id: 9,
p_color: "white",
p_img: {type: 'Buffer', data: Array(5771)},
p_name: "kurta",
p_price: 1000,
p_size: "s m l"
}
when I order from cart
[
{
b_name: "raymond,
id: 9,
p_color: "yellow",
p_img: {type: 'Buffer', data: Array(5771)},
p_name: "kurta",
p_price: 1000,
p_size: "s m l"
},
{
b_name: "peter England",
id: 9,
p_color: "red",
p_img: {type: 'Buffer', data: Array(5771)},
p_name: "kurta",
p_price: 1300,
p_size: "s m l"
}
]
this throws an error cause here I have multiple product.