-
-
Save ShariqAnsari88/4a1a11deb1d45367404baf37dcced36b to your computer and use it in GitHub Desktop.
("use strict"); | |
const stripe = require("stripe")(process.env.STRIPE_KEY); | |
/** | |
* order controller | |
*/ | |
const { createCoreController } = require("@strapi/strapi").factories; | |
module.exports = createCoreController("api::order.order", ({ strapi }) => ({ | |
async create(ctx) { | |
const { products } = ctx.request.body; | |
try { | |
const lineItems = await Promise.all( | |
products.map(async (product) => { | |
const item = await strapi | |
.service("api::product.product") | |
.findOne(product.id); | |
return { | |
price_data: { | |
currency: "inr", | |
product_data: { | |
name: item.title, | |
}, | |
unit_amount: Math.round(item.price * 100), | |
}, | |
quantity: product.attributes.quantity, | |
}; | |
}) | |
); | |
const session = await stripe.checkout.sessions.create({ | |
shipping_address_collection: { allowed_countries: ["IN"] }, | |
payment_method_types: ["card"], | |
mode: "payment", | |
success_url: process.env.CLIENT_URL + "/success", | |
cancel_url: process.env.CLIENT_URL + "?success=false", | |
line_items: lineItems, | |
}); | |
await strapi | |
.service("api::order.order") | |
.create({ data: { products, stripeId: session.id } }); | |
return { stripeSession: session }; | |
} catch (error) { | |
ctx.response.status = 500; | |
return { error }; | |
} | |
}, | |
})); |
("use strict"); const stripe = require("stripe")(process.env.STRIPE_KEY);
getting error in this line
kindly help ASAP
please help sir
process.env.STRIPE_KEY
still the error not resolved
("use strict"); const stripe = require("stripe")(process.env.STRIPE_KEY);
getting error in this line kindly help ASAP
use // @ts-ignore above your require statement.
Okay, seems like you're not getting the desired product images and data. Hopefully, The problem here lies in map function seens you are using map function in javascript you have to make sure to add optional chaining in order to fetch details from strapi. I'm attaching the screenshot of my code snippet to have better understanding. Feel free to ask if the problem still exists.
for those getting error before and after stripe integration in order.js file
use // @ts-ignore above your require statement.
it works.
If anyone who successfully hosts this website. please message me
i get the same error