![](/img/trans.png)
[英]Can't get onCreate function to trigger using TypeScript on Cloud Firestore
[英]How to update or set property of firestore document after .onCreate cloud function trigger
我目前正在嘗試通過使用Cloud Functions for Firebase將Stripe與Firebase的Cloud Firestore數據庫集成。 onCreate
觸發器發生正確,但我也希望它將其更新或設置一個名為“ customer_id”的特定字段到我的用戶集合中的正確文檔中。 我認為關於函數的編寫方式有些不足,因為我不是最有經驗的javascript。
我也嘗試過
return admin.firestore().ref(`Users/${user.uid}/customer_id`).set(customer.id);
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
//const logging = require('@google-cloud/logging')();
const stripe = require('stripe')(functions.config().stripe.token);
const currency = functions.config().stripe.currency || 'USD';
// When a user is created, register them with Stripe
exports.createStripeCustomer = functions.auth.user().onCreate((user) => {
return stripe.customers.create({
email: user.email,
}).then((customer) => {
return admin.firestore().collection("Users").doc(user.uid).update({"customer_id": customer.id})
});
});
使用Stripe創建客戶沒有問題,但是Firestore數據庫上的“ customter_id”字段未更新。
如評論中所述,在錯誤日志的打印屏幕上,您已部署的代碼與您在問題中引用的代碼不對應。
您問題中的代碼看起來正確。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.