Reputation: 1217
The following function executes successfully, the problem I have is that I need to return the status
code back, but I'm getting the following error:
TypeError: response.status is not a function
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')
}
});
});
Upvotes: 1
Views: 1566
Reputation: 317467
You're mixing up callable and HTTP type functions. Callable functions are declared with onCall
and accept a single object input, while HTTP functions are declared with onRequest
and accept a request and response object. What you've done is declare with onCall
and expect that you're getting HTTP function arguments.
If you want to write an HTTP type function, declare it like this:
exports.processApplePayment = functions.https.onRequest((request, response) => {
Upvotes: 1