Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 如何使用Angular 5向Firestore写入?_Firebase_Firebase Realtime Database_Stripe Payments_Google Cloud Firestore - Fatal编程技术网

Firebase 如何使用Angular 5向Firestore写入?

Firebase 如何使用Angular 5向Firestore写入?,firebase,firebase-realtime-database,stripe-payments,google-cloud-firestore,Firebase,Firebase Realtime Database,Stripe Payments,Google Cloud Firestore,我已经使用本教程将我的条带签出连接到Firebase实时数据库 这是成功的。但是,我需要使用Firestore执行签出过程,因为我们已经将数据库迁移到了Firestore。不幸的是,它不起作用!该功能起作用,但数据仍保存在实时数据库中,而不是Firestore中。这是我的密码: const functions = require('firebase-functions'); const admin = require('firebase-admin') admin.initializeApp(

我已经使用本教程将我的条带签出连接到Firebase实时数据库

这是成功的。但是,我需要使用Firestore执行签出过程,因为我们已经将数据库迁移到了Firestore。不幸的是,它不起作用!该功能起作用,但数据仍保存在实时数据库中,而不是Firestore中。这是我的密码:

const functions = require('firebase-functions');
const admin = require('firebase-admin')

admin.initializeApp(functions.config().firebase);

const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG);

const db = admin.firestore(); // Firebase
const stripe = require('stripe')(functions.config().stripe.testkey) // Stripe

exports.stripeCharge = functions.firestore
                                .document('/payments/{userId}') 
                                .onWrite(event => {

    const payment = event.data.val();
    const userId = event.params.userId;
    const paymentId = event.params.paymentId;

    // checks if payment exists or if it has already been charged
    if (!payment || payment.charge) return;

    return admin.firestore()
          .collection('payments')
          .doc('{userId}')
          .once('value')
          .then(snapshot => {
              return snapshot.val();
           })
           .then(customer => {

             const amount = payment.amount;
             const idempotency_key = paymentId;  // prevent duplicate charges
             const source = payment.testkey.id;
             const currency = 'php';
             const charge = {amount, currency, source};


             return stripe.charges.create(charge, { idempotency_key });

           })

           .then(charge => {
               db
               .collection('payments')
               .doc('{userId}')
               .collection('{paymentId}')
               .field('charge')
               .set(charge)
              })

 });
在本教程的第1部分中,数据库结构如下所示:

payments
    $userId
        $paymentId
             amount: number
             token: object
             charge: object

我认为您使用的是firebase函数>1.0.0

admin.initializeApp();

查看完整的迁移指南

Hi!谢谢你的帮助!我尝试了以下更改:
//admin.initializeApp(functions.config().firebase)
管理员初始化app()
.onWrite(event=>{
.onWrite((更改,上下文)=>{
),我添加了以下内容:
让firebaseConfig=JSON.parse(process.env.FIREBASE_CONFIG);
它仍在实时数据库中保存。我还可能缺少什么?当我执行
FIREBASE部署时没有任何错误--只执行函数