【发布时间】:2020-10-11 07:41:16
【问题描述】:
我正在尝试设置一个功能来翻转我:ephemeralKeys
firestoreCloud 返回的错误
Unhandled error TypeError: Cannot read property 'create' of undefined
at exports.createEphemeralKey.functions.https.onCall (/srv/index.js:28:32)
at func (/srv/node_modules/firebase-functions/lib/providers/https.js:272:32)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
我的条纹声明
const stripe = require('stripe')('MySecretApi');
我的 CreateEphemeralKeys 函数
exports.createEphemeralKey = functions.https.onCall((data, context) => __awaiter(this, void 0, void 0, function* () {
const customerId = data.customer_id;
const stripeVersion = data.stripe_version;
console.log(stripeVersion);
console.log(customerId);
return stripe.ephemeralKeys({ customer: customerId }, { stripe_version: stripeVersion }).then((key) => {
return key;
}).catch((err) => {
console.log(err);
throw new functions.https.HttpsError('internal', ' Unable to create ephemeral key: ' + err);
});
}));
"" 类 STPCustomerEphemeralKeyProvider ""
class _StripeApi: NSObject, STPCustomerEphemeralKeyProvider {
func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {
let data = [
"stripe_version": apiVersion,
"customer_id" : UserService.user.stripeId
]
Functions.functions().httpsCallable("createEphemeralKey").call(data) { (result, error) in
if let error = error {
debugPrint(error.localizedDescription)
completion(nil, error)
return
}
guard let key = result?.data as? [String: Any] else {
completion(nil, nil)
return
}
completion(key, nil)
}
}
}
【问题讨论】:
-
您好,您使用的是哪种语言? JavaScript 还是 TypeScript?
-
您好,感谢您对我的问题感兴趣。我正在使用 JavaScript
-
好的,我有两个问题:你为什么使用
__awaiter(this, void 0, void 0, function* ()并且你确定ephemeralKeys是Stripe Node.js 库的一个方法? -
我使用 STPCustomerEphemeralKeyProvider 从我的 IOS 应用程序调用我的后端,要求服务器生成一个 EphemeralKey。我将在帖子中添加我的课程
-
我不清楚你到底在做什么。你的云函数是一个callable,你应该从你的iOS应用程序中调用它,如下所述:firebase.google.com/docs/functions/callable#call_the_function。在您的 CF 中,您需要使用 Stripe Node.js 库中的方法。
标签: node.js firebase google-cloud-functions stripe-payments