javascript - Swift Firebase 函数 Javascript
问题描述
我正在寻求帮助以了解如何将数据添加到 firebase 函数。
exports.createStripeCustomer = functions.auth.user().onCreate(async (user) => {
const customer = await stripe.customers.create({ email: user.email });
const intent = await stripe.setupIntents.create({
customer: customer.id,
});
await admin.firestore().collection('stripe_customers').doc(user.uid).set({
customer_id: customer.id,
setup_secret: intent.client_secret,
});
return;
});
上述功能有效,但我可以为我的应用程序创建 3 种不同类型的配置文件,我不希望在每个用户登录时都调用它。
exports.createStripeCustomer = functions.https.onCall(async (data, context) => {
const full_name = data.full_name;
const email = data.email;
const customer = await stripe.customers.create({
email: email,
name: full_name,
description: full_name
});
console.log('new customer created: ', customer.id)
await admin.firestore().collection('stripe_customers').doc(user.uid).set({
customer_id: customer.id,
setup_secret: intent.client_secret,
});
await admin.database().ref(`/user_profiles/${user.uid}/customer_id`).set(customer.id);
return {
customer_id: customer.id
}
});
上面的代码适用于在条带中创建客户帐户,但不执行将数据保存到 Firestore 和实时数据库中。
func createCustomerId(email: String, completion: ((String?, Error?) -> Void)?){
let data: [String: Any] = [
"email": email,
"name": name
]
print("calling firebase function to create stripe customer")
Functions.functions().httpsCallable("createStripeCustomer")
.call(data) { result, error in
if let error = error {
completion!(nil, error)
} else if let data = result?.data as? [String: Any],
let customerId = data["customerId"] as? String {
completion!(customerId, nil)
}
}
}
上面的代码是我在客户登录期间调用我的 firebase 函数的方式。我做错了什么阻止数据保存到firebase?
解决方案
推荐阅读
- node.js - 使用 amqp10 npm 模块获取 AWS MQ 的所有队列名称?
- java - 预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者,没有找到依赖项类型的合格 bean
- python - 如何使用 matplotlib 可视化每个数据框实例?
- angular - Angular 6 动态表单问题
- python - 如何找到重叠矩形的面积
- azure-data-factory - 映射时使用 adf 管道参数作为源来接收列
- python - “return +/-”在python中做了什么?
- reactjs - 如何在 next.js 中测试 _app.js 内部的逻辑?
- ios - 添加标签栏控制器时如何防止子视图被切断?
- php - PHP按域排序子域列表