A complete, production-ready Stripe API integration for Firebase projects that eliminates CORS issues and provides full type safety.
- β 100% Stripe API Coverage - All 87 Stripe API endpoints implemented
- β CORS-Free - Firebase Cloud Function proxy eliminates all CORS issues
- β
Fully Type-Safe - 1100+ TypeScript definitions with zero
any
types - β Environment Switching - Runtime switching between test/live without redeployment
- β AI-Friendly - Consistent structure prevents AI coding errors
- β Production-Ready - Used in production with comprehensive error handling
services/stripe/
- 87 folders with 290+ service files covering all Stripe operationstypes/stripe/
- 77 modular type files with complete Stripe API type definitionscomponents/stripe/
- Reusable Stripe UI componentsconfig/environment.ts
- Environment configuration for test/live switchingutils/firebase/config.ts
- Firebase initialization and configurationservices/errorHandler.ts
- Centralized error handling for Stripe operations
stripe-proxy.ts
- Complete Stripe API proxy with all endpointscors-helper.ts
- CORS configuration and handling utilitiesenvironment.ts
- Runtime environment switching (test/live)services/errorHandler.ts
- Error handling for Cloud Functions
# Copy frontend files cp -r src/services/stripe YOUR_PROJECT/src/services/ cp -r src/types/stripe YOUR_PROJECT/src/types/ cp -r src/components/stripe YOUR_PROJECT/src/components/ cp src/config/environment.ts YOUR_PROJECT/src/config/ cp src/utils/firebase/config.ts YOUR_PROJECT/src/utils/firebase/ cp src/services/errorHandler.ts YOUR_PROJECT/src/services/ # Copy backend files cp functions/src/stripe-proxy.ts YOUR_PROJECT/functions/src/ cp functions/src/cors-helper.ts YOUR_PROJECT/functions/src/ cp functions/src/environment.ts YOUR_PROJECT/functions/src/ cp functions/src/services/errorHandler.ts YOUR_PROJECT/functions/src/services/
# Set up Stripe test credentials firebase functions:secrets:set STRIPE_TEST_SECRET_KEY firebase functions:secrets:set STRIPE_TEST_PUBLISHABLE_KEY firebase functions:secrets:set STRIPE_TEST_ACCOUNT_ID # Set up Stripe live credentials firebase functions:secrets:set STRIPE_LIVE_SECRET_KEY firebase functions:secrets:set STRIPE_LIVE_PUBLISHABLE_KEY firebase functions:secrets:set STRIPE_LIVE_ACCOUNT_ID
Create /config/stripe
document in Firestore:
{ "environment": "test", "testPublishableKey": "pk_test_...", "livePublishableKey": "pk_live_..." }
firebase deploy --only functions:stripeProxy
import { customersCreateService } from 'src/services/stripe'; // Create a customer const result = await customersCreateService.create({ email: 'customer@example.com', name: 'John Doe', phone: '+1234567890' }); if (result.success) { console.log('Customer created:', result.customer?.id); }
- Customers, PaymentIntents, PaymentMethods, Charges, Refunds
- Checkout Sessions, Payment Links
- Subscriptions, Invoices, Invoice Items
- Accounts, Account Links, Account Sessions
- Transfers, Payouts, Application Fees
- External Accounts, Persons, Capabilities
- Terminal, Identity, Issuing, Treasury
- Climate, Crypto, Entitlements, Financial Connections
- Tax, Radar, Sigma, Reporting, Reviews
- OAuth, Webhooks, Test Helpers
- Events, Event Destinations
- Core Accounts, Account Links
- Billing Meters, Meter Events, Licensed Items
The stripeProxy
Cloud Function acts as a proxy between your frontend and Stripe API:
Frontend β Firebase Function β Stripe API (CORS-free) (authenticated)
Switch between test and live environments without redeployment:
- Update Firestore
/config/stripe
document:{ environment: "live" }
- Changes take effect immediately
- No function redeployment needed
All services use centralized types from src/types/stripe/
:
// Type-safe parameters const params: CustomerCreateParams = { email: 'test@example.com', // β
Type-checked name: 'John Doe', // β
Type-checked invalidField: 'value' // β TypeScript error };
- All types match Stripe API documentation exactly (snake_case)
- JSDoc comments include Stripe API reference links
- Consistent error handling across all services
- Predictable file structure (alphabetically organized)
All services use ErrorHandler
for consistent error management:
import { ErrorHandler, ErrorContext } from 'src/services/errorHandler'; try { const result = await stripe.customers.create(params); } catch (error) { const context: ErrorContext = { operation: 'createCustomer', customerEmail: params.email }; const errorResult = ErrorHandler.handleStripeError(error, context); return { success: false, error: errorResult.userMessage }; }
- Firebase Project with Functions enabled
- Node.js 20+
- TypeScript 5.0+
- Firebase Admin SDK
- Stripe Node SDK
This is a production-tested implementation. Feel free to use in your own projects!
MIT License - Use freely in your projects
Created by Eric Wiedemann to solve Stripe CORS issues in Firebase projects.
Twizbee - Building better developer tools and solutions.
Need help? Check the Stripe API documentation: https://docs.stripe.com/api