Complete setup guide for integrating this Stripe API into your Firebase project.
- Have a Firebase project created
- Have Firebase CLI installed (
npm install -g firebase-tools) - Have a Stripe account (test mode is fine to start)
- Node.js 20+ installed
- Copy
src/services/stripe/to your project - Copy
src/types/stripe/to your project - Copy
src/components/stripe/to your project (optional) - Copy
src/config/environment.tsto your project - Copy
src/utils/firebase/config.tsto your project - Copy
src/services/errorHandler.tsto your project - Copy
functions/src/stripe-proxy.tsto your project - Copy
functions/src/cors-helper.tsto your project - Copy
functions/src/environment.tsto your project - Copy
functions/src/services/errorHandler.tsto your project
- Open
src/utils/firebase/config.ts - Replace
YOUR_FIREBASE_API_KEYwith your Firebase API key - Replace
YOUR_PROJECT_IDwith your Firebase project ID - Replace
YOUR_MESSAGING_SENDER_IDwith your sender ID - Replace
YOUR_APP_IDwith your app ID
- Open
functions/src/cors-helper.ts - Update allowed origins with your domains
- Add your production domain
- Add your staging domain (if applicable)
- Ensure localhost ports are included for development
Run these commands in your terminal:
-
firebase functions:secrets:set STRIPE_TEST_SECRET_KEY- Enter:
sk_test_YOUR_KEY_HERE
- Enter:
-
firebase functions:secrets:set STRIPE_TEST_PUBLISHABLE_KEY- Enter:
pk_test_YOUR_KEY_HERE
- Enter:
-
firebase functions:secrets:set STRIPE_TEST_ACCOUNT_ID- Enter:
acct_YOUR_ACCOUNT_ID(optional)
- Enter:
-
firebase functions:secrets:set STRIPE_LIVE_SECRET_KEY- Enter:
sk_live_YOUR_KEY_HERE
- Enter:
-
firebase functions:secrets:set STRIPE_LIVE_PUBLISHABLE_KEY- Enter:
pk_live_YOUR_KEY_HERE
- Enter:
-
firebase functions:secrets:set STRIPE_LIVE_ACCOUNT_ID- Enter:
acct_YOUR_ACCOUNT_ID(optional)
- Enter:
Create a document at /config/stripe in Firestore with:
{
"environment": "test",
"testPublishableKey": "pk_test_YOUR_KEY",
"livePublishableKey": "pk_live_YOUR_KEY",
"createdAt": "2025-10-01T00:00:00.000Z",
"updatedAt": "2025-10-01T00:00:00.000Z"
}- Document created at correct path
- Test publishable key added
- Live publishable key added
- Environment set to "test" initially
- Open
functions/src/index.ts - Add:
export { stripeProxy } from './stripe-proxy'; - Verify no import errors
- Open
src/config/environment.ts - Update
STRIPE_PROXY_URLwith your project ID - Should be:
https://us-central1-YOUR_PROJECT_ID.cloudfunctions.net/stripeProxy
-
npm install firebase
-
cd functions -
npm install firebase-functions firebase-admin stripe -
cd ..
- Run:
firebase deploy --only functions:stripeProxy - Wait for deployment to complete
- Note the function URL from output
- Verify URL matches your
STRIPE_PROXY_URLconfig
Create a test file or add to your code:
import { customersCreateService } from 'src/services/stripe';
async function testStripe() {
const result = await customersCreateService.create({
email: 'test@example.com',
name: 'Test Customer'
});
console.log('Result:', result);
}
testStripe();- Test runs without errors
- Customer created in Stripe Dashboard
- No CORS errors in console
- Deploy Firestore rules:
firebase deploy --only firestore:rules - Verify
/config/stripeis readable by authenticated users - Test read access from your app
Before going live:
- Update Firestore
/config/stripedocument:{ environment: "live" } - Verify live secret keys are set in Firebase Secret Manager
- Test a live mode transaction (use real test card first)
- Update CORS to restrict origins (remove
*if used) - Enable Firebase App Check for security
- Review Stripe webhook settings
- Set up Stripe webhook endpoints in Firebase Functions
- Test webhook deliveries
Your Stripe integration is ready to use. Key features:
- ✅ No CORS issues
- ✅ Full type safety
- ✅ Runtime environment switching
- ✅ Complete Stripe API coverage
- ✅ Production-ready error handling
- Verify
functions/src/cors-helper.tshas your domain - Redeploy functions:
firebase deploy --only functions:stripeProxy
- Check function deployed:
firebase functions:list - Verify URL in
src/config/environment.tsmatches deployed URL
- Ensure all files copied correctly
- Restart TypeScript server in IDE
- Check
tsconfig.jsonincludessrcdirectory
- Verify
/config/stripedocument exists in Firestore - Check function logs:
firebase functions:log --only stripeProxy - Ensure Firestore permissions allow read access
- Read the full documentation in
README.md - Review
INSTALLATION.mdfor advanced setup - Check
FEATURES.mdfor all available features - Explore the service files in
src/services/stripe/
Happy coding! 🚀