未处理的错误TypeError:无法读取未定义的属性“创建”

时间:2020-06-21 10:58:05

标签: node.js firebase google-cloud-functions stripe-payments

我正在尝试设置一个函数来翻转我: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)
        }
    }
}

1 个答案:

答案 0 :(得分:0)

stripe.ephemeralKeys不是函数。您需要stripe.ephemeralKeys.create。在此处查看文档:{​​{3}}