无法在我的https可调用云函数中与firestore进行交互

时间:2018-12-21 16:39:04

标签: angular firebase google-cloud-firestore stripe-payments

在我的云代码中,在HTTPS Callable函数中,一旦我尝试与Firestore进行交互,一切似乎就停止了工作。我的index.js文件中的函数:

exports.paymentInfoGiven = functions.https.onCall((data, context) => {
console.log(data);
console.log(context);

(async function() {
    // Create a Customer:
    const customer = await stripe.customers.create({
        source: data.tokenId,
        email: data.email,
    });
    admin.firestore().collection('users').doc(data.userId).update(
        {customerId: customer.id, givenPaymentInfo: true}
    ).then( 
        data => {
            console.log('it worked: ' + data);
        } // this logged 5 minutes after the above console.logs
    ).catch(
        err => {
            console.log('it didnt work1: ' + err);
        }
    );

    admin.firestore().collection('games').doc(data.gameId).collection('host').get()
        .then(
            hostCol => {
                hostCol.forEach(
                    host => {
                        if (data.userId === host.id) {
                            admin.firestore().collection('games').doc(data.userId)
                                .update({givenPaymentInfo: true})
                                .then(
                                    data => {
                                        console.log('worked' + data);
                                    }
                                )
                                .catch(
                                    err => {
                                        console.log('it didnt work2: ' + err);
                                    });
                        }
                    }
                );
            }
        )
        .catch(err => {
            console.log('it didnt work3: ' + err);
        });
})();
});

上面的代码在Stripe上创建了一个客户。它记录了前两行就可以了,这就是问题。不记录.then()或.catch()内的内容,我没有收到任何错误消息(请参见下图),当我是“ firebase部署”。不确定发生了什么。

我的index.js文件导入:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const stripe = require("stripe")("secret_key");

正在调用上述功能的客户端代码:

import {AngularFireFunctions} from '@angular/fire/functions';
import {from, Observable, Subscription} from 'rxjs';

constructor(private fns: AngularFireFunctions) {}

uponGivingPaymentInfo(email: string, tokenId: string, userId: string, gameId: string): Observable<any> {
   const callable = this.fns.httpsCallable('paymentInfoGiven');
   return callable({tokenId: tokenId, email: email, userId: userId, gameId:gameId});
}

My firestore logs after uponGivingPaymentInfo is executed

任何帮助将不胜感激!预先感谢!

0 个答案:

没有答案