For some reason I'm getting output on my terminal when I deploy cloud functions that I've never seen.
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint /Users/xxxxx/Desktop/cloud_functions/cloud_functions_live/functions
> eslint .
/Users/xxxxx/Desktop/cloud_functions/cloud_functions_live/functions/index.js
38:5 warning Arrow function expected no return value consistent-return
✖ 1 problem (0 errors, 1 warning)
Also line 38 in index.js is the return return docRef.doc("/payments/${payment}").get()
I am typing more info here simply because stackoverflow is saying I have too much code and not allowing me to add an update. I hope this isn't against policy as someone else has asked for more code and another individual has upvoted the question indicating that I've made my problem clear enough with limited details for others to identify with it.
exports.stripeCharge = functions.firestore.document('/payments/{payment}').onCreate((snap, context) => {
console.log("payment data", snap);
const payment = snap.data();
console.log("payment data2", payment.token);
//console.log("payment data2", payment.token.idempotency_key);
if (!payment || payment.charge) return;
var docRef = admin.firestore()
const idempotency_key = payment.idempotency_key; // prevent duplicate charges
//.document(`/payments/${payment}`);
//var docRef =
return docRef.doc(`/payments/${payment}`).get()
.then(snapshot => {
console.log("augu", snapshot);
return snapshot;
})
.then(customer => {
const amount = payment.amount;
const source = payment.token;
const currency = payment.currency;
const charge = {amount, currency, source};
console.log("brett", charge);
return stripe.charges.create(charge, { idempotency_key });
})
.then(charge => {
console.log("set charge back");
return docRef.doc(`/charges/${idempotency_key}`).set(charge);
})
})
The problem in your code is in this line:
if (!payment || payment.charge) return;
Since you later return a promise, you need to return a value here a swell. e.g. false.
The eslint rule expects if you return something from a function, it always returns a value. If that is not what you want, you could modify the rules to allow undefined and return undefined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With