Firebase云功能始终返回Null

时间:2018-09-23 23:11:39

标签: ios swift firebase stripe-payments google-cloud-functions

我正在尝试使用以下函数与Stripe API进行交互-由于app.post('/form',function(req,res){ var tf = req.body.termFound; // var reg =`/${tf}/i`; not an actual regex, still a string!!! var reg = new RegExp(tf, 'i') // as you have since discovered db.collection('a').find({"keyword": {$regex: reg }}).toArray(function (err,results){ if (err) return console.log(err) res.render('stest.ejs',{arr:results}) }); }) 对象已在控制台中正确记录并按预期显示,因此似乎可以正常工作。

key

但是,当我从Swift iOS应用程序调用此函数时,exports.createEphemeralKey = functions.https.onCall((data,context) => { const stripe_version = data.api_version; const customerId = data.customer_id; if (!stripe_version) { throw new functions.https.HttpsError('missing-stripe-version','The stripe version has not been provided.'); } if (customerId.length === 0) { throw new functions.https.HttpsError('missing-customerID','The customer ID has not been provided.'); } return stripe.ephemeralKeys.create( {customer: customerId}, {stripe_version: stripe_version} ).then((key) => { console.log(key); return key; }).catch((err) => { console.log(err); throw new functions.https.HttpsError('stripe-error', err); }); }); 始终为nil。

result?.data

1 个答案:

答案 0 :(得分:1)

可能是因为您没有返回“可以JSON编码的数据”(请参见doc)。以下应该起作用:

....
).then((key) => {
  console.log(key);
  return {key: key};
})
....