【发布时间】:2018-11-13 18:49:43
【问题描述】:
我一直在玩 Stripe,想了解如何通过以下方式获取临时密钥:
后端:
//Stripe API requirement for payment
exports.stripeEphemeralKey = functions.https.onCall((data, context) => {
const uid = context.auth.uid;
//Get values
admin.database().ref().child("users").child(uid)
.on("value", (snapshot) =>{
//Get user data
let user = snapshot.val()
//Log data
console.log("Create ephemeral key for:")
console.log(user)
//Create ephemeral key
stripe.ephemeralKeys.create(
{customer: user.customerid },
{stripe_version: '2018-11-08'}
)
.then((key) => {
console.log(key)
console.log("Succesful path. Ephemeral created.")
return "Testing"
})
.catch((err) => {
console.log("Unsuccesful path. Ephemeral not created.")
console.log(err)
return {
valid: false,
data: "Error creating Stripe key"
}
})
})
})
客户端:
functions.httpsCallable("stripeEphemeralKey").call(["text": "Testing"]) { (result, error) in
print(result?.data)
}
我已经通过用一个简单的“测试”字符串替换 stripeEphemeralKey 的主体来测试此代码,并且返回很好。但是使用上面的代码,我只是得到了 Optional() 。
为了测试,我添加了很多控制台日志。 Firebase 日志显示执行路径到达“成功路径。临时创建”。日志,此外,我实际上可以看到我从条带中返回的临时密钥。
那么,在 Swift for iOS 中使用 onCall Firebase 函数获取临时密钥的正确正确方法是什么?
后端做了它应该做的,但我似乎无法得到答案。
谢谢。
【问题讨论】:
标签: ios swift typescript firebase google-cloud-functions