firebase - Stripe firebase扩展,监听收集组中的发票收集

标签 firebase google-cloud-firestore google-cloud-functions stripe-payments firebase-extensions

关于 Firebase 的 strip 扩展:https://firebase.google.com/products/extensions/firestore-stripe-invoices 我还没有在文档中找到任何相关内容,源代码也没有向我透露太多信息(至少就我的理解而言)。

在扩展的配置中,它要求一个集合来监听发票。是否可以使用集合组来代替?因此,我不想在 invoices 处监听发票,而是希望它在 users/{uid}/invoices

处监听

最佳答案

来自extension code ,

let invoicesInFirestore = await admin
  .firestore()
  .collection(config.invoicesCollectionPath)
  .where('stripeInvoiceId', '==', invoice.id)
  .get();

在撰写本文时,似乎尚未预见到可以处理多个子集合。

我可以看到两种解决方案:

1。调整扩展代码以创建您自己的云函数

您复制扩展代码并以处理多个子集合的方式对其进行修改,以便创建您自己的 Cloud Functions。

请注意,扩展代码使用 export const sendInvoice =functions.handler.firestore.document.onCreate(...) 声明 Cloud Function。正如 doc 中所述“HandlerBuilder 类有助于构建 Firebase 扩展的开发人员编写函数...在编写通过Firebase CLI。”

因此您应该按如下方式对其进行调整:

export const sendInvoice = functions.firestore
    .document('users/{uid}/invoices')
    .onCreate((snap, context) => {...}

但是,请注意,通过编写自己的云函数,您将失去扩展的潜在未来改进。

2。创建一个云函数,从子集合中复制/粘贴发票

这个想法是让一个 Cloud Function 监听所有 users/{uid}/invoices 子集合(见上文),复制新文档并在“中央”扩展集合中创建副本。没有什么可以阻止您在复制的文档中添加一些额外的字段,例如用户的 uid。

请注意,如果您想从 Stripe 获得反馈,您可能需要另一个 Cloud Function(它监听“中央”扩展集合)来将 Stripe webhook 调用的结果复制/粘贴到原始文档中users/{uid}/invoices 子集合。

我个人会选择第二种方法。

关于firebase - Stripe firebase扩展,监听收集组中的发票收集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66453660/

相关文章:

javascript - 在 firebase 中使用 websockets 的正确方法是什么?

android - 有没有一种方法可以让每个 Firebase 项目显示 3 个以上的应用程序?

php - Firebase 错误 : Credentials fetcher does not implement Google\Auth\UpdateMetadataInterface

javascript - 在 firebase 云函数中拆分 index.js 文件时出错

xcode - "No such module ' Firebase '"//找不到FirebaseUI框架

android - 为什么在 Android onCreate 下匿名登录时 Firebase 控制台不创建匿名用户?

firebase - Flutter FireStore

python - 为什么 Firestore 对 64 位整数进行舍入?

javascript - 在 cloudfunction 中运行的 ffmpeg 静默失败/永远不会完成

javascript - 身份验证错误后的 Firebase 用户数据