Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 条纹-更新默认卡_Node.js_Firebase_Google Cloud Functions_Stripe Payments - Fatal编程技术网

Node.js 条纹-更新默认卡

Node.js 条纹-更新默认卡,node.js,firebase,google-cloud-functions,stripe-payments,Node.js,Firebase,Google Cloud Functions,Stripe Payments,我试图允许用户在添加默认付款方式后更新其默认付款方式。我在Firebase函数中得到了这一点:错误:没有这样的源代码:card_1emibfzw9pbnlo2avevfem6 这让我相信我需要传递default\u sourceasrc\u XXX…id而不是card\u XXX…id。有人对此有想法吗 Firebase功能: // Update Stripe default card based on user choice exports.updateDefaultSource = func

我试图允许用户在添加默认付款方式后更新其默认付款方式。我在Firebase函数中得到了这一点:
错误:没有这样的源代码:card_1emibfzw9pbnlo2avevfem6

这让我相信我需要传递
default\u source
a
src\u XXX…
id而不是
card\u XXX…
id。有人对此有想法吗

Firebase功能:

// Update Stripe default card based on user choice
exports.updateDefaultSource = functions.firestore
  .document("users/{userId}")
  .onUpdate(async (change, context) => {
    const newValue = change.after.data();
    const previousValue = change.before.data();
    console.log("previousValue.default_source: "+previousValue.default_source)
    console.log("newValue.default_source: "+newValue.default_source)
    if (
      previousValue.default_source &&
      newValue.default_source !== previousValue.default_source
    ) {
      // this triggers on every update to profile (more overhead), can we reduce this?
      try {
        console.log("newValue.default_source: "+newValue.default_source)
        const response = await stripe.customers.update(
          previousValue.customer_id,
          { default_source: newValue.default_source },
          (err, customer) => {
            console.log(err);
          }
        );
        return console.log("Response from Stripe update: " + response);
      } catch (error) {
        console.log(error);
        await change.ref.set(
          { error: userFacingMessage(error) },
          { merge: true }
        );
        return reportError(error, { user: context.params.userId });
      }
    }
  });
Firebase函数在我将第二张卡添加到帐户后记录:

看起来这个错误自己解决了,不是100%确定如何解决,但我猜这与Redux和/或Redux Persist没有将所有内容加载到存储中有关


我的主要问题由@hmunoz回答,默认的_源是否接受card_123类型,它确实接受

Hi DangerDoug,默认源字段支持客户上的附加卡,即卡对象(例如卡123)。最有可能的是,您试图设置为
默认\u源的卡ID在客户现有源中不是卡ID。您是否正在更新同一客户?i、 e.是previousValue.customer\u id==newValue.customer\u id?@hmunoz好的,很高兴知道并提供帮助。我添加了显示的firebase函数日志。我认为这可能与卡数据尚未在条带中传播有关。所有卡的详细信息在DB中都是正确的,包括错误中的卡号。在addPaymentSource的情况下,我真的不需要UpdatedFaultSource来触发,因为Stripe会自动触发。在这种情况下,如何防止updateDefaultSource触发?