以下函数执行成功,我遇到的问题是我需要返回status
代码,但我得到了以下错误:
类型错误:response.status不是函数
exports.processApplePayment = functions.https.onCall((data, context) => {
console.log('processApplePayment');
const stripeToken = data.stripeToken
const amount = data.amount
const description = data.description
const email = data.receipt_email
console.log('stripeToken', stripeToken);
console.log('amount', amount);
console.log('description', description);
console.log('email', email);
stripe.charges.create({
amount: amount,
currency: currency,
description: description,
source: stripeToken,
receipt_email: email
}, function(err, charge) {
if (err !== null) {
console.log('error capturing')
console.log(err)
response.status(400).send('error')
} else {
console.log('success')
response.status(200).send('success')
}
});
});
您将可调用函数和HTTP类型函数混合在一起。可调用函数用onCall
声明并接受单个对象输入,而HTTP函数则用onRequest
声明并接受请求和响应对象。您所做的是使用onCall
进行声明,并期望得到HTTP函数参数。
如果你想写一个HTTP类型的函数,可以这样声明:
exports.processApplePayment = functions.https.onRequest((request, response) => {