this is the first time I try to deploy cloud function in Firebase, usually I use Direbase emulator, but in this case , using Stripe, I am having problems with Cors. When I run the command: firebase deploy --only functions
, I have no compilation errors, but it tells me that there were errors during the release. Seeing from the Firebase console , I notice that in the logs, it says :
"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"Function failed on loading user code.
This is my cloud function, I don't understand the error what is:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
const stripe = require("stripe")(functions.config().stripe.secret_key);
admin.initializeApp(functions.config().firebase);
export const createCheckoutSessionGreen = functions.region("europe-west6")
.https.onCall(
async (data: any, context: any) => {
const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
mode: "payment",
success_url: "http://localhost:8100/tabs/types/song",
cancel_url: "http://localhost:8100/tabs/types/song",
line_items: [
{
price_data: {
currency: "eur",
product_data: {
name: data,
},
unit_amount: 1.99 * 100,
},
quantity: 1,
},
],
});
return session.id;
}
);
CodePudding user response:
You need to use Typescript with Cloud Function if you want to use the ES6
syntax. It seems you are using Javascript so try refactoring the code using exports
instead of export const
. Also you don't need to pass any parameters to initializeApp()
since you are deploying to Cloud Functions which will then use Application Default Credentials:
admin.initializeApp();
exports.createCheckoutSessionGreen = functions.region("europe-west6").https.onCall(...)