I'm building my first firebase function with Js to handle card payments with Checkout.com API, I've installed both checkout and firebase JavaScript SDK's and this is my index.js folder:
const functions = require("firebase-functions");
const { Checkout } = require("checkout-sdk-node");
const cko = new Checkout("sk_test_XXXXX-XXXX-XXXX");
exports.payWithToken = functions.https.onCall(async (data, context) => {
try {
const payment = await cko.payments.request({
source: {
token: data.token,
},
customer: {
email: context.auth.token.email
},
currency: data.currency,
amount: data.amount,
})
return {
"Status": payment.status,
"3DS-Link": payment.redirectLink,
"Approved": approved,
"Flagged": risk.flagged,
};
} catch (error) {
console.log(error)
throw new functions.https.HttpsError(error.name, error.message, error);
}
});
I think I followed the documentation correctly but for some reason, I couldn't deploy this function to firebase and I get this error:
In package.json ,
change this
"lint": "eslint .",
to this
"lint": "eslint",
I found the solution on this page .
Essentially
Arrow functions are an ES6 feature, but here you have an async arrow function.
Async functions in general are an ES8 (or 2017) feature. Therefore you need to specify the following setting at the root of your config: parserOptions: { ecmaVersion: 8 // or 2017 }
So I needed to update my .eslintrc.js file to this
module.exports = {
root: true,
env: {
es6: true,
node: true
},
parserOptions: {
ecmaVersion: 8
},
extends: ['eslint:recommended', 'google'],
rules: {
'comma-dangle': 'off',
'quote-props': 'off',
indent: ['error', 2]
}
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.