错误:收到未知参数:源

时间:2019-06-04 08:01:13

标签: javascript firebase firebase-realtime-database stripe-payments

我正在制作一个将firetore作为数据库的react-redux应用程序。现在,我想使用Firebase云功能来处理条带支付。

这是云函数“ createSubscription”:

exports.createSubscription = functions.database
  .ref("/teachers/{userId}/pro-membership/token")
  .onWrite((event, context) => {
    const tokenId = event.after.val();
    const userId = context.params.userId;

    if (!tokenId) throw new Error("Token Missing");

    return admin
      .database()
      .ref(`teachers/${userId}`)
      .once("value")
      .then(snapshot => snapshot.val())
      .then(user => {
        console.log(user);

        return stripe.subscriptions.create({
          customer: user.customerId,
            source: tokenId,                 **// Here is the error occuring**
          items: [
            {
              plan: "pro-membership"
            }
          ]
        });
      })
      .then(sub => {
        admin
          .database()
          .ref(`teachers/${userId}/pro-membership`)
          .update({
            status: "active"
          });
      })
      .catch(err => {
        console.log("ERRor", err);
      });
  });

以下是来自云功能日志的错误信息:

Below is the error information from cloud function's logs

1 个答案:

答案 0 :(得分:1)

sourcestripe.subscriptions.create请求中不是有效参数,请参见https://stripe.com/docs/api/subscriptions/create

尝试先更新客户,添加令牌https://stripe.com/docs/api/customers/update,然后创建订阅!