im trying to set up the stripe extension for firebase localy with the emulator suite, i followed the steps here: https://firebase.google.com/products/extensions/stripe-firestore-stripe-payments after step 3 an extension folder with the file firestore-stripe-payments.env is created and in the firebase.json file the extension gets listed,
created/changed files by the extension
but thats all what was created, from my understanding some
cloud functions regarding stripe should be created by the stripe extension(inside the index.ts file)
so in step 4: to Test this extension locally with '$ firebase emulators:start' i dont know how/where i can see these functions or test them.
also i dont see any collection regarding stripe in firestore(i already created a product in stripe dashboard), it should look like this image
ps: no error is thrown while execution all steps (i didnt do the last step for the deployment)
When you run firebase emulators:start, you should get back a link to the emulator UI. When you look at your installed extension in the emulator UI you should be able to see the functions for the extension under "APIs and resources".
For your question about there being no collection regarding Stripe - have you already created the Firestore database? It's called out as a step you need to complete before installing the extension under the "Additional setup" section.
Updating the firebase-tools to the latest version with "npm install -g firebase-tools" solved it for me, before i had v10.0.8 and only with v10.0.9 the emulator suite supports the extensions feature. https://github.com/firebase/firebase-tools/releases/tag/v10.9.0
I'm trying to deploy my firebase project, but Im getting the following error:
=== Deploying to 'my-proj'...
deploying firestore, functions, hosting
cloud.firestore: checking firestore.rules for compilation errors...
[W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]).
cloud.firestore: rules file firestore.rules compiled successfully
Error: Could not detect language for functions at
any thoughts?
In my case, I missed functions init:
firebase init functions
documentation
In my case I use firebase deploy --only hosting command
I can't tell what else is perhaps going wrong with your code, but I also had an error that looked like this part:
[W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]).
Some of your firebase rules are written using version 1. You may need to go in and add
rules_version = '2';
to the top of your firebase rule set, specifically for Firebase Firestore. You can do this in the firebase console, or in the firestore.rules in your project - which may be a newly generated file in your project.
For anyone else who ends up here. I had setup firebase static hosting 1yr+ ago, and at that point in time hosting was a "function". Since then, hosting is now a distinct offering separate of functions.
You need to convert the previous "default" function (which 'was' hosting) to hosting offering.
Delete (or edit) firebase.json in the root directory of your firebase project.
Firebase init hosting -> This will create a new "public" folder.
Copy your previous functions/public folder to overwrite the new one.
Delete the previous functions folder altogether.
Now hosting is fixed and you can deploy again.
Firebase init functions -> This will create a new functions folder, and all of the boilerplate json and .js files.
The problem I was having is the functions folder had both hosting and functions stepping on each other within the functions directory. The "today" process puts hosting in a separate folder altogether.
Please update your rule to version 2 as the error message says.
I experimented with firebase functions for the init part and it has created a folder for me. Now when I deploy each time it also picks up the functions folder. When I remove the functions folder I get an error, when deploying. How do I deploy everything but functions?
firebase deploy has a parameter --except . So to deploy everything except functions you can run:
firebase deploy --except functions
You can use the only option/flag, for example firebase deploy --only hosting,storage, see the CLI doc.
You can also use deploy targets which "are short-name identifiers (that you define yourself) for Firebase resources in your Firebase project".
Check to make sure that you have removed the implicit reference to the function in your index.js and then running firebase deploy should do the trick. If you want to explicitly delete the function completely, you can use the firebase functions:delete <myFunction> and then delete the functions folder. You can find more details in the doc here
I seem to be having issues getting my site live onto the Firebase Hosting.
I followed this tutorial: https://github.com/firebase/functions-samples/tree/master/stripe
Which has these steps:
Create a Firebase Project using the Firebase Developer Console
Enable billing on your project by switching to the Blaze or Flame plan. See pricing for more details. This is required to be able to do requests to non-Google services.
Enable Google sign on your Firebase project
Install Firebase CLI Tools if you have not already and log in with firebase login.
RESULT: Already logged in as user#gmail.com
Configure this sample to use your project using firebase use --add and select your project.
RESULT: Error: Firebase use must be run from a Firebase Directory
Run firebase init to start a project
Run firebase init
What Firebase CLI features do you want to setup for this directory?
Database
Functions
Hosting
I chose HOSTING.
Select a default Firebase project for this directory
I Chose the only project there and got:
✔ Firebase initialization complete
I Ran Firebase use --add again, chose and alias and not it says:
Now using alias stageTemp.
Install dependencies locally by running: cd functions; npm install; cd -
npm WARN stripe-functions# No repository field
npm WARN stripe-functions# No license field.
Add your Stripe API Secret Key to firebase config: firebase functions:config:set stripe.token=<YOUR STRIPE API KEY>
Optional: change your default currency firebase functions:config:set stripe.currency=GBP
Pass your Stripe publishable key to the Stripe.setPublishableKey call in public/index.html
Deploy your project using firebase deploy
When I run Firebase Deploy I get
i deploying functions
i functions: ensuring necessary APIs are enabled...
i runtimeconfig: ensuring necessary APIs are enabled...
✔ runtimeconfig: all necessary APIs are enabled
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (2.91 KB) for uploading
✔ functions: functions folder uploaded successfully
i starting release process (may take several minutes)...
i functions: updating function createStripeCharge...
i functions: updating function createStripeCustomer...
i functions: updating function addPaymentSource...
i functions: updating function cleanupUser...
✔ functions[createStripeCharge]: Successful update operation.
✔ functions[createStripeCustomer]: Successful update operation.
✔ functions[addPaymentSource]: Successful update operation.
✔ functions[cleanupUser]: Successful update operation.
✔ functions: all functions deployed successfully!
✔ Deploy complete!
Finally:
Test your Stripe integration by viewing your deployed site firebase open hosting:site
and then I get this:
Can anyone see why this is not working? I have gone through these steps several times and cannot seem to get it to work.
Much appreciated.
Questions for Firebase Devs:
1) This code on the example has: amount: parseInt(). What checks are in place to make sure that the DOM is not simply edited by the user?
2) This process saves a lot of data. Is Firebase PCI Compliant so that I am legally allowed to store this data?
3) I'm confused about the process flow of functions. Is there an editable file that is run on the cloud where I can add extra information and database interactions or email sending? - I ask this because I want to insert into the database only when payment is verified. If I code it from the front end then a user could just run that in the console or wherever and insert into my db as it will have write access. (I hope this makes sense - I basically just want my function to be able to access the database and not anyone else)
Thank you for your time, I understand that you will be terrible busy and I really appreciate your help with this.
I followed the following steps:
The Firebase CLI (Command Line Interface) requires Node.js and npm, which you can install by following the instructions on https://nodejs.org/
Installing Node.js also installs npm
Once you have Node.js and npm installed, install the Firebase CLI via npm:
npm install -g firebase-tools
This installs the globally available firebase command. To update to the latest version, re-run the same command
Initialize your project:
a. Run firebase login to log in via the browser and authenticate the firebase tool.
b.Go to your Firebase project directory or create the directory
c. Run firebase init functions
The tool gives you an option to install dependencies with npm. It is safe to decline if you want to manage dependencies in another way.
Select associated firebase project
Select Y to install dependencies with npm
Move to directory setup firebase functions
Edit index.js file with the function you created
Run the firebase use --add to add your Firebase project
Run firebase deploy --only functions to deploy the function
After all this I get the message in the terminal at deploy was completed but in the Firebase console, when i click on Functions tab there are no functions listed!?
Quick Tip: Make sure you are exporting the function you are trying to deploy in your index.js file. Your firebase project will deploy but Cloud Functions won't be available unless they are exported.
Make sure you save the file after uncommenting the default function and then use
firebase deploy
For Cloud Functions, it is required to add your function to the special exports object (it is a Node's way of making the function accessible outside of the current file)
Make sure to have index.js in your functions directory:
Example of a function:
// Import the Firebase SDK for Google Cloud Functions.
const functions = require('firebase-functions');
// Import and initialize the Firebase Admin SDK.
const admin = require('firebase-admin');
admin.initializeApp();
// Your function declaration. Example of a fired function when a user is created in Auth feature.
exports.myFunction = functions.auth.user().onCreate(async (user) => {
// ... your code here.
});
Then for deployment follow these steps:
First, if not done, make sure to have firebase-tools installed:
$ npm install -g firebase-tools
And initialised: $ firebase init
For full deployment:
$ firebase deploy
OR for functions deployment
$ firebase deploy --only functions
OR to deploy specific functions
$ firebase deploy --only functions:function1,functions:function2
A good read with a very useful example: https://codelabs.developers.google.com/codelabs/firebase-cloud-functions/#7
I went through the same issue recently, while performing Actions on Google Node.js Client Library Version 1 Migration Guide. to Node.js Client Library V2 (That I highly recommend) It took me a while to figure out what what was happening. At the I couldn't really figure out what the problem was! So here is what I did and it worked for me:
Make sure you have a backup copy of your cloud functions (index.js) and maybe your package.json (Just in case you don't want to remember what packages you previously had installed - Could be annoying sometimes).
Delete the entire functions directory from your project folder.
Re-launch firebase CLI with firebase init and choose Functions
Once your cloud function have been initialized, CD into the functions folder and Redeploy it using firebase deploy --only functions.
If everything goes well 😃, you should now see your function deployed on your firebase dashboard console.
N.B: Google recently released the Node.js Client Library version 2 (v2) in April 16th 2018 with a lot of new features. After April 16th, 2018, new features on Actions on Google will no longer be added to v1 of the client library. If you want to use new features, you must migrate to v2 client library.
In addition, the v1 client library does not support Dialogflow v2. If you need Dialogflow v2 functionality, you’ll also need to migrate to v2 of the client library.
Hope this helps 👍.
In step 7, you have to uncomment the sample function in there and save the file. Then, in the output of the deploy command, you will be given a url for the created helloWorld function.
I had exactly the same problem and I solved it by making sure the index.js file containing all my functions was saved on the "functions" folder inside the project folder. I am using vs code so I just clicked on file/save as and selected the correct folder.
#Learn2Code
I had the exact same issue.
Ensure that in your index.js file, you export your function before initializing your app.
Now, go ahead and run firebase deploy from your project directory.
For example:
// Take the text parameter passed to this HTTP endpoint and insert it into the
// Realtime Database under the path /messages/:pushId/original
exports.addMessage = functions.https.onRequest(async (req, res) => {
// Grab the text parameter.
const original = req.query.text;
// Push the new message into the Realtime Database using the Firebase Admin SDK.
const snapshot = await admin.database().ref('/messages').push({original: original});
// Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
res.redirect(303, snapshot.ref.toString());
});
const admin = require('firebase-admin');
admin.initializeApp();
Make sure you're running at least version 3.5.0 of firebase-tools. To check which version you have, run:
firebase --version
If you're running the default setup, you can update firebase-tools using:
npm install -g firebase-tools
Had the same situation. The problem was that when I was doing
$ firebase deploy --only "myFunction"
That filter name: myFunction, was not exactly the same as the name of the function I was trying to deploy. Silly mistake but took me a day to realize...
To clarify one issue - it appears as though your index.js file inside the functions folder must export functions created within the same file (similar to what Fran had said).
It seems trying to organize your files into subfolders will not work properly with Firebase functions - same rules apply for using firebase serve to test locally (must create codeinside functions/index.js).
Hope this helps someone!
1) Make sure you are exporting the function you are trying to deploy in your index.js file.
2) Write 'use-strict' at the top of your file (index.js) then use console to deploy your function
Check your "default project" at firebase init. Select one with similar name was my mistake. ;)
Use firebase projects:list and firebase use <project> to make sure the Firebase CLI's "current project" is set correctly regardless of what folder you're in.
Example:
> firebase projects:list
✔ Preparing the list of your Firebase projects
┌──────────────────────┬─────────────────────┬──────────────────────┐
│ Project Display Name │ Project ID │ Resource Location ID │
├──────────────────────┼─────────────────────┼──────────────────────┤
│ alpha │ alpha (current) │ [Not specified] │
├──────────────────────┼─────────────────────┼──────────────────────┤
│ beta │ beta │ [Not specified] │
└──────────────────────┴─────────────────────┴──────────────────────┘
2 project(s) total.
> firebase use beta
Now using project beta
I had this error as well. I had copied a working function running on Google Cloud Functions from a previous project and could not figure out why it would not show up once deployed.
I needed to wrap my function in functions.https.onRequest(), which is not required on normal cloud functions.
Had the same issue.
In my case solved by using firebase deploy wihtout any --only, which revealed better error messaging and I had to setup billing in Cloud Console for the project. The setup routine can be triggered by selecting Could Functions in the Console.
I had another issue in which the Service Account was missing from the Project, so I setup a fresh project through the Console first and then added this to Firebase.
Make sure you init firebase on step back from your firebase functions. and also firebase functions name must be functions.
It works for me
One dumb gotcha I just ran into, I was running "firebase deploy" from the top level folder (one above the /functions sub-folder), and it deployed "successfully" but I never saw it in Firebase itself. It wasn't until I cd'd into /functions and re-ran firebase deploy that the full deployment actually worked.