簡體   English   中英

使用 postman 測試 onWrite firestore function

[英]test onWrite firestore function using postman

我正在嘗試使用 Firestore 雲firestore實現stripe收費功能,我在 stackoverflow 線程上發現了這個 function。 我從來沒有使用過使用條帶觸發器的函數,所以我很難用 postman 測試這個postman 有什么方法可以使用postman測試這個 function 嗎? 如果是,那么請告訴我怎么做,但如果我不能這樣做,那么我想知道如何將這個 function 與我的angular應用程序一起使用,該應用程序包含一個名為 paymentRequest 的組件。 這是 function

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 })
     })
   });

Postman 無法直接調用 Firestore 觸發器。 它只能使用其端點 URL 調用 HTTP 類型的函數。

如果您想調用此 function,只需使用 Firebase 控制台或您編寫的其他代碼創建或修改與文檔模式匹配的文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM