Learn how to connect Firebase to Stripe with our step-by-step guide. Set up Firebase, integrate Stripe, deploy Cloud Functions, and test payments seamlessly.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Set Up Firebase Project
To begin connecting Firebase to Stripe, you first need to have a Firebase project. If you haven't created one yet, follow these steps:
Step 2: Configure Firebase for Web or Mobile
Depending on whether you’re working on web or mobile, implement Firebase into your app by following Firebase's guides:
npm install firebase
Step 3: Initialize Firebase
Once Firebase is included in your app, initialize it:
import { initializeApp } from "firebase/app";
const firebaseConfig = {
apiKey: "your-api-key",
authDomain: "your-auth-domain",
projectId: "your-project-id",
storageBucket: "your-storage-bucket",
messagingSenderId: "your-messaging-sender-id",
appId: "your-app-id"
};
const app = initializeApp(firebaseConfig);
Step 4: Set Up Stripe Account
Step 5: Integrate Stripe with Your Application
For web or mobile, integrate Stripe's SDK to handle payments:
react-native-stripe-sdk following its documentation.
Step 6: Create Cloud Functions to Handle Payment Intentions
cd functions
npm install stripe
const functions = require('firebase-functions');
const stripe = require('stripe')('your-secret-key');
exports.createPaymentIntent = functions.https.onCall(async (data, context) => {
const { amount, currency } = data;
try {
const paymentIntent = await stripe.paymentIntents.create({
amount: amount,
currency: currency,
});
return {clientSecret: paymentIntent.client\_secret};
} catch (error) {
throw new functions.https.HttpsError('unknown', error.message, error);
}
});
Step 7: Deploy Your Cloud Functions
firebase deploy --only functions
Step 8: Connect Frontend to Firebase Function
import { getFunctions, httpsCallable } from "firebase/functions";
import { loadStripe } from "@stripe/stripe-js";
const stripePromise = loadStripe('your-publishable-key');
async function handlePayment() {
const functions = getFunctions();
const createPaymentIntent = httpsCallable(functions, 'createPaymentIntent');
const { clientSecret } = await createPaymentIntent({ amount: 1000, currency: 'usd' });
const stripe = await stripePromise;
const result = await stripe.confirmCardPayment(clientSecret, {
payment\_method: {
card: yourCardElement, // Use Stripe's element
billing\_details: {
name: 'Customer Name',
},
},
});
if (result.error) {
console.error(result.error.message);
} else {
if (result.paymentIntent.status === 'succeeded') {
console.log("Payment succeeded!");
}
}
}
Step 9: Test the Integration
Step 10: Go Live
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.