【问题标题】:Stripe - Update default cardStripe - 更新默认卡片
【发布时间】:2019-10-20 12:22:27
【问题描述】:

我正在尝试允许用户在添加默认付款方式后对其进行更新。我在 Firebase 函数中得到了这个:Error: No such source: card_1EhmibFZW9pBNLO2aveVfEm6

这让我相信我需要传递 default_source 一个 src_XXX... id 而不是 card_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 功能日志:

【问题讨论】:

  • 嗨 DangerDoug,default_source 字段支持客户上的附加卡,即卡对象(例如 card_123)。您尝试设置为 default_source 的卡 ID 很可能不是客户现有来源中的卡 ID。您更新的是同一个客户吗?即是previousValue.customer_id == newValue.customer_id?
  • @hmunoz 好的,很高兴知道并提供帮助。我添加了显示的 firebase 功能日志。我认为这可能与尚未在条带中传播的卡数据有关。 DB中的所有卡详细信息都是正确的,包括错误中的卡号。在 addPaymentSource 的情况下,我真的不需要触发 updateDefaultSource,因为 Stripe 会自动执行此操作。在这种情况下如何防止 updateDefaultSource 触发?

标签: node.js firebase google-cloud-functions stripe-payments


【解决方案1】:

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

@hmunoz 回答了我的主要问题,即 default_source 是否接受 card_123 类型,它确实接受了。

【讨论】:

    猜你喜欢
    • 2015-06-27
    • 2021-02-14
    • 1970-01-01
    • 2019-12-01
    • 2019-08-03
    • 2019-11-11
    • 1970-01-01
    • 2014-02-22
    • 1970-01-01
    相关资源
    最近更新 更多