#!/bin/bash # Stripe Connect Functions Deployment Script # This script helps deploy Firebase Functions with proper environment setup set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color echo -e "${BLUE}🚀 Stripe Connect Functions Deployment${NC}" echo "==========================================" # Check if Firebase CLI is installed if ! command -v firebase &> /dev/null; then echo -e "${RED}❌ Firebase CLI not found. Install with: npm install -g firebase-tools${NC}" exit 1 fi # Check if logged in to Firebase if ! firebase projects:list &> /dev/null; then echo -e "${YELLOW}⚠️ Not logged in to Firebase. Logging in...${NC}" firebase login fi # Get current project PROJECT=$(firebase use 2>/dev/null | grep "active project" | awk '{print $4}' | tr -d '()') if [ -z "$PROJECT" ]; then echo -e "${RED}❌ No Firebase project selected. Run 'firebase use ' first.${NC}" exit 1 fi echo -e "${GREEN}📁 Project: ${PROJECT}${NC}" # Check Functions directory if [ ! -d "functions" ]; then echo -e "${RED}❌ Functions directory not found. Make sure you're in the project root.${NC}" exit 1 fi # Install Functions dependencies echo -e "${BLUE}📦 Installing Functions dependencies...${NC}" cd functions npm install # Check if environment config exists echo -e "${BLUE}🔧 Checking environment configuration...${NC}" CONFIG=$(firebase functions:config:get 2>/dev/null || echo "{}") if [ "$CONFIG" = "{}" ]; then echo -e "${YELLOW}⚠️ No environment config found. You'll need to set:${NC}" echo " firebase functions:config:set stripe.secret_key=\"sk_...\"" echo " firebase functions:config:set stripe.webhook_secret=\"whsec_...\"" echo " firebase functions:config:set app.url=\"https://your-domain.com\"" echo "" read -p "Continue anyway? (y/n): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi else echo -e "${GREEN}✅ Environment config found${NC}" fi # Build Functions echo -e "${BLUE}🔨 Building Functions...${NC}" npm run build # Deploy Functions echo -e "${BLUE}🚀 Deploying Functions...${NC}" cd .. firebase deploy --only functions if [ $? -eq 0 ]; then echo "" echo -e "${GREEN}✅ Functions deployed successfully!${NC}" echo "" echo "📋 Next steps:" echo "1. Configure Stripe webhook endpoint:" echo " URL: https://us-central1-${PROJECT}.cloudfunctions.net/stripeWebhook" echo " Events: account.updated" echo "" echo "2. Test the integration:" echo " - Visit your app and try connecting a Stripe account" echo " - Check function logs: firebase functions:log" echo "" echo "3. Update frontend API URL if needed:" echo " - In useStripeConnect.ts, update getApiUrl() function" echo "" else echo -e "${RED}❌ Deployment failed. Check the logs above.${NC}" exit 1 fi