【问题标题】:Return Stripe Response within Firebase Function to Swift Application将 Firebase 函数中的条带响应返回给 Swift 应用程序
【发布时间】:2019-04-27 06:05:39
【问题描述】:

我正在尝试制作一个连接到 Stripe 并可以显示用户信息、数据和事物的 iOS。

我是通过使用 Firebase 函数来完成这项工作的,所以我不需要维护服务器,而且我是一个极端的新手。

但是当我尝试说,通过使用 Firebase 可调用函数来获取客户时,例如。

exports.getCustomer = functions.callableFunctions((data, context) => { 
    stripe.customers.retrieve(
    data.customerID, function (err, customer) {
    console.log(‘customer’)
    });
});

我不确定在哪里放置“return”以便在我的应用程序中实际使用那个“customer”对象。我试图在 console.log 下添加一个“回头客”,但它永远不会......返回。我还尝试创建一个空字符串变量,我在控制台日志后设置并返回,但它总是在应用程序上显示为空字符串。

抱歉排版问题,这个问题非常理论化 - 我正在手机上打字,因为我不想忘记它,我会离开我的电脑一段时间。

谁能提供有关如何将“客户”对象返回到我的 iOS 应用程序的任何指导?

【问题讨论】:

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


    【解决方案1】:

    详细here,自 Stripe node.js API 版本 2 发布以来,他们增加了对 Promise 的支持:“每个资源方法现在除了支持常规回调之外,还返回一个 Promises/A+ 兼容的 Promise”。

    所以你可以这样做:

    exports.getCustomer = functions.callableFunctions((data, context) => { 
        const stripeCustomerID = data.customerID;
    
        return stripe.customers.retrieve(stripeCustomerID)
        .then(customer => {
           return { customer: customer };
        })
        .catch(err => {
           throw new functions.https.HttpsError('<status error code>', 'xxxxxxx');
        });
    
    });
    

    doc 所示,查看here 的可能值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-24
      • 2019-03-10
      • 2019-10-11
      • 2018-02-04
      • 1970-01-01
      • 1970-01-01
      • 2020-01-22
      相关资源
      最近更新 更多