将数据从Firebase函数返回到应用

Man*_*rio 6 stripe-payments firebase typescript ionic3

在我的离子应用程序中,我正在连接到条纹支付网关。

我有一个firebase在更新客户时会触发的功能。

exports.updateStripeCustomer = functions.database.ref("/Customers/{userId}")
  .onUpdate((snapshot, context) => {
    const data = snapshot.after.val();
    return stripe.customers.createSource(data.payment_sources.customer_id, {
        source: data.payment_sources.source
    }).then(customer => {
        console.log("Update Stripe Customer");
        return customer;
    },
        error => {
            return error;
        }
    );
});
Run Code Online (Sandbox Code Playgroud)

这是我在更新客户的应用程序端中的代码。更新firebase中调用的触发器时,如何在下面的代码中获取触发器(firebase函数)返回的数据?

 this.angularDb.object('/Customers/' + firebase.auth().currentUser.uid).update({
            cardsetup: 1,            
            payment_sources: {
              customer_id: this.user.customer_id,
              source: this.card.source.id
            }
          }).then((res) => {
            loading.dismiss();
            alert("card details has been successfully updated.");            
            this.navCtrl.push(LoginPage);

      }, (error) => {
        loading.dismiss();
        console.log("=========>", error.message)
        alert(JSON.stringify(error))
      });
Run Code Online (Sandbox Code Playgroud)

如果firebase函数返回错误,则需要显示触发器返回的错误消息。有什么办法吗?

Did*_*nel 1

触发器对数据库中的事件做出反应,并且不了解有关您的应用程序的任何信息。因此,您的触发器和应用程序之间没有任何链接。

您可以向您的用户添加一个包含交易 ID 和交易状态的交易集合。然后从您的应用程序中监听它并从触发器中更新它以在完成时收到通知。

或者您可以使用可调用的云函数而不是触发器。 https://firebase.google.com/docs/functions/callable