Pau*_*ane 6 javascript stripe-payments firebase firebase-realtime-database google-cloud-functions
我试图通过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});
});
});
});
Run Code Online (Sandbox Code Playgroud)
小智 2
您试图在这个函数中返回两件事。那是行不通的。它应该创建源,但不会更新它。
return stripe.customers.createSource(customer, {source});
return stripe.customers.update(customer, {default_source: source});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
325 次 |
| 最近记录: |