我试图通过firebase功能将添加到条带中的最后一张卡设置为默认卡,但我似乎无法使其工作。
// Add a payment source (card) for a user by writing a stripe payment source token to Realtime database
exports.addPaymentSource = functions.database.ref('/users/{userId}/sources/{pushId}/token').onWrite(event => {
const source = event.data.val();
if (source === null) return null;
return admin.database().ref(`/users/${event.params.userId}/customer_id`).once('value').then(snapshot => {
return snapshot.val();
}).then(customer => {
return stripe.customers.createSource(customer, {source});
return stripe.customers.update(customer, {default_source: source});
}).then(response => {
return event.data.adminRef.parent.set(response);
}, error => {
return event.data.adminRef.parent.child('error').set(userFacingMessage(error)).then(() => {
// return reportError(error, {user: event.params.userId});
consolg.log(error, {user: event.params.userId});
});
});
});
答案 0 :(得分:2)
你试图在这一个功能中返回两件事。那不会起作用。它应该创建源,但它不会更新它。
return stripe.customers.createSource(customer, {source});
return stripe.customers.update(customer, {default_source: source});