在我的离子应用程序中,我正在连接到条纹支付网关。
我在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;
}
);
});
这是我在更新客户的应用端中的代码。更新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))
});
如果firebase函数返回错误,则需要显示触发器返回的错误消息。有什么办法吗?
答案 0 :(得分:0)
触发器对数据库中的事件做出反应,对您的应用程序一无所知。因此,触发器和应用程序之间没有链接。
您可以使用交易ID和交易状态向您的用户添加一个交易集合。然后从您的应用程序中监听它,并从触发器中更新它,以在完成时得到通知。
或者您可以使用可调用的云函数代替触发器。 https://firebase.google.com/docs/functions/callable