【问题标题】:Unhandled error TypeError: Cannot read property 'create' of undefined未处理的错误类型错误:无法读取未定义的属性“创建”
【发布时间】: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


【解决方案1】:

stripe.ephemeralKeys 不是函数。你想要stripe.ephemeralKeys.create。在此处查看文档:https://stripe.com/docs/mobile/ios/basic#ephemeral-key

【讨论】:

    猜你喜欢
    • 2018-04-29
    • 1970-01-01
    • 2021-11-05
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    • 2021-12-03
    • 2021-11-22
    • 2018-07-12
    相关资源
    最近更新 更多