简体   繁体   中英

Get data from fire base to node.js file

I want to get data from my database on fire base and want to save that data to amount amount: snapshot, I did apply this const snapshot = firestore.collection('payment').doc(context.params.amount).get(); does that works in the same way? but I am getting an error that context is undefined. I actually want to get data from database.

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const firestore= admin.firestore();
const stripe = require('stripe')('');
const snapshot = firestore.collection('payment').doc(context.params.amount).get();

const customer =  stripe.customers.create({
  email: 'customer@example1.com',
});
stripe.customers
  .create({
    email: 'foo-customer@example.com',
  })
  .then((customer) => {
    return stripe.customers.createSource(customer.id, {
      source: 'tok_visa',
    });
  })
  .then((source) => {
    return stripe.charges.create({
      amount: snapshot,
      currency: 'usd',
      customer: source.customer,
    });
  })
  .then((charge) => {
    // New charge created on a new customer
  })
  .catch((err) => {
    // Deal with an error
  });

you are trying to get amount through accessing params through context, depends on your error, this means context is undefined which means you are trying to get params of undefined . you need to explain what is context means here, is it a global variable? is this code inside a cloud function ? if yes you need to move this declaration const snapshot = firestore.collection('payment').doc(context.params.amount).get(); inside your cloud function, this is an example of firebase cloud function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM