Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detailed stack trace: Error: Cannot find module 'stripe'

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

}
like image 506
Developer Avatar asked Dec 14 '22 10:12

Developer


2 Answers

It seems you installed strip instead you should install the following:

npm install stripe --save

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

like image 57
Peter Haddad Avatar answered Dec 21 '22 12:12

Peter Haddad


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.

like image 45
Cflux Avatar answered Dec 21 '22 11:12

Cflux