我正在创建一个Stripe支付系统,并且很难使这个集成代码正常运行。代码被提取from here。我要做的是创建对用户的特定用户ID(uid)的数据库引用,因为createStripeCharge
等待write event
发生/stripe_customers/XCXaweADowefj/charges/QC123XYZ
之类的事件。我不确定,但也许我的问题是我错误地引用了客户。如果您对我如何正确使用此功能有任何想法或反馈,我非常感谢!
触发器(这会导致云功能正常工作):
payByStripe(amount,email,userId, token): firebase.database.Reference {
return firebase.database().ref(`/stripe_customers/${userId}/charges/`).push({
amount:amount,
email:email,
token:token
});
}
云功能:
exports.createStripeCharge = functions.database.ref('/stripe_customers/{userId}/charges/{id}').onWrite(event => {
const val = event.data.val();
if (val === null || val.id || val.error) return null;
return admin.database().ref(`/stripe_customers/${event.params.userId}/customer_id`).once('value').then(snapshot => {
return snapshot.val();
}).then(customer => {
const amount = val.amount;
const idempotency_key = event.params.id;
let charge = {amount, currency, customer};
if (val.source !== null) charge.source = val.source;
return stripe.charges.create(charge, {idempotency_key});
}).then(response => {
return event.data.adminRef.set(response);
}, error => {
return event.data.adminRef.child('error').set(userFacingMessage(error)).then(() => {
return reportError(error, {user: event.params.userId});
});
}
);
});
目前,数据库正在创建条带客户,但收费并未通过,错误消息为"You have passed a blank string for 'customer'. You should remove the 'customer' parameter from your request or supply a non-blank value."
更新是我一直在迭代这个。试过以下内容:
firebase.database().ref(`/stripe_customers/${userId}/charges/`).push({
amount:amount,
email:email,
token:token,
customer: userId
});
&安培;&安培;
firebase.database().ref(`/stripe_customers/${userId}/charges/`).push({
amount:amount,
email:email,
token:token,
customer_id:{
customer: userId
}
});
仍然得到"您已经为客户'传递了一个空白字符串。您应该删除'客户'请求中的参数或提供非空值。"