恢复云写入功能不起作用



我正在尝试设置一个承诺链,这些承诺链在完成条纹付款时触发。我的函数正确 lint 和编译,但它们没有部署,但是当我尝试firebase deploy --only functions时出现此错误

+  functions: Finished running predeploy script.
i  functions: ensuring necessary APIs are enabled...
+  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (37.79 KB) for uploading
+  functions: functions folder uploaded successfully
i  functions: updating Node.js 6 function stripeCharge(us-central1)...
i  functions: updating Node.js 6 function getTime(us-central1)...
+  functions[getTime(us-central1)]: Successful update operation.
!  functions[stripeCharge(us-central1)]: Deployment error.
Failed to configure trigger providers/cloud.firestore/eventTypes/document.create@firestore.googleapis.com 
(__gcf__.us-central1.stripeCharge)

Functions deploy had errors. To continue deploying other features (such as 
database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.

这是我的函数代码

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp(functions.config().firebase);
const stripe = require('stripe')('mytestkey');
exports.stripeCharge = functions.firestore
   .document('/store{userId}/mypayments/activepayments/{paymentId}')
   .onCreate((snap, event) => {
     const payment = snap.data()
     const userId = event.params.userId
     const paymentId = event.params.paymentId
     console.log(payment);
   // checks if payment exists or if it has already been charged
   if (!payment || payment.charge) return null;
   return admin.firestore()
      .doc(`/users/${userId}`)
      .get()
      .then(snapshot => {
       return snapshot
      })
      .then(snapshot => {
        const amount = payment.amount // amount must be in cents
        const idempotency_key = paymentId  // prevent duplicate charges
        const source = payment.token.source.id;
        const currency = 'usd'
        const charge = { amount, currency, source }
        console.log(charge);
        return stripe.charges.create(charge, { idempotency_key })
      })
      .then((charge) => {
        admin.firestore()
          .doc(`store${userId}/mypayments/activepayments/${paymentId}`)
          .set({
            charge: charge 
          }, { merge: true })
          .then(() => {
            if (charge.status === 'succeeded') {
              if (payment.amount === 3000) {
                const validTill = Date.now() + 12 * 30 * 24 * 60 * 60 * 1000;
                admin.firestore()
                  .doc(`/store${userId}/stats/mystatistics/exp`)
                  .set({
                    validTill
                  }).then(() => {
                    console.log('successfully updated expiration date from server');
                  }
                  )
                  .catch(er => {
                    console.log(er);
                     return er;
                   })
               }
              if (payment.amount === 2000) {
                const validTill = Date.now() + 6 * 30 * 24 * 60 * 60 * 1000;
                admin.firestore()
                  .doc(`/store${userId}/stats/mystatistics/exp`)
                  .set({
                    exp: validTill
                  },{merge: false})
                  .catch(er => {
                    console.log(er);
                    return er;
                 })
              }
             if (payment.amount === 5100) {
                const validTill = Date.now() + 12 * 30 * 24 * 60 * 60 * 1000
                admin.firestore()
                   .doc(`/store${userId}/stats/mystatistics/exp`)
                   .set({
                   exp: validTill
                  },{merge: false})
                   .catch(er => {
                    return er;
                  })
              }
               if (payment.amount === 2700) {
               const validTill = Date.now() + 6 * 30 * 24 * 60 * 60 * 1000
                admin.firestore()
                  .doc(`/store${userId}/stats/mystatistics/exp`)
                  .set({
                    exp: validTill
                   },{merge: false})
                  .catch(er => {
                    return er;
                  })
              }  
              if (payment.amount === 500) {
                const validTill = Date.now() + 30 * 24 * 60 * 60 * 1000
                admin.firestore()
                 .doc(`/store${userId}/stats/mystatistics/exp`)
                 .set({
                    exp: validTill
                  },{merge: false})
                  .catch(er => {
                    return er;
                  })
               }
            }
           }).catch(er =>{
             console.log(er)
         })
       })
      .catch(er=>{
         console.log(er);
      })
  })  

我非常感谢任何帮助找出问题来自哪里以及为什么我的触发器没有被保存

根据我(和其他人)上面的评论,共识是您作为触发器监视的路由无效 - 我认为 Firebase 不支持像/store{userId}/这样的"部分"通配符......我明白你想做什么,我只是认为它不受支持。

尝试更改触发器以观看

.document('/{storeUserId}/mypayments/activepayments/{paymentId}')

这应该部署。您必须更改计划存储信息的方式,但触发器将起作用。

相关内容

  • 没有找到相关文章

最新更新