[使用邮递员测试onWrite Firestore函数

问题描述 投票:2回答:1

我正在尝试使用stripe云功能实现firestore收费功能,并且在stackoverflow线程上发现了此功能。我从未使用过使用条纹触发器的函数,所以我正努力用postman测试此函数。有什么方法可以使用postman测试此功能?如果是,那么请告诉我该怎么做,但是如果我不能这样做,那么我想知道如何在包含名为PaymentRequest的组件的angular应用程序中使用此功能。这是函数

exports.stripeCharge = functions.firestore
  .document('/users/{userId}/payments/{paymentId}')
  .onWrite(event => {
    const payment = event.data.data()
    const userId = event.params.userId
    const paymentId = event.params.paymentId

    // checks if payment exists or if it has already been charged
    if (!payment || payment.charge) return

    return admin.firestore()
      .doc(`/users/${userId}`)
      .get()
      .then(snapshot => {
        return snapshot
      })
      .then(customer => {
        const amount = payment.price * 100 // amount must be in cents
        const idempotency_key = paymentId  // prevent duplicate charges
        const source = payment.token.id
        const currency = 'usd'
        const description = 'irl Map Fine Print'
        const charge = {amount, currency, source}

        return stripe.charges.create(charge, { idempotency_key })
     })
     .then(charge => {
       admin.firestore()
        .doc(`/users/${userId}/payments/${paymentId}`)
        .set({
          charge: charge
        }, { merge: true })
     })
   });
javascript node.js google-cloud-firestore google-cloud-functions
1个回答
0
投票

邮递员无法直接调用Firestore触发器。它只能使用其端点URL调用HTTP类型的函数。

如果要调用此功能,请使用Firebase控制台或您编写的其他代码来创建或修改与文档模式匹配的文档。

© www.soinside.com 2019 - 2024. All rights reserved.