简体   繁体   English

条带 firebase 可调用 function 返回 null

[英]stripe firebase callable function returning null

I made a firebase callable function to call stripe api to get a stripe customer object我制作了一个 firebase 可调用 function 来调用条带 api 来获得条带客户 ZA8CFFDE6331BD5B62ZZ6669

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

then I'm trying to simply log that object然后我试图简单地记录 object

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

but the result is null但结果是 null

Your callable function isn't actually returning anything to the client.您的可调用 function 实际上并没有向客户端返回任何内容。 You need a return statement at the top level, not inside a callback.您需要在顶层使用 return 语句,而不是在回调中。 Also, it seems you're mixing up callbacks with async/await, which doesn't make sense.此外,您似乎将回调与 async/await 混为一谈,这没有意义。 Just use await - don't bother with the callback.只需使用 await - 不要打扰回调。 Perhaps this will work:也许这会起作用:

return stripe.customers.retrieve("cus_H5UarU16gpUbqM")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM