admin管理员组文章数量:1186151
I am working with stripe payment in flutter application. Flow is I am generating a token of card and send to fire base later cloud function will get card detail and use stripe API to charge the payment I am facing a problem npm install strip
successfully install the stripe but when I run the firebase deploy
it shows the error.
here is I am writing cloud function.
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 file
{
"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
}
I am working with stripe payment in flutter application. Flow is I am generating a token of card and send to fire base later cloud function will get card detail and use stripe API to charge the payment I am facing a problem npm install strip
successfully install the stripe but when I run the firebase deploy
it shows the error.
here is I am writing cloud function.
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 file
{
"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
}
Share
Improve this question
edited Nov 28, 2019 at 18:07
Developer
asked Nov 28, 2019 at 17:50
Developer Developer
7893 gold badges8 silver badges26 bronze badges
4 Answers
Reset to default 12It seems you installed strip
instead you should install the following:
npm install stripe --save
https://www.npmjs.com/package/stripe
I had the same problem. found out I needed to open terminal or command prompt and cd to the 'functions' folder for firebase and then run npm install stripe
there. Once that was done, it worked.
Make sure you installed the package from the functions directory instead of the project directory. I accidentally installed packages while in the project directory, It works locally fine, but creates error when you deploy it. so,
cd functions
npm install [your package]
Then it will work fine
steps: this also worked for me i had done the install in the right folder as in firebase functions folder (backend), and was having problems when i tried to deploy it using: firebase deploy --only functions Command, when the issue arose i ran the firebase functions log command firebase function log: --only "Myfunction name here". in the logs i found the error that: Detailed stack trace: Error: Cannot find module 'stripe' so i installed stripe using: npm install @stripe/stripe.js....this did not fix the problem! i had to install stripe like this first: npm install stripe and after this i ran the previous command: npm install @stripe/stripe.js after this i ran the firebase deploy command: firebase deploy --only functions and voila! everything works - deployment complete! - hope this helps someone!
本文标签: javascriptDetailed stack trace Error Cannot find module 39stripe39Stack Overflow
版权声明:本文标题:javascript - Detailed stack trace: Error: Cannot find module 'stripe' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738320735a2074482.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论