In this section, we accomplish the following tasks
- Create a new Firebase Project and make sure to enable billing. Your project will still be free on the Blaze plan.
- Initialize Cloud Functions by running
firebase init functions
. This repo uses TypeScript, but feel free to use vanilla JS and omit the type annotations where applicable. - Signup for Stripe and the API key to the functions environment.
- Initialize Firebase Admin & the Stripe Node SDK
command line
firebase init functions
cd functions
npm i stripe
npm i @types/stripe -D
config.ts
// Initialize Firebase Admin
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
// Initialize Cloud Firestore Database
export const db = admin.firestore();
const settings = { timestampsInSnapshots: true };
db.settings(settings);
// ENV Variables
export const stripeSecret = functions.config().stripe.secret;
// Export Stripe
import * as Stripe from 'stripe';
export const stripe = new Stripe(stripeSecret);