gpt4 book ai didi

javascript - 详细堆栈跟踪 : Error: Cannot find module 'stripe'

转载 作者:行者123 更新时间:2023-12-01 23:54:22 25 4
gpt4 key购买 nike

我正在flutter应用程序中使用 strip 支付。流程是我正在生成卡 token 并发送到 Fire Base,稍后云功能将获取卡详细信息并使用 stripe API 来收取付款我遇到的问题 npm install strip 成功安装了 stripe,但是当我运行 firebase deploy 它显示错误。这是我正在编写的云函数。

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
//const firestore= admin.firestore();
//const setting ={timestampInSnapshots:true};
// firebase.setting(setting);
const stripe = require('stripe')(functions.config().stripe.testkey)
exports.addStripeSource =functions.firestore.document('cards/{userid}/Tokens/{tokenid}}')
.onCreate(async (tokenSnap, context)=> {
var customer;
const data=tokenSnap.aftter.data();
if(data == null){
return null;
}
const token =data.tokenId;
const snapshot =await firestore.collection('cards').doc(context.params.userId).get();
const customerId=snapshot.data().custId;
const customerEmail=snapshot.data().Email;
if(customerId == 'new')
{
customer= await stripe.customers.create({
email: customerEmail,
source: token,
});
firestore.collection('cards').doc(context.params.userId).update ({
custId: customer.id,
})
}
else{
customer= await stripe.customers.retrieve(customerId);
}
const customerSource= customer.sources.data[0];
return firestore.collection('cards').doc(context.params.userId).collection('sources').doc(customerSource.card.fingerprint).set(customerSource)

}
)

package.json 文件

{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "8"
},
"dependencies": {
"firebase-admin": "^8.6.0",
"firebase-functions": "^3.3.0"
},
"devDependencies": {
"firebase-functions-test": "^0.1.6"
},
"private": true

}

最佳答案

看来您安装了 strip 而应该安装以下内容:

npm install stripe --save

https://www.npmjs.com/package/stripe

关于javascript - 详细堆栈跟踪 : Error: Cannot find module 'stripe' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59094147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com