Node.js 将条带错误传递给firebase firestore
我正在尝试将条带错误(如卡被拒绝、卡上没有足够的钱、卡过期等)传递给Firebase Firestore,然后传递给客户 我不知道如何让它为Firestore工作 任何帮助都将不胜感激。谢谢 这是我的密码:Node.js 将条带错误传递给firebase firestore,node.js,firebase,google-cloud-functions,google-cloud-firestore,stripe-connect,Node.js,Firebase,Google Cloud Functions,Google Cloud Firestore,Stripe Connect,我正在尝试将条带错误(如卡被拒绝、卡上没有足够的钱、卡过期等)传递给Firebase Firestore,然后传递给客户 我不知道如何让它为Firestore工作 任何帮助都将不胜感激。谢谢 这是我的密码: exports = module.exports = functions.firestore.document('/users/{userId}/charges/{id}').onWrite(event => { const val = event.data.data()
exports = module.exports = functions.firestore.document('/users/{userId}/charges/{id}').onWrite(event => {
const val = event.data.data();
const ref = event.data.ref;
if (val === null) return null;
const amount = val.amount;
const destination = val.destination;
return admin.firestore().collection('users').doc(`${event.params.userId}`).get().then(snapshot => {
return snapshot.data();
}).then(customer => {
if (!customer.exists) {
console.log("NO SUCH CUSTOMER");
} else {
const amount = val.amount;
const customer_id = customer.customer_id;
stripe.charges.create({
amount: amount * 100 ,
currency: "usd",
customer: customer_id,
destination: {
account: destination,
},
});
}
}).then(response => {
console.log("RESPONSE", response);
// If the result is successful, write it back to the database
// WRITE RESPONSE BACK
return event.data.ref.set(response, {merge: true});
}, error => {
// WRITE ERRORS BACK
console.log("ERROR", error);
return event.data.ref.set(error, {merge: true});
}).catch((error) => {
// // We want to capture errors and render them in a user-friendly way, while
// // still logging an exception with Stackdriver
return event.data.ref.set(userFacingMessage(error));
}).then(() => {
//return reportError(error, {user: event.params.userId});
});
});