17. Deploy Firebase Cloud Functions
The Cloud Functions Foodie needs are already written — you only have to deploy them to your own Firebase project. The package deploys two functions:
deliveryDispatch— a Firestore trigger on therestaurant_orderscollection. It runs whenever an order is written and drives the driver-assignment flow, following the broadcast or sequential mode you chose under Settings → Feature Settings.deleteUser— a callable function that removes a user from Firebase Authentication when an account is deleted from a panel or app.
Without this package deployed, orders are created but never dispatched to a driver, so deploy it before going live.
Before you deploy — enable the required Google Cloud APIs. Cloud Functions (2nd generation) build on Cloud Build, store images in Artifact Registry and run on Cloud Run using your project’s default compute service account. On a new Firebase project the Compute Engine API is usually not enabled yet, so the deploy fails for most functions with
"Compute Engine API has not been used…" or "Unknown service account" (typically only one function deploys and the rest error). In Google Cloud Console → APIs & Services → Enabled APIs & services, make sure all of the following are enabled — enable any that are missing (Compute Engine is the one most often turned off):
- Compute Engine API
- Cloud Build API
- Artifact Registry API
- Cloud Run Admin API
- Eventarc API
- Cloud Functions API
Or enable them all at once with the CLI, then wait 3–5 minutes for the change to propagate before deploying:
gcloud services enable compute.googleapis.com cloudbuild.googleapis.com \ artifactregistry.googleapis.com run.googleapis.com eventarc.googleapis.com \ cloudfunctions.googleapis.com --project=YOUR_PROJECT_ID
17.1. Install Node.js and the Firebase CLI
npm install -g firebase-tools
If you have already set up the Firebase tools, running npm install inside the functions folder is enough.
17.2. Log in to Firebase
firebase login
A browser window opens; sign in with the Google account that owns your Firebase project.
17.3. Point the package at your project and database
Extract the supplied Cloud Functions package. It contains:
Cloud Function/ ├── firebase.json deploy configuration — leave as it is ├── .firebaserc which Firebase project to deploy to └── functions/ ├── .env which Firestore database to use ├── index.js the function code ├── products/delivery.js the order-dispatch trigger ├── package.json dependencies (Node 22 runtime) └── serviceAccountKey.json shipped, but not used — see the note below
Step 1 — set the project. There are two ways to do this. They write the same value, so use one, not both:
Option A — let the CLI do it (recommended). From the folder containing firebase.json:
firebase use YOUR_PROJECT_ID
This creates or updates .firebaserc for you, so there is nothing to edit by hand. Run firebase projects:list if you are unsure of the exact project ID.
Option B — edit .firebaserc yourself. Open it and replace the project ID:
{
"projects": {
"default": "YOUR_PROJECT_ID"
}
}Step 2 — set the database. Open functions/.env and set FIRESTORE_DB to the same Firestore database your panels use:
FIRESTORE_DB=(default)
This value must match FIREBASE_PROJECT_DB in all three panels’ .env files. The dispatch trigger is a 2nd-generation function bound to one named database, so if the panels write orders to (default) while the function listens on a different one, the function deploys cleanly and then simply never fires — no error is reported anywhere.
Step 3 — install the dependencies:
cd functions npm install
You do not need to touch serviceAccountKey.json. It ships inside functions/, but the code never reads it — index.js calls admin.initializeApp() with no arguments, so once deployed the function authenticates automatically as your project’s own service account. The credentials.json from step 14.11 is for the Laravel panels, not for this package. There is likewise no database URL to fill in anywhere in index.js.
17.4. Deploy the functions
Run this from the folder containing firebase.json — the root of the extracted package, not the functions/ sub-folder:
firebase deploy --only functions
When the deploy finishes, open Firebase Console → Functions to confirm every function is listed. Each function has its own logs, which are the fastest way to debug a failing order or payment.
Please note: Cloud Functions require the Firebase Blaze (pay-as-you-go) plan — 2nd-generation functions build on Cloud Build and run on Cloud Run, neither of which is available on the free Spark plan. Payment gateways are not part of this package; their credentials live in the Laravel panels, so rotating a gateway key never requires a redeploy here.
17.5. Scheduled scripts run by the Admin Panel
Some recurring Firebase tasks have been moved out of Cloud Functions and into the Laravel Admin Panel, so you can control their timing from the panel instead of redeploying. The scripts live in:
root > storage > app > firebase
autoCancelOrder.js— automatically cancels orders that were never accepted.scheduleNotification.js— sends reminders for scheduled orders.
Important notes
- These scripts are executed by Laravel’s scheduler, which needs a server cron job — see Cron & Scheduled Tasks.
- They talk directly to Firebase Firestore using the panel’s
credentials.json. - Their timing values come from the admin panel — auto-cancellation duration under Settings, and reminder lead time under Settings → Schedule Order Notification.
