[英]Firebase Functions Error for Stripe Create Ephemeral Key
I am attempting to use firebase-functions to create a Stripe ephemeral key via a tutorial.我正在尝试使用 firebase-functions 通过教程创建 Stripe 临时密钥。 Here is the node.js code to do so:
这是执行此操作的 node.js 代码:
exports.createEphemeralKey = functions.https.onCall(async (data, context) => {
const customerId = data.customer_id;
const stripeVersion = data.stripe_version;
const uid = context.auth.uid;
if (uid === null) {
console.log('Illegal access attempt due to unauthenticated attempt.')
throw new functions.https.HttpsError('internal', 'Illegal access attempt');
}
return stripe.ephemeralKeys.create(
{ customer: customerId },
{ stripe_version: stripeVersion }
).then((key) => {
return key
}).catch( (err) => {
functions.logger.log('Error creating ephemeral key', err)
throw new functions.https.HttpsError('internal', 'Unable to create ephemeral key: ' + err)
});
});
Immediately upon running, Xcode shows the following error code: Xcode一运行,立即显示如下错误代码:
Error Domain=com.firebase.functions Code=13 "INTERNAL" UserInfo={NSLocalizedDescription=INTERNAL}
When I click to Manage my credit cards (which triggers the Stripe Payment Sheet), the Stripe payment sheet never loads and just shows "Loading..."当我单击“管理我的信用卡”(触发 Stripe 付款表)时,Stripe 付款表从不加载,只显示“正在加载...”
My hunch is that my Swift code is OK, and that this is a problem solely with the node.js createEphemeralKey function. I think the customerID is fine, as I can generate it with a print function in Xcode. Might this be an issue with the stripeVersion?我的预感是我的 Swift 代码没问题,这只是 node.js createEphemeralKey function 的问题。我认为 customerID 没问题,因为我可以在 Xcode 中使用打印 function 生成它。这可能是 stripeVersion 的一个问题? Or something else?
或者是其他东西?
Figured it out.弄清楚了。 There were two issues:
有两个问题:
Here is the code that worked:这是有效的代码:
exports.createEphemeralKey = functions.https.onCall(async (data, context) => {
const customerId = data.customerId;
const apiVersion = data.stripeVersion;
const uid = context.auth.uid;
if (uid === null) {
console.log('Illegal access attempt due to unauthenticated attempt.')
throw new functions.https.HttpsError('internal', 'Illegal access attempt');
}
return stripe.ephemeralKeys.create(
{ customer: customerId},
{ apiVersion: apiVersion}
).then((key) => {
return key
}).catch( (err) => {
functions.logger.log('Error creating ephemeral key', err)
throw new functions.https.HttpsError('internal', 'Unable to create ephemeral key: ' + err)
})
})
Then in Xcode remember to change your data:然后在Xcode记得改你的数据:
let data = [
"apiVersion": apiVersion,
"customerId": UserManager.instance.user?.stripeId
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.