将Firebase函数中的Stripe响应返回给Swift应用程序

时间:2018-11-25 11:02:53

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

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

我正在使用Firebase Functions进行此操作,因此不必维护服务器,也因为我是个极端的新手。

但是,当我尝试说时,请使用Firebase可调用函数来赢得客户。

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

我不确定要在我的应用中实际使用该“客户”对象的“返回”位置。我试图在console.log下放置一个“回头客”,但从来没有...回头客。我也尝试过创建一个空字符串变量,该变量是在控制台登录并返回后设置的,但是在应用程序中,该变量总是作为空字符串出现的。

很抱歉遇到排版问题,这个问题是非常理论性的-我正在手机上打字,因为我不想忘记它,所以我会暂时离开计算机。

任何人都可以提供有关如何将“客户”对象返回到我的iOS应用的指导吗?

1 个答案:

答案 0 :(得分:0)

详细的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可能的