Javascript Node.js/Stripe API |使用时产品创建不起作用(错误,产品)
目前,我正在尝试使用我将输入的表单数据中的给定细节创建一个新的条带产品。到目前为止,当创建条带产品时,它将在console.log(产品)中向我提供产品详细信息,前提是我不使用我希望能够使用的注释掉部分。如果我使用注释掉的部分,那么它会说产品未定义,并且我无法传递未定义的stripeID。我还将采取任何有关代码的一般提示,因为我仍在学习!谢谢大家!Javascript Node.js/Stripe API |使用时产品创建不起作用(错误,产品),javascript,node.js,mongodb,express,stripe-payments,Javascript,Node.js,Mongodb,Express,Stripe Payments,目前,我正在尝试使用我将输入的表单数据中的给定细节创建一个新的条带产品。到目前为止,当创建条带产品时,它将在console.log(产品)中向我提供产品详细信息,前提是我不使用我希望能够使用的注释掉部分。如果我使用注释掉的部分,那么它会说产品未定义,并且我无法传递未定义的stripeID。我还将采取任何有关代码的一般提示,因为我仍在学习!谢谢大家! //Product Create app.post('/products', async (req, res) => {
//Product Create
app.post('/products', async (req, res) => {
// Creates New Stripe Product
const product = await stripe.products.create({
name: req.body.productName,
images: [req.body.productImage]
/* },
(err, newProduct) => {
if (err) {
console.log(err);
} else {
console.log(`New Stripe Product Created`);
} */
});
console.log(product);
// Creates product with stripe Id and adds it to Mongo DB
Product.create({
productName: req.body.productName,
productDescription: req.body.productDescription,
price: req.body.productPrice,
img: req.body.productImage,
stripeProductId: product.id
},
(err, newProduct) => {
if (err) {
console.log('product not added to mongo');
console.log(err);
} else {
console.log('product created');
}
});
res.send('New/Post Create New Product');
});
在调用这些方法时,您似乎使用了两种方法,即
wait
和回调
await
方法的外观:newProduct
:const product = await stripe.products.create({
name: req.body.productName,
images: [req.body.productImage]
});
console.log("My product is" , product);
stripe.products.create({
name: req.body.productName,
images: [req.body.productImage]
},
(err, newProduct) => {
console.log("I am here");
if (err) {
console.log(err);
} else {
console.log('New Stripe Product Created', newProduct);
}
});