- Add comprehensive analytics components with export functionality - Implement territory management with manager performance tracking - Add seatmap components for venue layout management - Create customer management features with modal interface - Add advanced hooks for dashboard flags and territory data - Implement seat selection and venue management utilities - Add type definitions for ticketing and seatmap systems 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
5.8 KiB
5.8 KiB
Stripe Connect Integration
This implementation provides end-to-end Stripe Connect onboarding for organizations to link their own Stripe accounts.
Overview
- Each organization connects its own Stripe Express account
- Payment data stored in Firestore:
orgs/{orgId}.payment - No secrets stored client-side - all Stripe API calls via Cloud Functions
- Publish checklist validates payment connection before event goes live
Backend (Cloud Functions)
Environment Variables
Set these in Firebase Functions config:
# Stripe Configuration
firebase functions:config:set stripe.secret_key="sk_test_your_stripe_secret_key"
firebase functions:config:set stripe.webhook_secret="whsec_your_webhook_secret"
# Application Configuration
firebase functions:config:set app.url="https://your-app-domain.com"
For local development, create functions/.runtimeconfig.json:
{
"stripe": {
"secret_key": "sk_test_your_stripe_secret_key",
"webhook_secret": "whsec_your_webhook_secret"
},
"app": {
"url": "http://localhost:5173"
}
}
API Endpoints
The Cloud Functions provide these endpoints:
-
POST
/stripeConnectStart- Input:
{ orgId: string, returnTo?: string } - Creates Stripe Express account if needed
- Returns onboarding URL for Stripe Connect flow
- Input:
-
GET
/stripeConnectStatus?orgId=...- Fetches current account status from Stripe
- Updates Firestore with latest connection state
- Returns sanitized payment data
-
POST
/stripeWebhook- Handles
account.updatedevents from Stripe - Updates organization payment status in Firestore
- Verifies webhook signatures for security
- Handles
Deployment
# Install dependencies
cd functions && npm install
# Deploy all functions
firebase deploy --only functions
# Deploy specific functions
firebase deploy --only functions:stripeConnectStart,stripeConnectStatus,stripeWebhook
Frontend Integration
PaymentSettings Component
Located at /org/:orgId/payments, this component:
- Shows current Stripe Connect status
- Provides "Connect Stripe" button that redirects to Stripe onboarding
- Handles return flow with status updates
- Includes disconnect functionality (stub)
Publish Event Integration
The PublishEventModal includes payment validation:
- Checks
org.payment.connected === truebefore allowing publish - Provides "Connect Payments" button that navigates to payment settings
- Prevents event publishing until payment is configured
Usage Example
import { PaymentSettings } from './features/org/PaymentSettings';
// Navigate to payment settings
navigate(`/org/${orgId}/payments`);
// The component handles the full onboarding flow:
// 1. User clicks "Connect Stripe"
// 2. Redirects to Stripe Express onboarding
// 3. Returns to payment settings with status
// 4. Status automatically refreshes and updates UI
Firestore Schema
Organization Document
// /orgs/{orgId}
{
id: string;
name: string;
// ... other fields
payment?: {
provider: 'stripe';
connected: boolean;
stripe: {
accountId: string;
detailsSubmitted: boolean;
chargesEnabled: boolean;
businessName: string;
};
};
}
Example States
// Not connected
payment: undefined
// Account created, setup incomplete
payment: {
provider: 'stripe',
connected: false,
stripe: {
accountId: 'acct_1234567890',
detailsSubmitted: false,
chargesEnabled: false,
businessName: ''
}
}
// Fully connected and ready
payment: {
provider: 'stripe',
connected: true,
stripe: {
accountId: 'acct_1234567890',
detailsSubmitted: true,
chargesEnabled: true,
businessName: 'Example Business Inc.'
}
}
Webhook Configuration
- Go to your Stripe Dashboard
- Click "Add endpoint"
- Set endpoint URL:
https://us-central1-YOUR_PROJECT_ID.cloudfunctions.net/stripeWebhook - Select events:
account.updated - Copy the webhook secret and update Functions config
Testing Flow
- Start onboarding: Click "Connect Stripe" in payment settings
- Complete Stripe setup: Fill out Stripe Express onboarding form
- Return to app: Redirected back with
status=connectedparameter - Auto-refresh: Status automatically updates to show connection state
- Publish validation: Event publish now passes payment check
Development
Local Testing
- Start Firebase emulators:
firebase emulators:start --only functions,firestore
- Update frontend API URL in
PaymentSettings.tsx:
const API_BASE = 'http://localhost:5001/your-project-id/us-central1';
- Test webhook with Stripe CLI:
stripe listen --forward-to localhost:5001/your-project-id/us-central1/stripeWebhook
Mock Data
The demo includes mock users with different payment states:
- Admin user: Fully connected Stripe account
- Organizer user: Incomplete setup (shows payment required)
- Staff user: No payment data (read-only access)
Security Features
- ✅ No client secrets: All Stripe API calls server-side only
- ✅ Webhook verification: Signatures validated on all webhooks
- ✅ CORS protection: Functions restricted to app domains
- ✅ Auth validation: Firestore rules enforce organization access
- ✅ Data sanitization: Only necessary fields returned to frontend
Next Steps
To extend this implementation:
- Payment processing: Create checkout sessions with connected accounts
- Application fees: Configure platform fees on transactions
- Payout management: Monitor and manage payouts to connected accounts
- Tax reporting: Implement 1099 reporting for connected accounts
- Compliance: Add additional verification steps as needed
The foundation is now in place for full Stripe Connect payment processing!