【问题标题】:Stripe: Cannot read property 'token' of undefined at object条纹:无法读取对象未定义的属性“令牌”
【发布时间】:2021-01-10 06:33:31
【问题描述】:

我正在尝试使用 node.js 和 firebase 在我的 iOS 应用程序中添加 Stripe 支付。

到目前为止,我的主要目标是在用户使用我的应用程序创建帐户时创建条带客户。

我正在尝试按照这些说明进行操作,但遇到了问题。

https://www.iosapptemplates.com/blog/ios-development/stripe-firebase-swift

const logging = require('@google-cloud/logging');
const stripe = require('stripe')(functions.config().stripe.token);
const currency = functions.config().stripe.currency || 'USD';

exports.createStripeCustomer = functions.auth.user().onCreate((user) => {
return stripe.customers.create({
email: user.email,
}).then((customer) => {
return admin.database().ref(`/stripe_customers/${user.uid}/customer_id`).set(customer.id);
});
});

当我尝试在终端内运行 firebase deploy --only functions 时,我遇到了

Error: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'token' of undefined

我应该定义令牌吗?我认为它是与条带关联的自动完成值?

编辑显示 package.json

{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "10"
},
"dependencies": {
"firebase": "^7.15.5",
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.1"

},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}

【问题讨论】:

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


    【解决方案1】:

    token 在这种情况下可能有点不好命名,您实际上传递给该函数的是 Stripe API 密钥。

    您需要先从 Stripe dashboard directly 获取您的 API 密钥,然后您需要设置您的 Firebase 配置以设置该 API 密钥:

    firebase functions:config:set stripe.token=<YOUR STRIPE SECRET KEY>

    我已将参数设置为token,因此您的index.js 文件不需要任何修改,但最好将其命名为stripe.secretstripe.apiKey

    【讨论】:

    • 火基函数:将位于我的 package.Json 内部,对吗??
    • 我已经编辑了我的问题以显示我的 package.json。 '"firebase-functions": "^3.6.1"' 看起来像 '"firebase-functions": "^3.6.1"' ' config:set stripe.token=?
    • 对不起,我仍然对我应该在哪里设置这个感到困惑。我对 node.js 不是很熟悉。你能解释一下你放的是哪个文件吗?我试图在我的 package.json 中的日志下创建一个“令牌”:firebase 函数,但我仍然收到错误。
    • 嘿,朋友,我还是有问题。我已经采取了你的步骤,但我不知道我应该把它放在哪里
    • 我展示的命令是您在终端中运行以设置stripe.token 环境变量的命令。你可以在这里阅读更多信息:firebase.google.com/docs/functions/config-env
    猜你喜欢
    • 2018-03-07
    • 2021-02-07
    • 2021-07-05
    • 2021-04-30
    • 2014-11-20
    • 1970-01-01
    • 2020-12-04
    • 2019-10-31
    • 2021-12-15
    相关资源
    最近更新 更多