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
}