【发布时间】:2019-08-20 22:09:31
【问题描述】:
我正在构建一个将使用 Stripe API 来处理付款的云函数。这是在一个firebase项目中。当我运行firebase deploy 时,我收到错误“对象可能'未定义'”const existingSource = customer.sources.data.filter( (s) => s.id === source).pop();
我不确定如何解决这个问题。
这是我存在 getorCreateCustomer 的 xxx.ts
/** Read the stripe customer ID from firestore, or create a new one if missing */
export const getOrCreateCustomer = async(uid: string) => {
const user = await getUser(uid);
const customerId = user && user.stripeCustomerId;
//if missing customerId, create it
if (!customerId) {
return createCustomer(uid);
}
else {
return stripe.customers.retrieve(customerId);
}
}
【问题讨论】:
-
请编辑问题以显示
getOrCreateCustomer,因为这会返回可能未定义的对象。 -
@DougStevenson 抱歉,我编辑并添加了文件。希望你能帮忙。
标签: typescript firebase google-cloud-functions stripe-payments