0

I just added stripe to my firebase function index.js:

const stripe = require('stripe')('key');

and a creator function for checkout sessions:

    exports.createCheckoutSession = functions.https.onCall(async(data, context) => {
    const YOUR_DOMAIN = 'http://localhost:5000';
    const session = await stripe.checkout.sessions.create({
        payment_method_types: ['card'],
        metadata: { firebase_uid: context.auth.uid },
        line_items: [{
            price_data: {
                currency: 'usd',
                product_data: {
                    name: 'Stubborn Attachments',
                    images: ['https://i.imgur.com/EHyR2nP.png'],
                },
                unit_amount: 2000,
            },
            quantity: 1,
        }, ],
        mode: 'payment',
        success_url: `${YOUR_DOMAIN}/page/shop/shop.html`,
        cancel_url: `${YOUR_DOMAIN}/page/shop/shop.html`,
    });
    return session.id
})

Since I use stripe I always get an error when I deploy (firebase deploy --only functions)

I get this error: Error: Functions did not deploy properly. I already read this stackoverflow question but it didn't help: Error: Functions did not deploy properly

I also commented const stripe = require('stripe')('key'); out and then I was able to deploy. So I think it is an error with the stripe package. I also ran npm i stripe again but it didn't help.

my package.js:

{
    "name": "functions",
    "description": "Cloud Functions for Firebase",
    "scripts": {
        "lint": "eslint .",
        "serve": "firebase emulators:start --only functions",
        "shell": "firebase functions:shell",
        "start": "npm run shell",
        "deploy": "firebase deploy --only functions",
        "logs": "firebase functions:log"
    },
    "engines": {
        "node": "14"
    },
    "main": "index.js",
    "dependencies": {
        "firebase-admin": "^9.2.0",
        "firebase-functions": "^3.11.0"
    },
    "devDependencies": {
        "eslint": "^7.6.0",
        "eslint-config-google": "^0.14.0",
        "firebase-functions-test": "^0.2.0",
        "stripe": "^8.156.0"
    },
    "private": true
}

I hope you can help me. Thank you for your time!

Edit: my versions: npm: 7.18.1 node: 14.16.0 firebase-admin: 9.6.0 firebase-functions-test: 0.2.3 fireabse-functions: 3.13.2 stripe: 8.156.0

1 Answers1

0

I just found out what my mistake was. In the package.js the "stripe": "^8.156.0" needs to be in the dependencies not the devDependencies. Like this:

{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
    "lint": "eslint .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
},
"engines": {
    "node": "14"
},
"main": "index.js",
"dependencies": {
    "firebase-admin": "^9.2.0",
    "firebase-functions": "^3.11.0",
    "stripe": "^8.156.0"
},
"devDependencies": {
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "firebase-functions-test": "^0.2.0"
},
"private": true

}