【问题标题】:stripe firebase callable function returning null条纹firebase可调用函数返回null
【发布时间】:2020-08-15 10:31:21
【问题描述】:

我制作了一个 firebase 可调用函数来调用条带 api 来获取条带客户对象

exports.getDefaultPayment = functions.https.onCall(async (data, context) => {
  await stripe.customers.retrieve("cus_H5UarU16gpUbqM", (customer) => {
    // asynchronously called
    return customer;
  });
});

然后我尝试简单地记录该对象

onPress={() => {
              const getDefaultPayment = functions().httpsCallable(
                'getDefaultPayment'
              );
              getDefaultPayment().then((result) => {
                console.log(JSON.parse(result.data));
              });
            }}

但结果为空

【问题讨论】:

    标签: javascript firebase react-native google-cloud-functions stripe-payments


    【解决方案1】:

    您的可调用函数实际上并未向客户端返回任何内容。您需要在顶层使用 return 语句,而不是在回调中。此外,您似乎将回调与 async/await 混为一谈,这没有意义。只需使用 await - 不要打扰回调。也许这会起作用:

    return stripe.customers.retrieve("cus_H5UarU16gpUbqM")
    

    【讨论】:

      猜你喜欢
      • 2020-06-03
      • 2021-10-16
      • 2021-12-16
      • 2020-06-03
      • 1970-01-01
      • 2021-12-06
      • 2015-02-03
      • 2020-12-09
      • 2018-11-24
      相关资源
      最近更新 更多