我正在尝试将Cloud Firestore users
数据导入Stripe客户帐户。 Stripe可以工作,但在创建客户时不起作用。没有错误代码。只是跳过了。
代码:
import firebase from "../config/firebase";
import Stripe from "stripe";
const stripe = new Stripe("sk_test_xxxxxxxxxxxx");
console.log("stripe", stripe);
// successfully get
async componentDidMount() {
await db.collection("users")
.get()
.then((snap) => {
let promises = [];
snap.forEach(async (doc) => {
console.log('doc id", doc.id);
// successfully get
const stripeCustomer = await stripe.customers.create({
name: doc.data().name,
email: doc.data().email,
});
console.log("stripeCS", stripeCustomer.id);
// not working :(
});
return Promise.all(promises);
})
}
我添加了async await
,然后显示了Promise{<pending>}
。
答案 0 :(得分:1)
我本可以做到以下几点:
db.collection("users")
.get()
.then((snap) => {
let promises = [];
snap.forEach(async (doc) => {
console.log("doc", doc.data());
await stripe.customers.create({
name: doc.data().name,
email: doc.data().email,
});
});
return Promise.all(promises);
})
.then((hoge) => {
console.log("ends");
})
.catch((err) => {
console.log(`err: ${err}`);
});