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');
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)
}
}
}
答案 0 :(得分:0)
stripe.ephemeralKeys
不是函数。您需要stripe.ephemeralKeys.create
。在此处查看文档:{{3}}